本帖最后由 happy886rr 于 2018-11-11 13:16 编辑
经典俄罗斯方块游戏,再次用批处理和C重写。动态显示,迅捷如闪电。预留Settings设置,参数可自行调整。
操控说明- A左D右;W旋转;S加速下落;
- Q退出;P暂停;方向键继续;
复制代码 效果图
[2016/10/6] C语言版 C-Version 1.0- @echo off
- ::**************Happy's Tetris C语言版******
- REM 使用说明:
- REM A左D右;W旋转;S加速下落;
- REM Q退出;P暂停;任意键继续;
-
- ::**************Settings高级设置************
- REM 设置窗体
- title &mode con cols=35 lines=25&color F0
- REM 设置时钟T(毫秒)
- set T=300
- REM 按键黏度N(微秒)
- set N=5
- REM 设置旋转体系:填TGM 或 SRS
- set MODE=TGM
-
- ::**************Base64转码******************
- :START
- cls&Tetris.exe %N% %T% %MODE%&&exit /b||certutil -decode "%~f0" "%~dp0Tetris.exe"
- goto START
- -----BEGIN CERTIFICATE-----
- TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAEDAAAAAAAAAAAAAAAAAOAADwMLAQYAABAAAAAQAAAAQAAA0FgAAABQAAAAYAAAAABAAAAQAAAAAgAABAAAAAAAAAAEAAAAAAAAAABwAAAAEAAAAAAAAAMAAAAAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAAABgAADYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFVQWDAAAAAAAEAAAAAQAAAAAAAAAAIAAAAAAAAAAAAAAAAAAIAAAOBVUFgxAAAAAAAQAAAAUAAAAAwAAAACAA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AAAAAAAAAAAAAAAAAB4YAAAhmAAAJZgAACmYAAAtGAAAMJgAAAAAAAA0GAAAAAAAABLRVJORUwzMi5ETEwAbXN2Y3J0LmRsbAAAAExvYWRMaWJyYXJ5QQAAR2V0UHJvY0FkZHJlc3MAAFZpcnR1YWxQcm90ZWN0AABWaXJ0dWFsQWxsb2MAAFZpcnR1YWxGcmVlAAAARXhpdFByb2Nlc3MAAABleGl0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
- -----END CERTIFICATE-----
复制代码 源码Tetris.c
#include <conio.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <Windows.h> /**********初始化参数************/ int i,j,N,T,F,J,X,Y,dx,dy, KEY_V, Cache1,Cache2,NU,NI,RU,RI, P_X,P_Y,POS_Y_MAX, LEVEL=1,SCORE=0, P[4], POINT_V[12][22], MARK[21], FLAG[5]={0,0,0,1,0}; int TGM[7][4]={{0x159D,0x89AB,0x159D,0x89AB},{0x126A,0x4856,0x159A,0x4526},{0x926A,0x456A,0x1592,0x0456},{0x4859,0x4859,0x4859,0x4859},{0x5926,0x0156,0x5926,0x0156},{0x4159,0x4596,0x1596,0x4156},{0x156A,0x4152,0x156A,0x4152}}; int SRS[7][4]={{0x159D,0x89AB,0x26AE,0x4567},{0x0159,0x4856,0x159A,0x4526},{0x8159,0x456A,0x1592,0x0456},{0x4859,0x4859,0x4859,0x4859},{0x4815,0x459A,0x5926,0x0156},{0x4159,0x4596,0x1596,0x4156},{0x0459,0x8596,0x156A,0x4152}}; /**********光标位置函数**********/ void Pos(int x,int y) { COORD pos; HANDLE hOutput; pos.X=2*x; pos.Y=y; hOutput=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOutput,pos); } void HideCursor() { CONSOLE_CURSOR_INFO cursor_info={1,0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info); } /**********初始化界面************/ void CreatUI() { int i,j,BOUNDARY; printf("┏━━━━━━━━━━┓\n"); for(j=1;j<=20;j++) { if (j==3){printf("┃ ┃LEVEL:1\n");} else if(j==5){printf("┃ ┃SCORE:0\n");} else if(j==7){printf("┃ ┃NEXT \n");} else {printf("┃ ┃\n");} } printf("┗━━━━━━━━━━┛\n"); printf(" CopyRight@2016~2018 BY HAPPY\n"); for(j=1;j<=21;j++){ for(i=0;i<=11;i++){ BOUNDARY=i*(i-11)*(j-21); if(BOUNDARY==0){ POINT_V[i][j]=1; }else{ POINT_V[i][j]=0; } } } } /**********按键获取**************/ int Getkey(int N,int T) { if(KEY_V==115){return 115;} int start=clock(); do{ if(kbhit()){ KEY_V=(int)(getch()); if(KEY_V<97){KEY_V+=32;} return KEY_V; } for(i=0;i<=N;i++); }while((clock()-start)<T); dy=1; return -1; } /***********块体转置*************/ int Rote(int S, int I) { return (F==0)?TGM[S][(I+4)%4]:SRS[S][(I+4)%4]; } /***********擦除显示*************/ int Display(int x, int y, int CAC, int Mode) { for(j=0;j<=3;j++){ P[j]=CAC&0xF, CAC>>=4; if (Mode==1){Pos((P[j]>>2)+x,(P[j]&0x3)+y);printf("■");} else if(Mode==0){Pos((P[j]>>2)+x,(P[j]&0x3)+y);printf(" ");} } return 0; } /***********固化块体*************/ int DoBlocks() { //~~~游戏结束 if(Y<2){ Pos(1,22);printf("GAME OVER!"); exit(0); } //~~~固化块体 POS_Y_MAX=0, FLAG[3]=1; for(j=0;j<=3;j++){ P_X=(P[j]>>2)+X,P_Y=(P[j]&0x3)+Y; if(POS_Y_MAX<P_Y){POS_Y_MAX=P_Y;} POINT_V[P_X][P_Y]=1; } //~~~关卡得分 for(j=Y;j<=POS_Y_MAX;j++){ FLAG[2]=1; for(i=1;i<=10;i++){ if(POINT_V[i][j]==0){FLAG[2]=0;} } if(FLAG[2]){ SCORE+=10,MARK[j]=1; if(SCORE==400){ SCORE=0,LEVEL+=1,T-=100; FLAG[4]=1; } } } //~~~极品消行 for(j=20;j>=5;j--){ if(FLAG[4]){ for(i=1;i<=10;i++){ POINT_V[i][j]=0; Pos(i,j);printf(" "); } } else if(MARK[j]) { MARK[j]=0,J=j-1; for(N=1;N<=3;N++){ if(MARK[J]){J--;} } MARK[J]=1; for(i=1;i<=10;i++){ Pos(i,j); if(POINT_V[i][j]=POINT_V[i][J]){ printf("■"); }else{ printf(" "); } } } } FLAG[4]=0; return 0; } /***********碰撞检测*************/ int CheckCollision() { for(j=0;j<=3;j++){ P_X=(P[j]>>2)+X+dx,P_Y=(P[j]&0x3)+Y+dy; if(POINT_V[P_X][P_Y]){ if(dx!=0){return 1;} if(dy){ DoBlocks(); Pos(12,3);printf("LEVEL:%-3d",LEVEL); Pos(12,5);printf("SCORE:%-3d",SCORE); return 2; } if(KEY_V==119){FLAG[0]=1;} } } return 0; } /***********循环核心*************/ int GameCycle(int N, int T, int F) { srand((unsigned)time(NULL));RU=rand()%7,RI=(rand()%4); while(1){ if(FLAG[3]){ Display(12,8,Rote(RU,RI),0); X=4,Y=1, NU=RU,NI=RI, RU=rand()%7,RI=(rand()%4), FLAG[3]=0,KEY_V=0; Display(12,8,Rote(RU,RI),1); Display(X, Y,Rote(NU,NI),1); } dx=0,dy=0; KEY_V=Getkey(N,T); if(KEY_V==119){ NI++; Display(X,Y,Rote(NU,NI),2); }//旋W else if(KEY_V==115){dy= 1;}//下S else if(KEY_V==97 ){dx=-1;}//左A else if(KEY_V==100){dx= 1;}//右D else if(KEY_V==112){getch(); }//暂停P else if(KEY_V==113){return 0;}//退出Q if(dx!=0 || dy!=0 || KEY_V==119){ if(!CheckCollision()){ if(FLAG[0]){ NI--,FLAG[0]=0; Display(X,Y,Rote(NU,NI),0); } else if(KEY_V==119){ Display(X,Y,Rote(NU,NI-1),0); }else{ Display(X,Y,Rote(NU,NI),0); } Display(X+dx,Y+dy,Rote(NU,NI),1); X+=dx,Y+=dy; } } } return 0; } /**********Main主函数***********/ int main(char argc, char* argv[]) { if(argc!=4){ printf("参数错误。\n"); return 1; }else{ if (!strcasecmp(argv[3],"TGM")){F=0;} else if(!strcasecmp(argv[3],"SRS")){F=1;} else{return 2;} N=atoi(argv[1]); T=atoi(argv[2]); } HideCursor(); CreatUI(); GameCycle(N,T,F); return 0; }
一一一
一一一
一一一
一一一一一一一一一一一一一一一以下是批处理版本一一一一一一一一一一一一一一一一
[2016/10/4] Version 2.1新修版,修正NEXT下一个图块显示异常。采用16位数据处理,达到或接近C语言的运行速度。打造最快bat俄罗斯方块。- @echo off
- ::**************Happy's俄罗斯方块***********
- REM 使用说明:
- REM A左D右;W旋转;S加速下落;
- REM Q退出;P暂停;方向键继续;
-
- ::**************Settings高级设置************
- REM 设置窗体
- title &setlocal enabledelayedexpansion
- mode con cols=35 lines=25&color F0
- REM 开启防闪烁,用于画质增强
- set F1=1
- REM 设置时钟T, 越小下落越快
- set T=190
- REM 默认皮肤
- set "SKIN= ■"
- REM 设置旋转体系:依次为TGM、SRS(第二代超级形码)
- ::set "SHAPE=0x159D0x89AB0x159D0x89AB0x126A0x48560x159A0x45260x926A0x456A0x15920x04560x48590x48590x48590x48590x59260x01560x59260x01560x41590x45960x15960x41560x156A0x41520x156A0x4152"
- set "SHAPE=0x159D0x89AB0x26AE0x45670x01590x48560x159A0x45260x81590x456A0x15920x04560x48590x48590x48590x48590x48150x459A0x59260x01560x41590x45960x15960x41560x04590x85960x156A0x4152"
-
- ::**************方向控制台******************
- if "%1"=="CONTROLP" (
- title &MODE CON cols=15 lines=1
- for /l %%i in (1,1,100000) do (
- set "KEY="
- for /f "delims=" %%a in ('xcopy /W . 2^>NUL') do (
- if not defined KEY (
- set "KEY=%%a"&set "KEY=!KEY:~-1!"
- echo %%i!KEY!>key.ini&if /i "!KEY!"=="Q" (exit)
- )
- )
- )
- )
- start "" "%~f0" CONTROLP
-
- ::**************先导程序********************
- REM 准备元素
- set/a "LEVEL=1,SCORE=0, RU=!random!%%7,RI=(!random!%%4)*6"
- for /l %%N in (0,24,144) do (set/a "N=%%N/24"&set "SHAPE!N!=!SHAPE:~%%N,24!")
- for /l %%N in (0,1,1 ) do (set "E%%N=!SKIN:~%%N,1!")
- for /l %%N in (1,1,10 ) do (set "LINES=!LINES!━" )
- for /l %%N in (1,1,300 ) do (set "SPACE=!SPACE!" )
-
- REM 构建显存
- :DISPLAY_RAM
- for /l %%j in (0,1,21) do (
- set "#[%%j]=1"
- for /l %%i in (0,1,11) do (
- set/a "BOUNDARY=(%%i)*(%%i-11)*(%%j-21)"
- if !BOUNDARY! equ 0 (set "P[%%i][%%j]=1") else (set "P[%%i][%%j]=0")
- )
- )
-
- ::**************主体程序********************
- REM ~~~随机块体
- :RANDOM_SHAPE
- set/a "NU=RU,NI=RI, RU=!random!%%7,RI=(!random!%%4)*6, X=4,Y=1"
- echo RW>key.ini
-
- REM ~~~计数面板
- set "V1=!LEVEL! "
- set "V2=!SCORE! "
- set "READM[3]=LEVEL:!V1:~0,3!"
- set "READM[5]=SCORE:!V2:~0,3!"
- set "READM[7]=NEXT"
-
- REM ~~~读取按键
- :READKEY
- set/a "Dx=0,Dy=0"
- set/p KEY=<key.ini
- if /i "!KEY:~-1!"=="P" (goto :READKEY)
- if not "!PRE_KEY!"=="!KEY!" (
- set PRE_KEY=!KEY!
- if /i "!KEY:~-1!"=="A" (set "Dx=-1")
- if /i "!KEY:~-1!"=="D" (set "Dx=1" )
- if /i "!KEY:~-1!"=="W" (
- set "Cache=!SHAPE%NU%:~%NI%,6!"
- set/a "Xf=X,NI+=6,NI%%=24"
- REM ~~~16进制超级转码
- for /l %%j in (0,1,3) do (
- set/a "POS[%%j]=Cache&0xF, Cache=Cache>>4" 2>NUL
- )
- if "!KEY!"=="RW" (
- set "Cache2=!SHAPE%RU%:~%RI%,6!"
- for /l %%J in (0,1,3) do (
- set/a "RPOS[%%J]=Cache2&0xF, Cache2=Cache2>>4" 2>NUL
- for /l %%I in (0,1,3) do (
- set "R[%%I][%%J]=0"
- )
- )
- for %%p in (!RPOS[0]!,!RPOS[1]!,!RPOS[2]!,!RPOS[3]!) do (
- set/a "RPOS_X=%%p>>2,RPOS_Y=%%p&0x3"
- set "R[!RPOS_X!][!RPOS_Y!]=1"
- )
- for /l %%J in (0,1,3) do (
- set "TP="
- for /l %%I in (0,1,3) do (
- set "TP=!TP!!R[%%I][%%J]!"
- )
- set "TP=!TP:0=%E0%!"
- set "TP=!TP:1=%E1%!"
- set/a "SN=%%J+8"
- set "READM[!SN!]=!TP!"
- )
- echo WO>key.ini
- for /l %%j in (8,1,11) do (set/a "#[%%j]=1")
- )
- goto :DATA_PROCESSING
- )
- if /i "!KEY:~-1!"=="Q" (exit)
- )
- if /i "!KEY:~-1!"=="S" (set "Dy=1"&goto :DATA_PROCESSING)
-
- REM ~~~下落体系
- if !Mark! equ 0 (
- set "Mark=1"
- set "T1=!time:~9,2!"
- ) else (
- set/a "TS=2!time:~9,2!-1!T1!"
- set/a "TS=1!TS:~-2!"
- if !TS! lss !T! (set "Dy=0") else (set/a "Dy=1,Mark=0")
- )
- if !Dx! equ 0 if !Dy! equ 0 (goto :READKEY)
-
- REM ~~~数据处理
- :DATA_PROCESSING
- SETLOCAL
- for %%p in (!POS[0]!,!POS[1]!,!POS[2]!,!POS[3]!) do (
- set/a "POS_X=(%%p>>2)+X+Dx,POS_Y=(%%p&0x3)+Y+Dy"
- set/a "CHE=P[!POS_X!][!POS_Y!]"
- if !CHE! equ 0 (
- set "P[!POS_X!][!POS_Y!]=1"
- ) else (
- if !Dx! neq 0 (
- ENDLOCAL
- goto :READKEY
- )
- if !Dy! equ 1 (
- ENDLOCAL
- if !Y! lss 2 (
- echo GAME OVER!
- ping -n 2 127.1>NUL
- goto :DISPLAY_RAM
- )
- REM ~~~固化块体
- set "POS_Y_MAX=0"
- for %%P in (!POS[0]!,!POS[1]!,!POS[2]!,!POS[3]!) do (
- set/a "POS_X=(%%P>>2)+X,POS_Y=(%%P&0x3)+Y"
- if !POS_Y_MAX! lss !POS_Y! (set "POS_Y_MAX=!POS_Y!")
- set "P[!POS_X!][!POS_Y!]=1"
- )
- REM ~~~关卡得分
- for /l %%J in (!Y!,1,!POS_Y_MAX!) do (
- set "TP="
- for /l %%I in (1,1,10) do (
- set "TP=!TP!!P[%%I][%%J]!"
- )
- if "!TP!"=="1111111111" (
- set/a "SCORE+=10"
- set "#%%J=1"
- if !SCORE! equ 400 (
- for /l %%N in (!Y!,1,!POS_Y_MAX!) do (set "#%%N=")
- set/a "SCORE=0,LEVEL+=1,T-=10"
- goto :DISPLAY_RAM
- )
- )
- )
- REM ~~~极品消行
- for /l %%J in (20,-1,5) do (
- if defined #%%J (
- set "#%%J="
- set/a "MarkJ=%%J-1, GK=1"
- for /l %%N in (1,1,3) do (
- if defined #!MarkJ! (set/a "MarkJ-=1")
- )
- set "#!MarkJ!=1"
- for /l %%I in (1,1,10) do (
- set/a "P[%%I][%%J]=P[%%I][!MarkJ!]"
- )
- )
- )
- if defined GK (for /l %%J in (20,-1,5) do (set "#[%%J]=1")&set "GK=")
- goto :RANDOM_SHAPE
- )
- if /i "!KEY:~-1!"=="W" (
- ENDLOCAL
- echo OW>key.ini
- set/a "NI=(NI+12)%%24"
- goto :READKEY
- )
- )
- )
-
- REM ~~~绘图引擎
- if !F1! equ 1 (2>NUL echo !SPACE!&set/p=<NUL) else (cls)
- echo ┏%LINES%┓
- for /l %%j in (0,1,5) do (set/a "MARK_Y=Y+%%j,#[!MARK_Y!]=1")
- for /l %%j in (1,1,20) do (
- if not defined #[%%j] (
- echo;
- ) else (
- set "TP="
- for /l %%i in (1,1,10) do (set "TP=!TP!!P[%%i][%%j]!")
- set "TP=!TP:1=%E1%!"
- set "TP=!TP:0=%E0%!"
- echo ┃!TP!┃!READM[%%j]!
- )
- )
- echo ┗%LINES%┛
- echo CopyRight@2016~2018 BY HAPPY
- ENDLOCAL&for /l %%j in (1,1,20) do (set "#[%%j]=")
- set/a "X+=Dx,Y+=Dy"
- goto :READKEY
复制代码 一一一
一一一
一一一
一一一
一一一一一一一一一一一一一一一以下是过去的旧版本一一一一一一一一一一一一一一一一
[2016/10/3] Version 1.0初版- @echo off
- ::**************Happy's俄罗斯方块***********
- REM 使用说明:
- REM A左D右;W旋转;S加速下落;
- REM Q退出;P暂停;方向键继续;
-
- ::**************Settings高级设置************
- REM 设置窗体
- title &setlocal enabledelayedexpansion
- mode con cols=35 lines=25&color F0
- REM 开启防闪烁,用于画质增强
- set F1=1
- REM 设置时钟T, 越小下落越快
- set T=130
- REM 默认皮肤
- set "SKIN= ■"
- REM 设置旋转体系:依次为TGM、SRS
- ::set "SHAPE=0x0F000x22220x0F000x22220x08E00x64400x0E200x44C00x02E00x44600x0E800xC4400x66000x66000x66000x66000x06C00x8C400x06C00x8C400x4E000x46400x0E400x4C400x0C600x4C800x0C600x4C80"
- set "SHAPE=0x0F000x22220x00F00x44440x8E000x64400x0E200x44C00x2E000x44600x0E800xC4400x66000x66000x66000x66000x6C000x46200x06C00x8C400x4E000x46400x0E400x4C400xC6000x26400x0C600x4C80"
-
- ::**************方向控制台******************
- if "%1"=="CONTROLP" (
- title &MODE CON cols=15 lines=1
- for /l %%i in (1,1,100000) do (
- set "key="
- for /f "delims=" %%a in ('xcopy /W . 2^>NUL') do (
- if not defined key (
- set "key=%%a"&set "key=!key:~-1!"
- echo %%i!key!>key.ini&if /i "!key!"=="Q" (exit)
- )
- )
- )
- )
- start "" "%~f0" CONTROLP
-
- ::**************先导程序********************
- REM 准备元素
- set/a "LEVEL=1,SCORE=0, RU=!random!%%7,RI=(!random!%%4)*6"
- for /l %%N in (0,24,144) do (set/a "N=%%N/24"&set "SHAPE!N!=!SHAPE:~%%N,24!")
- for /l %%N in (0,1,1 ) do (set "P%%N=!SKIN:~%%N,1!")
- for /l %%N in (1,1,10 ) do (set "LINES=!LINES!━" )
- for /l %%N in (1,1,300 ) do (set "SPACE=!SPACE!" )
-
- REM 构建显存
- :DISPLAY_RAM
- for /l %%j in (0,1,21) do (
- set "#[%%j]=1"
- for /l %%i in (0,1,11) do (
- set/a "BOUNDARY=(%%i)*(%%i-11)*(%%j-21)"
- if !BOUNDARY! equ 0 (set "POINT[%%i][%%j]=1") else (set "POINT[%%i][%%j]=0")
- )
- )
-
- ::**************主体程序********************
- REM ~~~随机块体
- :RANDOM_SHAPE
- set/a "NU=RU,NI=RI, RU=!random!%%7,RI=(!random!%%4)*6, X=4,Y=1"
- echo RW>key.ini
-
- REM ~~~计数面板
- set "READM[3]=LEVEL:!LEVEL!"
- set "READM[5]=SCORE:!SCORE!"
- set "READM[7]=NEXT :"
-
- REM ~~~读取按键
- :READKEY
- set/a "dx=0,dy=0"&set/p key=<key.ini
- if /i "!key:~-1!"=="P" (goto :READKEY)
- if not "!PRE_KEY!"=="!key!" (
- set PRE_KEY=!key!
- if /i "!key:~-1!"=="A" (set "dx=-1")
- if /i "!key:~-1!"=="D" (set "dx=1" )
- if /i "!key:~-1!"=="W" (
- set "Cache=!SHAPE%NU%:~%NI%,6!"
- set/a "Xf=X,NI+=6,NI%%=24"
- if "!key!"=="RW" (set "Cache2=!SHAPE%RU%:~%RI%,6!")
- REM ~~~16进制旋转
- for /l %%j in (3,-1,0) do (
- set/a "DIV[3][%%j]=(Cache&0x1), DIV[2][%%j]=(Cache&0x2)>>0x1, DIV[1][%%j]=(Cache&0x4)>>0x2, DIV[0][%%j]=(Cache&0x8)>>0x3, Cache=Cache>>0x4"
- if "!key!"=="RW" (
- set/a "RDIV[3][%%j]=(Cache2&0x1), RDIV[2][%%j]=(Cache2&0x2)>>0x1, RDIV[1][%%j]=(Cache2&0x4)>>0x2, RDIV[0][%%j]=(Cache2&0x8)>>0x3, Cache2=Cache2>>0x4, RDI=%%j+8"
- set "RDISPLAY[%%j]=!RDIV[0][%%j]!!RDIV[1][%%j]!!RDIV[2][%%j]!!RDIV[3][%%j]!"
- set "RDISPLAY[%%j]=!RDISPLAY[%%j]:1=%P1%!"&set "READM[!RDI!]=!RDISPLAY[%%j]:0=%P0%!"
- )
- )
- if "!key!"=="RW" (echo WO>key.ini)
- goto :DATA_PROCESSING
- )
- if /i "!key:~-1!"=="Q" (exit)
- )
- if /i "!key:~-1!"=="S" (set "dy=1"&goto :DATA_PROCESSING)
-
- REM ~~~下落体系
- if !Mark! equ 0 (
- set "Mark=1"
- set "T1=!time:~9,2!"
- ) else (
- set/a "TS=2!time:~9,2!-1!T1!"
- set/a "TS=1!TS:~-2!"
- if !TS! lss !T! (set "dy=0") else (set/a "dy=1,Mark=0")
- )
- if !dx! equ 0 if !dy! equ 0 (goto :READKEY)
-
- REM ~~~数据处理
- :DATA_PROCESSING
- set/a "CYC=Y+4"
- SETLOCAL
- for /l %%j in (!Y!,1,!CYC!) do (
- set "#[%%j]=1"
- set "DISPLAY[%%j]="
- for /l %%i in (0,1,11) do (
- set/a "XV=%%i-X-dx,YV=%%j-Y-dy"
- if defined DIV[!XV!][!YV!] (
- set/a "CHE1=DIV[!XV!][!YV!]&POINT[%%i][%%j],CHE2=DIV[!XV!][!YV!]|POINT[%%i][%%j]"
- if !CHE1! equ 0 (
- set "POINT[%%i][%%j]=!CHE2!"
- ) else (
- if !dx! neq 0 (
- ENDLOCAL
- goto :READKEY
- )
- if !dy! equ 1 (
- ENDLOCAL
- if !Y! lss 4 (goto GAME_OVER)
- REM ~~~固化块体
- for /l %%J in (!CYC!,-1,!Y!) do (
- set "DISPLAY[%%J]="
- for /l %%I in (1,1,10) do (
- set/a "XV=%%I-X,YV=%%J-Y"
- if defined DIV[!XV!][!YV!] (
- set/a "POINT[%%I][%%J]=DIV[!XV!][!YV!]|POINT[%%I][%%J]"
- )
- set "DISPLAY[%%J]=!DISPLAY[%%J]!!POINT[%%I][%%J]!"
- )
- REM ~~~关卡得分
- if %%J leq 20 if "!DISPLAY[%%J]!"=="1111111111" (
- set/a "SCORE+=10"&set "#%%J=1"
- if !SCORE! equ 400 (
- for /l %%n in (!CYC!,-1,!Y!) do (set "#%%n=")
- set/a "SCORE=0,LEVEL+=1,T-=10"
- goto :DISPLAY_RAM
- )
- )
- )
- REM ~~~极品消行
- for /l %%J in (20,-1,5) do (
- if defined #%%J (
- set "#%%J="
- set/a "PJ=%%J-1"
- for /l %%n in (1,1,3) do (
- if defined #!PJ! (set/a "PJ-=1")
- )
- set "#!PJ!=1"
- for /l %%I in (1,1,10) do (
- set/a "POINT[%%I][%%J]=POINT[%%I][!PJ!]"
- )
- )
- set "#[%%J]=1"
- )
- goto :RANDOM_SHAPE
- )
- if /i "!key:~-1!"=="W" (
- ENDLOCAL
- echo OW>key.ini
- set/a "NI=(NI+12)%%24"
- goto :READKEY
- )
- )
- )
- )
- )
-
- REM ~~~绘图引擎
- if !F1! equ 1 (2>NUL echo !SPACE!&set/p=<NUL) else (cls)
- echo ┏%LINES%┓
- for /l %%j in (1,1,20) do (
- if defined #[%%j] (
- set "#[%%j]="
- set "DISPLAY[%%j]="
- for /l %%i in (1,1,10) do (set "DISPLAY[%%j]=!DISPLAY[%%j]!!POINT[%%i][%%j]:1=%P1%!")
- echo ┃!DISPLAY[%%j]:0=%P0%!┃!READM[%%j]!
- ) else (echo;)
- )
- echo ┗%LINES%┛
- echo CopyRight@2016~2018 BY HAPPY&ENDLOCAL&set/a "X+=dx,Y+=dy"
- goto :READKEY
-
- REM ~~~游戏结束
- :GAME_OVER
- echo GAME OVER!&ping -n 2 127.1>NUL&goto :DISPLAY_RAM
复制代码
|