-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain4.py
More file actions
63 lines (46 loc) · 1.72 KB
/
main4.py
File metadata and controls
63 lines (46 loc) · 1.72 KB
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
import tkinter as tk
import random
def rollDice():
return random.randint(1,6)
def updateConditions():
label2.config(text=f"Your health is currently: {player.health}\nThe goblin's health is currently {goblin.health}")
def goblinAction():
result = rollDice()
if result > 3:
player.health -= goblin.hit
label.config(text=f"The goblin rolled a {result}. Your health is now {player.health}")
updateConditions()
def goblinAttack():
root.after(3000, goblinAction)
def click():
result = rollDice()
hit = "You rolled higher than a 3. You manage to land a hit!"
miss = "You rolled 3 or lower. You missed!"
if result > 3:
goblin.health -= player.hit
label.config(text=f"You rolled a {result}.\n{hit}\n The goblin's health is now {goblin.health}")
updateConditions()
else:
label.config(text=f"You rolled a {result}.\n{miss}\n The goblin's health is now {goblin.health}")
updateConditions()
goblinAttack()
class unit:
def __init__ (self, health, hit):
self.health=health
self.hit=hit
player = unit(10, 2)
goblin = unit(10, 2)
#The first window
root = tk.Tk()
root.title("Test Roll")
root.geometry("500x500")
#The label to display dice roll result
label = tk.Label(root, text="Roll your dice")
label.place(relx=0.5,rely=0.5, anchor="center")
#Label for displaying starting condition
label2 = tk.Label(root, text=f"Your health is currently: {player.health}\nThe goblin's health is currently {goblin.health}")
label2.place(relx=0.5, rely=0.7, anchor="center")
#Button to roll the dice
button = tk.Button(root, text = "roll dice", command = click)
button.pack()
root.mainloop()