Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I am making a tic-tac-toe program for my culminating and need help on a simple problem with my graphics!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Seldrent




PostPosted: Fri Jan 08, 2010 2:40 pm   Post subject: I am making a tic-tac-toe program for my culminating and need help on a simple problem with my graphics!

Tic Tac Toe for culminating.
Everything in my arrays is exactly the same but only the first 2 boxes on the board work. Copy and paste this and press F2 then when u get to the board try typing 1,1 then 2,2 then 3,3 and watch what happens. Please Help!

var iX, iO : int
var sChoice, sChoice2 : string
var game : array 1 .. 9 of int
var game2 : array 1 .. 9 of int
game (1) := 1
game (2) := 2
game (3) := 3
game (4) := 4
game (5) := 5
game (6) := 6
game (7) := 7
game (8) := 8
game (9) := 9
game2 (1) := 1
game2 (2) := 2
game2 (3) := 3
game2 (4) := 4
game2 (5) := 5
game2 (6) := 6
game2 (7) := 7
game2 (8) := 8
game2 (9) := 9
put "Welcome to the game Tic-Tac-Toe!"
loop
put "Would you like to play against a computer or a friend?"
get sChoice
exit when (sChoice = "computer" or sChoice = "friend")
end loop
if sChoice = "computer" then
put "computer"
elsif sChoice = "friend" then
put "friend"
end if
cls
loop
put "Would you like to see the instructions on how to play? (yes / no)"
get sChoice2
exit when (sChoice2 = "yes" or sChoice2 = "no")
end loop
if sChoice2 = "yes" then
cls
put "You have to try and get 3 X's in a row and stop your opponent from getting 3 O's in a row."
put "You do this by pressing a number which represents each box as shown below."
put " "
put 1 : 5, 2 : 5, 3 : 5
put 4 : 5, 5 : 5, 6 : 5
put 7 : 5, 8 : 5, 9 : 5
delay (10000)
cls
elsif sChoice2 = "no" then
cls
end if
loop
Draw.Line (210, 0, 210, 400, black)
Draw.Line (420, 0, 420, 400, black)
Draw.Line (0, 150, 640, 150, black)
Draw.Line (0, 300, 640, 300, black)
for i : 1 .. upper (game)
get game (i)
exit when (i = 1)
end for
if game (1) = 1 then
Draw.Line (0, 300, 210, 400, black)
Draw.Line (0, 400, 210, 300, black)
elsif game (2) = 2 then
Draw.Line (210, 300, 420, 400, black)
Draw.Line (210, 400, 420, 300, black)
elsif game (3) = 3 then
Draw.Line (50, 100, 100, 50, black)
Draw.Line (420, 400, 640, 300, black)
elsif game (4) = 4 then
Draw.Line (0, 150, 210, 300, black)
Draw.Line (0, 300, 210, 150, black)
elsif game (5) = 5 then
Draw.Line (210, 150, 420, 300, black)
Draw.Line (210, 300, 420, 150, black)
elsif game (6) = 6 then
Draw.Line (420, 150, 640, 300, black)
Draw.Line (420, 300, 640, 150, black)
elsif game (7) = 7 then
Draw.Line (0, 0, 210, 150, black)
Draw.Line (0, 150, 210, 0, black)
elsif game (8) = 8 then
Draw.Line (210, 0, 420, 150, black)
Draw.Line (210, 150, 420, 0, black)
elsif game (9) = 9 then
Draw.Line (420, 0, 640, 150, black)
Draw.Line (420, 150, 640, 0, black)
end if
for i : 1 .. upper (game2)
get game2 (i)
exit when (i = 1)
end for
if game2 (1) = 1 then
Draw.Oval (105, 350, 40, 40, black)
elsif game2 (2) = 2 then
Draw.Oval (315, 350, 40, 40, black)
elsif game2 (3) = 3 then
Draw.Oval (530, 350, 40, 40, black)
elsif game2 (4) = 4 then
Draw.Oval (530, 225, 40, 40, black)
elsif game2 (5) = 5 then
Draw.Oval (315, 225, 40, 40, black)
elsif game2 (6) = 6 then
Draw.Oval (105, 75, 40, 40, black)
elsif game2 (7) = 7 then
Draw.Oval (105, 75, 40, 40, black)
elsif game2 (8) = 8 then
Draw.Oval (105, 75, 40, 40, black)
elsif game2 (9) = 9 then
Draw.Oval (105, 75, 40, 40, black)
end if
View.UpdateArea (0, 0, maxx, maxy)
end loop
Sponsor
Sponsor
Sponsor
sponsor
yumrum




PostPosted: Fri Jan 08, 2010 4:31 pm   Post subject: Re: I am making a tic-tac-toe program for my culminating and need help on a simple problem with my graphics!

So first of all u shouldn't let it play ontop on each other because i think if u forbide it to play on top u could solve the graphic problem
secondly tho y not us a for loop to shorten ur code such as


Turing:

for i : 1..9
game (i) := i
game2 (i) := i
end fo
Seldrent




PostPosted: Mon Jan 11, 2010 12:33 pm   Post subject: Re: I am making a tic-tac-toe program for my culminating and need help on a simple problem with my graphics!

I tried

for i : 1..9
game (i) := i
game2 (i) := i
end for

and im still getting the same problem. The problem has got to have something to do with the arrays or constants.
TerranceN




PostPosted: Mon Jan 11, 2010 4:23 pm   Post subject: RE:I am making a tic-tac-toe program for my culminating and need help on a simple problem with my graphics!

Your problem is not about constants and arrays, it is about your input loops and if statements.

What you wrote:

Turing:
for i : 1 .. upper (game)
    get game (i)
    exit when (i = 1)
end for


is no different than saying

Turing:
get game(1)


because the loop exits the first time it goes through. With this code you can only set game(1) to show up (this may have been your intention for debugging)

Also, with if/elsif/else statements only one block of code is run, for example:

Turing:
if true then
    put "a"
elsif true then
    put "b"
end if


"b" will never be printed to the screen, because after the first block of code, which prints "a", is called, it exits the if statement. But if you seperate the blocks of code into their own if statements:

Turing:
if true then
    put "a"
end if

if true then
    put "b"
end if


both "a" and "b" will be printed.

Finally, you may want to consider changing your arrays of integers to arrays of boolean, this wont change how the code runs, but it will make the code easier to understand.

Hope that helped.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: