-
Notifications
You must be signed in to change notification settings - Fork 1
/
Model.py
141 lines (115 loc) · 4.77 KB
/
Model.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from Board import Board
from random import randint
class Model:
def __init__(self, controller):
self.board = Board();
self.controller = controller;
self.firstGame = True;
self.selectedTokens = [];
# print("board init")
def getActivePlayer(self):
#returns the currently active player
for player in self.board.players:
if player.isActive:
return player;
def setHumanPlayers(self):
pass
# userInput = self.countHumanPlayers()
# def setHumanNames(self):
# # print('setting up names')
# for i in range(0, self.countHumanPlayers()):
# self.board.players[i].name = input ('Player {} enter your name: '.format(self.board.players[i].name))
# while len(self.board.players[i].name) not in range(1,21):
# self.board.players[i].name = input('Must be between 1 and 20 characters. Player {} enter your name: '.format(self.board.players[i].name))
def countHumanPlayers(self):
# helper function to count the number of human players
count = 0;
for player in self.board.players:
if player.ai == False:
count += 1;
return count;
def resetBoard(self):
self.board = None;
self.firstGame = True;
self.selectedTokens = [];
self.board = Board();
#some debug code please remove
# self.movePlayerToTile(self.board.players[0], 38)
def movePlayerBySpaces(self, player, spaces):
if (player.location + spaces + 1) >= 40:
moveTile = 40;
else:
moveTile = player.location + spaces + 1;
print("Moving " + player.name + " from tile " +str(player.location + 1) + " to tile " +
str( moveTile ));
destIndex = player.location + spaces;
player.tilesmoved = player.tilesmoved + spaces;
if destIndex >= 39:
destIndex = 39;
self.movePlayerToTile(player, destIndex);
self.portalCheck(player, destIndex);
def movePlayerToTile(self, player, index):
# move a player to a new tile
currentTile = self.board.tiles[player.location];
destinationTile = self.board.tiles[index];
#remove it from the current tile
currentTile.players.remove(player);
#add it to the new tile
destinationTile.players.append(player);
#update its local location variable
player.location = index;
def portalCheck(self, player, index):
#checks if a player has landed on a portal
#moves them through the portal if they have
if self.board.tiles[index].portal:
print("You slipped into a portal!")
portal = self.board.tiles[index].portal;
player.portalsactivated = player.portalsactivated + 1
destination = portal.destination;
origin = portal.origin;
if player.location == origin:
#player is at the head of the portal
#so we move them to the portals destination
self.movePlayerToTile(player, destination)
print("Phew! It was a shortcut!")
print("You appeared at tile "+ str(destination+1))
else:
#player is at the tail of the portal
#so we have to move them to the origin
self.movePlayerToTile(player, origin)
print("Oh no! It lead you backwards!")
print("You appeared at tile "+ str(origin+1))
def rollDice(self):
#randomisation of die roll returns between (1-6)
return randint(1, 6);
def setNextActivePlayer(self):
playerIndex = 0;
nextPlayerIndex = 1;
for player in self.board.players:
if player.isActive:
if playerIndex == self.board.maxPlayers - 1:
nextPlayerIndex = 0;
else:
nextPlayerIndex = playerIndex + 1;
player.isActive = False;
playerIndex += 1;
self.board.players[nextPlayerIndex].isActive = True;
def randomizePortalsTest(self):
self.board.tryRandomizePortals();
def resetTokens(self):
for player in self.board.players:
self.movePlayerToTile(player, 0);
def resetActivePlayer(self):
#just resets the active player back to player 1
for player in self.board.players:
player.isActive = False;
self.board.players[0].isActive = True;
def resetPlayerStats(self):
for player in self.board.players:
player.portalsactivated = 0;
player.tilesmoved = 0;
player.turncount = 0;
def resetPlayers(self):
self.resetBoard()
def getPlayers(self):
return self.board.players