-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (44 loc) · 1.52 KB
/
Copy pathmain.py
File metadata and controls
54 lines (44 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from farkel import ui
from farkel.player import Player, AIPlayer
from farkel.game import run_game
def setup_players(mode):
players = []
if mode == "1":
n = 0
while not 2 <= n <= 6:
try:
n = int(input("How many human players? (2-6) ").strip())
except ValueError:
n = 0
if not 2 <= n <= 6:
print(" Please enter a number between 2 and 6.")
for i in range(n):
name = input(f"Player {i+1} name: ").strip() or f"Player {i+1}"
players.append(Player(name))
else:
players.append(Player("Player"))
print("AI difficulty: 1=Easy 2=Medium 3=Hard")
diff_map = {"1": AIPlayer.DIFFICULTY_EASY,
"2": AIPlayer.DIFFICULTY_MEDIUM,
"3": AIPlayer.DIFFICULTY_HARD}
diff = diff_map.get(input("> ").strip(), AIPlayer.DIFFICULTY_MEDIUM)
players.append(AIPlayer("CPU", diff))
return players
def main():
while True:
ui.main_menu()
choice = input("Choice: ").strip()
if choice == "1" or choice == "2":
players = setup_players(choice)
run_game(players)
again = input("Play again? (y/n) ").strip().lower()
if again != "y":
break
elif choice == "3":
ui.rules_screen()
elif choice == "4" or choice.lower() == "q":
break
else:
print(" Invalid choice.")
if __name__ == "__main__":
main()