我爱模板网今天分享一款用DOS命令写的五子棋,不能用鼠标点击,只能输入行和列下棋,效果图如下:

dos五子棋
下面是代码分享:
001 | @echo off&setlocal enabledelayedexpansion |
002 | set li0=┌───────────────────┐ |
003 | set li1=│┌┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┬┐│1 |
004 | for /l %%a in (2,1,18) do (set li%%a=│├┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┤│%%a) |
005 | set li19=│└┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┴┘│19 |
006 | set li20=└───────────────────┘ |
007 | set li21= A B C D E F G H I J K L M N O P Q R S |
008 | for %%a in (%li21%) do (set/a .+=1,%%a=.&set z!.!=%%a) |
009 | set z0= &set z20= &set "z21= " |
011 | set li5=!li5! 五 棋 子 人 机 对 战 |
013 | set li9=!li9! 电 脑 水 平 中 等 |
014 | set li12=!li12! 由 netbenton 编写完成 |
015 | set li14=!li14! 棋盘设计参照了 batman |
019 | set str= ################### |
021 | for /l %%a in (1,1,19) do ( |
022 | set he%%a=!str!&set sh%%a=!str! |
023 | for /l %%b in (1,1,19) do set [%%a.%%b=0 |
027 | for /l %%a in (5,1,19) do ( |
028 | set pi%%a=!str:~,%%a!&set ni%%a=!str:~,%%a! |
029 | set pi!.!=!str:~,%%a!&set ni!.!=!str:~,%%a! |
038 | set idea=@@@@ #1 #@@@@5 @#@@@4 @@@#@2 @@#@@3 $#$$$4 $$#$$3 $$$#$2 $$$$#1 #$$$$5 #$$#$#3 #$#$$#4 #@@@##2 ##@@@#5 #@@#@#3 #@#@@#4 #@@@#1 |
039 | set idea=!idea! ##@@@4 @@@##2 ##$$$#5 #$$$##2 #$$$#1 ##@@#4 #@@##2 ##$$#4 #$$##2 #$#$#3 @@###3 ###@@3 |
040 | set idea=!idea! ##@##2 ###@#3 #@###3 @####4 ####@2 ##############7 ###########6 ########4 #####3 ####2 |
041 | set ttr=!idea:@=●!&set ttr=!ttr:$=○! |
042 | for %%a in (!ttr!) do (set var =%%a&set ! var :~,-1!=! var :~-1!&set idea=!idea! ! var :~,-1!) |
047 | for /l %%a in (0,1,21) do (echo !z%%a!!li%%a!) |
048 | setlocal enabledelayedexpansion |
049 | set li21=!li21! reboot重新开始,exit退出。 |
050 | set /p var =选择谁先下[ W,玩家 D,电脑 Q,退出 ]: |
051 | if /i "!var!" equ "Q" goto :eof |
052 | if /i "!var!" equ "W" (set zhi=●) else (set zhi=○) |
057 | if %zhi% equ ● goto :men |
059 | for %%a in (!idea!) do ( |
060 | for %%b in (he sh) do ( |
061 | for /l %%c in (1,1,19) do ( |
062 | if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c |
064 | for %%b in (pi ni) do ( |
065 | for /l %%c in (5,1,33) do ( |
066 | if "!%%b%%c:%%a=!" neq "!%%b%%c!" set/a .+=1&set put!.!=%%b %%c |
068 | if defined put1 set put=%%a&goto :get |
076 | for /l %%a in (0,1,21) do (echo !z%%a!!li%%a!) |
079 | if "!user!" equ "reboot" endlocal&goto :restart |
080 | if "!user!" equ "exit" exit |
081 | set/a pos=!user:~0,1!,poh=!user:~1,2!, var =pos-1 2>nul |
082 | if not defined [!poh!.!pos! echo 输入点不存在&goto :men |
083 | if "!he%poh%:~%var%,1!" neq "#" echo 该点已经有子&goto men |
087 | set /a .=!random!%%.+1 |
088 | set put=!put%.%! !put! |
091 | for /f "tokens=1-3" %%a in ( "%put%" ) do ( |
092 | set var =!%%a%%b:*%%c=!srqponmlkjihgfedcba0 |
093 | set/a var =! var :~19,1!+%%c |
094 | if "%%a" equ "he" (set/a poh=%%b,pos=20- var ) |
095 | if "%%a" equ "sh" (set/a poh=20- var ,pos=%%b) |
096 | if %%b lss 19 (set/a var =%%b- var +1) else (set/a var =38-%%b- var +1) |
097 | if "%%a" equ "pi" ( if %%b lss 19 (set/a pos= var ,poh=%%b- var +1) else (set/a poh=20- var ,pos=%%b-19+ var )) |
098 | if "%%a" equ "ni" ( if %%b lss 19 (set/a pos= var ,poh=19-%%b+ var ) else (set/a poh= var ,pos=%%b-19+ var )) |
100 | echo 电脑最后下在:!z%pos%!!z%poh%!(%poh%) |
103 | set zhi=!%zhi%!&set win=!zhi!!zhi!!zhi!!zhi!!zhi! |
104 | set/a piph=poh+pos-1,lips=pos+1,niph=19+pos-poh |
106 | if !piph! lss 19 (set/a pips=pos) else (set/a pips=20-poh) |
107 | if !niph! lss 19 (set/a nips=pos) else (set/a nips=poh) |
110 | for %%a in ( "li!poh! !lips!" "he!poh! !pos!" "sh!pos! !poh!" "pi!piph! !pips!" "ni!niph! !nips!" ) do ( |
111 | for /f "tokens=1,2" %%b in (%%a) do ( |
114 | for %%d in (!.!) do (set %%b=!%%b:~0,%%d!%zhi%!%%b:~%%c!) |
115 | if "!%%b:%win%=!" neq "!%%b!" set win=y |
120 | if !win! neq y goto :loop |
121 | for /l %%a in (0,1,21) do (echo !z%%a!!li%%a!) |
122 | set/p= !a%zhi%! %zhi%子 第!asc%zhi%!手 胜出 <nul |
124 | endlocal&goto :restart |
部分素材资源来源网站,本站提供免费下载,如有侵权请联系站长马上删除!