Yang ini adalah game pelajaran.
Caranya sangat mudah.
Berikut tutorialnya:
-Buka program notepad.
-Copy code berikut dan pate di notepad
@echo off
color b4
:menu
cls
echo Hai! Selamat Datang Di Game! Selamat bermain!
echo Game Ini Di Buat oleh:Loardzs
echo Link blog :www.loardzs.blogspot.com
echo 1) Mulai!
echo 2) cara main
echo 3) Keluar
set /p number=
if %number% == 1 goto Mulai!
if %number% == 2 goto cara main
if %number% == 3 goto keluar
:Mulai!
cls
echo Siapa Nama Mu:
set /p name=
echo Halo %name%!
echo Apakah Kamu akan mulai quiz? (ya/tidak)
set /p start=
if %start% == ya goto level1
if %start% == tidak goto menu
goto Mulai!
:cara main
cls
echo pencet pilihan lalu ketik enter
echo pergi ke menu? (ya/tidak)
set /p menugoto=
if %menugoto% == ya goto menu
if %menugoto% == tidak goto exit
goto cara main
:keluar
cls
echo apakah anda yaking ingin keluar game?(y/t)
set /p keluargoto=
if %keluargoto% == y goto exit
if %keluargoto% == t goto menu
goto keluar
:level1
cls
echo ok sekarang mulai.
echo berapa hasil 10 + 10?
echo a) 1
echo b) 20
echo c) 500
set /p answer1=
if %answer1% == a goto wrong1
if %answer1% == b goto correct1
if %answer1% == c goto wrong1
goto level1
:correct1
echo betul mau lanjut level 2?(ya/tidak)
set /p NL1=
if %NL1% == ya goto level2
if %NL1% == tidak goto menu
goto correct1
:Wrong1
Echo salah mau ulang? (ya/tidak)
set /p WA1=
if %WA1% == ya goto level1
if %WA1% == tidak goto menu
goto wrong1
:level2
cls
echo Siapa yang ada di uang 100 dollar?
echo a) Ben Franklin
echo b) Tommy King
echo c) Thomas Train
echo d) Jeff Dunham
set /p aa=
if %aa% == a goto correct2
if %aa% == b goto wrong2
if %aa% == c goto wrong2
if %aa% == d goto wrong2
goto level2
:correct2
echo Kamu betul mau Lanjut level 3?(ya/tidak)
set /p NL1=
if %NL1% == ya goto level3
if %NL1% == tidak goto menu
goto correct2
:wrong2
cls
echo SALAH!Mau ulang? (ya/tidak)
set/p retry=
if %retry% == ya goto level1
if %retry% == tidak goto exit
goto wrong2
:level3
cls
echo berapa 5x5?
echo a) 30
echo b) 89
echo c) 25
set /p answer3=
if %answer3% == a goto wrong3
if %answer3% == b goto wrong3
if %answer3% == c goto correct3
goto level3
:correct3
echo betul mau lanjut level 4?(ya/tidak)
set /p NL1=
if %NL1% == ya goto level4
if %NL1% == tidak goto menu
goto correct3
:wrong3
cls
echo salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level3
if %retry% == tidak goto exit
goto wrong3
:level4
cls
echo siapa penemu lampu?
echo a)Thomas Alvadison
echo b)Johan Edvard
echo c)John Shore
echo d)Samuel Miller
set /p aa=
if %aa% == a goto correct4
if %aa% == b goto wrong4
if %aa% == c goto wrong4
if %aa% == d goto wrong4
goto level4
:correct4
echo betul mau lanjut level 5?(ya/tidak)
set /p NL1=
if %NL1% == ya goto level5
if %NL1% == tidak goto menu
goto correct4
:wrong4
cls
echo salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level4
if %retry% == tidak goto exit
goto wrong4
:level5
cls
echo berapa hasil -20:(-2)?
echo a)10
echo b)5
echo c)20
set /p answer5=
if %answer5% == a goto correct5
if %answer5% == b goto wrong5
if %answer5% == c goto wrong5
goto level5
:correct5
echo betul mau lanjut level 6?(ya/tidak)
set/p NL1=
if %NL1% == ya goto level6
if %NL1% == tidak goto menu
goto correct1
:wrong5
cls
echo Salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level5
if %retry% == tidak goto exit
goto wrong5
:level6
cls
echo Siapa Penemu Bakteri?
echo a)Orang Gila
echo b)Alexander Fleming
echo c)Alexander Grahambell
echo d)Muhammad Faqih`
set /p aa=
if %aa% == a goto wrong6
if %aa% == b goto correct6
if %aa% == c goto wrong6
if %aa% == d goto wrong
goto level6
:correct6
echo betul mau lanjut level7?(ya/tidak)
set/p NL1=
if %NL1% == ya goto level7
if %NL1% == tidak goto menu
goto correct7
:wrong6
cls
echo Salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level7
if %retry% == tidak goto exit
goto wrong7
:level7
cls
echo berapa hasil -40:2:(-4)?
echo a)13
echo b)20
echo c)5
set/p answer7=
if %answer7% == a goto wrong7
if %answer7% == b goto wrong7
if %answer7% == c goto correct7
goto level7
:correct7
echo betul mau lanjut level8? (ya/tidak)
set/p NL1=
if %NL1% == ya goto level8
if %NL1% == tidak goto menu
goto correct7
:wrong7
cls
echo Salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level7
if %retry% == tidak goto exit
goto wrong7
:level8
cls
echo Siapa Presiden Amerika
echo a)Barrak Obama
echo b)SBY
echo c)Soekarano
echo d)Moh.Hatta
set /p aa=
if %aa% == a goto correct8
if %aa% == b goto wrong8
if %aa% == c goto wrong8
if %aa% == d goto wrong8
:correct8
echo betul mau lanjut level9?(ya/tidak)
set/p NL1=
if %NL1% == ya goto level9
if %NL1% == tidak goto menu
goto correct8
:wrong8
cls
echo Salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level8
if %retry% == tidak goto exit
goto wrong8
:level9
echo berapa hasil 3x(-2)=
echo a)-100
echo b)400
echo c)-6
set /p answer9=
if %answer9% == a goto wrong9
if %answer9% == b goto wrong9
if %answer9% == c goto correct9
goto level9
:correct9
echo betul mau lanjut level 10?(ya/tidak)
set/p NL1=
if %NL1% == ya goto level10
if %NL1% == tidak goto menu
goto correct1
:wrong9
cls
echo Salah mau ulang?(ya/tidak)
set/p retry=
if %retry% == ya goto level9
if %retry% == tidak goto exit
goto wrong9
:level10
cls
echo Siapa penemu telepon?
echo a)Orang Gembel
echo b)Muhammad Faqih
echo c)Alexander Grahambell
echo d)SBY
set /p aa=
if %aa% == a goto wrong10
if %aa% == b goto wrong10
if %aa% == c goto correct10
if %aa% == d goto wrong10
goto level10
:correct10
cls
echo SELAMAT KAMU MENANG!
echo KEEP VISIT :www.loardzs.blogspot.com
goto correct10
:wrong10
cls
echo KAMU KALAH MAU ULANG GAME!?(y/n)
set/p retry=
if %retry% == y goto level1
if %retry% == n goto exit
goto wrong10
-Simpan file tersebut.
-Dan silahkan bermain
-Game Tic Tac Toe
-Buka program notepad
-Copy code berikut dan paste di notepad:
@echo off
title Banzai's Tic Tac Toe
title Noughts and Crosses
echo Link blog:www.loardzs.blogspot.com
setlocal enabledelayedexpansion
::~ ^^^ Stops all commands appearing on screen, sets the title and enables the use of ! for environment variable
: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=
echo KEEP VISIT: www.loardzs.blogspot.com
title Banzai's Tic Tac Toe
title Noughts and Crosses
echo Link blog:www.loardzs.blogspot.com
setlocal enabledelayedexpansion
::~ ^^^ Stops all commands appearing on screen, sets the title and enables the use of ! for environment variable
: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=
echo KEEP VISIT: www.loardzs.blogspot.com
-Simpan file notepad.
-Silahkan Dimainkan.
Sorry kalo panjang.

Tidak ada komentar:
Posting Komentar