Wednesday, November 17, 2010

Batch game - Splat the rat source code

@echo off
if /i "%1"=="Attrib" (
goto checkhighscore.txt
)
if /i "%1"=="Countermode" (
goto countermode
)
title Splat-The-Rat
setlocal enabledelayedexpansion
for %%I in (%0) do set filename=%%~sI
if exist highscore.txt (
start /MIN CMD.exe /c "%FILENAME% Attrib"
)
if exist info.dat del info.dat
:menu
title Splat-The-Rat
cls
echo Main Menu
echo ---------
echo.
echo To play a game, enter 1
echo For instructions, enter 2
echo For Highscores, enter 3
echo To exit, enter 4
set menu=
set /p menu=""
if not defined menu goto menu
if %menu%==1 (goto startgame)
if %menu%==2 (goto instructions)
if %menu%==3 (goto Displayscores)
if %menu%==4 (exit /b)
goto menu

:checkhighscore.txt
attrib highscore.txt | find "SHR" >nul
if %errorlevel%==0 (exit)
attrib highscore.txt +S +H +R
exit

:instructions
cls
echo Splat The Rat
echo -------------
echo The aim of the game is to hit the rat with your club as soon as it
echo pops out of its hole. You can try hitting the rat
echo with the quickest reaction time, or hit as many rats in a row as
echo possible. Your score is recorded in the same directory as the game
echo file.
echo.
echo.
echo Press any key for the next page
pause>nul
cls
echo Splat The Rat
echo -------------
echo As soon as you start the game one extra window will appear, titled
echo 'Rat Window' this window shows the activity of the rat. As soon as
echo the window appears it should be dragged away from the original
echo Bat Window to allow you to see both. You should then click on the
echo Bat Window to allow you to use your bat.
echo.
echo.
echo Press any key for the next page
pause>nul
cls
echo Splat The Rat
echo -------------
echo To hit the rat, have the Bat Window selected, and press any key as soon
echo as you see the rat appear on the Rat Window.
echo.
echo.
echo Press any key to go to the main menu.
pause>nul
goto menu


:displayscores
cls
if not exist highscore.txt (
echo No high scores yet.
echo.
echo Press any key to return to menu
pause>nul
goto menu
)
find /i "Fastest-Single-Reaction=" Highscore.txt >nul
set count=%errorlevel%
find /i "Most-Rats-Hit=" Highscore.txt >nul
set /a count= %count% + %errorlevel%
find /i "Best-Average-Reaction=" Highscore.txt >nul
set /a count= %count% + %errorlevel%
if %count%==3 (
echo High Score File Incorrect
echo.
echo Press any key to return to menu
pause>nul
goto menu
)
echo High Scores
echo -----------
echo.
type highscore.txt | find /i "fastest-Single-Reaction"
type highscore.txt | find /i "Most-Rats-Hit"
type highscore.txt | find /i "Best-Average-Reaction"
echo.
echo.
echo Press any key to return to menu
pause>nul
goto menu



:startgame
title Bat Window
cls
set fastestreaction=999
set SN=0
set totalmil=0
set offset=10
echo nul >info.dat
start cmd /c "%filename% Countermode"
Echo Move the Rat window so you can see both windows, then click
echo this window.
echo.
echo Press any key to begin the game
pause>nul
echo START >info.dat
cls
echo Press Any Key To Swing Your Bat!
Pause>nul
set swingtime=%time:~2%
echo Y%SN%-%swingtime% >>info.dat


:result
find /i "w%SN%" info.dat >nul
if %errorlevel%==0 (
cls
set /a sn= %SN% + 1
goto Swingagain
)
find /i "l" info.dat >nul
if %errorlevel%==0 (
cls
echo Game Over
goto gotresult
)
goto result

:swingagain
echo Good Hit
if %sn%==1 (
echo Got 1 rat so far
) else (
echo Got %sn% rats so far
)

:processreactiontime
if %sn% geq 11 set offset=11
if %sn% geq 101 set offset=12
set x=1
for /f %%A in (info.dat) do set data=%%A & call :Setswingtime
set x=1
for /f %%A in (info.dat) do set data=%%A & call :Setfalltime
set /a CFN= ( %sn% * 3 ) - 1
set /a CSN= %sn% * 3
set truefalltime=!falltime%CFN%!
set truefalltime=!truefalltime:~%offset%,2!
set trueswingtime=!swingtime%CSN%!
set trueswingtime=!trueswingtime:~%offset%,2!
if /i %trueswingtime%==08 (
set trueswingtime=8
)
if /i %trueswingtime%==09 (
set trueswingtime=9
)
if /i %truefalltime%==08 (
set truefalltime=8
)
if /i %truefalltime%==09 (
set truefalltime=9
)
set /a reactionmil= %trueswingtime% - %truefalltime%
if /i %reactionmil% lss 0 (
set /a reactionmil= %reactionmil% + 100
)
if /i %reactionmil% leq 9 (
echo Your reaction time was 0.0%reactionmil% Seconds
) else (
echo Your reaction time was 0.%reactionmil% Seconds
)
goto continueswingagain

:setswingtime
set Swingtime%x%=%data%
set /a x= %x% + 1
exit /b

:setfalltime
set falltime%x%=%data%
set /a x= %x% + 1
exit /b

:continueswingagain
echo.
echo Press Any Key To Swing Your Bat
pause>nul
set swingtime=%time:~2%
echo Y%SN%-%swingtime% >>info.dat
set /a totalmil= %totalmil% + %reactionmil%
if not defined fastestreaction (set fastestreaction=%reactionmil%)
if /i %fastestreaction% gtr %reactionmil% (
set fastestreaction=%reactionmil%
)
goto result


:Gotresult
if %sn% equ 0 (
echo Sorry, you didn't get any rats
goto moreresults
)
if %sn% equ 1 (
echo Sorry, you only got one rat
goto Moreresults
)
if /i %sn% leq 3 (
echo Sorry, you only got %sn% rats
) else (
echo Well done, you got %sn% rats
)
:moreresults
find /i info.dat "LL" >nul
if /i %errorlevel% equ 0 (
Echo On that last one, you were too slow, he got away.
) else (
echo On that last one, you swung too soon.
)
IF %sn%==0 goto end
:processrats
set /a averagetime= %totalmil% / %sn%
echo You got %sn% rats
echo Your average reaction time was 0.%averagetime% seconds
if /i %fastestreaction% leq 9 (
echo Your reaction time was 0.0%fastestreaction% Seconds
) else (
echo Your reaction time was 0.%fastestreaction% Seconds
)
if not exist highscore.txt goto noscorelist
goto scorelistexists

:noscorelist
set most=1
set best=1
set fastest=1
goto changescore

:scorelistexists
set most=
set fastest=
set best=
find /i "Most-Rats-Hit" Highscore.txt >nul
if /i NOT %errorlevel% equ 0 (
set Most=1
)
find /i "Fastest-Single-Reaction" Highscore.txt >nul
if /i NOT %errorlevel% equ 0 (
set Fastest=1
)
find /i "Best-Average-reaction" Highscore.txt >nul
if /i NOT %errorlevel% equ 0 (
set Best=1
)
goto Mustcompare

:Mustcompare
for /f %%A in (highscore.txt) do set data=%%A & call :RHset
set sorted=
for /f %%A in (highscore.txt) do set data=%%A & call :BAset
set sorted=
for /f %%A in (highscore.txt) do set data=%%A & call :FRset
set sorted=
set oldRH=%oldRH:~20%
set oldBA=%oldBA:~30,2%
set oldFR=%oldFR:~32,2%
goto comparetime

:rhset
set variable=OldRH
set keyword=Most
call :sortvariables
exit /b

:baset
set variable=OldBA
set keyword=Best
call :sortvariables
exit /b

:frset
set variable=OldFR
set keyword=Fastest
call :sortvariables
exit /b

:sortvariables
if defined sorted (goto endsortvariables)
set %variable%=%data%
echo !%variable%! | find /i "%keyword%" >nul
if NOT errorlevel 1 (
set sorted=1
) else (
set %variable%=
)
:endsortvariables
exit /b

:comparetime
if defined fastest goto alreadyfastest
if /i %fastestreaction% lss %oldfr% (
set fastest=1
)
:alreadyfastest
if defined Most goto alreadymost
if /i %oldRH% lss %SN% (
set Most=1
)
:alreadymost
if defined best goto alreadybest
if /i %averagetime% lss %OldBA% (
set Best=1
)
:alreadybest
if defined best goto Changescore
if defined most goto Changescore
if defined fastest goto Changescore
goto end

:changescore
echo.
Echo New High Score!
echo ---------------
echo New Score In:
echo.
if defined most (
echo Most Rats Hit
)
if defined best (
echo Best Average Time
)
if defined fastest (
echo Fastest Single Reaction
)
echo.
set initials=
echo Please Enter Your Initials (3 Characters Maximum)
set /p initials=""
IF NOT defined initials (
cls
goto changescore
)
if "%initials:~1%"=="" (
set initials=%initials%--
)
if "%initials:~2%"=="" (
set initials=%initials%-
)
set initials=%initials:~0,3%

if defined most goto editmost
goto checkeditbest

:editmost
if /i %fastestreaction% leq 9 (
set fastestreaction=0%fastestreaction%
)
if exist highscore.txt (
type highscore.txt | find /i /v "most-rats-hit" >Highscore
attrib highscore.txt -s -h -r
type highscore >Highscore.txt
attrib highscore.txt +s +h +r
del highscore
attrib highscore.txt -s -h -r
echo %initials%---Most-Rats-Hit=%sn% >>Highscore.txt
attrib highscore.txt +s +h +r
) else (
echo %initials%---Most-Rats-Hit=%sn% >>Highscore.txt
attrib highscore.txt +s +h +r
)

:checkeditbest
if defined best goto editbest
goto checkeditfastest

:editbest
if exist highscore.txt (
type highscore.txt | find /i /v "best-average-reaction" >Highscore
attrib highscore.txt -s -h -r
type highscore >Highscore.txt
attrib highscore.txt +s +h +r
del highscore
attrib highscore.txt -s -h -r
echo %initials%---Best-Average-Reaction=0.%averagetime% >>Highscore.txt
attrib highscore.txt +s +h +r
) else (
echo %initials%---Best-Average-Reaction=0.%averagetime% >>Highscore.txt
attrib highscore.txt +s +h +r
)

:checkeditfastest
if defined fastest goto editfastest
goto scoresedited

:editfastest
if exist highscore.txt (
type highscore.txt | find /i /v "Fastest-Single-Reaction" >Highscore
attrib highscore.txt -s -h -r
type highscore >Highscore.txt
attrib highscore.txt +s +h +r
del highscore
attrib highscore.txt -s -h -r
echo %initials%---Fastest-Single-Reaction=0.%fastestreaction% >>Highscore.txt
attrib highscore.txt +s +h +r
) else (
echo %initials%---Fastest-Single-Reaction=0.%fastestreaction% >>Highscore.txt
attrib highscore.txt +s +h +r
)

:Scoresedited
echo Scores Saved
echo.
goto end


:end
del info.dat
pause>nul

:playagain
echo Go to menu? (Y/N)
:playagain1
set choice=
set /p choice=""
if /i "%choice:~0,1%"=="Y" (
goto menu
)
if /i "%choice:~0,1%"=="N" (
exit /b
)
goto playagain


::###################################################################

:COUNTERMODE
@echo off
color f0
title Rat Window
setlocal enabledelayedexpansion
echo Move this window so you can see both windows.
echo Have the Bat window selected and press any key to begin the game
:waittostart
type info.dat | find /i "start" >nul
if %errorlevel%==0 (goto TimeTostart) else (goto waittostart)
:TimeToStart
set timestart=%time:~2%
echo X%timestart% >info.dat
set SN=-1
set w=0
cls
goto timesetup


:1
find info.dat "Y%sn%" >nul
if %errorlevel%==0 goto stop
if /i %time:~6,2% equ %timechange% goto ShowRat
goto noRats

:ShowRat
set ztime%sn%=Z%sn%-%time:~2%
cls
call :showrat
set w=1
set timechange=CHANGE_DONE
echo !ztime%sn%! >>info.dat

:noRats
if /i %time:~6,2% equ %timeback% (
cls
call :norat
echo.
echo You missed the rat!
echo Swing your bat to end the game.
set w=0
set timeback=CHANGE_DONE
set L=L
)
goto 1

:STOP
if /i %w%==1 (
echo W%sn% >>info.dat
) else (
echo L%L% >>info.dat
exit /b
)

:Timesetup
cls
call :norat
set w=0
set /a sn= %sn% + 1
set timestart=%time:~2%
set timechange=%timestart:~4,2%
if /i %timechange% equ 08 (set timechange=8)
if /i %timechange% equ 09 (set timechange=9)
set /a timechange= %timechange% + 2 + %random:~1,1%
if %timechange% geq 60 (
set /a timechange= %timechange% - 60
)
set /a timeback= %timechange% + 1
if %timeback% geq 60 (
set /a timeback=%timeback% - 60
)
if /i %timechange% equ 8 (
set timechange=08
)
if /i %timechange% equ 9 (
set timechange=09
)
if /i %timeback% equ 8 (
set timeback=08
)
if /i %timeback% equ 9 (
set timeback=09
)

goto 1


:NORAT
echo __ __ __ __ __ __ __ __ __
echo [__][__][__][__][__][__][__][__][__]
echo _][__][__][__][__][__][__][__][__][_
echo [__][__][__][__][__][__][__][__][__]
echo _][__][__][__][__][__][__][__][__][_
echo [__][__][__][__][__][__][__][__][__]
echo _][__][__][__][__][__][__][__][__][_
echo [__][__][__][__][__][__][__][__][__]
echo ____________________________________
exit /b

:showrat
echo __ __ __ __ __ __ __ __ __
echo [__][__][__][__][__][__][__][__][__]
echo _][__][__][__][__][__][__][__][__][_
echo [__][__][__] __ __ _][__][__][__]
echo _][__][__] (_.)__(._) __][__][__][_
echo [__][__][__] (- -) _][__][__][__]
echo _][__][__][ --{()}-- [__][__][__][_
echo [__][__][__] (____) _][__][__][__]
echo ______________''__''________________
exit /b

Sunday, November 7, 2010

Batch game - Connect four (Source Code)

@echo off
title Connect Four By Mastahhaxor
color 1A
:titlescreen
color 0A
cls
Echo.
Echo.
Echo *************************************************
Echo.
Echo ##### # #
Echo # # # #
Echo # ## ## ## #### ### ### #####
Echo # # # # # # # # # # #
Echo ##### ## # # # # #### ### # #
Echo.
Echo *************************************************
Echo.
Echo By Mastahhaxor
Echo.
Echo.
Echo 1)Play Game
Echo 2)Instructions
Echo.
Echo.
set /p choice=
If %choice% EQU 1 goto superstart else goto titlescreen
If %choice% EQU 2 goto Instruct
:instruct
cls
Echo.
Echo.
Echo The goal of this game is to get four of your pieces in a row.
Echo in any direction. To choose a column to place your piece in
Echo type in the letter that corresponds with it (lowercase only).
Echo You must stack pieces in each column so the bottom will always
Echo fill up first. Enjoy! By the way, I do not claim to own Connect Four,
Echo this is just my representation of it.
Echo.
Echo.
pause
goto :superstart

:superstart
color 0E
cls
Echo.
Echo.
Echo Who will play X's?
Echo.
set /p xs=
cls
Echo.
Echo.
Echo And who will play O's?
Echo.
set /p os=
set /a scorex=0
set /a scoreo=0
set /a draw=0
set /a turns=0
:start
set a1=_
set a2=_
set a3=_
set a4=_
set a5=_
set b1=_
set b2=_
set b3=_
set b4=_
set b5=_
set c1=_
set c2=_
set c3=_
set c4=_
set c5=_
set d1=_
set d2=_
set d3=_
set d4=_
set d5=_
set e1=_
set e2=_
set e3=_
set e4=_
set e5=_
set f1=_
set f2=_
set f3=_
set f4=_
set f5=_


:map1
cls
Echo.
Echo.
Echo Score: %xs%:%scorex%
Echo %os%:%scoreo%
Echo Draw:%draw%
Echo.
Echo.
Echo A B C D E F
Echo *[%a1%] [%b1%] [%c1%] [%d1%] [%e1%] [%f1%]*
Echo * *
Echo *[%a2%] [%b2%] [%c2%] [%d2%] [%e2%] [%f2%]*
Echo * *
Echo *[%a3%] [%b3%] [%c3%] [%d3%] [%e3%] [%f3%]*
Echo * *
Echo *[%a4%] [%b4%] [%c4%] [%d4%] [%e4%] [%f4%]*
Echo * *
Echo *[%a5%] [%b5%] [%c5%] [%d5%] [%e5%] [%f5%]*
Echo.
goto P1

:map2
cls
Echo.
Echo.
Echo Score: %xs%:%scorex%
Echo %os%:%scoreo%
Echo Draw:%draw%
Echo.
Echo.
Echo A B C D E F
Echo *[%a1%] [%b1%] [%c1%] [%d1%] [%e1%] [%f1%]*
Echo * *
Echo *[%a2%] [%b2%] [%c2%] [%d2%] [%e2%] [%f2%]*
Echo * *
Echo *[%a3%] [%b3%] [%c3%] [%d3%] [%e3%] [%f3%]*
Echo * *
Echo *[%a4%] [%b4%] [%c4%] [%d4%] [%e4%] [%f4%]*
Echo * *
Echo *[%a5%] [%b5%] [%c5%] [%d5%] [%e5%] [%f5%]*
Echo.
goto P2R

:P1c
If %a1%+%a2%+%a3%+%a4% EQU O+O+O+O goto wino
If %a5%+%a2%+%a3%+%a4% EQU O+O+O+O goto wino
If %b1%+%b2%+%b3%+%b4% EQU O+O+O+O goto wino
If %b5%+%b2%+%b3%+%b4% EQU O+O+O+O goto wino
If %c1%+%c2%+%c3%+%c4% EQU O+O+O+O goto wino
If %c5%+%c2%+%c3%+%c4% EQU O+O+O+O goto wino
If %d1%+%d2%+%d3%+%d4% EQU O+O+O+O goto wino
If %d5%+%d2%+%d3%+%d4% EQU O+O+O+O goto wino
If %e1%+%e2%+%e3%+%e4% EQU O+O+O+O goto wino
If %e5%+%e2%+%e3%+%e4% EQU O+O+O+O goto wino
If %f1%+%f2%+%f3%+%f4% EQU O+O+O+O goto wino
If %f5%+%f2%+%f3%+%f4% EQU O+O+O+O goto wino
If %a1%+%b1%+%c1%+%d1% EQU O+O+O+O goto wino
If %e1%+%b1%+%c1%+%d1% EQU O+O+O+O goto wino
If %e1%+%f1%+%c1%+%d1% EQU O+O+O+O goto wino
If %a2%+%b2%+%c2%+%d2% EQU O+O+O+O goto wino
If %e2%+%b2%+%c2%+%d2% EQU O+O+O+O goto wino
If %e2%+%f2%+%c2%+%d2% EQU O+O+O+O goto wino
If %a3%+%b3%+%c3%+%d3% EQU O+O+O+O goto wino
If %e3%+%b3%+%c3%+%d3% EQU O+O+O+O goto wino
If %e3%+%f3%+%c3%+%d3% EQU O+O+O+O goto wino
If %a4%+%b4%+%c4%+%d4% EQU O+O+O+O goto wino
If %e4%+%b4%+%c4%+%d4% EQU O+O+O+O goto wino
If %e4%+%f4%+%c4%+%d4% EQU O+O+O+O goto wino
If %a5%+%b5%+%c5%+%d5% EQU O+O+O+O goto wino
If %e5%+%b5%+%c5%+%d5% EQU O+O+O+O goto wino
If %e5%+%f5%+%c5%+%d5% EQU O+O+O+O goto wino
If %a2%+%b3%+%c4%+%d5% EQU O+O+O+O goto wino
If %a1%+%b2%+%c3%+%d4% EQU O+O+O+O goto wino
If %e5%+%b2%+%c3%+%d4% EQU O+O+O+O goto wino
If %b1%+%c2%+%d3%+%e4% EQU O+O+O+O goto wino
If %f5%+%c2%+%d3%+%e4% EQU O+O+O+O goto wino
If %c1%+%d2%+%e3%+%f4% EQU O+O+O+O goto wino
If %c5%+%d4%+%e3%+%f2% EQU O+O+O+O goto wino
If %c5%+%d4%+%e3%+%f2% EQU O+O+O+O goto wino
If %b5%+%c4%+%d3%+%e2% EQU O+O+O+O goto wino
If %f1%+%c4%+%d3%+%e2% EQU O+O+O+O goto wino
If %a5%+%b4%+%c3%+%d2% EQU O+O+O+O goto wino
If %e1%+%b4%+%c3%+%d2% EQU O+O+O+O goto wino
If %a4%+%b3%+%c2%+%d1% EQU O+O+O+O goto wino
If %turns% EQU 30 goto draw
goto map1

:P1
Echo.
Echo.
Echo %xs%, it's your turn.
Echo.
Echo.
set /p x=
If %x% EQU a goto A5
If %x% EQU b goto B5
If %x% EQU c goto C5
If %x% EQU d goto D5
If %x% EQU e goto E5
If %x% EQU f goto F5
goto Map1

:A5
If %a5% EQU X goto A4
If %a5% EQU O goto A4
set a5=X
goto P2

:A4
If %a4% EQU X goto A3
If %a4% EQU O goto A3
set a4=X
goto P2

:A3
If %a3% EQU X goto A2
If %a3% EQU O goto A2
set a3=X
goto P2

:A2
If %a2% EQU X goto A1
If %a2% EQU O goto A1
set a2=X
goto P2

:A1
If %a1% EQU X goto error1
If %a1% EQU O goto error1
set a1=X
goto P2



:B5
If %b5% EQU X goto B4
If %b5% EQU O goto B4
set b5=X
goto P2

:B4
If %b4% EQU X goto B3
If %b4% EQU O goto B3
set b4=X
goto P2

:B3
If %b3% EQU X goto B2
If %b3% EQU O goto B2
set b3=X
goto P2

:B2
If %b2% EQU X goto B1
If %b2% EQU O goto B1
set b2=X
goto P2

:B1
If %b1% EQU X goto error1
If %b1% EQU O goto error1
set b1=X
goto P2



:C5
If %c5% EQU X goto C4
If %c5% EQU O goto C4
set c5=X
goto P2

:C4
If %c4% EQU X goto C3
If %c4% EQU O goto C3
set c4=X
goto P2

:C3
If %c3% EQU X goto C2
If %c3% EQU O goto C2
set c3=X
goto P2

:C2
If %c2% EQU X goto C1
If %c2% EQU O goto C1
set c2=X
goto P2

:C1
If %c1% EQU X goto error1
If %c1% EQU O goto error1
set c1=X
goto P2


:D5
If %d5% EQU X goto D4
If %d5% EQU O goto D4
set d5=X
goto P2

:D4
If %d4% EQU X goto D3
If %d4% EQU O goto D3
set d4=X
goto P2

:D3
If %d3% EQU X goto D2
If %d3% EQU O goto D2
set d3=X
goto P2

:D2
If %d2% EQU X goto D1
If %d2% EQU O goto D1
set d2=X
goto P2

:D1
If %d1% EQU X goto error1
If %d1% EQU O goto error1
set d1=X
goto P2


:E5
If %e5% EQU X goto E4
If %e5% EQU O goto E4
set e5=X
goto P2

:E4
If %e4% EQU X goto E3
If %e4% EQU O goto E3
set e4=X
goto P2

:E3
If %e3% EQU X goto E2
If %e3% EQU O goto E2
set e3=X
goto P2

:E2
If %e2% EQU X goto E1
If %e2% EQU O goto E1
set e2=X
goto P2

:E1
If %e1% EQU X goto error1
If %e1% EQU O goto error1
set e1=X
goto P2

:F5
If %f5% EQU X goto F4
If %f5% EQU O goto F4
set f5=X
goto P2

:F4
If %f4% EQU X goto F3
If %f4% EQU O goto F3
set f4=X
goto P2

:F3
If %f3% EQU X goto F2
If %f3% EQU O goto F2
set f3=X
goto P2

:F2
If %f2% EQU X goto F1
If %f2% EQU O goto F1
set f2=X
goto P2

:F1
If %f1% EQU X goto error1
If %f1% EQU O goto error1
set f1=X
goto P2




:P2
If %a1%+%a2%+%a3%+%a4% EQU X+X+X+X goto winx
If %a5%+%a2%+%a3%+%a4% EQU X+X+X+X goto winx
If %b1%+%b2%+%b3%+%b4% EQU X+X+X+X goto winx
If %b5%+%b2%+%b3%+%b4% EQU X+X+X+X goto winx
If %c1%+%c2%+%c3%+%c4% EQU X+X+X+X goto winx
If %c5%+%c2%+%c3%+%c4% EQU X+X+X+X goto winx
If %d1%+%d2%+%d3%+%d4% EQU X+X+X+X goto winx
If %d5%+%d2%+%d3%+%d4% EQU X+X+X+X goto winx
If %e1%+%e2%+%e3%+%e4% EQU X+X+X+X goto winx
If %e5%+%e2%+%e3%+%e4% EQU X+X+X+X goto winx
If %f1%+%f2%+%f3%+%f4% EQU X+X+X+X goto winx
If %f5%+%f2%+%f3%+%f4% EQU X+X+X+X goto winx
If %a1%+%b1%+%c1%+%d1% EQU X+X+X+X goto winx
If %e1%+%b1%+%c1%+%d1% EQU X+X+X+X goto winx
If %e1%+%f1%+%c1%+%d1% EQU X+X+X+X goto winx
If %a2%+%b2%+%c2%+%d2% EQU X+X+X+X goto winx
If %e2%+%b2%+%c2%+%d2% EQU X+X+X+X goto winx
If %e2%+%f2%+%c2%+%d2% EQU X+X+X+X goto winx
If %a3%+%b3%+%c3%+%d3% EQU X+X+X+X goto winx
If %e3%+%b3%+%c3%+%d3% EQU X+X+X+X goto winx
If %e3%+%f3%+%c3%+%d3% EQU X+X+X+X goto winx
If %a4%+%b4%+%c4%+%d4% EQU X+X+X+X goto winx
If %e4%+%b4%+%c4%+%d4% EQU X+X+X+X goto winx
If %e4%+%f4%+%c4%+%d4% EQU X+X+X+X goto winx
If %a5%+%b5%+%c5%+%d5% EQU X+X+X+X goto winx
If %e5%+%b5%+%c5%+%d5% EQU X+X+X+X goto winx
If %e5%+%f5%+%c5%+%d5% EQU X+X+X+X goto winx
If %a2%+%b3%+%c4%+%d5% EQU X+X+X+X goto winx
If %a1%+%b2%+%c3%+%d4% EQU X+X+X+X goto winx
If %e5%+%b2%+%c3%+%d4% EQU X+X+X+X goto winx
If %b1%+%c2%+%d3%+%e4% EQU X+X+X+X goto winx
If %f5%+%c2%+%d3%+%e4% EQU X+X+X+X goto winx
If %c1%+%d2%+%e3%+%f4% EQU X+X+X+X goto winx
If %c5%+%d4%+%e3%+%f2% EQU X+X+X+X goto winx
If %c5%+%d4%+%e3%+%f2% EQU X+X+X+X goto winx
If %b5%+%c4%+%d3%+%e2% EQU X+X+X+X goto winx
If %f1%+%c4%+%d3%+%e2% EQU X+X+X+X goto winx
If %a5%+%b4%+%c3%+%d2% EQU X+X+X+X goto winx
If %e1%+%b4%+%c3%+%d2% EQU X+X+X+X goto winx
If %a4%+%b3%+%c2%+%d1% EQU X+X+X+X goto winx
If %turns% EQU 30 goto draw
goto map2


:P2R
Echo.
Echo.
Echo %os%, it's your turn.
Echo.
Echo.
set /p x=
If %x% EQU a goto A5o
If %x% EQU b goto B5o
If %x% EQU c goto C5o
If %x% EQU d goto D5o
If %x% EQU e goto E5o
If %x% EQU f goto F5o
goto Map2

:A5o
If %a5% EQU X goto A4o
If %a5% EQU O goto A4o
set a5=O
goto P1c

:A4o
If %a4% EQU X goto A3o
If %a4% EQU O goto A3o
set a4=O
goto P1c

:A3o
If %a3% EQU X goto A2o
If %a3% EQU O goto A2o
set a3=O
goto P1c

:A2o
If %a2% EQU X goto A1o
If %a2% EQU O goto A1o
set a2=O
goto P1c

:A1o
If %a1% EQU X goto error2
If %a1% EQU O goto error2
set a1=O
goto P1c



:B5o
If %b5% EQU X goto B4o
If %b5% EQU O goto B4o
set b5=O
goto P1c

:B4o
If %b4% EQU X goto B3o
If %b4% EQU O goto B3o
set b4=O
goto P1c

:B3o
If %b3% EQU X goto B2o
If %b3% EQU O goto B2o
set b3=O
goto P1c

:B2o
If %b2% EQU X goto B1o
If %b2% EQU O goto B1o
set b2=O
goto P1c

:B1o
If %b1% EQU X goto error1
If %b1% EQU O goto error1
set b1=O
goto P1c



:C5o
If %c5% EQU X goto C4o
If %c5% EQU O goto C4o
set c5=O
goto P1c

:C4o
If %c4% EQU X goto C3o
If %c4% EQU O goto C3o
set c4=O
goto P1c

:C3o
If %c3% EQU X goto C2o
If %c3% EQU O goto C2o
set c3=O
goto P1c

:C2o
If %c2% EQU X goto C1o
If %c2% EQU O goto C1o
set c2=O
goto P1c

:C1o
If %c1% EQU X goto error1
If %c1% EQU O goto error1
set c1=O
goto P1c


:D5o
If %d5% EQU X goto D4o
If %d5% EQU O goto D4o
set d5=O
goto P1c

:D4o
If %d4% EQU X goto D3o
If %d4% EQU O goto D3o
set d4=O
goto P1c

:D3o
If %d3% EQU X goto D2o
If %d3% EQU O goto D2o
set d3=O
goto P1c

:D2o
If %d2% EQU X goto D1o
If %d2% EQU O goto D1o
set d2=O
goto P1c

:D1o
If %d1% EQU X goto error1
If %d1% EQU O goto error1
set d1=O
goto P1c


:E5o
If %e5% EQU X goto E4o
If %e5% EQU O goto E4o
set e5=O
goto P1c

:E4o
If %e4% EQU X goto E3o
If %e4% EQU O goto E3o
set e4=O
goto P1c

:E3o
If %e3% EQU X goto E2o
If %e3% EQU O goto E2o
set e3=O
goto P1c

:E2o
If %e2% EQU X goto E1o
If %e2% EQU O goto E1o
set e2=O
goto P1c

:E1o
If %e1% EQU X goto error1
If %e1% EQU O goto error1
set e1=O
goto P1c

:F5o
If %f5% EQU X goto F4o
If %f5% EQU O goto F4o
set f5=O
goto P1c

:F4o
If %f4% EQU X goto F3o
If %f4% EQU O goto F3o
set f4=O
goto P1c

:F3o
If %f3% EQU X goto F2o
If %f3% EQU O goto F2o
set f3=O
goto P1c

:F2o
If %f2% EQU X goto F1o
If %f2% EQU O goto F1o
set f2=O
goto P1c

:F1o
If %f1% EQU X goto error1
If %f1% EQU O goto error1
set f1=O
goto P1c



:error1
Echo.
Echo Invalid Entry, That Column is Full
Echo.
pause
goto map1

:error2
Echo.
Echo Invalid Entry, That Column is Full
Echo.
pause
goto map2



:winx
cls
color 0A
set /a scorex=%scorex%+1
Echo.
Echo.
Echo Congrats %xs%, because...
Echo.
Echo.
Echo **
Echo **** **** * ********* ** ** ** **** **
Echo **** **** ** ** ** ** **** **
Echo ******** ** ** ** ** ** ** * **
Echo ****** ********* ** ** ** ** ** * **
Echo ******** ** ** ** ** ** ** * **
Echo **** **** ** ************ ** ** * **
Echo **** **** ******** ************ ** ** ****
Echo.
Echo.
pause
goto ending

:wino
cls
Color 0C
set /a scoreo=%scoreo%+1
Echo.
Echo.
Echo Congrats %os%, because...
Echo.
Echo.
Echo **
Echo ************ * ********* ** ** ** **** **
Echo ************ ** ** ** ** **** **
Echo ** ** ** ** ** ** ** ** * **
Echo ** ** ********* ** ** ** ** ** * **
Echo ** ** ** ** ** ** ** ** * **
Echo ************ ** ************ ** ** * **
Echo ************ ******** ************ ** ** ****
Echo.
Echo.
pause
goto ending

:draw
cls
color 0E
set /a draw=%draw%+1
Echo.
Echo.
Echo Sorry %xs% and %os%, but it's a...
Echo.
Echo.
Echo ######
Echo ## #
Echo ## # #### ##### # #
Echo ## # # # # # # #
Echo ## # # # # # # #
Echo ###### # #### # #####
Echo.
Echo.
pause
goto ending

:ending
cls
color 0E
Echo.
Echo.
Echo Press 1 to Play Again
Echo Press 2 to Change Players
Echo Press 3 to Exit
Echo.
set /p v=
IF %v% EQU 1 goto start
IF %v% EQU 2 goto superstart
IF %v% EQU 3 goto close

:close

Sunday, June 20, 2010

Batch Program - Deal or No Deal game

::~ Instructions start with "::~"
::~ Created by Mastahhaxor
::~ I have based this game's format loosely on the British tv show 'Deal Or No Deal' owned
::~ by Endemol.
echo.
:: I do not own any part of the show and have created this basic program only to
echo.
::~ educate on ways to use, and the capabilities of, the language.
echo.
::~ Note, throughout the game I have had to use dollar signs instead of pound signs, as batch
echo.
::~ files won't accept them for some reason...


@echo off
echo Loading...
setlocal enabledelayedexpansion
set dealdone=0
set Spaces=

for /l %%I in (1,1,22) do set gapline%%I= ___________

set amount1=1
set amount2=10
set amount3=50
set amount4=100
set amount5=500
set amount6=1000
set amount7=5000
set amount8=10000
set amount9=25000
set amount10=50000
set amount11=75000
set amount12=100000
set amount13=300000
set amount14=500000
set amount15=1000000
set amount16=1500000
set amount17=2000000
set amount18=3500000
set amount19=5000000
set amount20=7500000
set amount21=10000000
set amount22=25000000


set famount1=$0.01
set famount2=$0.1
set famount3=$0.50
set famount4=$1
set famount5=$5
set famount6=$10
set famount7=$50
set famount8=$100
set famount9=$250
set famount10=$500
set famount11=$750
set famount12=$1,000
set famount13=$3,000
set famount14=$5,000
set famount15=$10,000
set famount16=$15,000
set famount17=$20,000
set famount18=$35,000
set famount19=$50,000
set famount20=$75,000
set famount21=$100,000
set famount22=$250,000




set Damount1={___$0.01___}
set Damount2={____$0.1___}
set Damount3={____$0.5___}
set Damount4={_____$1____}
set Damount5={_____$5____}
set Damount6={____$10____}
set Damount7={____$50____}
set Damount8={____$100___}
set Damount9={____$250___}
set Damount10={____$500___}
set Damount11={____$750___}
set Damount12={___$1000___}
set Damount13={___$3000___}
set Damount14={___$5000___}
set Damount15={___$10000__}
set Damount16={___$15000__}
set Damount17={___$20000__}
set Damount18={___$35000__}
set Damount19={___$50000__}
set Damount20={___$75000__}
set Damount21={__$100000__}
set Damount22={__$250000__}




for /l %%I in (1,1,22) do set boxtop%%I= _____
for /l %%I in (1,1,22) do set boxlid%%I=[_____]
for /l %%I in (1,1,9) do set boxmid%%I=[ %%I ]
for /l %%I in (10,1,22) do set boxmid%%I=[ %%I ]
for /l %%I in (1,1,22) do set boxbot%%I=[_____]

for /l %%I in (23,1,24) do set boxtop%%I=
for /l %%I in (23,1,24) do set boxlid%%I=
for /l %%I in (23,1,24) do set boxmid%%I=
for /l %%I in (23,1,24) do set boxbot%%I=

for /l %%I in (1,4,24) do (
set /a box2number= %%I + 1
set /a box3number= %%I + 2
set /a box4number= %%I + 3
set DisplayLine%%I=#boxtop%%I##boxtop!box2number!##boxtop!box3number!##boxtop!box4number!#
)

for /l %%I in (2,4,24) do (
set /a boxnumber= %%I - 1
set /a box2number= !boxnumber! + 1
set /a box3number= !boxnumber! + 2
set /a box4number= !boxnumber! + 3
set DisplayLine%%I=#boxlid!boxnumber!##boxlid!box2number!##boxlid!box3number!##boxlid!box4number!#
)

for /l %%I in (3,4,24) do (
set /a boxnumber= %%I - 2
set /a box2number= !boxnumber! + 1
set /a box3number= !boxnumber! + 2
set /a box4number= !boxnumber! + 3
set DisplayLine%%I=#boxmid!boxnumber!##boxmid!box2number!##boxmid!box3number!##boxmid!box4number!#
)

for /l %%I in (4,4,24) do (
set /a boxnumber= %%I - 3
set /a box2number= !boxnumber! + 1
set /a box3number= !boxnumber! + 2
set /a box4number= !boxnumber! + 3
set DisplayLine%%I=#boxbot!boxnumber!##boxbot!box2number!##boxbot!box3number!##boxbot!box4number!#
)

set amountnumber1=0
set amountnumber2=11
for /l %%I in (1,2,22) do set /a AmountNumber1= !amountnumber1! + 1 && set /a Amountnumber2= !amountnumber2! + 1 && for /l %%J in (!Amountnumber1!,1,!Amountnumber1!) do for /l %%K in (!Amountnumber2!,1,!Amountnumber2!) do (
set Displayline%%I=#gapline%%J# !Displayline%%I! #gapline%%K#
)

set amountnumber1=0
set amountnumber2=11

for /l %%I in (2,2,22) do set /a AmountNumber1= !amountnumber1! + 1 && set /a Amountnumber2= !amountnumber2! + 1 && for /l %%J in (!Amountnumber1!,1,!Amountnumber1!) do for /l %%K in (!Amountnumber2!,1,!Amountnumber2!) do (
set Displayline%%I=#Damount%%J# !Displayline%%I! #Damount%%K#
)

for /l %%I in (23,1,24) do set displayline%%I= !Displayline%%I!

set amountsleft=
for /l %%I in (1,1,22) do set AmountsLeft=!Amountsleft!%%I,


set Amountnumber=1

:RandomNumber

set minval=1

set maxval=22

:NumberGenerator
set /a RandomNumber= %random% / 1489
set /a RandomNumber= %RandomNumber% + %MinVal%
if /i %RandomNumber% GTR %Maxval% goto NumberGenerator

if not defined box%randomnumber% (
set box%randomnumber%=%amountnumber%
set /a Amountnumber= !Amountnumber! + 1
if /i !amountnumber!==23 goto intro
)
goto Randomnumber


:intro
cls
echo Let's Play...
echo.
echo.
echo ############################################
echo # #
echo # @@ @@@@ @ @ @ @@@ #
echo # @ @ @ @ @ @ @ @ @ @ #
echo # @ @ @ @ @ @ @ @ @ #
echo # @ @ @@@ @@@@@ @ @ @ @ #
echo # @ @ @ @ @ @ @ @ @ #
echo # @@ @@@@ @ @ @@@@ @ @ #
echo # #
echo # @ @ @ @@ @@@@ @ @ #
echo # @@ @ @ @ @ @ @ @ @ @ #
echo # @@ @ @ @ @ @ @ @ @ @ #
echo # @ @@ @ @ @ @ @@@@ @@@@@ @ #
echo # @ @@ @ @ @ @ @ @ @ @ #
echo # @ @ @ @@ @@@@ @ @ @@@@ #
echo # #
echo ############################################
echo.
echo I do not own the "Deal Or No Deal" format or concept. All copyrights
echo and trademarks are property of their respective owners.
echo.
set /p helpyn="Press enter to continue, or type HELP for instructions.
if /i "%HelpYN%"=="HELP" (
cls
echo The aim of the game is to have as much money as possible in your case
echo The game concept is simple. There are 22 sums of money inside 22 different cases.
echo The player must choose a case to keep, then remove the others from play.
echo one by one not knowing what sum is inside each box.
echo.
echo After a certain number of choices, The Banker will phone. He will make
echo you an offer to buy your case off you. You may choose to accept this offer,
echo or keep removing money. Removing high sums makes lower offers and vice-
echo versa.
echo.
echo If you play until there are only two cases left, you have the choice to
echo open the case you started with, or switch to the other box. You win the
echo money in the case.
echo.
echo The knack to the game is knowing whether to take the deal or stop removing
echo money from the game.
pause
)
cls


:ChooseBox
call :display
set /p OwnBox="Choose your own case to keep: "
if not defined Ownbox goto Choosebox
if /i not %ownbox%0 leq 220 goto ChooseBox
if /i not %ownbox%0 geq 10 goto ChooseBox

set boxtop%ownbox%=
set boxlid%ownbox%=
set boxmid%ownbox%=
set boxbot%ownbox%=


set BoxesLeft=22

Set turns=5

set boxmessage=Choose the case you want to open
call :gameloop

if %dealdone%==1 exit /b

Set turns=3
set boxmessage=Choose the case you want to open
call :gameloop

if %dealdone%==1 exit /b

Set turns=3
set boxmessage=Choose the case you want to open
call :gameloop

if %dealdone%==1 exit /b

Set turns=3
set boxmessage=Choose the case you want to open
call :gameloop

if %dealdone%==1 exit /b

Set turns=3
set boxmessage=Choose the case you want to open
call :gameloop

if %dealdone%==1 exit /b

Set turns=3
set boxmessage=Choose the case you want to open
call :gameloop

if %dealdone%==1 exit /b

goto SwapOrNot


:gameLoop
cls
call :display
set boxtoremove=

:OpenBox
set /p BoxToRemove="%BoxMessage%"
if not defined BoxToRemove goto OpenBox
if /i not %BoxToRemove%0 leq 220 goto OpenBox
if /i not %BoxToRemove%0 geq 10 goto openBox
if /i %BoxToRemove%==%OwnBox% goto OpenBox
if /i "!Box%boxtoremove%!"=="DONE" goto OpenBox

call :removebox %boxtoremove%
set /a BoxesLeft=%BoxesLeft% - 1
set /a Turns= %Turns% - 1

if /i %turns%==0 (
cls
call :display
set /p asdfghj="You lost amount %Amountinbox%. The Phone is ringing, press enter to answer it."
set asdfghj=
call :MakeOffer
exit /b
)

set boxmessage=You lost amount %Amountinbox%. Choose the box you want to open.

Goto GameLoop






:RemoveBox
set boxtop%1=
set boxlid%1%=
set boxmid%1=
set boxbot%1=

set AmountInBox=!Box%1!

call :Remove_Amounts %AmountInBox%
set Box%1=DONE
exit /b

:Remove_Amounts
set damount%1=
set gapline%1=

for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 delims=," %%A in ("%AmountsLeft%") do (
set amountsleft=
if /i not %%A==%1 set AmountsLeft=%%A,
if /i not %%B==%1 set AmountsLeft=!AmountsLeft!%%B,
if /i not %%C==%1 set AmountsLeft=!AmountsLeft!%%C,
if /i not %%D==%1 set AmountsLeft=!AmountsLeft!%%D,
if /i not %%E==%1 set AmountsLeft=!AmountsLeft!%%E,
if /i not %%F==%1 set AmountsLeft=!AmountsLeft!%%F,
if /i not %%G==%1 set AmountsLeft=!AmountsLeft!%%G,
if /i not %%H==%1 set AmountsLeft=!AmountsLeft!%%H,
if /i not %%I==%1 set AmountsLeft=!AmountsLeft!%%I,
if /i not %%J==%1 set AmountsLeft=!AmountsLeft!%%J,
if /i not %%K==%1 set AmountsLeft=!AmountsLeft!%%K,
if /i not %%L==%1 set AmountsLeft=!AmountsLeft!%%L,
if /i not %%M==%1 set AmountsLeft=!AmountsLeft!%%M,
if /i not %%N==%1 set AmountsLeft=!AmountsLeft!%%N,
if /i not %%O==%1 set AmountsLeft=!AmountsLeft!%%O,
if /i not %%P==%1 set AmountsLeft=!AmountsLeft!%%P,
if /i not %%Q==%1 set AmountsLeft=!AmountsLeft!%%Q,
if /i not %%R==%1 set AmountsLeft=!AmountsLeft!%%R,
if /i not %%S==%1 set AmountsLeft=!AmountsLeft!%%S,
if /i not %%T==%1 set AmountsLeft=!AmountsLeft!%%T,
if /i not %%U==%1 set AmountsLeft=!AmountsLeft!%%U,
if /i not %%V==%1 set AmountsLeft=!AmountsLeft!%%V,
)

set amountinbox=!FAmount%1!
exit /b









:MakeOffer
set amount=0
for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 delims=," %%A in ("%AmountsLeft%") do (
set /a Offer= !Amount%%A! + !Amount%%B! + !Amount%%C! + !Amount%%D! + !Amount%%E! + !Amount%%F! + !Amount%%G! + !Amount%%H! + !Amount%%I! + !Amount%%J! + !Amount%%K! + !Amount%%L! + !Amount%%M! + !Amount%%N! + !Amount%%O! + !Amount%%P! + !Amount%%Q! + !Amount%%R! + !Amount%%S! + !Amount%%T! + !Amount%%U! + !Amount%%V! + 0
)
set /a Offer= (%Offer%/((%BoxesLeft%*999)/500))/100


cls
echo.
echo ####################################
echo ## ##
echo ## ############################ ##
echo ###### ## ## ######
echo ######################
echo ####### #######
echo ##### #####
echo #### ####
echo #### ####
echo ##### #####
echo ####### #######
echo ##########################
echo ############################
echo ##############################
echo ################################
echo.
echo.
echo The Banker Offers: $%Offer%
echo.
echo.
echo DEAL OR NO DEAL?
:DealOrNoDeal
set deal=
set /p Deal=" "
if not defined Deal goto DealOrNoDeal
if /i %Deal:~0,1%==d echo.&& Goto Deal_Taken
if /i %Deal:~0,1%==N (exit /b) else (goto :DealOrNoDeal)









:Display


echo/ %displayline1:#=!%
echo/ %displayline2:#=!%
echo/ %displayline3:#=!%
echo/ %displayline4:#=!%
echo/ %displayline5:#=!%
echo/ %displayline6:#=!%
echo/ %displayline7:#=!%
echo/ %displayline8:#=!%
echo/ %displayline9:#=!%
echo/ %displayline10:#=!%
echo/ %displayline11:#=!%
echo/ %displayline12:#=!%
echo/ %displayline13:#=!%
echo/ %displayline14:#=!%
echo/ %displayline15:#=!%
echo/ %displayline16:#=!%
echo/ %displayline17:#=!%
echo/ %displayline18:#=!%
echo/ %displayline19:#=!%
echo/ %displayline20:#=!%
echo/ %displayline21:#=!%
echo/ %displayline22:#=!%
echo/ %displayline23:#=!%
echo/ %displayline24:#=!%

exit /b



:SwapOrNot
cls
echo.
echo ####################################
echo ## ##
echo ## ############################ ##
echo ###### ## ## ######
echo ######################
echo ####### #######
echo ##### #####
echo #### ####
echo #### ####
echo ##### #####
echo ####### #######
echo ##########################
echo ############################
echo ##############################
echo ################################
echo.
echo.
echo The Banker Has Offered You The Swap
echo.
echo.
echo SWAP OR NO SWAP?

:SwapOrNoSwap
set swap=
set /p Swap=" "
if not defined Swap goto SwapOrNoSwap
if /i %Swap:~0,1%==S echo.&& goto Swap_Taken
if /i %Swap:~0,1%==N (echo.&& goto Swap_Not_Taken) else (goto SwapOrNoSwap)




:Swap_Not_Taken
for /f "tokens=1,2 delims=," %%I in ("%AmountsLeft%") do if /i "%%I"=="!Box%OwnBox%!" (set Offer=!Amount%%I!& set OtherBox=%%J& Set OwnBox=%%I) else (set offer=!Amount%%J!& set OtherBox=%%I&& Set OwnBox=%%J)
if /i %offer% lss 100 set offer=0.%offer%&& goto SwapResult
set /a offer= %offer% / 100
if /i %Offer% geq 35000 call :bigWin
goto SwapResult






:Swap_Taken
for /f "tokens=1,2 delims=," %%I in ("%AmountsLeft%") do if /i "%%I"=="!Box%OwnBox%!" (set Offer=!Amount%%J!& set OtherBox=%%I& Set OwnBox=%%J) else (set offer=!Amount%%I!& set OtherBox=%%J& Set OwnBox=%%I)
if /i %offer% lss 100 set offer=0.%offer%&& goto SwapResult
set /a offer= %offer% / 100
if /i %Offer% geq 35000 call :bigWin






:SwapResult
if /i %OwnBox% gtr %Otherbox% (
Echo You took the chance and won :D Well done
) else (
echo Hard luck, you got the smaller prize.
)
echo You won $%Offer% :)
pause>nul
goto endofgame






:Deal_Taken

set dealdone=1

if /i %Offer% geq 35000 call :bigWin

if /i %offer% lss 100 (
set Newoffer=0.%offer%
) else (
set Newoffer=%offer%
)


set temp=!Box%ownbox%!

if /i !Amount%temp%! lss 100 (
set Newtemp=0.!Amount%temp%!
) Else (
set /a Newtemp= !Amount%temp%! / 100
)

if /i %newtemp:.=% gtr %offer% (
echo Hard luck, in your case there was $%newtemp%, but you dealed at $%Newoffer%
)

if /i %newtemp:.=% lss %offer% (
echo Well done, you beat the banker :D
echo Your case was worth $%newtemp% but you sold it for $%NewOffer%
)

if /i %newtemp:.=% equ %offer% (
echo You managed to sell your case for exactly what it was worth, well done :D
echo You won $%NewOffer% :)
)
pause >nul
goto EndOfGame











:BigWin
cls
echo #######################################################
echo # #
echo # #
echo # @ @ @ @ @ @ @ @@@@ @@@@ @ #
echo # @ @ @ @@ @ @@ @ @ @ @ @ #
echo # @ @ @ @ @ @ @ @ @ @ @ @ @ #
echo # @ @ @ @ @ @ @ @ @ @ @@@ @@@ @ #
echo # @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ #
echo # @ @ @ @ @ @ @ @ @ @ @ @ @ @ #
echo # @ @ @ @ @@ @ @@ @@@@ @ @ @ #
echo # #
echo # #
echo #######################################################
echo.
echo.
exit /b





:endOfGame
exit /b

::~ don't forget to save as (anything).bat

Saturday, June 19, 2010

How to make a calculator in batch

::~Instructions are started with ::~

::~Open notepad

::~Copy and paste the code below.

@echo off
color 1f
title Calculator
:start
cls
set /p math=Enter problem:
if %math%==Exit exit
set /a math2=%math%
echo %math%=%math2%
echo.
pause
goto start

::~Save as (anything).bat

Scheduled Shutdown / Restart

::~Instructions start with ::~

::~Open notepad

::~Copy and paste the code below.

@echo off
title Shutdown Timer
Color 1f
:menu
cls
time /t
echo.
echo Welcome to shutdown timer!
echo.
echo Stop shutdown or create new?
echo.
echo C=Create New
echo A=Abort
echo E=Exit
echo.
set input=
set /p input=
if %input%==a goto stop
if %input%==A goto stop
if %input%==e exit
if %input%==E exit
if %input%==C goto 1
if %input%==c goto 1
goto menu
:1
cls
time /t
echo.
echo Welcome to shutdown timer!
echo.
echo Shutdown or Restart? (S/R)
echo.
set input=
set /p input=
if %input%==R set x=r
if %input%==r set x=r
if %input%==S set x=s
if %input%==s set x=s
cls
time /t
echo.
echo Welcome to shutdown timer!
echo.
echo Enter time when to shutdown in following format:
echo h:mm:ss.mm
echo Example: 17:47:00.00 would shutdown at 5:47. (Uses a 24 hour clock)
set /p time=
cls
time /t
echo.
echo Welcome to shutdown timer!
echo.
echo Enter message: (Can't use spaces, use underscores, commas, or periods)
set /p message=
at %time% /interactive shutdown -%x% -t 30 -c %message%
cls
time /t
echo.
echo Welcome to shutdown timer!
echo.
echo The computer will shutdown at %time%, with message: %message%
echo.
pause
goto Menu
:stop
at 1 /delete
at 2 /delete
at 3 /delete
at 4 /delete
at 5 /delete
at 6 /delete
at 7 /delete
at 8 /delete
at 9 /delete
at 10 /delete
shutdown -a
cls
time /t
echo.
echo Welcome to shutdown timer!
echo.
echo Shutdown has been deleted.
echo.
pause
goto menu

::~Then save as (anything).bat

How to protect a file or folder

::~Instructions are with ::~ to start with them.

Open Notepad

::~Then put in the code below.

@Echo off
cls
:Password
Set input=
set /p input= Password (input then press enter) :
if %input%==mastahhaxor goto YES
if not %input%==mastahhaxor goto NO

:YES

Start MSpaint.exe
Exit

:NO

Echo INCORRECT PASSWORD
goto Password

====================

MSPaint = file or program

Mastahhaxor = password

::~Change the MSPaint and the MSPaint.exe to whatever file you want to put a password on.

::~Change the Mastahhaxor everywhere to whatever you want the password to be at.

::~Then save as the programs name and then .bat

Wednesday, June 16, 2010

Tic-tac-toe (Noughts and crosses)

::~ Lines that are explaining the code begin with '::~' ... so not just ::

@echo off
title Noughts and Crosses
setlocal enabledelayedexpansion

::~ ^^^ Stops all commands appearing on screen, sets the title and enables the use of ! for environment variables.

:menu
cls
echo Main Menu
echo To Play A 1-Player Game, Enter 1
echo To Play A 2-Player Game, Enter 2
echo To Exit, Enter 3
set /p menu=
if not defined menu goto menu
if /i %menu% equ 1 (
set menu=
cls
goto 1p
)
if /i %menu% equ 2 (
set menu=
cls
goto 2p
)
if /i %menu% equ 3 (
goto end
)
set menu=
goto menu


::~ ^^ The menu system, gives all the options, allows the user to input a number using "set /p menu="
:~ If the user didn't enter a value, it 'goto's back to ask again.
::~ Checks the Menu variable, tests to see if it matches 1, 2 or 3, then 'goto's the appropriate place.

:1p
set turns=0
set x1=0
set x2=0
set x3=0
set x4=0
set x5=0
set x6=0
set x7=0
set x8=0
set x9=0
set o1=0
set o2=0
set o3=0
set o4=0
set o5=0
set o6=0
set o7=0
set o8=0
set o9=0

::~ Sets the number of turns taken so far to 0
::~ Sets all the places on the noughts and crosses grid to 0


set d1=1
set d2=2
set d3=3
set d4=4
set d5=5
set d6=6
set d7=7
set d8=8
set d9=9

::~ Sets the display characters for game to their appropriate number

set rnumber=%random%
set rnumber2=%rnumber%
set /a rnumber= %rnumber% / 2
set /a rnumber= %rnumber% * 2

::~ Sets a variable "rnumber" to a random number
::~ Sets a variable "rnumber2" to the same number as "rnumber"
::~ Divides "rnumber" by two, then multiplies by two.
::~ If the number was even, it would be equal to "rnumber2", if it was odd it would end up one less than "rnumber2"
::~ This is the method I use to create a 50% chance, as there's a 50% that a random number will be odd or even


if %rnumber%==%rnumber2% (
echo Crosses go first
echo You are noughts
pause>nul
set rnumber=
set rnumber2=
set go=1xgame
goto 1display
) else (
echo Noughts go first
echo You are noughts
pause>nul
set rnumber=
set rnumber2=
set go=1ogame
goto 1display
)

::~ This tests to see if the numbers are equal, then sets the "go" variable to whichever possibility came out and deletes the "rnumber" variables
::~ Then 'Goto's the display

:1display
cls
echo %d1% %d2% %d3%
echo %d4% %d5% %d6%
echo %d7% %d8% %d9%
if /i %turns% equ 9 (goto draw)
echo.
echo Your Turn
echo.
goto %go%

::~ ^^ Displays the current status of each place in the grid. At the start these will all just be numbers.
::~ Checks that the turns hasn't reach nine. If it has, all the spaces on the grid have been used up and nobody has won, so the game is a draw.

:1ogame
echo Choose the number of the space you'd like to choose
set guess=
set /p guess=
if not defined guess goto 1display
set guess=%guess:~0,1%
if /i not %guess% leq 9 goto 1display
if /i not %guess% gtr 0 goto 1display
if /i !d%guess%! neq %guess% goto 1display
goto 1o%guess%

::~ Asks the user to input the number of the space they want to choose and allows them to using "Set /p"
::~ If the user didn't input or entered something that wasn't a number between 1 and 9, it 'goto's back, to ask again
::~ Checks that the number hasn't been already chosen by checking that !d%guess%! is equal to guess. This works becauseif the user guesses 1, d1 should equal 1.
::~ If it has already been chosen, d1 would be a O or a X, so it would not be equal.
::~ 'Goto's the number chosen.

:1o1
set o1=1
set x1=1000
set d1=O
goto 1oprocess
:1o2
set o2=10
set x2=1000
set d2=O
goto 1oprocess
:1o3
set o3=100
set x3=1000
set d3=O
goto 1oprocess
:1o4
set o4=1
set x4=1000
set d4=O
goto 1oprocess
:1o5
set o5=10
set x5=1000
set d5=O
goto 1oprocess
:1o6
set o6=100
set x6=1000
set d6=O
goto 1oprocess
:1o7
set o7=1
set x7=1000
set d7=O
goto 1oprocess
:1o8
set o8=10
set x8=1000
set d8=O
goto 1oprocess
:1o9
set o9=100
set x9=1000
set d9=O
goto 1oprocess

::~ The space of the number chosen on the display grid is changed to the correct letter (X or O) and a number is added to the %x-% grid and the %o-% grid.
::~ These two grids are used to work out whether someone has won, and allows the computer to work out which place to go next.



:1oprocess
set /a line1= %o1% + %o2% + %o3%
if /i %line1% equ 111 (goto owin)

set /a line2= %o4% + %o5% + %o6%
if /i %line2% equ 111 (goto owin)

set /a line3= %o7% + %o8% + %o9%
if /i %line3% equ 111 (goto owin)

set /a line4= %o1% + %o5% + %o9%
if /i %line4% equ 111 (goto owin)

set /a line5= %o3% + %o5% + %o7%
if /i %line5% equ 111 (goto owin)

set /a line6= %o1% + %o4% + %o7%
if /i %line6% equ 3 (goto owin)

set /a line7= %o2% + %o5% + %o8%
if /i %line7% equ 30 (goto owin)

set /a line8= %o3% + %o6% + %o9%
if /i %line8% equ 300 (goto owin)

::~ This section of code adds up all of the possible winning combinations on the %o-% grid i.e. each row, column and diagional, to check if the player has got three Os in a row. If so 'goto's the owin section.

set go=1xgame
set guess=
set /a turns= %turns% + 1
goto 1display

::~ Sets the go to the computer's and adds one to the number of turns taken
::~ 'Goto's the display.






:1xgame

set /a line1= %x1% + %x2% + %x3%
if /i %line1% equ 11 (
set guess=3
goto 1ac
)

set /a line1= %x1% + %x2% + %x3%
if /i %line1% equ 101 (
set guess=2
goto 1ac
)

set /a line1= %x1% + %x2% + %x3%
if /i %line1% equ 110 (
set guess=1
goto 1ac
)


set /a line1= %x4% + %x5% + %x6%
if /i %line1% equ 11 (
set guess=6
goto 1ac
)

set /a line1= %x4% + %x5% + %x6%
if /i %line1% equ 101 (
set guess=5
goto 1ac
)

set /a line1= %x4% + %x5% + %x6%
if /i %line1% equ 110 (
set guess=4
goto 1ac
)

set /a line1= %x7% + %x8% + %x9%
if /i %line1% equ 11 (
set guess=9
goto 1ac
)

set /a line1= %x7% + %x8% + %x9%
if /i %line1% equ 101 (
set guess=8
goto 1ac
)

set /a line1= %x7% + %x8% + %x9%
if /i %line1% equ 110 (
set guess=7
goto 1ac
)

set /a line1= %x1% + %x5% + %x9%
if /i %line1% equ 11 (
set guess=9
goto 1ac
)

set /a line1= %x1% + %x5% + %x9%
if /i %line1% equ 101 (
set guess=5
goto 1ac
)

set /a line1= %x1% + %x5% + %x9%
if /i %line1% equ 110 (
set guess=1
goto 1ac
)

set /a line1= %x3% + %x5% + %x7%
if /i %line1% equ 11 (
set guess=3
goto 1ac
)

set /a line1= %x3% + %x5% + %x7%
if /i %line1% equ 101 (
set guess=5
goto 1ac
)

set /a line1= %x3% + %x5% + %x7%
if /i %line1% equ 110 (
set guess=7
goto 1ac
)

set /a line1= %x1% + %x4% + %x7%
if /i %line1% equ 2 (
if /i %d1% equ 1 (
set guess=1
goto 1ac
)
if /i %d4% equ 4 (
set guess=4
goto 1ac
)
if /i %d7% equ 7 (
set guess=7
goto 1ac
)
)

set /a line1= %x2% + %x5% + %x8%
if /i %line1% equ 20 (
if /i %d2% equ 2 (
set guess=2
goto 1ac
)
if /i %d5% equ 5 (
set guess=5
goto 1ac
)
if /i %d8% equ 8 (
set guess=8
goto 1ac
)
)

set /a line1= %x3% + %x6% + %x9%
if /i %line1% equ 200 (
if /i %d3% equ 3 (
set guess=3
goto 1ac
)
if /i %d6% equ 6 (
set guess=6
goto 1ac
)
if /i %d9% equ 9 (
set guess=9
goto 1ac
)
)


::~ ^^^ These sections add up all the %x-% grid and checks to see if there is a way the computer can win this turn.
::~ If so, it sets the guess to the correct number and 'goto's the 1ac section.






set /a line1= %o1% + %o2% + %o3%
if /i %line1% equ 11 (
set guess=3
goto 1ac
)

set /a line1= %o1% + %o2% + %o3%
if /i %line1% equ 101 (
set guess=2
goto 1ac
)

set /a line1= %o1% + %o2% + %o3%
if /i %line1% equ 110 (
set guess=1
goto 1ac
)


set /a line1= %o4% + %o5% + %o6%
if /i %line1% equ 11 (
set guess=6
goto 1ac
)

set /a line1= %o4% + %o5% + %o6%
if /i %line1% equ 101 (
set guess=5
goto 1ac
)

set /a line1= %o4% + %o5% + %o6%
if /i %line1% equ 110 (
set guess=4
goto 1ac
)

set /a line1= %o7% + %o8% + %o9%
if /i %line1% equ 11 (
set guess=9
goto 1ac
)

set /a line1= %o7% + %o8% + %o9%
if /i %line1% equ 101 (
set guess=8
goto 1ac
)

set /a line1= %o7% + %o8% + %o9%
if /i %line1% equ 110 (
set guess=7
goto 1ac
)

set /a line1= %o1% + %o5% + %o9%
if /i %line1% equ 11 (
set guess=9
goto 1ac
)

set /a line1= %o1% + %o5% + %o9%
if /i %line1% equ 101 (
set guess=5
goto 1ac
)

set /a line1= %o1% + %o5% + %o9%
if /i %line1% equ 110 (
set guess=1
goto 1ac
)

set /a line1= %o3% + %o5% + %o7%
if /i %line1% equ 11 (
set guess=3
goto 1ac
)

set /a line1= %o3% + %o5% + %o7%
if /i %line1% equ 101 (
set guess=5
goto 1ac
)

set /a line1= %o3% + %o5% + %o7%
if /i %line1% equ 110 (
set guess=7
goto 1ac
)

set /a line1= %o1% + %o4% + %o7%
if /i %line1% equ 2 (
if /i %d1% equ 1 (
set guess=1
goto 1ac
)
if /i %d4% equ 4 (
set guess=4
goto 1ac
)
if /i %d7% equ 7 (
set guess=7
goto 1ac
)
)

set /a line1= %o2% + %o5% + %o8%
if /i %line1% equ 20 (
if /i %d2% equ 2 (
set guess=2
goto 1ac
)
if /i %d5% equ 5 (
set guess=5
goto 1ac
)
if /i %d8% equ 8 (
set guess=8
goto 1ac
)
)

set /a line1= %o3% + %o6% + %o9%
if /i %line1% equ 200 (
if /i %d3% equ 3 (
set guess=3
goto 1ac
)
if /i %d6% equ 6 (
set guess=6
goto 1ac
)
if /i %d9% equ 9 (
set guess=9
goto 1ac
)
)


::~ This section checks that there is no way the noughts can win next turn by adding up the %o-% grid. If so it sets the guess to the right number and 'goto's 1ac.

set guess=%time:~9,1%

::~ If there is no way that the computer OR the player can win next turn, the computer chooses a random number as its guess. The random number I use is the millisecond digit of the clock.

:1ac
if /i %guess% equ 0 goto 1display
echo !d%guess%!
if /i NOT !d%guess%!==%guess% goto 1display
goto 1x%guess%

::~ Checks that the place hasn't already been taken (as explained above) and 'goto's the corresponding place below.

:1x1
set x1=1
set o1=1000
set d1=X
goto 1xprocess
:1x2
set x2=10
set o2=1000
set d2=X
goto 1xprocess
:1x3
set x3=100
set o3=1000
set d3=X
goto 1xprocess
:1x4
set x4=1
set o4=1000
set d4=X
goto 1xprocess
:1x5
set x5=10
set o5=1000
set d5=X
goto 1xprocess
:1x6
set x6=100
set o6=1000
set d6=X
goto 1xprocess
:1x7
set x7=1
set o7=1000
set d7=X
goto 1xprocess
:1x8
set x8=10
set o8=1000
set d8=X
goto 1xprocess
:1x9
set x9=100
set o9=1000
set d9=X
goto 1xprocess



::~ This section, as for the noughts, changes the display character of the chosen place, and adds numbers to the %x-% grid.

:1xprocess
set /a line1= %x1% + %x2% + %x3%
if /i %line1% equ 111 (goto xwin)

set /a line2= %x4% + %x5% + %x6%
if /i %line2% equ 111 (goto xwin)

set /a line3= %x7% + %x8% + %x9%
if /i %line3% equ 111 (goto xwin)

set /a line4= %x1% + %x5% + %x9%
if /i %line4% equ 111 (goto xwin)

set /a line5= %x3% + %x5% + %x7%
if /i %line5% equ 111 (goto xwin)

set /a line6= %x1% + %x4% + %x7%
if /i %line6% equ 3 (goto xwin)

set /a line7= %x2% + %x5% + %x8%
if /i %line7% equ 30 (goto xwin)

set /a line8= %x3% + %x6% + %x9%
if /i %line8% equ 300 (goto xwin)

set go=1ogame
set /a turns= %turns% + 1
goto 1display

::~ Sets the turn to the player, increases the turns variable by one. 'Goto's the display.











::#######################################################






::~ Two player is exactly the same as one player, apart from the computer is replaced by a second player, the code is otherwise identical and does not need explaining again.


:2p
set turns=0
set x1=0
set x2=0
set x3=0
set x4=0
set x5=0
set x6=0
set x7=0
set x8=0
set x9=0
set o1=0
set o2=0
set o3=0
set o4=0
set o5=0
set o6=0
set o7=0
set o8=0
set o9=0

set d1=1
set d2=2
set d3=3
set d4=4
set d5=5
set d6=6
set d7=7
set d8=8
set d9=9

set rnumber=%random%
set rnumber2=rnumber
set /a rnumber= %rnumber% / 2
set /a rnumber= %rnumber% * 2
if %rnumber%==%rnumber2% (
echo Crosses go first
pause>nul
set rnumber=
set rnumber2=
set go=2xgame
goto 2display
) else (
echo Noughts go first
pause>nul
set rnumber=
set rnumber2=
set go=2ogame
goto 2display
)

:2display
cls
echo %d1% %d2% %d3%
echo %d4% %d5% %d6%
echo %d7% %d8% %d9%
if /i %turns% equ 9 (goto draw)
echo.
if /i "%go%"=="2ogame" (
echo Nought's Turn
) ELSE (
echo Cross's Turn
)
echo.
goto %go%

:2ogame
echo Choose the number of the space you'd like to choose
set guess=
set /p guess=
if not defined guess goto 2display
set guess=%guess:~0,1%
if /i not %guess% leq 9 goto 2display
if /i not %guess% gtr 0 goto 2display
if /i !d%guess%! neq %guess% goto 2display
goto 2o%guess%


:2o1
set o1=1
set d1=O
goto 2oprocess
:2o2
set o2=10
set d2=O
goto 2oprocess
:2o3
set o3=100
set d3=O
goto 2oprocess
:2o4
set o4=1
set d4=O
goto 2oprocess
:2o5
set o5=10
set d5=O
goto 2oprocess
:2o6
set o6=100
set d6=O
goto 2oprocess
:2o7
set o7=1
set d7=O
goto 2oprocess
:2o8
set o8=10
set d8=O
goto 2oprocess
:2o9
set o9=100
set d9=O
goto 2oprocess

:2oprocess
set /a line1= %o1% + %o2% + %o3%
if /i %line1% equ 111 (goto owin)

set /a line2= %o4% + %o5% + %o6%
if /i %line2% equ 111 (goto owin)

set /a line3= %o7% + %o8% + %o9%
if /i %line3% equ 111 (goto owin)

set /a line4= %o1% + %o5% + %o9%
if /i %line4% equ 111 (goto owin)

set /a line5= %o3% + %o5% + %o7%
if /i %line5% equ 111 (goto owin)

set /a line6= %o1% + %o4% + %o7%
if /i %line6% equ 3 (goto owin)

set /a line7= %o2% + %o5% + %o8%
if /i %line7% equ 30 (goto owin)

set /a line8= %o3% + %o6% + %o9%
if /i %line8% equ 300 (goto owin)

set go=2xgame
set guess=
set /a turns= %turns% + 1
goto 2display








:2xgame
echo Choose the number of the space you'd like to choose
set guess=
set /p guess=
if not defined guess goto 2display
set guess=%guess:~0,1%
if /i not %guess% leq 9 goto 2display
if /i not %guess% gtr 0 goto 2display
if /i !d%guess%! neq %guess% goto 2display
goto 2x%guess%


:2x1
set x1=1
set d1=X
goto 2xprocess
:2x2
set x2=10
set d2=X
goto 2xprocess
:2x3
set x3=100
set d3=X
goto 2xprocess
:2x4
set x4=1
set d4=X
goto 2xprocess
:2x5
set x5=10
set d5=X
goto 2xprocess
:2x6
set x6=100
set d6=X
goto 2xprocess
:2x7
set x7=1
set d7=X
goto 2xprocess
:2x8
set x8=10
set d8=X
goto 2xprocess
:2x9
set x9=100
set d9=X
goto 2xprocess

:2xprocess
set /a line1= %x1% + %x2% + %x3%
if /i %line1% equ 111 (goto xwin)

set /a line2= %x4% + %x5% + %x6%
if /i %line2% equ 111 (goto xwin)

set /a line3= %x7% + %x8% + %x9%
if /i %line3% equ 111 (goto xwin)

set /a line4= %x1% + %x5% + %x9%
if /i %line4% equ 111 (goto xwin)

set /a line5= %x3% + %x5% + %x7%
if /i %line5% equ 111 (goto xwin)

set /a line6= %x1% + %x4% + %x7%
if /i %line6% equ 3 (goto xwin)

set /a line7= %x2% + %x5% + %x8%
if /i %line7% equ 30 (goto xwin)

set /a line8= %x3% + %x6% + %x9%
if /i %line8% equ 300 (goto xwin)

set go=2ogame
set /a turns= %turns% + 1
goto 2display




:draw
echo.
Echo It's A Draw!
pause>nul
goto menu


:owin
cls
echo %d1% %d2% %d3%
echo %d4% %d5% %d6%
echo %d7% %d8% %d9%
Echo Noughts Win!
pause>nul
goto menu


:xwin
cls
echo %d1% %d2% %d3%
echo %d4% %d5% %d6%
echo %d7% %d8% %d9%
Echo Crosses Win!
Pause>nul
goto menu



:end
set d1=
set d2=
set d3=
set d4=
set d5=
set d6=
set d7=
set d8=
set d9=
set o1=
set o2=
set o3=
set o4=
set o5=
set o6=
set o7=
set o8=
set o9=
set x1=
set x2=
set x3=
set x4=
set x5=
set x6=
set x7=
set x8=
set x9=
set guess=
set turns=
set line1=
set line2=
set line3=
set line4=
set line5=
set line6=
set line7=
set line8=