-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_game.py
236 lines (215 loc) · 5.73 KB
/
play_game.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
from turtle import update
from games import run_game
from games import sudoku
from games import packman
from games import game4
from player import player
from matplotlib import pyplot as plt
# from scoreboard import get_score
Game1="alien_invasion"
Game2="sudoku"
Game3="Packman"
Game4="snake"
def play_game():
# num=numm
print('Now choose the game you want to play:')
print(f'1.{Game1}')
print(f'2.{Game2}')
print(f'3.{Game3}')
print(f'4.{Game4}')
num=int(input('Choose the number associated with the game:'))
# num=printing()
if num==1:
file=open('highscore.txt','r')
score=file.read()
Player.createOrUpdateFile(score,num)
file.close()
if num==1:
run_game()
elif num==2:
score2=sudoku()
if score2==None:
score2=0
Player.createOrUpdateFile(score2,num)
elif num==3:
score3=packman()
Player.createOrUpdateFile(score3,num)
elif num==4:
score4=game4()
Player.createOrUpdateFile(score4,num)
else:
print('Please Enter a Valid Number!!')
play_game()
Player=player()
Player.GetName()
def check_scoreboard():
status=input('Do you want to check the scoreboard? y/n : ')
if status=='y':
flag=1
elif status=='n':
flag=0
if flag==1:
print(f'1.{Game1}')
print(f'2.{Game2}')
print(f'3.{Game3}')
print(f'4.{Game4}')
num=int(input("choose the game who's scoreboard you want to see: "))
if num==1:
i=0
f=open('all_players.txt','r')
for each in f:
i+=1
score=[]
# print("h")
f.close()
f=open('all_players.txt','r')
for each in f:
nm=each
b=nm.replace('\n','')
line_number=line_num(b,1)
if line_number>-1:
file=open(f'{b}.txt','r')
all_lines=file.readlines()
line=all_lines[line_number-1]
lt=line.split()
score.append(int(lt[3]))
# print(score)
length=len(score)
i=0
x=[]
while(length):
x.append(i+1)
i=i+1
length=length-1
# print(x)
plt.title('ALIEN INVASION SCOREBOARD')
plt.plot(x,score)
plt.xlabel('players')
plt.ylabel('scores')
plt.show()
if num==2:
i=0
f=open('all_players.txt','r')
for each in f:
i+=1
score=[]
# print("h")
f.close()
f=open('all_players.txt','r')
for each in f:
nm=each
b=nm.replace('\n','')
line_number=line_num(b,2)
if line_number>-1:
file=open(f'{b}.txt','r')
all_lines=file.readlines()
line=all_lines[line_number-1]
lt=line.split()
score.append(int(lt[3]))
# print(score)
length=len(score)
i=0
x=[]
while(length):
x.append(i+1)
i=i+1
length=length-1
# print(x)
plt.title('SUDOKU SCOREBOARD')
plt.plot(x,score)
plt.xlabel('players')
plt.ylabel('scores')
plt.show()
if num==3:
i=0
f=open('all_players.txt','r')
for each in f:
i+=1
score=[]
# print("h")
f.close()
f=open('all_players.txt','r')
for each in f:
nm=each
b=nm.replace('\n','')
line_number=line_num(b,3)
if line_number>-1:
file=open(f'{b}.txt','r')
all_lines=file.readlines()
line=all_lines[line_number-1]
lt=line.split()
score.append(int(lt[3]))
# print(score)
length=len(score)
i=0
x=[]
while(length):
x.append(i+1)
i=i+1
length=length-1
# print(x)
plt.title('PACKMAN SCOREBOARD')
plt.plot(x,score)
plt.xlabel('players')
plt.ylabel('scores')
plt.show()
if num==4:
i=0
f=open('all_players.txt','r')
for each in f:
i+=1
score=[]
# print("h")
f.close()
f=open('all_players.txt','r')
for each in f:
nm=each
b=nm.replace('\n','')
line_number=line_num(b,4)
if line_number>-1:
file=open(f'{b}.txt','r')
all_lines=file.readlines()
line=all_lines[line_number-1]
lt=line.split()
score.append(int(lt[3]))
# print(score)
length=len(score)
i=0
x=[]
while(length):
x.append(i+1)
i=i+1
length=length-1
# print(x)
plt.title('SNAKE SCOREBOARD')
plt.plot(x,score)
plt.xlabel('players')
plt.ylabel('scores')
plt.show()
def line_num(name,num):
string1=f'Game{num}'
f=open(f'{name}.txt','r')
flag=0
index=0
for line in f:
index+=1
if string1 in line:
flag=1
break
if flag==0:
return -1
else:
return index
def check_status():
status=input('Do you want to continue? y/n : ')
if status=='y':
flag=1
elif status=='n':
flag=0
if flag==1:
play_game()
check_scoreboard()
check_status()
play_game()
check_scoreboard()
check_status()