Tic-Tac-Toe
Author |
Message |
myckem
|
Posted: Tue Jan 24, 2006 5:47 pm Post subject: Tic-Tac-Toe |
|
|
I have made a Tic-Tac-Toe program but I must have messed up somewhere since there seems to be a problem. Keep in mind that I just started Turing not long ago
Here is the program. Sorry some stuff are in french
code: | var font1, font2, font3 : int
var position : array 1 .. 9 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
var post2 : array 1 .. 9 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
var lettre, check : string
var nom : array 1 .. 2 of string
var c1, c2 : int := 0
font1 := Font.New ("serif:24")
font2 := Font.New ("serif:28:bold")
font3 := Font.New ("serif:20:bold")
check := "ABCDEFGHI"
procedure choix (couleur : int, j : int)
if j = 1 then
if lettre = "A" then
Font.Draw ("X", 400, 350, font2, couleur)
elsif lettre = "B" then
Font.Draw ("X", 450, 350, font2, couleur)
elsif lettre = "C" then
Font.Draw ("X", 500, 350, font2, couleur)
elsif lettre = "D" then
Font.Draw ("X", 400, 300, font2, couleur)
elsif lettre = "E" then
Font.Draw ("X", 450, 300, font2, couleur)
elsif lettre = "F" then
Font.Draw ("X", 500, 300, font2, couleur)
elsif lettre = "G" then
Font.Draw ("X", 400, 250, font2, couleur)
elsif lettre = "H" then
Font.Draw ("X", 450, 250, font2, couleur)
elsif lettre = "I" then
Font.Draw ("X", 500, 250, font2, couleur)
else
put "Vous perdez votre tour!"
end if
else
if lettre = "A" then
Font.Draw ("O", 400, 350, font2, couleur)
elsif lettre = "B" then
Font.Draw ("O", 450, 350, font2, couleur)
elsif lettre = "C" then
Font.Draw ("O", 500, 350, font2, couleur)
elsif lettre = "D" then
Font.Draw ("O", 400, 300, font2, couleur)
elsif lettre = "E" then
Font.Draw ("O", 450, 300, font2, couleur)
elsif lettre = "F" then
Font.Draw ("O", 500, 300, font2, couleur)
elsif lettre = "G" then
Font.Draw ("O", 400, 250, font2, couleur)
elsif lettre = "H" then
Font.Draw ("O", 450, 250, font2, couleur)
elsif lettre = "I" then
Font.Draw ("O", 500, 250, font2, couleur)
else
put "Vous perdez votre tour!!!"
end if
end if
end choix
put "Quel est le nom du joueur 1 ?"
get nom (1)
put "Quel est le nom du joueur 2 ?"
get nom (2)
Font.Draw ("A", 400, 350, font1, black)
Font.Draw ("B", 450, 350, font1, black)
Font.Draw ("C", 500, 350, font1, black)
Font.Draw ("D", 400, 300, font1, black)
Font.Draw ("E", 450, 300, font1, black)
Font.Draw ("F", 500, 300, font1, black)
Font.Draw ("G", 400, 250, font1, black)
Font.Draw ("H", 450, 250, font1, black)
Font.Draw ("I", 500, 250, font1, black)
loop
locate (15, 1)
put "Joueur #1", "", nom (1) : 2, ",", "entrez votre lettre"
loop
get lettre
if index (check, lettre) not= 0 then
c1 := +1
position (c1) := index (check, lettre)
position (index (check, lettre)) := 1
check := check (1 .. position (c1) - 1) + "*" + check (position (c1) + 1 .. *)
exit
else
put "Cela n'est pas un choix,essayer encore"
end if
end loop
choix (red, 1)
put "Joueur #2" : 2, "", nom (2) : 2, ",", "entrez votre lettre"
loop
get lettre
if index (check, lettre) not= 0 then
c2 := +1
post2 (c2) := index (check, lettre)
post2 (index (check, lettre)) := 2
check := check (1 .. post2 (c2) - 1) + "*" + check (post2 (c2) + 1 .. *)
exit
else
put "Cela n'est pas un choix,essayer encore"
end if
end loop
choix (blue, 2)
if position (1) = position (3) and position (1) = position (2) then
Draw.ThickLine (400, 360, 500, 360, 3, red)
end if
end loop
|
It's a basic Tic-Tac-Toe game with letters. The game is not done but I am stuck at the end. The if at the end doest work. Thank you for your time ![Very Happy Very Happy](images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tupacalypse_Vinsanity
![](http://x1.putfile.com/9/26017025785.gif)
|
Posted: Tue Jan 24, 2006 6:30 pm Post subject: ~ |
|
|
Can you try to post an english version? I could try to help if you do. |
|
|
|
|
![](images/spacer.gif) |
myckem
|
Posted: Tue Jan 24, 2006 10:23 pm Post subject: (No subject) |
|
|
Well here is the new version since I couldnt edit my post
code: |
var font1, font2, font3 : int
var position : array 1 .. 9 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
var position2 : array 1 .. 9 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
var letter, check : string
var name : array 1 .. 2 of string
var c1, c2 : int := 0
font1 := Font.New ("serif:24")
font2 := Font.New ("serif:28:bold")
font3 := Font.New ("serif:20:bold")
check := "ABCDEFGHI"
procedure choice (colour : int, j : int)
if j = 1 then
if letter = "A" then
Font.Draw ("X", 400, 350, font2, colour)
elsif letter = "B" then
Font.Draw ("X", 450, 350, font2, colour)
elsif letter = "C" then
Font.Draw ("X", 500, 350, font2, colour)
elsif letter = "D" then
Font.Draw ("X", 400, 300, font2, colour)
elsif letter = "E" then
Font.Draw ("X", 450, 300, font2, colour)
elsif letter = "F" then
Font.Draw ("X", 500, 300, font2, colour)
elsif letter = "G" then
Font.Draw ("X", 400, 250, font2, colour)
elsif letter = "H" then
Font.Draw ("X", 450, 250, font2, colour)
elsif letter = "I" then
Font.Draw ("X", 500, 250, font2, colour)
else
put "You lose a turn!"
end if
else
if letter = "A" then
Font.Draw ("O", 400, 350, font2, colour)
elsif letter = "B" then
Font.Draw ("O", 450, 350, font2, colour)
elsif letter = "C" then
Font.Draw ("O", 500, 350, font2, colour)
elsif letter = "D" then
Font.Draw ("O", 400, 300, font2, colour)
elsif letter = "E" then
Font.Draw ("O", 450, 300, font2, colour)
elsif letter = "F" then
Font.Draw ("O", 500, 300, font2, colour)
elsif letter = "G" then
Font.Draw ("O", 400, 250, font2, colour)
elsif letter = "H" then
Font.Draw ("O", 450, 250, font2, colour)
elsif letter = "I" then
Font.Draw ("O", 500, 250, font2, colour)
else
put "You lose a turn!!!"
end if
end if
end choice
put "Enter the name of player 1"
get name (1)
put "Enter the name of player 2"
get name (2)
Font.Draw ("A", 400, 350, font1, black)
Font.Draw ("B", 450, 350, font1, black)
Font.Draw ("C", 500, 350, font1, black)
Font.Draw ("D", 400, 300, font1, black)
Font.Draw ("E", 450, 300, font1, black)
Font.Draw ("F", 500, 300, font1, black)
Font.Draw ("G", 400, 250, font1, black)
Font.Draw ("H", 450, 250, font1, black)
Font.Draw ("I", 500, 250, font1, black)
loop
locate (15, 1)
put "Player #1", "", name (1) : 2, ",", "enter your letter"
loop
get letter
if index (check, letter) not= 0 then
c1 := +1
position (c1) := index (check, letter)
position (index (check, letter)) := 1
check := check (1 .. position (c1) - 1) + "*" + check (position (c1) + 1 .. *)
exit
else
put "That is not a possible choice, try again"
end if
end loop
choice (red, 1)
put "Player #2" : 2, "", name (2) : 2, ",", "enter your letter"
loop
get letter
if index (check, letter) not= 0 then
c2 := +1
position2 (c2) := index (check, letter)
position2 (index (check, letter)) := 2
check := check (1 .. position2 (c2) - 1) + "*" + check (position2 (c2) + 1 .. *)
exit
else
put "That is not a possible choice, try again"
end if
end loop
choice (blue, 2)
if position (1) = position (3) and position (1) = position (2) then
Draw.ThickLine (400, 360, 500, 360, 3, red)
end if
end loop
|
![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
sylvester-27
![](http://www.icejerseys.com/images/vintage_collection/toronto_st_pats/heritage_jersey.jpg)
|
Posted: Wed Jan 25, 2006 12:50 pm Post subject: (No subject) |
|
|
you should make the program recognize when the user wins...also the is a very...unique way to make tic tac toe. And whats the problem?
The program itself works fine. |
|
|
|
|
![](images/spacer.gif) |
Albrecd
|
Posted: Wed Jan 25, 2006 1:29 pm Post subject: (No subject) |
|
|
If ther is an O on A, you can still put an X on it. |
|
|
|
|
![](images/spacer.gif) |
myckem
|
Posted: Wed Jan 25, 2006 10:00 pm Post subject: (No subject) |
|
|
The problem is it doesnt recognize when someone wins. And I dont know how to fix the A problem. |
|
|
|
|
![](images/spacer.gif) |
myckem
|
Posted: Fri Jan 27, 2006 4:46 pm Post subject: (No subject) |
|
|
Nobody can help? ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
myckem
|
Posted: Sun Jan 29, 2006 11:50 pm Post subject: (No subject) |
|
|
I would appreciate it if someone could tell me where I went wrong or guide in the right direction ![Confused Confused](http://compsci.ca/v3/images/smiles/icon_confused.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Mon Jan 30, 2006 11:03 am Post subject: (No subject) |
|
|
Ah, mon ami! Une programme en francais, c'est vraiment fraise, bien-sur. Oui, je sais, je sais, mon francais est terrible, mais, on peut essayer un peut, non?
La probleme principal, je pense, est ici:
code: |
if index (check, lettre) not= 0 then
c1 := +1
%...
|
Est-ce que tu peut dire que 'c1'...uh...bah. Yeah, that's not going to work much longer.
Ok, as I was saying, are you trying to say that 'c1' ought to increase by one? Because this line sets c1 to 1, as opposed to adding 1 to it.
code: |
c1 += 1
% Or equivalently:
% c1 := c1 + 1
|
Would be what you'd need to do.
There is a problem though. If you, for instance, echo the contents of position(1)...position(3), you'll notice that they increase over time. I'm not sure if this is intentional, but it nullifies the effect of this statement:
code: |
if position (1) = position (3) and position (1) = position (2) then
%...
|
Try it out for yourself. Add these lines to the end of the loop:
code: |
locate (6, 3)
put position (1), " ", position (2), " ", position (3) ..
|
If I understand your intent correctly, 'position' will hold all the positions of player 1? And post2 will do the same for player 2? If so, it would simply be easier to use one array, and use an indicator for each block that specifies which player occupies it. For instance, if position (1) were '2' then player 2 would have a piece there.
From this you may check which triplets are held by which players.
Bon chance! |
|
|
|
|
![](images/spacer.gif) |
redrenagade
|
Posted: Sat Feb 11, 2006 12:14 pm Post subject: (No subject) |
|
|
try adding a instructions page. Would really help clear up how to play. Figured it out though... |
|
|
|
|
![](images/spacer.gif) |
|
|