TokenHerbz
|
Posted: Mon Oct 03, 2005 12:13 am Post subject: Shortning code |
|
|
Ok 1st ill post my ever long TIC TAC TOE code which works...
code: |
%%Tick Tack Toe
setscreen("Graphics:225;300")
%variables
var playerx: boolean %%which player it is
var TL, TM, TR: boolean := false %%top lines
var ML, MM, MR: boolean := false %%mid lines
var BL, BM, BR: boolean := false %%bot lines
var random: int %%to see who goes 1st
var playgame: boolean := true %%to play game
var endgame: boolean:= false %%to end the game
var ans: string
%%This is so i can tell which player owns which tiles...
var mtl, mtm, mtr, mml, mmm, mmr, mbl, mbm, mbr: boolean %%If True - player 1, false = player 2
%%Picks which player goes 1st
randint(random,1,2)
%%Player 1's 1st
if random = 1 then
put "Player one goes 1st"
put "Player one is"," 'X'"
playerx := true
else
%%Player 2's 1st
put "Player two goes 1st"
put "Player two is"," 'O'"
playerx := false
end if
Input.Pause
cls
proc draw
%%Draws the TicTacToe lines
for i: 1 .. 5
drawline(i+75,0,i+75,225,7)
drawline(i+150,0,i+150,225,7)
drawline(0,i+75,225,i+75,7)
drawline(0,i+150,225,i+150,7)
end for
end draw
proc TopLeft
if TL = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(20-i,170,60-i,210,7)
drawline(20-i,210,60-i,170,7)
end for
playerx := false %%player 2 turn
mtl:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(38,190,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mtl:= false %%player 2 owns it
end if
TL := true
end if
end TopLeft
proc TopMid
if TM = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(100-i,170,140-i,210,7)
drawline(100-i,210,140-i,170,7)
end for
playerx := false %%player 2 turn
mtm:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(113,190,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mtm:= false %%player 2 owns it
end if
TM := true
end if
end TopMid
proc TopRight
if TR = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(175-i,170,215-i,210,7)
drawline(175-i,210,215-i,170,7)
end for
playerx := false %%player 2 turn
mtr:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(188,190,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mtr:= false %%player 2 owns it
end if
TR := true
end if
end TopRight
proc MidLeft
if ML = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(20-i,95,60-i,135,7)
drawline(20-i,135,60-i,95,7)
end for
playerx := false %%player 2 turn
mml:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(38,115,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mml:= false %%player 2 owns it
end if
ML := true
end if
end MidLeft
proc MidMid
if MM = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(100-i,95,140-i,135,7)
drawline(100-i,135,140-i,95,7)
end for
playerx := false %%player 2 turn
mmm:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(113,115,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mmm:= false %%player 2 owns it
end if
MM := true
end if
end MidMid
proc MidRight
if MR = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(175-i,95,215-i,135,7)
drawline(175-i,135,215-i,95,7)
end for
playerx := false %%player 2 turn
mmr:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(188,115,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mmr:= false %%player 2 owns it
end if
MR := true
end if
end MidRight
proc BotLeft
if BL = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(20-i,20,60-i,60,7)
drawline(20-i,60,60-i,20,7)
end for
playerx := false %%player 2 turn
mbl:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(38,38,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mbl:= false %%player 2 owns it
end if
BL := true
end if
end BotLeft
proc BotMid
if BM = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(100-i,20,140-i,60,7)
drawline(100-i,60,140-i,20,7)
end for
playerx := false %%player 2 turn
mbm:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(113,38,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mbm:= false %%player 2 owns it
end if
BM := true
end if
end BotMid
proc BotRight
if BR = false then %%hasn't been pict yet
if playerx = true then %%1st player
for i: 1 .. 10 %%to fatten the X up
drawline(175-i,20,215-i,60,7)
drawline(175-i,60,215-i,20,7)
end for
playerx := false %%player 2 turn
mbr:= true %%player 1 owns it
else %%its player 2
for i: 1 .. 10 %%fatten up the circle
drawoval(188,38,i+10,i+10,7)
end for
playerx := true %%now player 1 turn
mbr:= false %%player 2 owns it
end if
BR := true
end if
end BotRight
proc win
% % % H O R R I Z O N T A L - W I N S % % %
%%player 1 gets top 3 tiles
if TL = true and mtl = true and TM = true and mtm = true and TR = true and mtr = true then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,184+i,225,184+i,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets top 3 tiles
elsif TL = true and mtl = false and TM = true and mtm = false and TR = true and mtr = false then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,184+i,225,184+i,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets mid 3 tiles
elsif ML = true and mml = true and MM = true and mmm = true and MR = true and mmr = true then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,110+i,225,110+i,7)
end for
put "P L A Y E R 1 W O N !"
%%player 1 gets middle 3 tiles
elsif ML = true and mml = false and MM = true and mmm = false and MR = true and mmr = false then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the vctory
drawline(0,110+i,225,110+i,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets bot 3 tiles
elsif BL = true and mbl = true and BM = true and mbm = true and BR = true and mbr = true then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,34+i,225,34+i,7)
end for
put "P L A Y E R 1 W O N !"
%%player 1 gets bot 3 tiles
elsif BL = true and mbl = false and BM = true and mbm = false and BR = true and mbr = false then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the vctory
drawline(0,34+i,225,34+i,7)
end for
put "P L A Y E R 2 W O N !"
% % % V E R T I C L E - W I N S % % %
%%player 1 gets left row
elsif TL = true and mtl = true and ML = true and mml = true and BL = true and mbl = true then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(34+i,0,34+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets left row
elsif TL = true and mtl = false and ML = true and mml = false and BL = true and mbl = false then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(34+i,0,34+i,225,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets mid row
elsif TM = true and mtm = true and MM = true and mmm = true and BM = true and mbm = true then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(110+i,0,110+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets mid row
elsif TM = true and mtm = false and MM = true and mmm = false and BM = true and mbm = false then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(110+i,0,110+i,225,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets right row
elsif TR = true and mtr = true and MR = true and mmr = true and BR = true and mbr = true then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(184+i,0,184+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets eight row
elsif TR = true and mtr = false and MR = true and mmr = false and BR = true and mbr = false then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(184+i,0,184+i,225,7)
end for
put "P L A Y E R 2 W O N !"
% % % S L A N T E D - W I N S % % %
%%player 1 wins with top left, to bottom right cross win - \
elsif TL = true and mtl = true and MM = true and mmm = true and BR = true and mbr = true then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,225,225+i,0,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 wins with TL - BR slash - \
elsif TL = true and mtl = false and MM = true and mmm = false and BR = true and mbr = false then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,225,225+i,0,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 wins with bot left, to top right cross win - /
elsif TR = true and mtr = true and MM = true and mmm = true and BL = true and mbl = true then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,0,225+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 wins with TR - BL slash - /
elsif TR = true and mtr = false and MM = true and mmm = false and BL = true and mbl = false then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,0,225+i,225,7)
end for
put "P L A Y E R 2 W O N !"
% % % C A T S - E Y E % % %
elsif TL = true and TM = true and TR = true and ML = true and MM = true and MR = true and BL = true and BM = true and BR = true then
endgame := true
for i: 1 .. 20
drawoval(125,125,75+i,75+i,7)
drawline(50+i,50,175+i,175,7)
end for
put " C A T S E Y E !"
end if
end win
proc game
if playerx = true then
locate(1,1)
put "It is player One's turn, 'X'"
elsif playerx = false then
locate(1,1)
put "It is player Two's turn, 'O'"
end if
var mx,my,mb: int %%Mouse chords
Mouse.Where(mx,my,mb)
if mb = 1 then %%if mouse is clicked
if mx <= 75 and mx >= 0 and my <= 225 and my >= 175 then %%Location for top left tile
TopLeft
elsif mx <= 150 and mx >= 75 and my <= 225 and my >= 175 then %%location for top mid tile
TopMid
elsif mx <= 225 and mx >= 150 and my <= 225 and my >= 175 then %%top right location
TopRight
elsif mx <= 75 and mx >= 0 and my <= 150 and my >= 75 then %%Midleft tile location
MidLeft
elsif mx <= 150 and mx >= 75 and my <= 150 and my >= 75 then %%midmid tile loc
MidMid
elsif mx <= 225 and mx >= 150 and my <= 150 and my >= 75 then %%mid right loc
MidRight
elsif mx <= 75 and mx >= 0 and my <= 75 and my >= 0 then %%Bot left tile
BotLeft
elsif mx <= 150 and mx >= 75 and my <= 75 and my >= 0 then %%Mot mid tile
BotMid
elsif mx <= 225 and mx >= 150 and my <= 75 and my >= 0 then %%Bot Right tile loc
BotRight
end if
end if
draw
win
end game
%%main loop
loop
if playgame = true then
game
end if
if endgame = true then
Input.Pause
cls
put "Made By: The Legit Derek!!"
put ""
put ""
put ""
put ""
put "Please Tell me errors, etc:"
put "How to make this better?"
put "And rate it 1 - 10! :)"
put "AI COMP SOON TO COME!"
put ""
put " E N J O Y !"
put ""
put ""
put ""
put "Would you like to play again"
put "'Y'/'y' OR 'N'/'n'"
get ans
if ans = 'Y' or ans = 'y' then
playgame:= true
endgame := false
TL:= false
TM:= false
TR:= false
ML:= false
MM:= false
MR:= false
BL:= false
BM:= false
BR:= false
cls
else
exit
end if
end if
end loop
cls
put "Thanks For Playing"
put ""
put " BYE"
|
Now i get errors when i try to shorten this code, and im stumped, i need some serious help on this cookie, please??
Here is my Current attempt to shorten the code which dosn't work and gives me errors of T1 not being declared, when i did at the top...
code: |
%%Tick Tack Toe
setscreen("Graphics:225;300")
%variables
var playerx: boolean %%which player it is
var T: array 1 .. 9 of boolean
var random: int %%to see who goes 1st
var playgame: boolean := true %%to play game
var endgame: boolean:= false %%to end the game
var ans: string
var i :array 1 .. 9 of int
%%This is so i can tell which player owns which tiles...
var TT: array 1 .. 9 of boolean %%If True - player 1, false = player 2
for k: 1 .. 9
T(k) := false
end for
%%Picks which player goes 1st
randint(random,1,2)
%%Player 1's 1st
if random = 1 then
put "Player one goes 1st"
put "Player one is"," 'X'"
playerx := true
else
%%Player 2's 1st
put "Player two goes 1st"
put "Player two is"," 'O'"
playerx := false
end if
Input.Pause
cls
proc draw
%%Draws the TicTacToe lines
for i: 1 .. 5
drawline(i+75,0,i+75,225,7)
drawline(i+150,0,i+150,225,7)
drawline(0,i+75,225,i+75,7)
drawline(0,i+150,225,i+150,7)
end for
end draw
%%the tiles for the game
proc Tiles
for i: 1 .. 9
if TT(i) = false then %%hasn't been pict yet
if playerx = true then %%1st player
for k: 1 .. 10 %%to fatten the X up
drawline(20-k,170,60-k,210,7)
drawline(20-k,210,60-k,170,7)
end for
playerx := false %%player 2 turn
TT(i):= true %%player 1 owns it
else %%its player 2
for k: 1 .. 10 %%fatten up the circle
drawoval(38,190,k+10,k+10,7)
end for
playerx := true %%now player 1 turn
TT(i):= false %%player 2 owns it
end if
TT(i) := true
end if
end for
end Tiles
proc win
% % % H O R R I Z O N T A L - W I N S % % %
%%player 1 gets top 3 tiles
if T1 = true and TT1 = true and T2 = true and TT2 = true and T3 = true and TT3 = true then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,184+i,225,184+i,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets top 3 tiles
elsif T1 = true and TT1 = false and T2 = true and TT2 = false and T3 = true and TT3 = false then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,184+i,225,184+i,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets mid 3 tiles
elsif T4 = true and TT4 = true and T5 = true and TT5 = true and T6 = true and TT6 = true then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,110+i,225,110+i,7)
end for
put "P L A Y E R 1 W O N !"
%%player 1 gets middle 3 tiles
elsif T4 = true and TT4 = false and T5 = true and TT5 = false and T6 = true and TT6 = false then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the vctory
drawline(0,110+i,225,110+i,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets bot 3 tiles
elsif T7 = true and TT7 = true and T8 = true and TT8 = true and T9 = true and TT9 = true then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the victory
drawline(0,34+i,225,34+i,7)
end for
put "P L A Y E R 1 W O N !"
%%player 1 gets bot 3 tiles
elsif T7 = true and TT7 = false and T8 = true and TT8 = false and T9 = true and TT9 = false then
endgame := true %%to end game
for i: 1 .. 10 %%draws a line threw the vctory
drawline(0,34+i,225,34+i,7)
end for
put "P L A Y E R 2 W O N !"
% % % V E R T I C L E - W I N S % % %
%%player 1 gets left row
elsif T1 = true and TT1 = true and T4 = true and TT4 = true and T7 = true and TT7 = true then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(34+i,0,34+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets left row
elsif T1 = true and TT1 = false and T4 = true and TT4 = false and T7 = true and TT7 = false then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(34+i,0,34+i,225,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets mid row
elsif T2 = true and TT2 = true and T5 = true and TT5 = true and T8 = true and TT8 = true then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(110+i,0,110+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets mid row
elsif T2 = true and TT2 = false and T5 = true and TT5 = false and T8 = true and TT8 = false then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(110+i,0,110+i,225,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 gets right row
elsif T3 = true and TT3 = true and T6 = true and TT6 = true and T9 = true and TT9 = true then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(184+i,0,184+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 gets eight row
elsif T3 = true and TT3 = false and T6 = true and TT6 = false and T9 = true and TT9 = false then
endgame := true
for i: 1 .. 10 %%Fatten the line
drawline(184+i,0,184+i,225,7)
end for
put "P L A Y E R 2 W O N !"
% % % S L A N T E D - W I N S % % %
%%player 1 wins with top left, to bottom right cross win - \
elsif T1 = true and TT1 = true and T5 = true and TT5 = true and T9 = true and TT9 = true then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,225,225+i,0,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 wins with TL - BR slash - \
elsif T1 = true and TT1 = false and T5 = true and TT5 = false and T9 = true and TT9 = false then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,225,225+i,0,7)
end for
put "P L A Y E R 2 W O N !"
%%player 1 wins with bot left, to top right cross win - /
elsif T3 = true and TT3 = true and T5 = true and TT5 = true and T7 = true and TT7 = true then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,0,225+i,225,7)
end for
put "P L A Y E R 1 W O N !"
%%player 2 wins with TR - BL slash - /
elsif T3 = true and TT3 = false and T5= true and TT5 = false and T7 = true and TT7 = false then
endgame := true
for i: 1 .. 10 %%fatten up line
drawline(0+i,0,225+i,225,7)
end for
put "P L A Y E R 2 W O N !"
% % % C A T S - E Y E % % %
elsif T1 = true and T2 = true and T3 = true and T4 = true and T5 = true and T6 = true and T7 = true and T8 = true and T9 = true then
endgame := true
for i: 1 .. 20
drawoval(125,125,75+i,75+i,7)
drawline(50+i,50,175+i,175,7)
end for
put " C A T S E Y E !"
end if
end win
proc game
if playerx = true then
locate(1,1)
put "It is player One's turn, 'X'"
elsif playerx = false then
locate(1,1)
put "It is player Two's turn, 'O'"
end if
var mx,my,mb: int %%Mouse chords
Mouse.Where(mx,my,mb)
if mb = 1 then %%if mouse is clicked
if mx <= 75 and mx >= 0 and my <= 225 and my >= 175 then %%Location for top left tile
i := 1
elsif mx <= 150 and mx >= 75 and my <= 225 and my >= 175 then %%location for top mid tile
i := 2
elsif mx <= 225 and mx >= 150 and my <= 225 and my >= 175 then %%top right location
i := 3
elsif mx <= 75 and mx >= 0 and my <= 150 and my >= 75 then %%Midleft tile location
i := 4
elsif mx <= 150 and mx >= 75 and my <= 150 and my >= 75 then %%midmid tile loc
i := 5
elsif mx <= 225 and mx >= 150 and my <= 150 and my >= 75 then %%mid right loc
i := 6
elsif mx <= 75 and mx >= 0 and my <= 75 and my >= 0 then %%Bot left tile
i := 7
elsif mx <= 150 and mx >= 75 and my <= 75 and my >= 0 then %%Mot mid tile
i := 8
elsif mx <= 225 and mx >= 150 and my <= 75 and my >= 0 then %%Bot Right tile loc
i := 9
end if
end if
draw
win
end game
%%main loop
loop
if playgame = true then
game
end if
if endgame = true then
Input.Pause
cls
put "Made By: The Legit Derek!!"
put ""
put ""
put ""
put ""
put "Please Tell me errors, etc:"
put "How to make this better?"
put "And rate it 1 - 10! :)"
put "AI COMP SOON TO COME!"
put ""
put " E N J O Y !"
put ""
put ""
put ""
put "Would you like to play again"
put "'Y'/'y' OR 'N'/'n'"
get ans
if ans = 'Y' or ans = 'y' then
playgame:= true
endgame := false
TL:= false
TM:= false
TR:= false
ML:= false
MM:= false
MR:= false
BL:= false
BM:= false
BR:= false
cls
else
exit
end if
end if
end loop
cls
put "Thanks For Playing"
put ""
put " BYE"
|
plz help! |
|
|