-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontroller.py
More file actions
38 lines (33 loc) · 1.45 KB
/
controller.py
File metadata and controls
38 lines (33 loc) · 1.45 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
from game import Game, Field, GameEnded
from player import Player
from reader import read_field
from position import Position
class Controller:
def __init__(self):
print("Введите имя файла с полем: ", end="")
fname = input()
field = read_field(fname)
print("Поле имеет размеры {0}x{0}".format(field.fields[0].size))
print("Введите имена игроков через пробел: ", end="")
players = input().split()
while True:
print("Введите позиции игроков в формате x:y через пробел: ", end="")
positions = list(
map(lambda x: tuple(map(int, x.split(":"))), input().split()))
if len(positions) == len(players) and all([field.fields[0].is_legal(Position(0, el)) for el in positions]):
break
else:
print("Недопустимые стартовые позиции!")
players = [Player(name, Position(0, pos, ind))
for ind, (name, pos) in enumerate(zip(players, positions))]
self.game = Game(self, field, players)
def loop(self):
try:
while True:
print("Введите команду: ", end="")
action = input()
self.game.action(action)
except GameEnded:
pass
def log(self, message):
print(message)