-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghostgame.py
121 lines (117 loc) · 3.53 KB
/
ghostgame.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
#!/usr/bin/env python3
# Ghost Game
from random import randint
from io import StringIO
import sys
import urllib.request
import requests
import time
#updator
currentVersion = "2.0.0"
URL = urllib.request.urlopen('https://raw.githubusercontent.com/MesVisiDraugai/Python-Ghost-Game/main/version.txt')
data = URL.read()
if (data == currentVersion):
print("Ghost Game is up to date!\n", "Current version: ", currentVersion)
else:
print("Ghost Game is not up to date! App is on version " + currentVersion + " but could be on version " + data + "!")
print("Downloading new version now!")
newVersion = requests.get("https://github.com/MesVisiDraugai/Python-Ghost-Game/releases/download/",data,"Ghost_game.exe")
# file deepcode ignore MissingClose: <please specify a reason of ignoring this>
open("ghost_game.exe", "wb").write(newVersion.content)
print("New version downloaded, restarting the app in 5 seconds!")
time.sleep(5)
quit()
buffer = StringIO()
sys.stdout = buffer
with open(r"C:\ProgramData\GhostGame\name.txt", "rb") as thefile:
name = thefile.read()
with open(r"C:\ProgramData\GhostGame\score.txt", "rb") as thefile:
past_score = thefile.read()
print("Ghost Game")
print("Welcome ", name," !" )
print("Your past score: ", past_score)
lvl = input("What level of difficulty? easy, medium, hard or custom?")
feeling_brave = True
score = 0
if lvl == "easy":
while feeling_brave:
ghost_door = randint(1,3)
print("Three doors ahead...")
print("A ghost behind one.")
print("Which door do you open?\n")
door = input("1, 2 or 3?\n")
door_num = int(door)
if door_num == ghost_door:
print("GHOST!")
feeling_brave = False
else:
print("No ghost!")
print("You enter the next room.")
score = score + 1
print ("Run away!")
print("Game over! You scored", score)
input()
elif lvl == "medium":
while feeling_brave:
ghost_door = randint(1,5)
print("Five doors ahead...")
print("A ghost behind one.")
print("Which door do you open?\n")
door = input("1, 2, 3, 4 or 5?\n")
door_num = int(door)
if door_num == ghost_door:
print("GHOST!")
feeling_brave = False
else:
print("No ghost!")
print("You enter the next room.")
score = score + 1
print ("Run away!")
print("Game over! You scored", score)
input()
elif lvl == "hard":
while feeling_brave:
ghost_door = randint(1,10)
print("Ten doors ahead...")
print("A ghost behind one.")
print("Which door do you open?\n")
door = input("1, 2, 3, 4, 5, 6, 7, 8, 9 or 10?\n")
door_num = int(door)
if door_num == ghost_door:
print("GHOST!")
feeling_brave = False
else:
print("No ghost!")
print("You enter the next room.")
score = score + 1
print ("Run away!")
print("Game over! You scored", score)
input()
elif lvl == "custom":
while feeling_brave:
number = int(input("how many doors do you want? Integer only"))
ghost_door = randint(1,number)
print(number," doors ahead...")
print("A ghost behind one.")
print("Which door do you open?\n")
for i in range(number):
print(i)
number_range = buffer.getvalue()
door = input(number_range, "?\n")
door_num = int(door)
if door_num == ghost_door:
print("GHOST!")
feeling_brave = False
else:
print("No ghost!")
print("You enter the next room.")
score = score + 1
print ("Run away!")
print("Game over! You scored", score)
input()
else:
print("Please choose a valid option.")
sys.exit
f = open("score.txt", "w")
f.write(score)
f.close()