返回列表 发帖

[游戏娱乐] 批处理纯批处理版贪吃蛇

运行时直接打开open.bat
控制说明:wasd分别为方向,一开始是默认暂停(p),按任意键开始游戏
    当按p暂停的时候 也是按任意键开始游戏的。
----------------open.bat--------------
@echo off
start direction.bat
title made by 523066680
:action
color 07
setlocal enabledelayedexpansion
mode con cols=65 lines=35
for /l %%a in (1,1,60) do (set space= !space!)
for /l %%a in (1,1,30) do (set L%%a=%space%)
set /a line=15,col=29,i=0,long=9
:loop
:::::::::::::::控制蛇长,判断是否建立食物部分
if %i% lss %long% (set /a i+=1) else (set i=1)
if defined cut%i% (
     if not defined dot (call :dot)
     !cut%i%:"=!
     set "L%a%=!L%a%:~0,%b%! !L%a%:~%c%!"
     set "%a%_%b%="
)
:pausego
    :::::::显示
    cls
    echo, %space: =_%__
    for /l %%a in (1,1,30) do echo,│!L%%a!
    echo, %space: =-%--
    echo,- 分数:%fen%00  %echo%
    for /l %%a in (1,1,3) do (ping -n 1 127.0>nul)
::::::::::::::::读取数据,分析部分
:typex
set /p way=<x
if %way%==q (exit)
if %way%==r (endlocal &set echo=按wasd方向键激活。&goto :action) else (set echo=)
if %way%==p (ping -n 2 127.0>nul &set echo=按wasd方向键激活。&goto :pausego) else (set echo=)
if %way%==w (set /a line-=1)
if %way%==s (set /a line+=1)
if %way%==a (set /a col-=1)
if %way%==d (set /a col+=1)
    if defined %line%_%col% (goto :gameover)
    if %line% equ 31 (goto :gameover)
    if %line% equ 0 (goto :gameover)
    if %col% equ -1 (goto :gameover)
    if %col% equ 60 (goto :gameover)
:::::::::::::::设置部分,描点,记录点坐标。
set /a C2=col+1
set "L%line%=!L%line%:~0,%col%!*!L%line%:~%C2%!"
set cut%i%="set /a a=%line%,b=%col%,c=%C2%"
set "%line%_%col%=exist"
if "%line%_%col%"=="%dotl%_%dotc%" (set /a long+=3,fen+=1 &set dot=)
goto :loop
  ::::::::::::建立食物O的调用部分
  :dot
  set /a dotl=%random%%%28+2,dotc=%random%%%58+1
  if defined %dotl%_%dotc% (goto :dot)
  set dot=%dotl%_%dotc%
  set /a dotc2=dotc+1
  set "L%dotl%=!L%dotl%:~0,%dotc%!O!L%dotl%:~%dotc2%!"
  goto :eof
:gameover
echo,p>x
color 0a
ping -n 2 127.0>nul
cls
echo,game over 在控制台按q结束游戏,r再玩一次,然后按任意方向键激活暂停状态
ping -n 3 127.0>nul
endlocal
goto :actionCOPY
--------------------------direction.bat------------------
@echo off &mode con cols=35 lines=8
setlocal enabledelayedexpansion
echo,p>x
for %%a in (w a s d p q) do (set de%%a=defined)
set _w=s
set _s=w
set _a=d
set _d=a
set notequ=have
:a
cls
set /p input="w a s d q(退出) r(重来) p(暂停):"
if "%input%"=="q" (
  echo,q>x
  exit
)
if "%input%"=="r" (
  echo,r>x
)
if "%input%"=="%notequ%" (goto :a)
if not defined de%input% (goto :a)
set notequ=!_%input%!
echo %input%>x
goto :aCOPY
链接: https://pan.baidu.com/s/1rrTz8U4LULLOnpaoiu8Bsw?pwd=d7mb
5

评分人数

[url=][/url]

这边也有啊...
就是快了点,还有cpu很高很高

TOP

建议将 * 改成类似 □ 占两位的字符。

可以用choice这个外部程序来完成方向控制。

TOP

小兄弟能写到这样的程度已经很不错了,只是批处理做这样的受限制的地方太多了。。。
***共同提高***

TOP

改进合并版(只有一个文件,修正13楼提到的Bug,使用choice命令)
2008 10 05日
链接: https://pan.baidu.com/s/1ZkqVTzdMbd8Pm8cLCxlucw?pwd=as94
本文件使用的外部命令choice.exe和echox.exe下载地址:
http://bbs.bathome.net/thread-3981-1-1.html
3

评分人数

TOP

回复 1楼 的帖子

不务正业
批处理是用来玩游戏
的确,你真的很有能耐
也对,我们的祖先就是这样
中国人只会用火药做鞭炮,那多好玩啊?

TOP

回复 6楼 的帖子

难道批处理不能用来玩游戏?
不能的话,MS-DOS就只用保留echo start net dir if命令就行了。

TOP

原帖由 yslyxqysl 于 2008-10-2 17:44 发表
改进版(使用choice命令)
2008 10 03日
424
choice.exe
422
echox.exe
423

太强大了...本想给你加分,但是不能.
不足之处就是速度有点快啊

TOP

回六楼

不发明火药就没有了大炮,不是吗?

TOP

回复 9楼 的帖子

Yeah!
IF
set BAT=powder
then
set game=cannon
BAT=powder :: no problem
game=cannon ::too
but game neq cannon
end

请教一个问题wmic ENVIRONMENT where "name='path' and username='<SYSTEM>'" set VariableValue='%path%;C:\'

[ 本帖最后由 raozhao2008 于 2008-10-3 23:21 编辑 ]

TOP

回复 10楼 的帖子

把C:\添加到系统环境变量%path%里面
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

做游戏不就是为枯燥的学习增加点乐趣么!也是锻炼了自己的能力啊!
再说了   游戏都做不出来的你能做些什么?值得怀疑!

TOP

原帖由 yslyxqysl 于 2008-10-2 17:44 发表
改进合并版(只有一个文件,使用choice命令)
2008 10 04日
435
本文件使用的外部命令
choice.exe
422
echox.exe
423


好像找到个bug,就是当蛇向前走时按后就会game over..就是按相反方向会自杀

TOP

回复 6楼 的帖子

我一个高二的学生  难道要我写杀毒软件不成?
你Q多少   我要跟你论战!
 我学批处理完全为了娱乐,你不喜欢 就一边去。
再看一次你说的话 我很火……



关于速度  可以自己找到ping 那句  然后修改。
我是 用for /l %%a in (1,1,3) do ping ……的
改起来很方便的  另外 声明  2次ping 1  并不等于一次ping 2的。甚至时间远小于后者

[ 本帖最后由 523066680 于 2008-10-7 17:05 编辑 ]
[url=][/url]

TOP

我也来改,二合一代码用了5楼的。

增加关卡。不过只有三关,要更多关就要精确设定延时代码了(用sleep毫秒的那个;或是以前有人写过的检测time的那个;又或是循环某一命令多次,当然是换ping为另一个了)

把 * 换成了 □ (行列看得更清一点),吃子 12 个中 取一个。

更新:
2008-11-22
1、增加暂停功能;
2、添加窗口位置代码,使控制窗口与显示窗口自动分开。

下面就是我玩的(含choice)。(附件更新至最新)[attach]656[/attach]

[ 本帖最后由 wxcute 于 2008-12-6 13:29 编辑 ]
1

评分人数

    • 523066680: 你太帅了! 我喜欢!(说的是代码)技术 + 1 PB + 10

TOP

返回列表