
If not, it will increase and decrease length. …and its body will progress toward the head If there is input, snake head will progress toward input direction. Snake will put its head toward its direction and let body extend to its head

Snake movign toward a direction (E/X right) When eaten, regenerate raspberry, which we will talk about later.īut if not eaten, undo the length increase just now. Snake will increase toward its current direction. If changeDirection = 'R' and direction != 'L' : If changeDirection = 'L' and direction != 'R' : If changeDirection = 'D' and direction != 'U' : #detect if opposite direction input if changeDirection = 'U' and direction != 'D' : If input is valid and not opposite, its direction will be stored, and later be used to changed snake direction. 原理就是看原始方向 direction与输入方向 changeDirection是否相反。īy checking if the input direction is opposite to original direction. This step makes sure that does not happen. key = ord ( 'D' ) :ĬhangeDirection = 'R' if event. key = ord ( 'A' ) :ĬhangeDirection = 'L' if event. key = ord ( 'S' ) :ĬhangeDirection = 'D' if event. key = ord ( 'W' ) :ĬhangeDirection = 'U' if event. type = KEYDOWN : #detect keyboard event if event. def main ( ) : print ( '=' ) print ( 'Welcome to PySnake, a Python-based snake-eating-raspberry game with help of the Pygame module' ) print ( '=' ) print ( ' _= ̄=_ ' ) print ( ' // \\\ _**_ ' ) print ( ' // \\\ / ̄O-_ // \\' ) print ( ' // \\\ /// _=-上 Up,即UĬhangeDirection = ‘R’ while True : #detect python event for event in pygame. The single, multi mode of the game and the quit are listed as options. There are nothing special about the ugly snake and raspberry, but the use of “ ̄”. import sys, pygame, PySnakeSingle, PySnakeMulti
HACKINTOOL 2.2.1 CODE
Other two files imported are source code of the two modes.

Imports sys to ensure program functions like quit run normally 游戏主菜单 PySnakeMenu 1.导入必要的库和文件 import modules and files 蛇死了之后,不结束游戏,重新生成蛇 snake regenerate after death, instead of game over.两条蛇,一红一绿。一个玩家用WASD控制,另外一个用上下左右控制 one player control with WASD while the other with arrow keys.树莓的位置会随机生成 raspberry regenerate after eaten.蛇吃树莓后增加长度 snake grow longer after eating raspberry.蛇会根据用户输入改变方向 snake changes firection with player input.蛇会动(看似简单)the snake moves(harder than you think).

