mirror of
https://github.com/d3vyce/Python-Game.git
synced 2025-04-03 12:23:22 +02:00
add level limit check
This commit is contained in:
parent
27b501e363
commit
efb27a0a92
@ -29,18 +29,26 @@ class List:
|
|||||||
|
|
||||||
return i
|
return i
|
||||||
|
|
||||||
def Snake_move(M, L, dir):
|
def Snake_move(M, L, dir, heigh, width):
|
||||||
Fruit = False
|
Fruit = False
|
||||||
List_save = L
|
List_save = L
|
||||||
Save_Value = L.val
|
Save_Value = L.val
|
||||||
|
|
||||||
# Calculate new snake head coord
|
# Calculate new snake head coord
|
||||||
Next_coord = (DIRECTION[dir][0] + L.val[0], DIRECTION[dir][1] + L.val[1])
|
if dir == 'left' and L.val[1] == 0:
|
||||||
|
Next_coord = (L.val[0], width-1)
|
||||||
|
elif dir == 'right' and L.val[1] == width-1:
|
||||||
|
Next_coord = (L.val[0], 0)
|
||||||
|
elif dir == 'up' and L.val[0] == 0:
|
||||||
|
Next_coord = (heigh-1, L.val[1])
|
||||||
|
elif dir == 'down' and L.val[0] == heigh-1:
|
||||||
|
Next_coord = (0, L.val[1])
|
||||||
|
else:
|
||||||
|
Next_coord = (DIRECTION[dir][0] + L.val[0], DIRECTION[dir][1] + L.val[1])
|
||||||
|
|
||||||
# Check nature of the future snake head coord
|
# Check nature of the future snake head coord
|
||||||
if M[Next_coord[0]][Next_coord[1]] == 3:
|
if M[Next_coord[0]][Next_coord[1]] == 3:
|
||||||
Fruit = True
|
Fruit = True
|
||||||
M[Next_coord[0]][Next_coord[1]] == 0
|
|
||||||
elif M[Next_coord[0]][Next_coord[1]] == 2:
|
elif M[Next_coord[0]][Next_coord[1]] == 2:
|
||||||
raise ValueError(1) # Error : You take a wall !
|
raise ValueError(1) # Error : You take a wall !
|
||||||
quit
|
quit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user