|
Page 1 of 1 |
|
Posted: Mon, 23rd Apr 2012 23:10 Post subject: Refreshing / Redrawing a table in C++ (I suck at coding lol) |
|
 |
Well now that I have my web development part of the course done I have moved onto C++ part.
If you havent saw my other thread I have been told to make Minesweeper in C++ just using the console (not graphical just a dos style version)
So far I have a menu system setup which takes you to the game.
To make it simple I have just stripped the main game out of my C++ code so I dont have to bother going through the menu.
I have my board setup but how would you refresh / Reload the board without clearing the marked / revealed squares??
Would you use a while loop??
heres my code so far, right now I have a while loop setup and an input to test it, entering any number except -1 will reload the table / board.
Code: | // I suck at coding.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h> //Used for the maximize window code
#include <string> //Help from http://www.cprogramming.com/tutorial/string.html
#include <cmath>
#include <stdio.h>
#include <crtdbg.h>
#include <limits>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ShowWindow( GetConsoleWindow() , SW_MAXIMIZE); //Auto maximizes
int diff;
char hidden = char(254);
cout << "Enter 1 to start";
cin >> diff;
if (diff == 1)
{
const int easy[8][8] = {{0,0,1,1,1,0,0,0},{0,0,1,-1,3,2,1,0},{0,0,2,3,-1,-1,2,1},{0,0,1,-1,3,3,-1,2},{0,0,2,2,2,1,2,-1},{0,0,1,-1,2,1,2,1},{1,1,1,1,2,-1,2,1},{-1,1,0,0,1,1,2,-1}};
int X=0;
int Y=0;
char arrayName[8][8];
int square = 1;
char hidden=char(254);
int heightOfBoard=8;
int widthOfBoard=8;
while (square != -1)
{
system("CLS");
for (Y=0; Y<heightOfBoard; Y++){
for (X=0; X<widthOfBoard; X++){
arrayName [Y][X] = hidden;
cout << arrayName [Y][X] << " ";
}
cout << endl;
}
cout << "enter number -- enter -1 to end\n\n";
cin >> square;
}
}
return 0;
} |
Any help would be great, I only want the game to work at a basic level so nothing intense.
Hopefully will get to use that code PumpAction shared in my other thread for making the random mine array but for now Im happy to just get a basic game working with a fixed array and then go from there 
George W Bush -
'...more and more of our imports are coming from overseas.'
|
|
Back to top |
|
 |
|
Posted: Mon, 23rd Apr 2012 23:24 Post subject: |
|
 |
My butt is hurting from playing too much BF3, but I just wanted to say system("CLS");
I'll try and see if I can come back with something constructive when my butt stops hurting 
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
Posted: Tue, 24th Apr 2012 15:34 Post subject: |
|
 |
I now have number shizzles going around ma nizzles to help locate the square you want
Code: | // I suck at coding.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <windows.h> //Used for the maximize window code
#include <string> //Help from http://www.cprogramming.com/tutorial/string.html
#include <cmath>
#include <stdio.h>
#include <crtdbg.h>
#include <limits>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ShowWindow( GetConsoleWindow() , SW_MAXIMIZE); //Auto maximizes
int diff;
char hidden = char(254);
cout << "Enter 1 to start";
cin >> diff;
if (diff == 1)
{
const int easy[8][8] = {{0,0,1,1,1,0,0,0},{0,0,1,-1,3,2,1,0},{0,0,2,3,-1,-1,2,1},{0,0,1,-1,3,3,-1,2},{0,0,2,2,2,1,2,-1},{0,0,1,-1,2,1,2,1},{1,1,1,1,2,-1,2,1},{-1,1,0,0,1,1,2,-1}};
int X=0;
int Y=0;
char arrayName[8][8];
int square = 1;
char hidden=char(254);
int heightOfBoard=8;
int widthOfBoard=8;
while (square != -1)
{
system("CLS");
cout << "1 2 3 4 5 6 7 8";
for (Y=0; Y<heightOfBoard; Y++){
for (X=0; X<widthOfBoard; X++){
arrayName [Y][X] = hidden;
cout << arrayName [Y][X] << " ";
}
cout << Y+1 << "\n\n";
}
cout << "enter number -- enter -1 to end\n\n";
cin >> square;
}
}
return 0;
} |
George W Bush -
'...more and more of our imports are coming from overseas.'
|
|
Back to top |
|
 |
|
Posted: Tue, 24th Apr 2012 20:15 Post subject: |
|
 |
is this sounding more like what I should be using?
--eg-- setting up a void rule thingy like -- void printarray(char arrayName[8][8])
And keeping my board settings seperate from my main game code??
George W Bush -
'...more and more of our imports are coming from overseas.'
|
|
Back to top |
|
 |
|
Posted: Sat, 28th Apr 2012 01:29 Post subject: |
|
 |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|