1
+ #Define matrix
2
+
3
+ matrix = [["🐭" ,"⬜️" ,"⬜️" ,"⬜️" ,"⬜️" ,"⬛️" ],
4
+ ["⬛️" ,"⬜️" ,"⬛️" ,"⬜️" ,"⬜️" ,"⬜️" ],
5
+ ["⬜️" ,"⬜️" ,"⬛️" ,"⬜️" ,"⬜️" ,"⬜️" ],
6
+ ["⬜️" ,"⬜️" ,"⬜️" ,"⬜️" ,"⬛️" ,"⬛️" ],
7
+ ["⬜️" ,"⬛️" ,"⬜️" ,"⬜️" ,"⬜️" ,"⬜️" ],
8
+ ["⬛️" ,"⬜️" ,"⬛️" ,"⬜️" ,"⬜️" ,"🚪" ]]
9
+
10
+
11
+ def print_matrix ():
12
+ for row in matrix :
13
+ row_string = ""
14
+ for column in row :
15
+ row_string += column
16
+
17
+ print (row_string )
18
+
19
+ #Mickey's initial position
20
+ mickey_pos = [0 ,0 ]
21
+ prev_value = "⬜️"
22
+ print_matrix ()
23
+ while True :
24
+ print ("Enter left to move to the left" )
25
+ print ("Enter right to move to the right" )
26
+ print ("Enter up to move up" )
27
+ print ("Enter down to move down" )
28
+ print ("Enter exit to termiante the program" )
29
+ option = str (input ("Enter option " )).lower ()
30
+
31
+ if option == "left" :
32
+ if mickey_pos [1 ] - 1 < 0 :
33
+ print ("Imposible to move outsite the limits" )
34
+ else :
35
+ if matrix [mickey_pos [0 ]][mickey_pos [1 ]- 1 ] == "⬛️" :
36
+ print ("Imposible to move there is an obstacle" )
37
+ else :
38
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]] = prev_value
39
+ prev_value = matrix [mickey_pos [0 ]][mickey_pos [1 ]- 1 ]
40
+ mickey_pos [1 ]-= 1
41
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]]= "🐭"
42
+
43
+ elif option == "right" :
44
+ if mickey_pos [1 ] + 1 > 5 :
45
+ print ("Imposible to move outsite the limits" )
46
+ else :
47
+ if matrix [mickey_pos [0 ]][mickey_pos [1 ]+ 1 ] == "⬛️" :
48
+ print ("Imposible to move there is an obstacle" )
49
+ else :
50
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]] = prev_value
51
+ prev_value = matrix [mickey_pos [0 ]][mickey_pos [1 ]+ 1 ]
52
+ mickey_pos [1 ]+= 1
53
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]]= "🐭"
54
+ elif option == "up" :
55
+ if mickey_pos [0 ] - 1 < 0 :
56
+ print ("Imposible to move outsite the limits" )
57
+ else :
58
+ if matrix [mickey_pos [0 ]- 1 ][mickey_pos [1 ]] == "⬛️" :
59
+ print ("Imposible to move there is an obstacle" )
60
+ else :
61
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]] = prev_value
62
+ prev_value = matrix [mickey_pos [0 ]- 1 ][mickey_pos [1 ]]
63
+ mickey_pos [0 ]-= 1
64
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]]= "🐭"
65
+ elif option == "down" :
66
+ if mickey_pos [0 ] + 1 > 5 :
67
+ print ("Imposible to move outsite the limits" )
68
+ else :
69
+ if matrix [mickey_pos [0 ]+ 1 ][mickey_pos [1 ]] == "⬛️" :
70
+ print ("Imposible to move there is an obstacle" )
71
+ else :
72
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]] = prev_value
73
+ prev_value = matrix [mickey_pos [0 ]+ 1 ][mickey_pos [1 ]]
74
+ mickey_pos [0 ]+= 1
75
+ matrix [mickey_pos [0 ]][mickey_pos [1 ]]= "🐭"
76
+ elif option == "exit" :
77
+ break
78
+ else :
79
+ print ("Incorrect option, please try again" )
80
+
81
+ #Check if it is the end
82
+ if prev_value == "🚪" :
83
+ print ("Exit has been found..." )
84
+ break
85
+ print_matrix ()
0 commit comments