help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 4
Reputation: dinozulf is an unknown quantity at this point 
Solved Threads: 0
dinozulf dinozulf is offline Offline
Newbie Poster

help

 
0
  #1
Apr 24th, 2008
can anyone please help me with my program, my hand in date is on monday so i really need some help thank you
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: help

 
0
  #2
Apr 24th, 2008
Where is your project??? what is it suppose to do? where is the code U have done, what is it that u need help with.... you know that kinda thing
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,508
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help

 
0
  #3
Apr 24th, 2008
Anyone have a crystle ball I can borrow? I lost mine somewhere.

Also, that seems to be a C program, not c++.
Last edited by Ancient Dragon; Apr 24th, 2008 at 11:02 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 4
Reputation: dinozulf is an unknown quantity at this point 
Solved Threads: 0
dinozulf dinozulf is offline Offline
Newbie Poster

Re: help

 
0
  #4
Apr 28th, 2008
SPECIFICATIONS
The game is a board game in which the player controls a (single) little character, known as the "mouse", which can move and collect "apples". The grid which is displayed on the screen shows a (static) maze made of walls, tunnels and food storage places. The mouse and a few apples also appear in the tunnels.
The player can move the mouse in the free parts of the maze, one step (up, down, left or right) at a time, using a specific set of keyboard keys.
The mouse can push one apple along the tunnels towards one of the free storage places, but it can only do this in a straight line (i.e., it must be behind the apple and move it forward) and if the path on the other side of the apple is free (e.g., it cannot push two apples at the same time).
The aim of the game is for the mouse to collect all the apples as efficiently as possible. The final score of a game corresponds to the number of moves the mouse made to put all the apples into the storage places. Clearly the best score is the lowest. As the game progresses the current score and the number of apples already collected by the mouse are updated and displayed.
The game ends, and an appropriate message is displayed, when the player chooses to quit (i.e., press the 'Q' key) or when the game is over (i.e., all apples have been collected).

More advanced versions of the game offer additional features such as several game levels of increasing complexity, identification of the player(s), a two-player game option, a save option and a more friendly display. Such features are described below.

VERSIONS/REQUIREMENTS
Basic version
The basic version should include the following features:
1a. Mouse & Apples Game
The players can play the game with the basic configuration of the maze in which a mouse can move and push apples, one at a time, until the 6 apples are placed in the store. It shows the number of moves made and number of apples in store at any time.
This includes:
• creating the maze, positioning the mouse and 6 apples on the grid according to the first configuration shown in Appendix 1 on p 7
• allowing the player to control the mouse's movements on the maze using the arrow keys
• allowing the apples to be pushed by the mouse when the rules allow this
• ensuring that the mouse moves safely in the maze (i.e., stays within the grid's boundaries, and remains stuck in the same position if the player tries to move it onto a wall or an apple that cannot move)
• indicating at any time the number of apples that are currently in store
• indicating at any time the number of moves that the mouse has already made
• detecting when the game ends (i.e., all the apples have been collected or the player enters the ‘Q’ key)
• terminating the program and displaying an appropriate message (e.g., "PLAYER WANTS TO QUIT." or "GAME IS OVER!").
1b. Player Identification
When the game starts the player enters his/her name. This information is used to create a friendlier display. (In more advanced versions it will also be used to keep a record of the player’s performance and access any previously saved games for that player).
This includes:
• asking the player for its name (a single word) when the program starts
• displaying that name on the screen while the game is being played
• storing the best score of the player into a file (using the player's name with extension .txt) at the end of a game
• displaying the player's best score so far (or 500 if no previous score has been recorded) on the screen while the game is being played.
1c. Cheat
At any point in the program the player can cheat and move the game along to a point when the game can be won in one move. This is useful for testing purpose.
This includes:
• detecting that the 'C' key has been pressed
• beeping the alarm 3 times
• moving 5 apples in the store area, updating the number of apples in store accordingly and leaving the last one ready to be pushed in a free storage place.
• placing the mouse in a position where it is ready to push the last apple in the store.
• setting the number of moves to 1000 and updating the player's score accordingly,
• displaying a message indicating that the cheat key was used (e.g., "PLAYER CHEATED!").

Additional features
The following features are all independent and can be attempted in any order. If more than one feature is implemented they should work together.
2a. Cheese Bonuses
There are 6 bits of cheese scattered at random in the maze. The apples can be pushed over them and they get "eaten" by the mouse when it goes over them and they must all be eaten before a game can end.
This feature should include:
• positioning the bits of cheese at random in free cells of the maze (they should all be visible when the game starts)
• showing the mouse or the apple when they are passing over (and so covering) a bit of cheese
• not displaying the bits of cheese that have been eaten
• ensuring that all the bits of cheese have been eaten before a game can be won.
2b. Game Levels
The game has several levels that offer the player an increasing challenge. The maze configuration becomes more complex and there are more apples to be collected.
The player can choose any entry level when starting the game. When the player succeeds in collecting all the apples in one level, the game automatically offers the next level configuration.
This feature should include:
• offering at least two levels corresponding to the game configurations shown in Appendix 1 (p 7) (for further levels, add any other interesting combinations you can think of)
• storing the game configurations in text files (level1.maz , level2.maz, etc.) and reading this information in the program when appropriate
• displaying the game levels available when the program starts and allowing the user to select one
• displaying the current game level on the screen at any time
• displaying an appropriate message at the end of a level (e.g., "Level 2 completed" when all apples have been collected at that level or “Game Over” if there is no further level available)
• detecting when a level is over and allowing the player to get to the next level game configuration (new maze and number of apples)
• ensuring that the player can see the state of a grid and the messages that have been displayed (e.g., wait for a key press before closing the game or moving to the next level)
2c. Best Scores Record
The best player’s performances are recorded and displayed when the player presses ‘B’.
This feature should include:
• keeping track of the six best players’ name and score, which should be set initially to anonymous1, anonymous2, ..., anonymous6 with a score of 500 each
• recording this information in a text file bestScores.txt so that it can be used in each session
• offering an option for the player to see the names and scores of these "best" players (displayed in descending order).
If you program offers levels you may wish to store the best performances per level too (maybe using different text files).
2d. A (simple) Save Option
The player should be able to save a game session, keep a record of the current state of the game and reload it later when he/she runs the program again. A player can only save one game (i.e., each time a player saves a game any previously saved data for that player is lost).
This feature should include:
• storing all necessary data in a file (named after the player with .sav extension) when the player presses ‘S’
• checking when the program starts whether some "saved" data is available for the player and, if it is, offering him/her the choice to reload the last saved image or start a new game.

2e. A Two-Player Game Option
When the game starts the player is offered a two-player option. Two mice can move in the same maze at the same time and compete for the apples.
This feature should include:
• offering special maze configuration(s) with two separate storage areas for each of the mice (the second configuration in Appendix 1 can be adapted for that purpose)
• allocating another four keys on the keyboard for the control of the second mouse
• using different symbols (or colours) for each mouse and each storage area
• displaying a message associating a player's name to a mouse, set of keys and storage area
• controlling that each player moves his/her allocated mouse in turn (i.e., one valid move per player on each turn)
2f. An Undo Option
At any time the player can undo the single last move. This should be done without saving any information into a file.
This feature should include:
• detecting that the 'U' key has been pressed.
• displaying a message indicating that the undo key has been used.
• resetting all other aspects of the game exactly as they were before the last move so that the game can carry on as normal.
2g. Graphical User Interface (GUI)
A fully-fledged Graphical User-Interface to the system would certainly be an interesting development of the console application developed. The design of the graphics is left up to you. The code should be well structured and documented.
Even without writing a pure GUI application, you can gain some marks in this section for appropriately handling colour, flashing, sound, etc.
VIEWS OF GAME ON CONSOLE
The grid is represented on the screen by a playable area (in which the mouse can move and push the apples).
Distinct characters are used to represent each of the elements in the game, e.g., the tunnels are left blank (‘ ‘), the mouse could be represented with the symbol '@', an apple with the letter 'O', the walls of the maze with ‘#’, the storage areas with'+' and the cheese with '*'. You can choose to use other symbols (colours or icons) providing that their meaning is clearly indicated on the screen.

here is the code i have done:

  1. //---------------------------------------------------------------------------
  2. //Program: Skeleton for Ass 2
  3.  
  4. //---------------------------------------------------------------------------
  5.  
  6. //---------------------------------------------------------------------------
  7. //----- include libraries
  8. //---------------------------------------------------------------------------
  9.  
  10. //include standard libraries
  11. #include <iostream> //for output and input: getch(), cout <<, cin >>
  12. #include <conio.h> //for kbhit
  13. #include <iomanip> //for formatted output
  14. #include <string> //for string
  15. using namespace std;
  16.  
  17. //include our own libraries
  18. #include "RandomUtils.h" //for Seed, Random,
  19. #include "ConsoleUtils.h" //for Clrscr, Gotoxy, etc.
  20.  
  21. //---------------------------------------------------------------------------
  22. //----- define constants
  23. //---------------------------------------------------------------------------
  24.  
  25. //defining the size of the grid
  26. #define SIZEY (6) //vertical dimension
  27. #define SIZEX (10) //horizontal dimension
  28. //defining symbols used for display of the grid & content
  29. #define MOUSE ('@') //mouse
  30. #define TUNNEL (' ') //tunnel
  31. #define WALL ('#') //border
  32. //defining the command letters to move the mouse on the maze
  33. #define UP (72) //up arrow
  34. #define DOWN (80) //down arrow
  35. #define RIGHT (77) //right arrow
  36. #define LEFT (75) //left arrow
  37. //defining the other command letters
  38. #define QUIT ('Q') //to end the game
  39.  
  40. //---------------------------------------------------------------------------
  41. //----- run game
  42. //---------------------------------------------------------------------------
  43.  
  44. int main()
  45. {
  46. //function declarations (prototypes)
  47. void initialiseGame( char g[][ SIZEX+1], char m[][ SIZEX+1], int mouse[]);
  48. void paintGame( const char g[][ SIZEX+1], string& mess);
  49. bool isArrowKey( int k);
  50. void setKeyDirection( int k, int& dx, int& dy);
  51. int getKeyPress();
  52. void moveMouse( const char g[][ SIZEX+1], int m[], int dx, int dy, string& mess);
  53. void updateGrid( char g[][ SIZEX+1], const char m[][ SIZEX+1], int mouse[]);
  54. void endProgram();
  55.  
  56. //local variable declarations //arrays that store ...
  57. char grid[ SIZEY+1][ SIZEX+1]; //grid for display
  58. char maze[ SIZEY+1][ SIZEX+1]; //structure of the maze
  59. int mouse[2]; //mouse's position ([y-coordinate][x-coordinate])
  60. string message = "LET'S START..."; //current message to player
  61. int key; //arrow or letter command
  62.  
  63.  
  64.  
  65. //action...
  66. Clrscr();
  67. Seed(); //seed the random number generator
  68. initialiseGame( grid, maze, mouse); //initialise grid (incl. walls & mouse)
  69. paintGame( grid, message); //display game info, modified grid & messages
  70. key = getKeyPress(); //display menu & read in selected option
  71. while (key != QUIT) //while user does not want to quit
  72. {
  73. if ( isArrowKey( key))
  74. {
  75. int dx( 0), dy( 0);
  76. setKeyDirection( key, dx, dy); //find direction indicated by key
  77. moveMouse( grid, mouse, dx, dy, message); //move mouse in that direction
  78. updateGrid( grid, maze, mouse); //update grid information
  79. }
  80. else
  81. message = "INVALID KEY!"; //set 'Invalid key' message
  82. paintGame( grid, message); //display game info, modified grid & messages
  83. key = getKeyPress(); //display menu & read in next option
  84. }
  85. endProgram(); //display final message
  86. return 0;
  87. } //end main
  88.  
  89.  
  90. //---------------------------------------------------------------------------
  91. //----- initialise game state
  92. //---------------------------------------------------------------------------
  93.  
  94. void initialiseGame( char grid[][ SIZEX+1], char maze[][ SIZEX+1], int mouse[])
  95. { //initialise grid & place mouse in middle
  96. void setInitialMazeStructure( char g[][ SIZEX+1]);
  97. void setInitialMouseCoordinates( int mouse[]);
  98. void updateGrid( char g[][ SIZEX+1], const char m[][ SIZEX+1], int mouse[]);
  99.  
  100. setInitialMazeStructure( maze); //initialise maze
  101. setInitialMouseCoordinates( mouse); //initialise mouse's position
  102. updateGrid( grid, maze, mouse); //prepare grid
  103. } //end of initialiseGrid
  104.  
  105. void setInitialMazeStructure( char maze[][ SIZEX+1])
  106. { //set the position of the walls in the maze
  107. //initialise maze configuration
  108. char initialMaze[ SIZEY+1][ SIZEX+1] //local array to store the maze structure
  109. = { {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'},
  110. {'X', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'},
  111. {'X', '#', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#'},
  112. {'X', '#', ' ', ' ', '#', ' ', ' ', '#', ' ', ' ', '#'},
  113. {'X', '#', ' ', ' ', '#', '#', ' ', '#', ' ', '#', '#'},
  114. {'X', '#', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#'},
  115. {'X', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'} };
  116. // with '#' for wall, ' ' for tunnel and 'X' for unused part of array
  117. //copy into maze structure
  118. for ( int row( 1); row <= SIZEY; ++row) //for each row (vertically)
  119. for ( int col( 1); col <= SIZEX; ++col) //for each column (horizontally)
  120. maze[row][col] = initialMaze[row][col];
  121. } //end of setMazeStructure
  122.  
  123. void setInitialMouseCoordinates( int mouse[])
  124. { //calculate mouse's coordinates at beginning of game
  125. mouse[0] = 3; //y-coordinate: vertically
  126. mouse [1] = 5; //x-coordinate: horizontally
  127. } //end of setInitialMouseCoordinates
  128.  
  129.  
  130. //---------------------------------------------------------------------------
  131. //----- update grid state
  132. //---------------------------------------------------------------------------
  133.  
  134. void updateGrid( char grid[][ SIZEX+1], const char maze[][ SIZEX+1], int mouse[])
  135. { //update grid configuration after each move
  136. void setMaze( char g[][ SIZEX+1], const char m[][ SIZEX+1]);
  137. void placeMouse( char g[][ SIZEX+1], int mouse[]);
  138.  
  139. setMaze( grid, maze); //reset the empty maze configuration into grid
  140. placeMouse( grid, mouse); //set mouse in grid
  141. } //end of updateGrid
  142.  
  143.  
  144.  
  145. void setMaze( char grid[][ SIZEX+1], const char maze[][ SIZEX+1])
  146. { //reset the empty/fixed maze configuration into grid
  147. for ( int row( 1); row <= SIZEY; ++row) //for each row (vertically)
  148. for ( int col( 1); col <= SIZEX; ++col) //for each column (horizontally)
  149. grid[row][col] = maze[row][col];
  150. } //end of setFrame
  151.  
  152. void placeMouse( char g[][ SIZEX+1], int m[])
  153. { //place mouse at its new position in grid
  154. g[m[0]][m[1]] = MOUSE;
  155. } //end of placeMouse
  156.  
  157.  
  158. //---------------------------------------------------------------------------
  159. //----- move the mouse
  160. //---------------------------------------------------------------------------
  161.  
  162. void moveMouse( const char g[][ SIZEX+1], int m[], int dx, int dy, string& mess)
  163. { //move mouse in required direction
  164. //check new target position in grid & update mouse coordinates if move is possible
  165. switch( g[m[0]+dy][m[1]+dx])
  166. { //...depending on what's on the target position in grid...
  167. case TUNNEL: //can move
  168. m[0] += dy; //go in that Y direction
  169. m[1] += dx; //go in that X direction
  170. break;
  171. case WALL: //hit a wall & stay there
  172. cout << '\a'; //beep the alarm
  173. mess = "CANNOT GO THERE!";
  174. break;
  175. }
  176. } //end of moveMouse
  177.  
  178. //---------------------------------------------------------------------------
  179. //----- process key
  180. //---------------------------------------------------------------------------
  181.  
  182. void setKeyDirection( int key, int& dx, int& dy)
  183. { //
  184. switch( key) //...depending on the selected key...
  185. {
  186. case LEFT: //when LEFT arrow pressed...
  187. dx = -1; //decrease the X coordinate
  188. dy = 0;
  189. break;
  190. case RIGHT: //when RIGHT arrow pressed...
  191. dx = +1; //increase the X coordinate
  192. dy = 0;
  193. break;
  194. case UP: //when UP arrow pressed...
  195. dx = 0;
  196. dy = -1; //decrease the Y coordinate
  197. break;
  198. case DOWN: //when DOWN arrow pressed...
  199. dx = 0;
  200. dy = +1; //increase the Y coordinate
  201. break;
  202. }
  203. } //end of setKeyDirection
  204.  
  205. int getKeyPress()
  206. { //get key or command selected by user
  207. int keyPressed( getch(); //read in the selected arrow key or command letter
  208. while ( keyPressed == 224) //ignore symbol following cursor key
  209. keyPressed = getch();
  210. keyPressed = toupper( keyPressed); //put it in uppercase
  211. return( keyPressed);
  212. } //end of getKeyPress
  213.  
  214. bool isArrowKey( int key)
  215. { //check if the key pressed is an arrow key (also accept 'K', 'M', 'H' and 'P')
  216. return ((key == LEFT) || (key == RIGHT) || (key == UP) || ( key == DOWN));
  217. }
  218.  
  219.  
  220. //---------------------------------------------------------------------------
  221. //----- display info on screen
  222. //---------------------------------------------------------------------------
  223. void paintGame( const char gd[][ SIZEX+1], string& mess)
  224. { //display game title, messages, maze, mouse & apples on screen
  225. void paintGrid( const char g[][ SIZEX+1]);
  226.  
  227. Clrscr();
  228.  
  229. //display game title
  230. SelectTextColour( clYellow);
  231. Gotoxy(0, 0);
  232. cout << "___MOUSE AND APPLES GAME___\n" << endl;
  233. SelectBackColour( clWhite);
  234. SelectTextColour( clRed);
  235. Gotoxy(40, 0);
  236. cout << "Pascale Vacher: February 08";
  237.  
  238. // display grid contents
  239. paintGrid( gd);
  240.  
  241. //display menu options available
  242. SelectBackColour( clRed);
  243. SelectTextColour( clYellow);
  244. Gotoxy(40, 3);
  245. cout << "TO MOVE USE KEYBOARD ARROWS ";
  246. Gotoxy(40, 4);
  247. cout << "TO QUIT ENTER 'Q' ";
  248.  
  249. //print auxiliary messages if any
  250. SelectBackColour( clBlack);
  251. SelectTextColour( clWhite);
  252. Gotoxy(40, 8);
  253. cout << mess; //display current message
  254. mess = ""; //reset message to blank
  255. } //end of paintGame
  256.  
  257. void paintGrid( const char g[][ SIZEX+1])
  258. { //display grid content on screen
  259. SelectBackColour( clBlack);
  260. SelectTextColour( clWhite);
  261. Gotoxy(0, 2);
  262. for ( int row( 1); row <= SIZEY; ++row) //for each row (vertically)
  263. {
  264. for ( int col( 1); col <= SIZEX; ++col) //for each column (horizontally)
  265. {
  266. cout << g[row][col]; //output cell content
  267. } //end of col-loop
  268. cout << '\n';
  269. } //end of row-loop
  270. } //end of paintGrid
  271.  
  272.  
  273. void endProgram()
  274. {
  275. SelectBackColour( clRed);
  276. SelectTextColour( clYellow);
  277. Gotoxy(40, 8);
  278. //hold output screen until a keyboard key is hit
  279. cout << "PRESS ANY KEY TO END PROGRAM!";
  280. while (!_kbhit()) /* do nothing */;
  281. }

please help!
Last edited by Ancient Dragon; Apr 28th, 2008 at 9:43 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,508
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help

 
0
  #5
Apr 28th, 2008
>>please help!
Help do what? Write the rest of your assignment for you? The answer to that is a big NO.

We would need RandomUtils.h and ConsoleUtils.h too if someone wants to compile your code. But since this assignment is due TODAY I doubt you will get help quickly enough to do you any good.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: help

 
0
  #6
Apr 28th, 2008
Read this before your next project.
http://cboard.cprogramming.com/showthread.php?t=88495
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC