Skip to content

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐍🎲 Snake and Ladders Game (C++)

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.


πŸ“‹ Features

  • 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.txt file
  • View last game's dice rolls and stats

▢️ How to Run

  1. Compile the program:

    g++ -o SnakeAndLadders SnakeAndLadders.cpp
  2. Run the game:

    ./SnakeAndLadders

πŸ•ΉοΈ Gameplay Instructions

  • 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

πŸ“ File Overview

  • SnakeAndLadders.cpp β€” Main source code
  • Scores.txt β€” Output file containing last game statistics

🧠 Code Structure

Main Components:

  • main() – Game loop and menu handler
  • Play() – Launches game logic based on selected mode
  • SnakesOrLadders(int &position) – Modifies position based on game rules
  • GameBoard() – Renders board and player positions
  • RollDice() – Simulates dice roll using rand()
  • DiceDraw(int) – Displays rolled number in ASCII-art style
  • SaveScores() – Saves game statistics to Scores.txt

πŸ’‘ Notes

  • The random seed is initialized with time(0) each time the dice is rolled, which may not be ideal. For better randomness, consider initializing srand() once in main() instead.
  • The code uses characters to represent players on the board.

About

A Snake & Ladders game for 2 players in C++.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages