Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions grid_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
(0, 3), (1, 3), (2, 3), (3, 3), (4, 3),
(0, 4), (1, 4), (2, 4), (3, 4), (4, 4)]


# Function to get locations of the grid

def get_locations():
return random.sample(CELLS, 3)

# Function to move the player

def move_player(player, move):
x, y = player
Expand All @@ -25,7 +26,7 @@ def move_player(player, move):
if move == "DOWN":
y += 1
return x, y

# Function to get the player input to move in the grid

def get_moves(player):
moves = ["LEFT", "RIGHT", "UP", "DOWN"]
Expand All @@ -40,6 +41,7 @@ def get_moves(player):
moves.remove("DOWN")
return moves

# Function to draw a map

def draw_map(player, monster, door):
print(" _"*5)
Expand Down Expand Up @@ -70,6 +72,8 @@ def draw_map(player, monster, door):
output = tile.format("_|")
print(output, end=line_end)

# Function to loop the game till anyone wins

def game_loop():
monster, door, player = get_locations()
playing = True
Expand Down Expand Up @@ -104,10 +108,13 @@ def game_loop():
game_loop()


# Some print messages

print("Welcome to the dungeon!")
print("You have 1 life with you Try your luck!!")
input("Press Enter to start!")

# Function call game_loop

game_loop()