Implement local game

This commit is contained in:
nemunaire 2020-03-12 20:06:08 +01:00
parent 9b7cdcef10
commit 3d50eb8719

47
game.py Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from opale.game import Game
game = Game("PO", "A<3")
def play_turn():
print("\n\n\n====================================================================\n")
print("\033[1mCurrent player:\033[0m \033[93m%s\033[0m \033[91m%s\033[0m" % (game.current_player.name, "DRAGON" if game.current_player.dragonPetrified else ""))
while True:
print(game.board)
print("\033[1mHere is your hand currently:\033[0m %s" % {i+1: game.current_player.hand[i] for i in range(len(game.current_player.hand))})
icards = input("Choose one or more card to play: ")
pcards = map(lambda x: int(x), icards.split(" "))
good = True
cards = []
for card in pcards:
if card <= 0 or card > len(game.current_player.hand):
print("\033[91m%s is not a valid card.\033[0m" % card)
good = False
break
else:
cards.append(game.current_player.hand[card-1])
if good:
try:
game.play_round(*cards)
break
except Exception as e:
print("\033[91m%s\033[0m" % e)
while not game.isFinished():
try:
play_turn()
except Exception as e:
print("\033[91mSorry, something goes wrong: '%s'.\033[0m" % e)
pass
print("\n\033[1;92mCité sous-marine découverte ! Last round\033[0m")
input("Press enter to play last round! ")
play_turn()
print("\n")
print("\033[93m%s\033[0m: \033[1m%d\033[0m pts" % (game.current_player.name, game.current_player.get_score()))
print("\033[93m%s\033[0m: \033[1m%d\033[0m pts" % (game.current_partner.name, game.current_partner.get_score()))