-
Notifications
You must be signed in to change notification settings - Fork 0
/
avalon.py
58 lines (50 loc) · 2.27 KB
/
avalon.py
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
55
56
57
58
import card_images
import time
from player import Player
from game import AvalonGame
def start_game():
""" Starts game, takes player input and initializes and returns AvalonGame objects with players and roles assigned. """
print("\033[0mStart game!\033[0m\033c")
time.sleep(1)
try:
num_players = int(input("Please enter number of players in the game (5-10): "))
except ValueError:
num_players = 0
while not 5 <= num_players <= 10: # validate number of players
try:
num_players = int(input("Invalid input. Please enter number of players in the game as a number (5-10): "))
except ValueError:
num_players = 0
curr_game = AvalonGame(num_players)
for i in range(num_players):
id = i
name = input("Please enter a name for Player {} (unique is preferred): ".format(str(i+1)))
curr_game.add_player(id, name)
return curr_game
def instructions():
print("\033c\nWelcome to Avalon!\n")
print("Avalon is a game of hidden loyalty. Players are either Loyal Servants of Arthur fighting for the Goodness or aligned with the Evil ways of Mordred. Evil wins if three Quests fail or by assassinating Merlin at the end of the game. Good wins by letting at least three Quests pass and by not letting Merlin be assassinated at the end of the game.\n")
print("When it is your turn to see the screen, the screen will refresh and display your name and player ID at the top. When you see the next player, please pass on the device.\n")
print("To enter in a list of players, type out a comma-separated list of IDs, i.e. '1, 3, 5'\n")
# TODO: enable hints in game
input("Press Enter when you're ready to begin!")
if __name__ == '__main__':
game = start_game()
instructions()
game.run_player_assignment()
round = 1
successes = 0
failures = 0
while game.in_progress:
team = game.run_team_proposal(round)
quest_succeeded = game.run_quest(team, round)
if quest_succeeded:
successes += 1
else:
failures += 1
if successes >= 3:
game.success()
game.in_progress = False
elif failures >= 3:
game.failure()
game.in_progress = False