This is a console-based implementation of the classic Snakes and Ladders game in C++. The game supports two-player (PvP) and player vs computer (PvC) modes. It includes dice rolling, a visual board, snakes and ladders behavior, and score saving.
- Player vs. Player and Player vs. Computer modes
- Rolling dice mechanic with "roll again if 6"
- Board visualization with player tokens
- Snakes and ladders altering player positions
- Win condition requiring exact roll to reach square 100
- Score logging to a
Scores.txtfile - View last game's dice rolls and stats
-
Compile the program:
g++ -o SnakeAndLadders SnakeAndLadders.cpp
-
Run the game:
./SnakeAndLadders
-
Choose from the main menu:
- 1. How to Play β View rules
- 2. Play β Start a new game
- 3. Last Game Dice Rolls β View dice rolls from the previous game
- 4. Quit β Exit the program
-
Roll the dice by pressing
Enter. -
If you roll a 6, you get another turn.
-
You must roll the exact number to land on the 100th square and win.
-
Ladders move you up, and snakes move you down:
Ladders Snakes 4 β 14 36 β 6 8 β 30 48 β 26 21 β 42 62 β 18 28 β 76 88 β 24 50 β 67 95 β 56 71 β 92
SnakeAndLadders.cppβ Main source codeScores.txtβ Output file containing last game statistics
main()β Game loop and menu handlerPlay()β Launches game logic based on selected modeSnakesOrLadders(int &position)β Modifies position based on game rulesGameBoard()β Renders board and player positionsRollDice()β Simulates dice roll usingrand()DiceDraw(int)β Displays rolled number in ASCII-art styleSaveScores()β Saves game statistics toScores.txt
- The random seed is initialized with
time(0)each time the dice is rolled, which may not be ideal. For better randomness, consider initializingsrand()once inmain()instead. - The code uses characters to represent players on the board.