docjyJ 3 years ago
parent
commit
e7a9b2ff0c
2 changed files with 80 additions and 0 deletions
  1. 47
    0
      game.py
  2. 33
    0
      player.py

+ 47
- 0
game.py View File

@@ -0,0 +1,47 @@
1
+from player import get_player_move
2
+
3
+drug = [3, 5, 7]
4
+
5
+playerType = {
6
+    "human": get_player_move
7
+}
8
+
9
+players = [
10
+    {
11
+        "name": "Joueur 1",
12
+        "type": "human"
13
+    },
14
+    {
15
+        "name": "Joueur 2",
16
+        "type": "human"
17
+    }
18
+]
19
+
20
+
21
+def show_current_game():
22
+    print("=============")
23
+    for index, val in enumerate(drug):
24
+        print(f"L{index + 1}: {'o' * val}")
25
+    print("=============")
26
+
27
+
28
+def execute_move(row, value, name):
29
+    drug[row] -= value
30
+    print(f"{name} à enlever {value} pièce sur la ligne L{row + 1}")
31
+
32
+
33
+def play(name, type):
34
+    show_current_game()
35
+    execute_move(*playerType[type](name, drug), name)
36
+    if sum(drug) == 0:
37
+        show_current_game()
38
+        print(f"{name} à gangné !!")
39
+        return True
40
+    else:
41
+        return False
42
+
43
+
44
+while True:
45
+    for player in players:
46
+        if play(player["name"], player["type"]):
47
+            exit(0)

+ 33
- 0
player.py View File

@@ -0,0 +1,33 @@
1
+def get_row(rows):
2
+    i = 0
3
+    while not (i in range(1, rows + 1)):
4
+        print(f"Sur quel ligne voulez vous jouer ? (un nombre entre 1..{rows}) :")
5
+        try:
6
+            i = int(input())
7
+        except ValueError:
8
+            i = 0
9
+    return i - 1
10
+
11
+
12
+def get_value(values):
13
+    i = 0
14
+    while not (i in range(1, values + 1)):
15
+        print(f"Combien de pièce voulez vous jouer (un nombre entre 1..{values}, c pour annuler) :")
16
+        try:
17
+            tmp = input()
18
+            if tmp == "c":
19
+                return 0
20
+            else:
21
+                i = int(tmp)
22
+        except ValueError:
23
+            i = 0
24
+    return i
25
+
26
+
27
+def get_player_move(name, game):
28
+    print(f"{name} c'est à vous !")
29
+    value = 0
30
+    while value == 0:
31
+        row = get_row(len(game))
32
+        value = get_value(game[row])
33
+    return row, value

Loading…
Cancel
Save