commit
This commit is contained in:
parent
6a53ef0852
commit
e7a9b2ff0c
2 changed files with 80 additions and 0 deletions
47
game.py
Normal file
47
game.py
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
from player import get_player_move
|
||||||
|
|
||||||
|
drug = [3, 5, 7]
|
||||||
|
|
||||||
|
playerType = {
|
||||||
|
"human": get_player_move
|
||||||
|
}
|
||||||
|
|
||||||
|
players = [
|
||||||
|
{
|
||||||
|
"name": "Joueur 1",
|
||||||
|
"type": "human"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Joueur 2",
|
||||||
|
"type": "human"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def show_current_game():
|
||||||
|
print("=============")
|
||||||
|
for index, val in enumerate(drug):
|
||||||
|
print(f"L{index + 1}: {'o' * val}")
|
||||||
|
print("=============")
|
||||||
|
|
||||||
|
|
||||||
|
def execute_move(row, value, name):
|
||||||
|
drug[row] -= value
|
||||||
|
print(f"{name} à enlever {value} pièce sur la ligne L{row + 1}")
|
||||||
|
|
||||||
|
|
||||||
|
def play(name, type):
|
||||||
|
show_current_game()
|
||||||
|
execute_move(*playerType[type](name, drug), name)
|
||||||
|
if sum(drug) == 0:
|
||||||
|
show_current_game()
|
||||||
|
print(f"{name} à gangné !!")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
for player in players:
|
||||||
|
if play(player["name"], player["type"]):
|
||||||
|
exit(0)
|
||||||
33
player.py
Normal file
33
player.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
def get_row(rows):
|
||||||
|
i = 0
|
||||||
|
while not (i in range(1, rows + 1)):
|
||||||
|
print(f"Sur quel ligne voulez vous jouer ? (un nombre entre 1..{rows}) :")
|
||||||
|
try:
|
||||||
|
i = int(input())
|
||||||
|
except ValueError:
|
||||||
|
i = 0
|
||||||
|
return i - 1
|
||||||
|
|
||||||
|
|
||||||
|
def get_value(values):
|
||||||
|
i = 0
|
||||||
|
while not (i in range(1, values + 1)):
|
||||||
|
print(f"Combien de pièce voulez vous jouer (un nombre entre 1..{values}, c pour annuler) :")
|
||||||
|
try:
|
||||||
|
tmp = input()
|
||||||
|
if tmp == "c":
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
i = int(tmp)
|
||||||
|
except ValueError:
|
||||||
|
i = 0
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_move(name, game):
|
||||||
|
print(f"{name} c'est à vous !")
|
||||||
|
value = 0
|
||||||
|
while value == 0:
|
||||||
|
row = get_row(len(game))
|
||||||
|
value = get_value(game[row])
|
||||||
|
return row, value
|
||||||
Loading…
Reference in a new issue