Batch Game: Slide Puzzle

Intro: 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

Share

Recommendations

  • Metalworking Contest

    Metalworking Contest
  • Furniture Contest 2018

    Furniture Contest 2018
  • Audio Contest 2018

    Audio Contest 2018

6 Discussions

0
None
rimar2000

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

2 replies
0
None
Gwalinrimar2000

Reply 4 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.