不知道po在這邊是不是恰當
有一個問題 剛剛在批兔的版上看到一個用"bbs-lua"寫的貪食蛇
按下大P就真的開始在BBS上玩貪食蛇
讓我覺得很神奇
這跟動畫功能的指令好像不一樣
不知道是從哪冒出來的 而且轉來批萬就無效了
很好奇 不知有沒有人知道這東西的相關事情
以下是我看到的文章 (批萬不能執行的樣子)
請按大寫 P
--#BBSLUA
snake={{x=20,y=12}} -- snake body
snakelen = 3
score = 0
dir={x=1, y=0}
target=nil
duration=0.2
miny = 1
maxy = 24
minx = 0
maxx = 40
function drawSnake(m, t)
local i
bbs.color(1,33)
for i = 1, table.getn(m) do
bbs.move(m[i].y, m[i].x*2)
bbs.outs('▉')
if (i == 1) then bbs.color(0,33) end
end
bbs.color(1,31)
bbs.move(target.y, target.x*2)
bbs.outs('★')
-- prevent stupid terminal clients sending double keys
bbs.move(target.y, target.x*2+1)
end
function hitSnake(m, y, x)
local i
if y < miny or y >= maxy then return 1 end
if x < minx or x >= maxx then return 1 end
for i = 1, table.getn(m) do
if (m[i].y == y) and (m[i].x == x) then
return 1
end
end
return nil
end
function hitTarget(y, x)
if y == target.y and x == target.x then
return 1
end
return nil
end
function drawGameOver()
bbs.clear()
bbs.move(12, 30)
print([[G A M E O V E R]]);
end
function nextTarget(m)
local t
t = {}
repeat
t.y = math.random(maxy-miny)-1+miny
t.x = math.random(maxx-minx)-1+minx
until not hitSnake(m, t.y, t.x)
return t
end
target = nextTarget(snake)
repeat
-- draw all
bbs.clear()
bbs.title('BBS-Lua 貪食蛇 範例 (按 END 或 Ctrl-C 中斷) 分數: ' .. score .. " ")
drawSnake(snake)
bbs.refresh()
if bbs.kbhit(duration) then
c = bbs.getch()
if c == 'UP' then dir.x = 0; dir.y = -1; end
if c == 'DOWN' then dir.x = 0; dir.y = 1; end
if c == 'RIGHT' then dir.x = 1; dir.y = 0; end
if c == 'LEFT' then dir.x = -1; dir.y = 0; end
if c == 'END' then break; end
end
-- update snake
local o, n
o = snake[1]
n = {}
n.x = o.x + dir.x
n.y = o.y + dir.y
if (hitSnake(snake, n.y, n.x)) then
-- gameover
drawGameOver()
break
end
-- ok to increase length
table.insert(snake, 1, n)
while table.getn(snake) > snakelen do
table.remove(snake, snakelen+1)
end
if (hitTarget(n.y, n.x)) then
-- hit target, increase length
score = score + 100
snakelen = snakelen + (score / 100) * 3
target = nextTarget(snake)
end
until false
--#BBSLUA
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.62.229.133
推
01/06 22:04, , 1F
01/06 22:04, 1F
→
01/06 22:04, , 2F
01/06 22:04, 2F
→
01/06 22:05, , 3F
01/06 22:05, 3F
推
01/06 22:06, , 4F
01/06 22:06, 4F
推
01/06 22:15, , 5F
01/06 22:15, 5F
→
01/06 22:19, , 6F
01/06 22:19, 6F
→
01/06 22:22, , 7F
01/06 22:22, 7F
→
01/06 22:29, , 8F
01/06 22:29, 8F
推
01/06 23:19, , 9F
01/06 23:19, 9F
推
01/06 23:20, , 10F
01/06 23:20, 10F
推
01/06 23:22, , 11F
01/06 23:22, 11F
→
01/06 23:35, , 12F
01/06 23:35, 12F
推
01/07 01:57, , 13F
01/07 01:57, 13F
推
01/07 15:01, , 14F
01/07 15:01, 14F
推
01/08 20:25, , 15F
01/08 20:25, 15F
推
01/09 12:56, , 16F
01/09 12:56, 16F
推
01/11 20:27, , 17F
01/11 20:27, 17F
→
01/20 11:47, , 18F
01/20 11:47, 18F