Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C++ Design Document
- 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.
- Once you run the program, you will be asked to select your game.
- 1 for Connect Four
- 2 for Snakes and Ladders
- 3 for Checkers
- 4 to quit the program
- Once the user has selected their choice, they will press Enter to begin the game.
- Depending on which choice the user makes, different methods and classes will be used
- to play.
- CONNECT FOUR:
- Overview
- - Print a board in the command window. The board is 7x6(Column x Row)
- - The player pieces will be represented by an X for red and a O for yellow
- - The player will enter the column he would like to drop a piece in, resulting in the
- correct player piece being dropped in
- - If there is no other pieces below it, the player piece will drop to the bottom,
- if there is more pieces below, the player piece will build on top of the previous ones.
- - After each piece has been dropped, the program will check for a winner, this will require
- 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
- do the same check. If it does this successfully 4 times, the player has won. Otherwise,
- the game will ask the next player to select his column and so on.
- Variables
- int [][] board = new int [7] [6] //variables
- players turn = 1
- Methods
- connectFour() // constructor
- call setupBoard method
- void changeTurn() //method used to change between player 1 and 2
- swap player turn, for example, if player 1, change to player 2
- void setupBoard()
- list through each array index to set the value to 0
- boolean insertChip(int Col) //has to check if the coloumn and row below
- initialize row
- go through the row array while the value of
- row is not equal to 0,
- if row is equal to 6 return false
- increment row
- if the player is player 1, use a red chip
- if player is player 2 use a yellow chip
- changeTurn
- return true
- boolean checkForWin() //checks if player has won the game
- // do this later Slav
- displayBoard()
- Display 1-7 on top seperated by ‘|’,
- Display 1-6 down the side, with a ‘|’ following it
- clearBoard()
- Works like CLS command, but will clear the entire screen
- Used for when players win, to print winning player
- Or if players want to play again
- SNAKES AND LADDERS
- Overview
- - Print a board that is 10x10(Columns x Rows), this will have 5 ladders and 5 snakes
- that we can add at random places on the board. The snakes will be represented as
- ‘=’ and the ladders will be represented by ‘H’
- - When the player starts the game, a Player1 and Player2 token will be places at the start position.
- - 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.
- - 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.
- - 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.
- - After each roll of the dice, the player piece moves and the next player will roll his dice.
- Variables
- int [][] board = new array[10][10] //Board array and variables
- int rollNum
- playersTurn = 1
- int [][] playerPosition1 = new int [1][1];
- int [][] playerPosition2 = new int [1][1];
- Methods
- Snakes() //Constructor
- void changeTurn()
- Method used to change between player 1 and 2
- int rollDice()
- Rolls a random integer between 1 and 6 and returns it
- void placePlayer()
- Places player 1 and 2 in the starting position on the board
- void movePlayer(rollNum)
- Takes the rolled dice number.
- Moves player to correct number
- Moves player right until he gets to the 10th column, increment row
- and then proceed left to the 1st column, where the process
- will repeat
- boolean checkForWin()
- If the player is between the 6th last column and the winning column
- he must roll an exact number to land on the
- void displayBoard() //displays the board with snakes and ladders
- This method will just be initializing several array index’s to either a snake or
- a ladder
- board[3][0] = ‘H’
- board[4][0] = ‘H’
- board[5][0] = ‘H’
- updateBoard(int col, int row) // display the new positions of the players
- checkTile (board) // will check the tile to see if it corrosponds to the
- //array index of a ladder or snake
- if the player is on ladder tiles ie, row 2 column 3
- move player to top of ladder at row 6 column 3
- //do this 5 times
- board[2][3] (playerPosition)= board[2][3] - playerValue
- board[6][3](playerPosition) = board[6][3] + playerValue
- if player is on snake tiles //ie row 8 column 7
- move player to bottom of snakes at row 2 column 9
- board[8][7] (playerPosition)= board[8][7] - playerValue
- board[2][9](playerPosition) = board[2][9] + playerValue
- getPlayerInfo(string player) //gets players information
- print statement asking for playername
- initialize string to players name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement