Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- if "%~1" neq "" goto %~1
- call :canvas 60 30
- :: generate ball
- set /a "bx=30", "by=15", "bi=!random! %% 2 + 1", "bj=!random! %% 2 + 1"
- :: generate self
- set /a "ml=6"
- set /a "mx=1", "my=11", "myl=my + ml"
- "%~F0" Input >out.txt | "%~F0" Engine <out.txt
- goto :eof
- :Engine
- for /l %%# in () do (
- set /p "com="
- if /i "!com!" equ "W" if !my! geq 0 set /a "my-=1"
- if /i "!com!" equ "S" if !myl! leq %height% set /a "my+=1"
- set /a "bx+=bi"
- set /a "by+=bj"
- set /a "myl=my + ml"
- rem Bounce off top, bottom, and right walls
- if !bx! geq %width% set /a "bx=width", "bi*=-1"
- if !by! geq %height% set /a "by=height", "bj*=-1"
- if !by! leq 0 set /a "by=0", "bj*=-1"
- rem Detect if we miss the ball
- if !bx! lss 0 (
- if !points! gtr 0 set /a "points-=1"
- set /a "bx=30", "by=15"
- set /a "bi=!random! %% 2 + 1", "bj=!random! %% 2 + 1"
- )
- rem Detect if we hit the ball
- if !bx! equ %mx% if !by! geq !my! if !by! leq !myl! (
- set /a "points+=2", "bi*=-1"
- )
- rem This is ball!
- call :plot !bx! !by! O
- rem This is me!
- call :plotLine %mx% !my! %mx% !myl!
- call :showCanvas
- call :updateCanvas
- echo=W - Move up S - Move Down Points = !points!
- )
- exit /b
- :Input
- for /f "tokens=*" %%a in ('choice /c:ws /n') do echo %%a
- goto :Input
- :canvas
- @echo off
- set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
- call :cursorpos
- for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- call :updateCanvas
- mode con: cols=%conWidth% lines=%conHeight%
- goto :eof
- :updateCanvas
- set "_=-1"
- for /l %%a in (0,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
- set "_="
- goto :eof
- :showCanvas
- "%temp%\cursorpos.exe" 0 0
- echo=%outerBuffer%
- for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
- echo=%outerBuffer%
- goto :eof
- goto :eof
- :plot x y
- setlocal
- set /a "_x2=%~1 + 1"
- (endlocal
- set "_[%~2]=!_[%~2]:~0,%~1!%~3!_[%~2]:~%_x2%!"
- )
- goto :eof
- :plotLine x0 y0 x1 y1
- set /a "x0=%~1", "y0=%~2", "x1=%~3", "y1=%~4", "dx=x1 - x0", "dy=y1 - y0"
- if %dy% lss 0 ( set /a "dy=-dy", "stepy=-1" ) else ( set /a "stepy=1")
- if %dx% lss 0 ( set /a "dx=-dx", "stepx=-1" ) else ( set /a "stepx=1")
- set /a "dx<<=1", "dy<<=1"
- if %dx% gtr %dy% (
- set /a "fraction=dy - (dx >> 1)"
- for /l %%x in (%x0%,%stepx%,%x1%) do (
- if !fraction! geq 0 (
- set /a "y0+=stepy"
- set /a "fraction-=dx"
- )
- set /a "fraction+=dy"
- if 0 leq %%x if %%x lss %width% if 0 leq !y0! if !y0! lss %width% (
- call :plot %%x !y0! "|"
- )
- )
- ) else (
- set /a "fraction=dx - (dy >> 1)"
- for /l %%y in (%y0%,%stepy%,%y1%) do (
- if !fraction! geq 0 (
- set /a "x0+=stepx"
- set /a "fraction-=dy"
- )
- set /a "fraction+=dx"
- if 0 leq !x0! if !x0! lss %width% if 0 leq %%y if %%y lss %width% (
- call :plot !x0! %%y "|"
- )
- )
- )
- for %%a in (x0 y0 x1 y1 dx dy stepx stepy fraction) do set "%%a="
- goto :eof
- :cursorpos
- if not exist "%temp%\cursorpos.exe" (
- for %%a in (
- "TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAsAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v"
- "dCBiZSBydW4gaW4gRE9TI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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAG4gAACMIAAAnCAAALogAADWIAAAYCAAAAAAAABEIAAA"
- "AAAAAAAAAADoIAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAbiAAAIwgAACcIAAA"
- "uiAAANYgAABgIAAAAAAAAJsARXhpdFByb2Nlc3MA9QBHZXRDb25zb2xlU2NyZWVu"
- "QnVmZmVySW5mbwAAagFHZXRTdGRIYW5kbGUAADgCUmVhZENvbnNvbGVPdXRwdXRD"
- "aGFyYWN0ZXJBAG0CU2V0Q29uc29sZUN1cnNvclBvc2l0aW9uAADmAEdldENvbW1h"
- "bmRMaW5lQQBrZXJuZWwzMi5kbGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
- ) do echo %%~a>>cursorpos.txt
- certutil -decode cursorpos.txt %temp%\cursorpos.exe
- del /f /a cursorpos.txt
- )
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement