forked from SGover/monopoly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.py
176 lines (141 loc) · 5.39 KB
/
console.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import gameClasses
import pygame
from gui import guiButton
from gameGui import *
import time
P_COLORS = [(255,25,255),
(25,255,255),(255,25,25),
(25,25,255),(25,255,25)]
class console():
init=False
def __init__(self):
self.massage='New Game of Monopoly!'
self.massege_list=['New Game of Monopoly!']
self.controls=[]
self.value=0
self.clicked=False
def setGameWindow(self,gameWindow):
self.gameWindow=gameWindow
def display(self, string):
print(string)
self.massege_list.append(string)
def start(self):
print("******************************\n New Game of Monopoly!\n******************************")
def draw(self,surface):
if not self.init:
pygame.font.init()
self.font = pygame.font.Font(os.path.normpath("fonts//consola.ttf"), 16)
size=len(self.massege_list)
for i in range(1,9):
if (size-i)>=0 and size-i<size:
txt = self.font.render('>> '+self.massege_list[size-i], True, (0,0,0))
text_pos = txt.get_rect().move(5,690-i*16)
surface.blit(txt, text_pos)
if len(self.controls)>0:
for control in self.controls:
surface.blit(control,control.position)
return surface
#####GUI TODO TASKS#####
#replace choose from options
def create_buttons_from_action_dict(self,actions):
self.controls=[]
i=0
for name in actions.keys():
self.controls.append(guiButton(name,(600+i//3*100,550+(i%3)*50),actions[name],sizing=1.5))
i+=1
def check_click():
for control in self.controls:
if control.clicked:
return True
return False
while not check_click():
time.sleep(0.2)
#replace prompt commands and prompt commands index
def create_selection_menu(self,options):
def set_value(value):
self.value=value
i=0
self.controls=[]
for option in options:
x=600+(i//3)*150
y=550+(i%3)*50
if len(str(option))>10:
self.controls.append(guiButton(str(option),(x,y),set_value,option,1.75,7))
else:
self.controls.append(guiButton(str(option),(x,y),set_value,option,1.75))
i+=1
self.value=0
while (self.value==0):
time.sleep(0.1)
print (self.value)
return self.value
#passing events from the main pygame thread(currently in gameWindow)
def handle_event(self,event):
for control in self.controls:
control.handle_event(event)
######################
def get_player_name(self):
name = input("Enter the Player name :_ ");
while name=="":
name = input("Empty input string, Please Enter the Player name :_ ");
print (name)
return name
def show_winner(self, winner):
print(winner,"is the winner!")
def prompt_commands(self, list_cmds):
return self.create_selection_menu(list_cmds)
self.massage="Select a command:"
print("\nSelect a command:")
return input(" {} : ".format(list_cmds))
def prompt_commands_index(self,list_cmds):
return self.create_selection_menu(list_cmds)
'''
print ("use the number to select an option from the following options:")
str1=''
for cmd in list_cmds:
str1+=" "+str(list_cmds.index(cmd)+1)+". "+str(cmd)
index = -1
while index<0 or index>=len(list_cmds):
index= int(input(str1+'\n'))-1
return list_cmds[index]
'''
def printBoard(self,board):
for block in board.blocks:
bType=type(block)
if bType==type(gameClasses.block):
if bType==type(gameClasses.assetBlock):
print (block.asset.name+" in : "+block.asset.groupName)
elif bType==type(gameClasses.cardBlock):
print ("Deck : "+block.deck.name)
def createChooseButtonPopup(self,actions,image=None):
i=0
self.buttons=[]
for name in actions.keys():
self.buttons.append(guiButton(name,(70+i//3*100,110+(i%3)*50),actions[name],sizing=1.5))
i+=1
def check_click():
for control in self.buttons:
if control.clicked:
return True
return False
popup=PopupWindow(self.gameWindow,'Choose',self.buttons,image)
self.gameWindow.open_popup(popup)
while not check_click():
time.sleep(0.2)
popup.close()
def chooseFromOptions(self,actions):
self.create_buttons_from_action_dict(actions)
"""take a name:value pair as actions"""
'''
print("\nSelect a command :")
i=0
for key in actions.keys():
i+=1
print (str(i)+". "+key)
cmd=input(" select :")
while not (cmd in actions):
print ("wrong command try again")
cmd=input(" select :")
print(" ")
actions[cmd]()
'''