-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
85 lines (79 loc) · 3.52 KB
/
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
import sys
from initialize import make_grid
from update_move import update_grid
print("_______Welcome to Dungeons and Dragons game_______")
print("____First you should determine the grid size____")
grid_size = int(input("____Enter the grid size(n>1): "))
print("____Here is what your battle field looks like: ")
initial_information = make_grid(n=grid_size)
player_index = initial_information[0][0]
dragon_index = initial_information[0][1]
dungeon_index = initial_information[0][2]
limited_places = initial_information[1]
print(" \nEnter 'QUIT' to exit!")
user_command = input("Which direction do you want to move? ")
while user_command != 'QUIT':
if user_command == 'LEFT':
if user_command not in limited_places:
new_player_index = player_index - 2
if new_player_index == dragon_index:
print("Oh no! unfortunately you lost the game!")
break
if new_player_index == dungeon_index:
print("Hooray! you win the game!")
break
updated_information = update_grid(new_player_index, grid_size)
player_index = updated_information[0]
limited_places = updated_information[1]
else:
print("You can't move in that direction as I said before!")
elif user_command == 'RIGHT':
if user_command not in limited_places:
new_player_index = player_index + 2
if new_player_index == dragon_index:
print("Oh no! unfortunately you lost the game!")
break
if new_player_index == dungeon_index:
print("Hooray! you win the game!")
break
updated_information = update_grid(new_player_index, grid_size)
player_index = updated_information[0]
limited_places = updated_information[1]
else:
print("You can't move in that direction as I said before!")
elif user_command == 'UP':
if user_command not in limited_places:
new_player_index = player_index - (2*(grid_size)+1)
if new_player_index == dragon_index:
print("Oh no! unfortunately you lost the game!")
break
if new_player_index == dungeon_index:
print("Hooray! you win the game!")
break
updated_information = update_grid(new_player_index, grid_size)
player_index = updated_information[0]
limited_places = updated_information[1]
else:
print("You can't move in that direction as I said before!")
elif user_command == 'DOWN':
if user_command not in limited_places:
new_player_index = player_index + (2*(grid_size)+1)
if new_player_index == dragon_index:
print("Oh no! unfortunately you lost the game!")
break
if new_player_index == dungeon_index:
print("Hooray! you win the game!")
break
updated_information = update_grid(new_player_index, grid_size)
player_index = updated_information[0]
limited_places = updated_information[1]
else:
print("You can't move in that direction as I said before!")
else:
print("\nYou entered an invalid format please enter a valid command!")
print("You are only allowed to use:'UP', 'DOWN', 'LEFT', 'RIGHT'")
print(" \nEnter 'QUIT' to exit!")
user_command = input("Which direction do you want to move? ")
else:
print("Byebye, See you soon!")
sys.exit()