-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamemap.py
133 lines (111 loc) · 4.53 KB
/
gamemap.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
import random;
from traps import *;
from treasures import *;
from soldiers import *;
from towers import *;
class GameMap(object):
def getInstanceOfTrap(self, sClassName):
return eval(sClassName +"()");
def getInstanceOfTreasure(self, sClassName):
return eval(sClassName +"(self.economy, self)");
def getInstanceOfFoe(self, sClassName):
return eval(sClassName +"(self.economy, self)");
def __init__(self, economy, xSize=10, ySize=10, trapProbability=0.05, treasureProbability=0.05, foeProbability =0.10,
towerProbability = 0.01):
self.economy = economy;
self.xSize = xSize;
self.ySize = ySize;
self.trapProbability = trapProbability;
self.treasureProbability = treasureProbability;
self.foeProbability = foeProbability;
self.towerProbability = towerProbability;
self.homePos = (0, 0);
self.traps = [];
self.treasures = [];
self.foes = [];
self.applyTraps();
self.applyTreasures();
self.applyFoes();
def applyTraps(self, possibleTraps = ["Pit"]): #, "TrapClass", "ArrowSlit", "Explosion", "Labyrinth"]):
# Apply traps
self.traps = [];
# Omit 0,0 because it is HOME
for iCnt in range(1, self.xSize):
for iCnt2 in range(1, self.ySize):
if iCnt == self.homePos[0] and iCnt2 == self.homePos[1]:
continue # Do not put anything at home
if (random.random() < self.trapProbability):
curTrap = self.getInstanceOfTrap(random.choice(possibleTraps));
curTrap.x = iCnt;
curTrap.y = iCnt2;
self.traps.append(curTrap);
def applyTreasures(self, possibleTreasures = ["TreasureClass"]):#, "SmallTreasure", "BigTreasure", "HugeTreasure",
# "Ration", "SmallRation", "BigRation", "HugeRation",
# "Chest", "SmallChest", "BigChest", "HugeChest"
# ]):
# Apply treasures
for iCnt in range(0, self.xSize):
for iCnt2 in range(0, self.ySize):
if iCnt == self.homePos[0] and iCnt2 == self.homePos[1]:
continue # Do not put anything at home
if (random.random() < self.treasureProbability):
curTreasure = self.getInstanceOfTreasure(random.choice(possibleTreasures));
curTreasure.x = iCnt;
curTreasure.y = iCnt2;
self.treasures.append(curTreasure);
def applyFoes(self, possibleFoes = [
# "AssassinClass", "BarbarianClass",
# "CartographerClass",
# "DruidClass",
# "EnchanterClass",
# "KnightClass",
"MageClass",
# "RangerClass",
"SoldierClass",
# "TechnicianClass",
# "BridgeBuilderClass",
# "WizardClass",
],
possibleTowers = [
#"FireElementalistTower", "Fort",
"TowerClass",
#"IllusionistTower", "WaterElementalistTower",
]):
# Apply foes
for iCnt in range(0, self.xSize):
for iCnt2 in range(0, self.ySize):
if iCnt == self.homePos[0] and iCnt2 == self.homePos[1]:
continue # Do not put anything at home
if (random.random() < self.foeProbability):
curFoe = self.getInstanceOfFoe(random.choice(possibleFoes));
curFoe .x = iCnt;
curFoe .y = iCnt2;
self.foes.append(curFoe);
# Apply foes
for iCnt in range(0, self.xSize):
for iCnt2 in range(0, self.ySize):
if iCnt == self.homePos[0] and iCnt2 == self.homePos[1]:
continue # Do not put anything at home
if (random.random() < self.towerProbability):
curFoe = self.getInstanceOfFoe(random.choice(possibleTowers));
curFoe .x = iCnt;
curFoe .y = iCnt2;
self.foes.append(curFoe);
def getTraps(self, x, y):
res = [];
for curTrap in self.traps:
if (curTrap.x == x and curTrap.y == y):
res.append(curTrap);
return res;
def getTreasures(self, x, y):
res = [];
for curTreasure in self.treasures:
if (curTreasure.x == x and curTreasure.y == y):
res.append(curTreasure);
return res;
def getFoes(self, x, y):
res = [];
for curFoe in self.foes:
if (curFoe.x == x and curFoe.y == y):
res.append(curFoe);
return res;