python micro project
python micro project
This is a Ludo game which is very easy to understand and use. Talking about
the gameplay, all the playing rules are the same just like we play in real time
ludo. Here at first, the user has to select players i.e. either human or
computer. After selecting human, the player has to enter details such as
name and select colour (red, green, yellow and blue). the player can also
start the game within two players if he/she wants.After starting the game, a
console based ludo board appears, other rules are the same. First, the
The main thing in this console based game is that the player just has to
press “Enter Key” to roll the dice. At the top of the board, it displays a dice
with the number. The system keeps on rolling until there’s a possible pawn
the player tries to end the game, there’s an option available to save the
unfinished game so that he/she can continue it later. A simple console GUI
is provided for the easy gameplay. The gameplay design is so simple thauser
• How to Play
1. Ludo player path.
2. Ludo Home.
3. Start area.
5. No resting squares.
• Game Rules
1. Four pieces are placed in the start area of their colour.
8. No doubling rules.
Sr
No Name of Resource/Material Specification Qty. Remarks
Processor i3/HDD-
1 Hardware Resource 1TB/RAM-8GB 1
Python IDE
2 Software Resource 1
it (self):
self.prompt_end = "> " self.game = Game() # used for nicer
print
self.prompted_for_pawn = False # saving game data
self.record_maker = MakeRecord() # getting game data
self.record_runner =
None
def validate_input(self, prompt, desire_type,
allawed_input=None, error_mess="Invalid Option!",
str_len=None):
'''
loop while receive correct value
param allowed_input can be list of allowed values param
str_len is two sized tuple if min and max
'''
prompt += linesep + self.prompt_end while True:
choice = input(prompt) if not choice:
print(linesep + error_mess) continue
try:
choice = desire_type(choice) except ValueError:
print(linesep + error_mess) continue
if allawed_input:
if choice in allawed_input: break
else:
print("Invalid Option!") continue
elif str_len:
min_len, max_len = str_len
if min_len < len(choice) < max_len: break
else:
print(linesep + error_mess)
else:
break print()
return choice
def get_user_initial_choice(self):
text = linesep.join(["choose option",
"0 - start new game", "1
- continue game",
"2 - run (review) recorded game"]) choice =
self.validate_input(text, int, (0, 1, 2)) return choice
def prompt_for_file(self, mode="rb"): '''return file
descriptor'''
text = "Enter filename (name of the record)" while True:
filename = self.validate_input(text, str) try:
file_descr = open(filename, mode=mode) return file_descr
except IOError as e: print(e) print("Try again")
def prompt_for_player(self):
''' get player attributes from input,
if choice == 1:
def print_info_after_turn(self):
'''it used game attributes to print info'''
pawns_id = [pawn.id for pawn in self.game.allowed_pawns] #
nicer print of dice
message = present_6_die_name(self.game.rolled_value,
str(self.game.curr_player)) message
+= linesep
if self.game.allowed_pawns: message_moved = "{} is moved.
".format(
self.game.picked_pawn.id) if self.prompted_for_pawn:
self.prompted_for_pawn = False print(message_moved)
return
message += "{} possible pawns to move.".format( "
".join(pawns_id))
message += " " + message_moved if self.game.jog_pawns:
message += "Jog pawn "
message += " ".join([pawn.id for pawn in
self.game.jog_pawns])
else:
message += "No possible pawns to move." print(message)
def print_standing(self):
standing_list = ["{} - {}".format(index + 1, player)
for index, player in enumerate(self.game.standing)] message =
"Standing:" + linesep + linesep.join(standing_list)
print(message)
def print_board(self):
print(self.game.get_board_pic()) def run_recorded_game(self):
'''get history of game (rolled_value and index's allowed pawn)
from
record_runner in order to replay game'''
self.load_recorded_players() self.print_players_info()
self.prompt_to_continue()
for rolled_value, index in self.record_runner:
self.game.play_turn(index, rolled_value)
self.print_info_after_turn() self.print_board()
self.prompt_to_continue() self.print_board()
self.game.rolled_value, self.game.index)
self.print_players_info() self.print_info_after_turn()
self.print_board()
def load_players_for_new_game(self):
self.prompt_for_players() self.print_players_info()
self.record_players()
if self.does_user_want_save_game():
file_descr = self.prompt_for_file(mode="wb")
self.record_maker.save(file_descr) file_descr.close()
print("Game is saved")
def start(self):
'''main method, starting cli''' print()
try:
choice = self.get_user_initial_choice() if choice == 0: # start
new game
self.load_players_for_new_game() self.play_game()
elif choice == 1: # continue game
self.continue_recorded_game() if self.game.finished:
print("Could not continue.", "Game is already finished",
linesep + "Exit")
else:
self.prompt_to_continue() self.play_game()
elif choice == 2: # review played game
self.run_recorded_game()
except (KeyboardInterrupt, EOFError): print(linesep + "Exit
Game")
if name == ' main ': CLIGame().start()
def offer_save_game(self): '''offer user save game'''
if self.does_user_want_save_game():
file_descr = self.prompt_for_file(mode="wb")
self.record_maker.save(file_descr) file_descr.close()
print("Game is saved") def start(self):
OUTPUT:-
CONCLUSION
The Ludo Game project developed in Python has been a successful implementation of the
classic board game in a digital environment. Using Python's libraries such as pygame, we
recreated the traditional rules and gameplay mechanics in an interactive format. The project
enhanced our understanding of game loops, event handling, graphics rendering, and object-
oriented programming. It also demonstrated how Python can be effectively used for building
engaging GUI-based games. Overall, this project not only improved our programming skills but
also provided insight into real-world application development using Python.
REFERENCES
• https://www.studocu.com/in/document
• https://www.google.com/python