Coding Global Background
Coding Global

game error!! (batch)

Archived 3 years ago
1 messages
0 members
3 years ago
Open in Discord
C
Deleted user
Copy Paster!

@echo off title Snake color 0a set display_width=40 set display_height=20 set snake_length=3 set snake_symbol=O set apple_symbol=X set direction=right set "snake=0 0 0" set "apple=%random% %random%" :main_loop cls for /f "tokens=1,2 delims= " %%a in ("%apple%") do ( set /a "x=%%a %% %display_width%" set /a "y=%%b %% %display_height%" set "apple_pos=%x% %y%" ) for /f "tokens=1,2 delims= " %%a in ("%apple_pos%") do ( set /a "x=%%a" set /a "y=%%b" set "display[%y%][%x%]=%apple_symbol%" ) setlocal enabledelayedexpansion set idx=0 for /f "tokens=1,2 delims= " %%a in (%snake%) do ( set /a "x=%%a" set /a "y=%%b" set "display[!y!][!x!]=%snake_symbol%" set /a idx+=1 if !idx! leq %snake_length% ( set "snake_tail[!idx!]=!x! !y!" ) ) if "%direction%" == "up" ( set /a "y=%y%-1" ) else if "%direction%" == "down" ( set /a "y=%y%+1" ) else if "%direction%" == "left" ( set /a "x=%x%-1" ) else if "%direction%" == "right" ( set /a "x=%x%+1" ) set "snake=%x% %y% %snake%" if "%snake%" == "%apple_pos% %snake%" ( set "apple=%random% %random%" set /a "snake_length+=1" ) for /l %%i in (1,1,%display_height%) do ( for /l %%j in (1,1,%display_width%) do ( set "display[%%i][%%j]=" ) ) for /l %%i in (0,1,%display_height%) do ( set "display[%%i][0]=#" set "display[%%i][%display_width%]=#" ) for /l %%i in (0,1,%display_width%) do ( set "display[0][%%i]=#" set "display[%display_height%][%%i]=#" ) for /l %%i in (1,1,%display_height%) do ( for /l %%j in (1,1,%display_width%) do ( echo(!display[%%i][%%j]! )

Replies (1)