Introduction: Batch Game: Slide Puzzle

Picture of 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

Comments

Mister Tech Guy made it! (author)2016-07-13

Amazing!

Neroitech Inventions (author)2014-10-17

cool

skuxxinit (author)2014-04-16

nice Gwalin

Gwalin (author)skuxxinit2014-04-17

Thx skuxxinit

rimar2000 (author)2014-04-09

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).

Gwalin (author)rimar20002014-04-10

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.

rimar2000 (author)Gwalin2014-04-10

Yes, it works fine now. Congratulations, it is very clever and well done.

About This Instructable

1,519views

14favorites

License:

More by Gwalin:Batch Game: DodgemsBatch Game: Slide PuzzleBatch Number Organiser
Add instructable to: