Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/game.exe
Binary file not shown.
51 changes: 51 additions & 0 deletions docs/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <iostream>
#include <map>
#include <vector>
#include <cstdlib>
#include <ctime>

using namespace std;

int rollDice() {
return rand() % 6 + 1;
}

int main() {
srand(time(0));

map<int, int> snakes = {{14, 7}, {31, 12}, {37, 3}, {73, 56}};
map<int, int> ladders = {{2, 23}, {8, 34}, {20, 77}, {32, 68}};

vector<int> playerPositions = {0, 0}; // 2 players

bool won = false;
int turn = 0;

while (!won) {
int player = turn % playerPositions.size();
cout << "Player " << player + 1 << "'s turn. Press Enter to roll dice.";
cin.ignore();

int dice = rollDice();
cout << "Rolled a " << dice << endl;

playerPositions[player] += dice;

if (snakes[playerPositions[player]])
playerPositions[player] = snakes[playerPositions[player]];

if (ladders[playerPositions[player]])
playerPositions[player] = ladders[playerPositions[player]];

cout << "Player " << player + 1 << " is now at position " << playerPositions[player] << endl;

if (playerPositions[player] >= 100) {
cout << "Player " << player + 1 << " wins!" << endl;
won = true;
}

turn++;
}

return 0;
}
Binary file added docs/main.exe
Binary file not shown.