Refreshing / Redrawing a table in C++ (I suck at coding lol)
Page 1 of 1
Steve-O 2004




Posts: 2851

PostPosted: 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. Very Happy

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 Smile


George W Bush -

'...more and more of our imports are coming from overseas.'
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: 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


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Steve-O 2004




Posts: 2851

PostPosted: Tue, 24th Apr 2012 10:25    Post subject:
lol thanks, yea since its only going to be marked on a windows machine in the console / dos we were told that we can use system("CLS");

Im going to go watch a load of videos on www.daniweb.com and see if that helps Very Happy

thanks

I mean http://thenewboston.org/list.php?cat=16 not daniweb


George W Bush -

'...more and more of our imports are coming from overseas.'


Last edited by Steve-O 2004 on Tue, 24th Apr 2012 16:06; edited 1 time in total
Back to top
Steve-O 2004




Posts: 2851

PostPosted: 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
Steve-O 2004




Posts: 2851

PostPosted: 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
Steve-O 2004




Posts: 2851

PostPosted: Sat, 28th Apr 2012 01:29    Post subject:
Update update read all about it............ Very Happy

Finally after messing around I have it working, I dont suck that much at it after all Very Happy Very Happy Very Happy I actually found that just walking away and leaving it for a few hours then coming back to it worked. I think it can piss you off so much that you cant actually see what you have to do if you know what I mean.

My code is a mess but I dont care, the basic game of minesweeper can be played (very basic that is!!)

Now I just need to implament a random array.

Pissing around for ages trying to get my board to update and then it just clicked... I need 3 Arrays not 2... One to show the board, one to hold the minefield and one that updates with the moves and then updates the display board when it is redrawn. Unless it can be done with 2? Im not bothered realy as its working now Very Happy Very Happy


George W Bush -

'...more and more of our imports are coming from overseas.'
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
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