Introduction: Batch Game: Slide Puzzle
Here i have made a classic slide puzzle game in batch. Use the wasd keys to move the pieces and r to reset it. Please leave comments or suggestions of what else i could make in batch below.
Step 1: The Code
@echo off
title Slide Puzzle
setlocal enabledelayedexpansion
set default= %
set pos=9
set loop=1
:reset
set slide1=1
set slide2=7
set slide3=3
set slide4=5
set slide5=8
set slide6=4
set slide7=2
set slide8=6
set slide9=%default%
set pos=9
:display
cls
echo ____ ____ ____
echo ^| ^| ^| ^|
echo ^| %slide1% ^| %slide2% ^| %slide3% ^|
echo ^|____^|____^|____^|
echo ^| ^| ^| ^|
echo ^| %slide4% ^| %slide5% ^| %slide6% ^|
echo ^|____^|____^|____^|
echo ^| ^| ^| ^|
echo ^| %slide7% ^| %slide8% ^| %slide9% ^|
echo ^|____^|____^|____^|
choice /c wasdr /n
if %errorlevel% == 1 goto movew
if %errorlevel% == 2 goto movea
if %errorlevel% == 3 goto moves
if %errorlevel% == 4 goto moved
if %errorlevel% == 5 goto reset
:movew
if %pos% GEQ 7 goto display
set /a helper=%pos% + 3
set /a slide%pos%=!slide%helper%!
set slide%helper%=%default%
set /a pos=%pos% + 3
goto display
:movea
if %pos% == 3 goto display
if %pos% == 6 goto display
if %pos% == 9 goto display
set /a helper=%pos% + 1
set /a slide%pos%=!slide%helper%!
set slide%helper%=%default%
set /a pos=%pos% + 1
goto display
:moves
if %pos% LEQ 3 goto display
set /a helper=%pos% - 3
set /a slide%pos%=!slide%helper%!
set slide%helper%=%default%
set /a pos=%pos% - 3
goto display
:moved
if %pos% == 1 goto display
if %pos% == 4 goto display
if %pos% == 7 goto display
set /a helper=%pos% - 1
set /a slide%pos%=!slide%helper%!
set slide%helper%=%default%
set /a pos=%pos% - 1
goto display
1 Person Made This Project!
- Professor Dragon made it!
7 Comments
4 months ago
Smart game. This is going to help me with my program.
7 years ago on Introduction
cool
8 years ago on Introduction
nice Gwalin
Reply 8 years ago on Introduction
Thx skuxxinit
8 years ago on Introduction
I can't make it work. At first the echoes was erroneous, I fixed them but after this the .bat aborts saying "missing operator" (really "falta el operador", my DOS is Spanish).
Reply 8 years ago on Introduction
Hi rimar2000, I've looked though the code and it seems that when I published it it messed with the program. So ive fixed it and it should be working fine now.
Reply 8 years ago on Introduction
Yes, it works fine now. Congratulations, it is very clever and well done.