0% found this document useful (0 votes)
5 views

Python ludo game

The document describes a simple text-based game called Mini Ludo where two players take turns rolling a dice to move towards a winning position of 30. Each player starts at position 0 and can only move forward based on the dice roll, with the first to reach the winning position declared the winner. The game continues until one player reaches the winning position, after which it ends.

Uploaded by

zcdn68pwtt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python ludo game

The document describes a simple text-based game called Mini Ludo where two players take turns rolling a dice to move towards a winning position of 30. Each player starts at position 0 and can only move forward based on the dice roll, with the first to reach the winning position declared the winner. The game continues until one player reaches the winning position, after which it ends.

Uploaded by

zcdn68pwtt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import random

WINNING_POSITION = 30

class Player:
def __init__(self, name):
self.name = name
self.position = 0

def move(self, dice_roll):


self.position += dice_roll
if self.position > WINNING_POSITION:
self.position = WINNING_POSITION

def __str__(self):
return f"{self.name} is at position {self.position}"

def roll_dice():
return random.randint(1, 6)

def main():
print("=== Welcome to Mini Ludo ===")
print(f"First to reach position {WINNING_POSITION} wins!\n")

player1 = Player("Player 1")


player2 = Player("Player 2")
turn = 1

while True:
current_player = player1 if turn == 1 else player2
input(f"{current_player.name}'s turn. Press Enter to roll the dice...")
dice = roll_dice()
print(f"{current_player.name} rolled a {dice}")
current_player.move(dice)
print(current_player)

if current_player.position == WINNING_POSITION:
print(f"🎉 {current_player.name} wins! 🎉")
break

turn = 2 if turn == 1 else 1

print("Game Over!")

if __name__ == "__main__":
main()

You might also like