snake-game
snake-game copied to clipboard
A snake game based on Qt.
The snake crushes itself when you quickly press the buttons.  For example when snake goes to right side ______________________________ |..........................................................| |..........................................................| |..........~~~~~~~>......................| |.........................................................| |.........................................................| |____________________________| By pressing the down...
Add different types of food Add walls Add Game settings Other improvements Fix bugs
Adding some comment to understand by everyone. Some bug fixes and improve redability.
Hi, I noticed an issue in the game consists in incremental speed for snake and that's happening \ by clicking too many times on the resume option of the menu...
Hello!) I just created snake-game server. If you are not busy, how about create a client for snake game multiplayer? It will be funny!)) https://github.com/ivan1993spb/snake-server
当蛇向右移动到右侧边界时,你快速按下向下或向上和向左的方向键。由于蛇在移动过程中,方向的改变可能没有按照预期的顺序进行,或者在一个短时间内方向改变过于频繁,导致蛇头在下次移动时直接移动到了身体所在的位置,游戏结束。同理,当蛇向其他方向(向左、向上、向下)时,同时按下相反方向和相邻方向都会导致蛇误判为撞到自己,游戏结束。 为了避免这种情况,可以在 setMoveDirection 函数中添加更多的逻辑,确保蛇在一个较短的时间内不能进行过于频繁的方向改变。例如,可以添加一个计数器,记录蛇最近一次改变方向的时间,只有当时间间隔超过一定值时,才允许蛇改变方向。 msecsTo() 是 QTime 类的另一个成员函数,用于计算从当前 QTime 对象(lastDirectionChangeTime)到指定 QTime 对象(currentTime)之间的毫秒数差值。 lastDirectionChangeTime 是一个 QTime 类型的对象,用于记录蛇上一次改变方向的时间。 isValid() 是 QTime 类的一个成员函数,用于检查该 QTime 对象是否包含一个有效的时间值。