Author Topic: Some more C++ questions.  (Read 557 times)

RussianVodka

  • Hydlaa Notable
  • *
  • Posts: 689
    • View Profile
Some more C++ questions.
« on: September 04, 2005, 12:48:32 am »
It may be a tad ambitious... But I\'m gona try my hand at making a game that resembles something that could be found on those old hand-held pre-gameboy things. You know those B&W ones I\'m talking about.

Here is the best example of one of \'em I could find:


But there are a few things I have a problem with.

1.) What is the command that creates a loop which is only broken when a key is pressed? Also, how would I \"return\" the key that was pressed, so that it can be passed on to some other part of the code?

2.) I\'m still going to be using command prompt, so how should I impliment the \"game board\". I was thinking of creating a two-dementional array, in which characters will be filled with a \"#\" to represent a filled space, and left blank to represent unfiled spaces.

Code would look something like this:

Code: [Select]


char board[10][10];

// Fill board with blank spaces.
for(int i=0; i<10; i++){
     for(int x=0; x<10; x++){
          board[i][x] = x;
     }
}

//Display board.
cout << board[0][0] << board[0][1] << board[0][2] << board[0][3] ..........

//And just continue with ten rows each conaining ten \"blocks\".



Or better yet i could automate the entire thing:

Code: [Select]


//Displays board.
void displayBoard(int yAxis, int xAxis){

     if(xAxis == 0){
          cout << \"Invalid argument\";
          return;
     }

     char board[yAxis][xAxis];


     //Automated board display.
     for(int y=0; y          cout << \"\\n\";
          for(int x=0; x               cout << board[y][x];
          }
     }
}


If i do it the second way I could have a function that writes to the board, a function that displays the board, and the board array. All of which will be part of the \"Board\" class (not very creative with my names), making them easey to use.

Anyone wana share their knowledge/ideas?




« Last Edit: September 04, 2005, 12:49:18 am by RussianVodka »



Q: How many Planeshifters does it take to expalin a simple concept to a newb?
A: Six. Five to argue on who\'s explanation is right, and Moogie to lock the thread.

RussianVodka

  • Hydlaa Notable
  • *
  • Posts: 689
    • View Profile
(No subject)
« Reply #1 on: September 04, 2005, 08:03:42 pm »
Anyone?



Q: How many Planeshifters does it take to expalin a simple concept to a newb?
A: Six. Five to argue on who\'s explanation is right, and Moogie to lock the thread.