-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice07.py
More file actions
63 lines (51 loc) · 1.84 KB
/
practice07.py
File metadata and controls
63 lines (51 loc) · 1.84 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 os
class StoryBlock:
def __init__(self, storyText = "", Button1Text = "", Button2Text = "", Button1Block = None, Button2Block = None):
self.storyText = storyText
self.Button1Text = Button1Text
self.Button2Text = Button2Text
self.Button1Block = Button1Block
self.Button2Block = Button2Block
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def welcome():
print("Hello World!")
input("Press Enter to continue!")
def button1(currentBlock):
if currentBlock.Button1Block is not None:
return currentBlock.Button1Block
else:
print("DebugLine: Button 1 block is not available!")
return currentBlock
def button2(currentBlock):
if currentBlock.Button2Block is not None:
return currentBlock.Button2Block
else:
return None # to exit loop
def main():
welcome()
block1 = StoryBlock("Hello! You are trapped!", "Release me", "Give me key")
block2 = StoryBlock("You got key!", "Open the lock!", "Get out asap!")
block3 = StoryBlock("Congrats! You have escaped!","Restart", "Game Over!")
block1.Button1Block = block2
block1.Button2Block = block3
block2.Button1Block = block3
block2.Button2Block = None
block3.Button1Block = block1
block3.Button2Block = None
currentBlock = block1
while currentBlock is not None:
clear_screen()
print(currentBlock.storyText)
print(f"1. {currentBlock.Button1Text}")
print(f"2. {currentBlock.Button2Text}")
choice = input("Press the button! ")
if choice == "1":
currentBlock = button1(currentBlock)
elif choice == "2":
currentBlock = button2(currentBlock)
else:
print("Invalid choice!")
input("press Enter to continue!")
if __name__ == "__main__":
main()