James1998
|
Posted: Sun Jan 24, 2016 9:06 am Post subject: Tic Tace Toe Game HELP |
|
|
I have this so far but Please Can someone help me am not suppose to use arrrays am stuck i cant get the the computer to count the numbers of wins orrr say when a player wins or tie
can someone plz help me
var p1, p2 : int
var b1 := " "
var b2 := " "
var b3 := " "
var b4 := " "
var b5 := " "
var b6 := " "
var b7 := " "
var b8 := " "
var b9 := " "
var bxfont : int
var character : string (1)
var player1, player2, first : string
var numberOfWins1, numberOfWins2 : int
put ""
put "--------", " ------- ", "*******", "--------", "******* ", "******* ", "---------", "******** ", "********"
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "******* ", "* ", " * ", "* * ", "********"
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " -------- ", "*******", " * ", "* * ", "******* ", " * ", "******** ", "********"
put "Instructions: "
put "1. Players alternate by placing Xs and Os on the board until either (a) one player has three in a row, horizontally, vertically or diagonally"
put "2. If a player is able to draw three Xs or three Os in a row, that player wins."
put "3. If all nine squares are filled and neither player has three in a row, the"
put "game is a draw."
put "4. If a player is able to draw four Xs or four Os in a row, that player wins."
put "Press any key to continue.."
getch (character)
cls
delay (100)
put "--------", " ------- ", "*******", "--------", "******* ", "******* ", "---------", "******** ", "********"
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "******* ", "* ", " * ", "* * ", "********"
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " -------- ", "*******", " * ", "* * ", "******* ", " * ", "******** ", "********"
put "==============================================================================="
put ""
put "Please input the name of player 1: " ..
get player1 : *
put "Please input the name of player 2: " ..
get player2 : *
put ""
cls
delay (100)
put "******** ", "******* ", " ******* ", " ******** ", "******* ", "******* ", "******** ", "******** ", "********"
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", "******* ", "* ", " * ", "* * ", "********"
put " * ", " * ", "* ", " * ", "* * ", "* ", " * ", "* * ", "* "
put " * ", " * ", "* ", " * ", " * * ", "* ", " * ", "* * ", "* "
put " * ", " ******* ", "******* ", " * ", " * * ", "******* ", " * ", "******** ", "********"
put "==============================================================================="
locate (12, 10) %12 = row12, 10=column
put "here is the empty board"
put b1, "|", b2, "|", b3
put "---+--"
put b4, "|", b5, "|", b6
put "---+--"
put b7, "|", b8, "|", b9
loop
% loop begins here
put "eneter a position for p1 1-9"
get p1
if (p1 = 1) then
b1 := "x"
end if
if (p1 = 2) then
b2 := "x"
end if
if (p1 = 3) then
b3 := "x"
end if
if (p1 = 4) then
b4 := "x"
end if
if (p1 = 5) then
b5 := "x"
end if
if (p1 = 6) then
b6 := "x"
end if
if (p1 = 7) then
b7 := "x"
end if
if (p1 = 8) then
b8 := "x"
end if
if (p1 = 9) then
b9 := "x"
end if
put "here is the empty board"
put b1, "|", b2, "|", b3
put "---+--"
put b4, "|", b5, "|", b6
put "---+--"
put b7, "|", b8, "|", b9
if ((b1 = "x") and (b2 = "x") and (b3 = "x")) then
put "p1 you win"
Font.Draw ("Player 1 is the winner!", 130, 30, bxfont, 80)
exit
end if
if ((b4 = "x" and b5 = "x") and (b6 = "x")) then
put "p1 you win"
Font.Draw ("Player 1 is the winner!", 130, 30, bxfont, 80)
exit
end if
%%%%%%middle
%%%%%%%p2 starts here
% put "enter a position for p2 1-9"
loop
randomize
randint (p2, 1, 9)
if (p2 = 1) and b1 not= "x" and b1 not= "o" then
b1 := "o"
exit
end if
if (p2 = 2) and b2 not= "x" and b2 not= "o" then
b2 := "o"
exit
end if
if p2 = 1 and b3 not= "x" and b3 not= "o" then
b3 := "o"
exit
end if
if p2 = 1 and b4 not= "x" and b4 not= "o" then
b4 := "o"
exit
end if
if p2 = 1 and b5 not= "x" and b5 not= "o" then
b5 := "o"
exit
end if
if p2 = 1 and b6 not= "x" and b6 not= "o" then
b6 := "o"
exit
end if
if p2 = 1 and b7 not= "x" and b7 not= "o" then
b7 := "o"
exit
end if
if p2 = 1 and b8 not= "x" and b8 not= "o" then
b8 := "o"
exit
end if
if p2 = 1 and b9 not= "x" and b9 not= "o" then
b9 := "o"
exit
end if
end loop
put "here is the empty board"
put b1, "|", b2, "|", b3
put "---+--"
put b4, "|", b5, "|", b6
put "---+--"
put b7, "|", b8, "|", b9
loop
if ((b1 = "o") and (b2 = "o") and (b3 = "o")) then
put "p2 you win"
Font.Draw ("Player 2 is the winner!", 130, 30, bxfont, 80)
exit
end if
if ((b4 = "o" and b5 = "o") and b6 = "o") then
put "p2 you win"
Font.Draw ("Player 2 is the winner!", 130, 30, bxfont, 80)
exit
end if
if ((b7 = "o" and b8 = "o") and b9 = "o") then
put "p2 you win"
Font.Draw ("Player 2 is the winner!", 130, 30, bxfont, 80)
exit
end if
end loop
loop
if ((b1 = "x") and (b2 = "x") and (b3 = "x")) then
put "p1 you win"
Font.Draw ("Player 1 is the winner!", 130, 30, bxfont, 80)
exit
end if
if ((b4 = "x" and b5 = "x") and b6 = "x") then
put "p1 you win"
Font.Draw ("Player 1 is the winner!", 130, 30, bxfont, 80)
exit
end if
if ((b7 = "x" and b8 = "x") and b9 = "x") then
put "p1 you win"
Font.Draw ("Player 1 is the winner!", 130, 30, bxfont, 80)
exit
end if
end loop |
|
|