-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_library.py
More file actions
561 lines (514 loc) · 19.4 KB
/
game_library.py
File metadata and controls
561 lines (514 loc) · 19.4 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
#!/usr/bin/python3
#Lane Doyle
#1/27/2020
import pickle
import sys
'''Program to create a game library'''
#Dictionary
games = {}
data_file = open("game_lib.pickle", "rb")
games = pickle.load(data_file)
data_file.close()
#Functions
def add_and_edit():
#print("Running add_and_edit()")
while True:
print('''
---------------------
Changing Your Library
---------------------
Editing Options:
1) Add a game
2) Edit an already existing game
''')
editing_option = input("What would you like to do? ")
if editing_option == '1':
add()
continue_edit = False
elif editing_option == '2':
edit()
continue_edit = False
confirmation = input("Would you like to continue editing? Y/N ")
if confirmation.lower() == "n":
break
def add():
new_key = len(games) + 1
valid = False
while not valid:
new_genre = input("What is the genre? ")
new_title = input("What is the title? ")
new_developer = input("Who is the developer? ")
new_publisher = input("Who is the publisher? ")
new_system = input("What is the system it is played on? ")
new_release = input("What is the release date? ")
new_rating = input("What is the rating? ")
new_sme = input("Is it single player, mulit, or either? ")
new_price = input("What is the price? ")
new_beat = input("Have you beaten it? ")
new_purchase = input("What is the purchase date? ")
new_notes = input("Any notes? ")
new_entry = [new_genre, new_title, new_developer, new_publisher, new_system,
new_release, new_rating, new_sme, new_price, new_beat, new_purchase,
new_notes]
print("------------------------")
print("Genre: ", new_genre)
print("Title: ", new_title)
print("Developer: ", new_developer)
print("Publisher: ", new_publisher)
print("System: ", new_system)
print("Release Date: ", new_release)
print("Rating: ", new_rating)
print("Single/multi/either: ", new_sme)
print("Price: ", new_price)
print("Beat it?: ", new_beat)
print("Purchase Date: ", new_purchase)
print("Notes: ", new_notes)
answer = input("Is all of this information correct? Y/N ")
if answer.lower() == "y":
valid = True
games[new_key] = new_entry
def edit():
valid = False
while not valid:
print("Your current library: ")
for key in games.keys():
print(key, "-", games[key][1])
edit_key = input("What is the number of the game would you like to edit? ")
edit_key = int(edit_key)
edit_entry = games[edit_key]
if edit_key in games:
print("Current genre: ", edit_entry[0])
edit_entry[0] = input("New Genre: ")
print("")
print("Current title: ", edit_entry[1])
edit_entry[1] = input("New title: ")
print("")
print("Current developer: ", edit_entry[2])
edit_entry[2] = input("New developer: ")
print("")
print("Current publisher: ", edit_entry[3])
edit_entry[3] = input("New publisher: ")
print("")
print("Current system: ", edit_entry[4])
edit_entry[4] = input("New system: ")
print("")
print("Current release date: ", edit_entry[5])
edit_entry[5] = input("New release date: ")
print("Current rating: ", edit_entry[6])
print("")
edit_entry[6] = input("New rating: ")
print("Current single player/multi/either: ", edit_entry[7])
edit_entry[7] = input("New single player/multi/either: ")
print("")
print("Current price: ", edit_entry[8])
edit_entry[8] = input("New price: ")
print("")
print("Current status(beaten): ", edit_entry[9])
edit_entry[9] = input("New status: ")
print("")
print("Current purchase date: ", edit_entry[10])
edit_entry[10] = input("New purchase date: ")
print("")
print("Current notes: ", edit_entry[11])
edit_entry[11] = input("New notes: ")
print("------------------------")
print("Genre: ", edit_entry[0])
print("Title: ", edit_entry[1])
print("Developer: ", edit_entry[2])
print("Publisher: ", edit_entry[3])
print("System: ", edit_entry[4])
print("Release Date: ", edit_entry[5])
print("Rating: ", edit_entry[6])
print("Single/multi/either: ", edit_entry[7])
print("Price: ", edit_entry[8])
print("Beat it?: ", edit_entry[9])
print("Purchase Date: ", edit_entry[10])
print("Notes: ", edit_entry[11])
answer = input("Is all of this information correct? Y/N ")
if answer.lower() == "y":
valid = True
edit_entry = games[edit_key]
else:
print("NO MATCHES FOUND!")
def print_all():
#print("Running print_all()")
games_key_list = games.keys()
for key in games_key_list:
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
def search():
#print("Running search_by_title()")
while True:
print('''
----------------------
Searching Your Library
----------------------
Search Options:
1) Genre
2) Title
3) Developer
4) Publisher
5) System
6) Release Date
7) Rating
8) Single Player/Multi/Either
9) Price
10) Beat it?
11) Purchase Date
''')
search_option = input("What would you like to search by? ")
if search_option == '1':
search_by_genre()
elif search_option == '2':
search_by_title()
elif search_option == '3':
search_by_developer()
elif search_option == '4':
search_by_publisher()
elif search_option == '5':
search_by_system()
elif search_option == '6':
search_by_release()
elif search_option == '7':
search_by_rating()
elif search_option == '8':
search_by_sme()
elif search_option == '9':
search_by_price()
elif search_option == '10':
search_by_beat()
elif search_option == '11':
search_by_purchasedate()
else:
print("That is not a valid option!")
search_input = input("Would you like to continue searching? Y/N ")
if search_input == 'N' or search_input == 'n':
break
def search_by_title():
found_one = False
search_results = {}
title = input("What is the title of the game? ")
for key in games.keys():
if title in games[key][1]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_genre():
found_one = False
genre = input("What is the genre of the game? ")
for key in games.keys():
if genre in games[key][0]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_developer():
found_one = False
developer = input("Who developed the game? ")
for key in games.keys():
if developer in games[key][2]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_publisher():
found_one = False
publisher = input("Who published the game? ")
for key in games.keys():
if publisher in games[key][3]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_system():
found_one = False
system = input("What system is it played on? ")
for key in games.keys():
if system in games[key][4]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_release():
found_one = False
release = input("When was it released? ")
for key in games.keys():
if release in games[key][5]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_rating():
found_one = False
rating = input("What is the rating? ")
for key in games.keys():
if rating in games[key][6]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_sme():
#sme = single, multi, or either
found_one = False
sme = input("Is it single player, multi or either? ")
for key in games.keys():
if sme in games[key][7]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_price():
found_one = False
price = input("What was the price of the game? ")
for key in games.keys():
if price in games[key][8]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_beat():
found_one = False
beat = input("Have you beaten it? ")
for key in games.keys():
if beat in games[key][9]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def search_by_purchasedate():
found_one = False
purchasedate = input("When did ou purchase it? ")
for key in games.keys():
if purchasedate in games[key][10]:
found_one = True
print()
print("Genre: ", games[key][0])
print("Title: ", games[key][1])
print("Developer: ", games[key][2])
print("Publisher: ", games[key][3])
print("System: ", games[key][4])
print("Release Date: ", games[key][5])
print("Rating: ", games[key][6])
print("Single player/multi/either: ", games[key][7])
print("Price: ", games[key][8])
print("Beat it?: ", games[key][9])
print("Purchase Date: ", games[key][10])
print("Notes: ", games[key][11])
print("-----------")
if not found_one:
print("NO MATCHES FOUND!")
def remove_title():
#print("Running remove_title()")
valid = False
while not valid:
print("Your current library: ")
for key in games.keys():
print(key, "-", games[key][1])
chosen_title = input("What is the number of the game would you like to remove? ")
chosen_title = int(chosen_title)
if chosen_title in games:
for key in range(1, len(games)+1):
if key >= chosen_title and key != len(games):
games[key] = games[key +1]
if key == len(games):
removed_game = games.pop(chosen_title)
print(removed_game[1], " removed!")
valid = True
else:
print("NO MATCHES FOUND!")
try_again = input("Would you still like to remove a game? Y/N ")
if try_again.lower() == "y":
pass
else:
valid = True
def save_library():
#print("Running save_library()")
data_file = open("game_lib.pickle", "wb")
pickle.dump(games, data_file)
data_file.close()
print("File saved!")
def quit():
#print("Running quit()")
confirm_save = input("Would you like to save? Y/N ")
if confirm_save.lower() == "y":
data_file = open("game_lib.pickle", "wb")
pickle.dump(games, data_file)
data_file.close()
print("File saved!")
print("Goodbye!")
sys.exit()
else:
print("Goodbye!")
sys.exit()
#Main Menu
while True:
print('''
------------------------
Welcome to your library!
------------------------
Main Menu:
1) Add/Edit Game
2) Print All Games
3) Search
4) Remove a Game
5) Save Library
Q) Quit
''')
choice = input("What would you like to do? ")
if choice == "1":
add_and_edit()
elif choice == "2":
print_all()
elif choice == "3":
search()
elif choice == "4":
remove_title()
elif choice == "5":
save_library()
elif choice == "Q" or choice == "q":
quit()
else:
print("That is not a valid option!")