贪吃蛇

像下图这样的蛇如何拐弯?绿点是新蛇头,红点是旧蛇尾。

 

搜了下,有用JavaScript写的,有用Python写的,好像都是把蛇身用一系列的点来表示。这样比我原先想的用若干根线段表示简单清晰多了,最前面加一个点,最后面删一个点即可,不用把一根线段折/拆成两根。几百个点速度也很快。当把蛇身画成一系列椭圆之类时,本来也没法MoveTo(point); LineTo(point). 可以用list而不是vector。

JavaScript的unshift()方法可向数组的开头添加一个或更多元素。请看下面的.bat:

D:\>type t.bat
@echo off
echo %1 %2 %3
shift
echo %1 %2 %3
D:\>t a b c d
a b c
b c d
D:\>echo/?
显示消息,或者启用或关闭命令回显。
D:\>shift/?
更改批处理文件中可替换参数的位置。

shift这个词意思很多。如>> right shift, 改变大小写也是shift等。

可insert_before(), push_front()之类去调用unshift(),不会JS的C/C++程序员看起来更方便。类似地,pop_back()调用slice().

An alternate key (Alt key) is a key that is present on most computer keyboards and is considered a modifier key that can used similarly to the shift or control keys. In other words, the alternate key provides alternate input and operations when pressed in combination with other keys.

Python Conio 1.1.0 is a wrapper for Turbo C conio,但居然不小。而且蛇自动移动所需的timer呢?不自动移动游戏难度降为0.

Python的Thread类有一个 Timer子类,该子类可用于控制指定函数在特定时间内执行一次。

有pygame包和用它写的: python snake game

果然有Excel实现贪吃蛇

posted @ 2023-01-14 12:03  Fun_with_Words  阅读(81)  评论(0编辑  收藏  举报









 张牌。