-
Notifications
You must be signed in to change notification settings - Fork 42
/
cards.py
128 lines (125 loc) · 4.52 KB
/
cards.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
import style as s
import random
from board import Board
from player_class import MonopolyPlayer
class Cards:
"""
Cards class for Monopoly game\n
Contains card data.\n
"""
def __init__(self) -> None:
self.chance = s.get_graphics().get('chance cards text').split("\n")
self.community_chest = s.get_graphics().get('community chest text').split("\n")
random.shuffle(self.chance)
random.shuffle(self.community_chest)
def draw_chance(self, p: MonopolyPlayer, board: Board, players) -> str:
"""
Draw chance card\n
"""
self.chance.append(self.chance.pop(0))
card_number = int(self.chance[-1].split(".")[0])
match card_number:
case 1:
board.update_location(p, p.location, 39)
case 2:
board.update_location(p, p.location, 0)
case 3:
board.update_location(p, p.location, 24)
case 4:
board.update_location(p, p.location, 11)
case 5:
if p.location < 5 or p.location > 35:
board.update_location(p, p.location, 5)
elif p.location < 15:
board.update_location(p, p.location, 15)
elif p.location < 25:
board.update_location(p, p.location, 25)
else:
board.update_location(p, p.location, 35)
case 6:
if p.location < 5 or p.location > 35:
board.update_location(p, p.location, 5)
elif p.location < 15:
board.update_location(p, p.location, 15)
elif p.location < 25:
board.update_location(p, p.location, 25)
else:
board.update_location(p, p.location, 35)
case 7:
if p.location < 12 or p.location > 28:
board.update_location(p, p.location, 12)
else:
board.update_location(p, p.location, 28)
case 8:
p.receive(50)
case 9:
p.jail_cards += 1
case 10:
board.update_location(p, p.location, p.location - 3)
case 11:
p.jail = True
board.update_location(p, p.location, 10)
case 12:
for property in p.properties:
if(board.locations[property].houses == 5):
p.pay(150) #price for 4 houses x1.5
elif(board.locations[property].houses > 0):
p.pay(25*board.locations[property].houses)
case 13:
p.pay(15)
case 14:
board.update_location(p, p.location, 5)
case 15:
for receiver in players:
p.pay(50)
receiver.receive(50)
case 16:
p.receive(150)
return self.chance[-1]
def draw_community_chest(self, p: MonopolyPlayer, board: Board, players) -> str:
"""
Draw community chest card\n
"""
self.community_chest.append(self.community_chest.pop(0))
card_number = int(self.community_chest[-1].split(".")[0])
match card_number:
case 1:
board.update_location(p, p.location, 0)
case 2:
p.receive(200)
case 3:
p.pay(50)
case 4:
p.receive(50)
case 5:
p.jail_cards += 1
case 6:
board.update_location(p, p.location, 10)
p.jail = True
case 7:
p.receive(100)
case 8:
p.receive(20)
case 9:
for payer in players:
payer.pay(10)
p.receive(10)
case 10:
p.receive(100)
case 11:
p.pay(100)
case 12:
p.pay(50)
case 13:
p.receive(25)
case 14:
for property in p.properties:
if(board.locations[property].houses == 5):
p.pay(240) #price for 4 houses x1.5
elif(board.locations[property].houses > 0):
p.pay(40*board.locations[property].houses)
case 15:
p.receive(10)
case 16:
p.receive(100)
return self.community_chest[-1]