Advertisement
Guest User

Untitled

a guest
Apr 5th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.42 KB | None | 0 0
  1. C++ Design Document
  2.  
  3.  
  4. Our approach to this will be to create the program in the command window, depending on how much time we have left after completing it, we may or may not add in a GUI.
  5.  
  6. Once you run the program, you will be asked to select your game.
  7. 1 for Connect Four
  8. 2 for Snakes and Ladders
  9. 3 for Checkers
  10. 4 to quit the program
  11.  
  12. Once the user has selected their choice, they will press Enter to begin the game.
  13. Depending on which choice the user makes, different methods and classes will be used
  14. to play.
  15.  
  16. CONNECT FOUR:
  17.  
  18. Overview
  19. - Print a board in the command window. The board is 7x6(Column x Row)
  20.  
  21. - The player pieces will be represented by an X for red and a O for yellow
  22.  
  23. - The player will enter the column he would like to drop a piece in, resulting in the
  24. correct player piece being dropped in
  25.  
  26. - If there is no other pieces below it, the player piece will drop to the bottom,
  27. if there is more pieces below, the player piece will build on top of the previous ones.
  28.  
  29. - After each piece has been dropped, the program will check for a winner, this will require
  30. it to check both the x and y axis, along with the diagonal of the piece. If there is a piece of the same color on either the x, y or diagonal, the computer will move to that piece and then
  31. do the same check. If it does this successfully 4 times, the player has won. Otherwise,
  32. the game will ask the next player to select his column and so on.
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. Variables
  40.  
  41. int [][] board = new int [7] [6] //variables
  42. players turn = 1
  43.  
  44. Methods
  45.  
  46. connectFour() // constructor
  47. call setupBoard method
  48.  
  49. void changeTurn() //method used to change between player 1 and 2
  50. swap player turn, for example, if player 1, change to player 2
  51.  
  52. void setupBoard()
  53. list through each array index to set the value to 0
  54.  
  55.  
  56. boolean insertChip(int Col) //has to check if the coloumn and row below
  57. initialize row
  58. go through the row array while the value of
  59. row is not equal to 0,
  60. if row is equal to 6 return false
  61. increment row
  62. if the player is player 1, use a red chip
  63. if player is player 2 use a yellow chip
  64. changeTurn
  65. return true
  66.  
  67.  
  68. boolean checkForWin() //checks if player has won the game
  69. // do this later Slav
  70.  
  71. displayBoard()
  72. Display 1-7 on top seperated by ‘|’,
  73. Display 1-6 down the side, with a ‘|’ following it
  74.  
  75. clearBoard()
  76. Works like CLS command, but will clear the entire screen
  77. Used for when players win, to print winning player
  78. Or if players want to play again
  79.  
  80.  
  81.  
  82.  
  83. SNAKES AND LADDERS
  84.  
  85. Overview
  86.  
  87. - Print a board that is 10x10(Columns x Rows), this will have 5 ladders and 5 snakes
  88. that we can add at random places on the board. The snakes will be represented as
  89. ‘=’ and the ladders will be represented by ‘H’
  90.  
  91. - When the player starts the game, a Player1 and Player2 token will be places at the start position.
  92.  
  93. - The user will press R to roll the dice, this will cause the player to move the correct amount of squares. If the player rolls 3 6’s, he will go back to the starting position and will have to roll a 6 again to move again.
  94.  
  95. - If a player lands on the bottom of a ladder he will move to the top of the ladder, if he lands on the top of a snake he moves to the bottom of the snake.
  96.  
  97. - When the player is at the end of the game he must roll the exact number to land on the last square. If he has 4 squares to go and rolls a 6 he will move 4 spaces forward, landing on the winning square, but then have to take 2 steps back.
  98.  
  99. - After each roll of the dice, the player piece moves and the next player will roll his dice.
  100.  
  101. Variables
  102.  
  103. int [][] board = new array[10][10] //Board array and variables
  104. int rollNum
  105. playersTurn = 1
  106. int [][] playerPosition1 = new int [1][1];
  107. int [][] playerPosition2 = new int [1][1];
  108.  
  109. Methods
  110.  
  111. Snakes() //Constructor
  112.  
  113. void changeTurn()
  114. Method used to change between player 1 and 2
  115.  
  116. int rollDice()
  117. Rolls a random integer between 1 and 6 and returns it
  118.  
  119.  
  120. void placePlayer()
  121. Places player 1 and 2 in the starting position on the board
  122.  
  123. void movePlayer(rollNum)
  124. Takes the rolled dice number.
  125. Moves player to correct number
  126. Moves player right until he gets to the 10th column, increment row
  127. and then proceed left to the 1st column, where the process
  128. will repeat
  129.  
  130. boolean checkForWin()
  131. If the player is between the 6th last column and the winning column
  132. he must roll an exact number to land on the
  133.  
  134. void displayBoard() //displays the board with snakes and ladders
  135. This method will just be initializing several array index’s to either a snake or
  136. a ladder
  137. board[3][0] = ‘H’
  138. board[4][0] = ‘H’
  139. board[5][0] = ‘H’
  140.  
  141.  
  142.  
  143. updateBoard(int col, int row) // display the new positions of the players
  144.  
  145.  
  146. checkTile (board) // will check the tile to see if it corrosponds to the
  147. //array index of a ladder or snake
  148. if the player is on ladder tiles ie, row 2 column 3
  149. move player to top of ladder at row 6 column 3
  150. //do this 5 times
  151. board[2][3] (playerPosition)= board[2][3] - playerValue
  152. board[6][3](playerPosition) = board[6][3] + playerValue
  153. if player is on snake tiles //ie row 8 column 7
  154. move player to bottom of snakes at row 2 column 9
  155. board[8][7] (playerPosition)= board[8][7] - playerValue
  156. board[2][9](playerPosition) = board[2][9] + playerValue
  157.  
  158.  
  159. getPlayerInfo(string player) //gets players information
  160. print statement asking for playername
  161. initialize string to players name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement