-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2dMapMovement.py
More file actions
64 lines (48 loc) · 1.58 KB
/
2dMapMovement.py
File metadata and controls
64 lines (48 loc) · 1.58 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
import os
x_pos = 0
y_pos = 0
width = 5
height = 5
game_map_revealed = ((".", ".", ".", ".", "."),
(".", ".", ".", ".", "."),
(".", ".", ".", ".", "."),
(".", ".", ".", ".", "."),
(".", ".", ".", ".", "."))
game_map = [["X", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "]]
def clear_terminal() -> None:
"""Clear the terminal."""
os.system('cls')
def draw_map() -> None:
"""Draw the map inside a box."""
print(".-----.")
for line in game_map:
print("|", end="")
for tile in line:
print(tile, end="")
print("|")
print("'-----'")
def move_player(move_input: str, x: int, y: int) -> tuple[int, int]:
"""Move the player if the inputs and conditions are valid."""
if move_input == "w" and y > 0:
y -= 1
elif move_input == "s" and y < height - 1:
y += 1
elif move_input == "a" and x > 0:
x -= 1
elif move_input == "d" and x < width - 1:
x += 1
return x, y
while True:
clear_terminal()
draw_map()
choice = input("")
# switch the tile on your position to the one on the revealed map
game_map[y_pos][x_pos] = game_map_revealed[y_pos][x_pos]
# move your player
x_pos, y_pos = move_player(move_input=choice, x=x_pos, y=y_pos)
# draw an X to your current position
game_map[y_pos][x_pos] = "X"