-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen_battle.py
68 lines (46 loc) · 2.35 KB
/
screen_battle.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
import tkinter
from Battle.characters import Character
class Screen_Battle (tkinter.Frame):
def __init__ (self, master, player1, player2, call_on_next):
super(Screen_Battle, self).__init__(master)
# Save references to the two player objects
self.player1 = player1
self.player2 = player2
# Store the maximum number of hit points which are needed on the screen display.
self.player1_max_hp = player1.hit_points
self.player2_max_hp = player2.hit_points
# Save the method reference to which we return control after this page Exits.
self.call_on_selected = call_on_next
self.create_widgets()
self.grid()
def create_widgets (self):
self.attack_bttn = tkinter.Button(self, text='Attack', command=self.attack_clicked()).grid(row=1, column=0)
tkinter.Label(self, text='You').grid(row=1, column=1)
tkinter.Label(self, text='Computer').grid(row=1, column=3)
imageSmall = tkinter.PhotoImage(file="images/" + self.player1.small_image)
w = tkinter.Label(self, image=imageSmall)
w.photo = imageSmall
w.grid(row=2, column=0)
imageSmall = tkinter.PhotoImage(file="images/" + self.player2.small_image)
w = tkinter.Label(self, image=imageSmall)
w.photo = imageSmall
w.grid(row=2, column=1)
tkinter.Label(self, text=self.player1.hit_points + '/' + self.player1_max_hp).grid(row=3, column=1)
tkinter.Label(self, text=self.player2.hit_points + '/' + self.player2_max_hp).grid(row=3, column=3)
def attack_clicked(self):
while self.player1.hit_points > 0 and self.player2.hit_points > 0:
Character.attack(self, self.player1)
Character.attack(self, self.player2)
if self.player1.hit_points <= 0:
print()
else:
print()
self.attack_bttn.destroy()
self.exit_bttn = tkinter.Button(self, text='Exit', command=self.exit_clicked()).grid(row=1, column=0)
'''
2) Updates the labels on the top right with the result of the attacks.
'''
def exit_clicked(self):
''' This method is called when the Exit button is clicked.
It passes control back to the callback method. '''
self.call_on_selected()