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

Username:   Password: 
 RegisterRegister   
 tic tac toe
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ohgeez_




PostPosted: Wed Apr 05, 2006 9:27 pm   Post subject: tic tac toe

my first game =D. I didn't use x's and o's because i didn't want to waste time drawing them. Just finished a massive pixel graphic program for school. Please give comments on how to improve this.


code:


setscreen ("graphics: 460;480")

var x, y, button : int
var count : int := 1
var reds : array 1 .. 8 of int
var blues : array 1 .. 8 of int

for i : 1 .. 8
    reds (i) := 0
    blues (i) := 0
end for

%blue1 top horizontal
%blue2 middle horizontal
%blue3 bottom horizontal
%blue4 left vertical
%blue5 middle vertical
%blue6 right vertical
%blue7 diagonal from top left
%blue8 diagonal form top right

%layout
drawbox (100, 100, 400, 400, black)
drawline (200, 100, 200, 400, black)
drawline (300, 100, 300, 400, black)
drawline (100, 200, 400, 200, black)
drawline (100, 300, 400, 300, black)

procedure one_and_one
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (150, 150, 50, 50, brightblue)
        blues (3) := blues (3) + 1
        blues (4) := blues (4) + 1
        blues (8) := blues (8) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (150, 150, 50, 50, brightred)
        reds (3) := reds (3) + 1
        reds (4) := reds (4) + 1
        reds (8) := reds (8) + 1
    end if
end one_and_one

procedure one_and_two
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (150, 250, 50, 50, brightblue)
        blues (2) := blues (2) + 1
        blues (4) := blues (4) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (150, 250, 50, 50, brightred)
        reds (2) := reds (2) + 1
        reds (4) := reds (4) + 1
    end if
end one_and_two

procedure one_and_three
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (150, 350, 50, 50, brightblue)
        blues (1) := blues (1) + 1
        blues (4) := blues (4) + 1
        blues (7) := blues (7) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (150, 350, 50, 50, brightred)
        reds (1) := reds (1) + 1
        reds (4) := reds (4) + 1
        reds (7) := reds (7) + 1
    end if
end one_and_three

procedure two_and_one
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (250, 150, 50, 50, brightblue)
        blues (3) := blues (3) + 1
        blues (5) := blues (5) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (250, 150, 50, 50, brightred)
        reds (3) := reds (3) + 1
        reds (5) := reds (5) + 1
    end if
end two_and_one

procedure two_and_two
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (250, 250, 50, 50, brightblue)
        blues (2) := blues (2) + 1
        blues (5) := blues (5) + 1
        blues (7) := blues (7) + 1
        blues (8) := blues (8) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (250, 250, 50, 50, brightred)
        reds (2) := reds (2) + 1
        reds (5) := reds (5) + 1
        reds (7) := reds (7) + 1
        reds (8) := reds (8) + 1
    end if
end two_and_two

procedure two_and_three
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (250, 350, 50, 50, brightblue)
        blues (1) := blues (1) + 1
        blues (5) := blues (5) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (250, 350, 50, 50, brightred)
        reds (1) := reds (1) + 1
        reds (5) := reds (5) + 1
    end if
end two_and_three

procedure three_and_one
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (350, 150, 50, 50, brightblue)
        blues (3) := blues (3) + 1
        blues (6) := blues (6) + 1
        blues (7) := blues (7) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (350, 150, 50, 50, brightred)
        reds (3) := reds (3) + 1
        reds (6) := reds (6) + 1
        reds (7) := reds (7) + 1
    end if
end three_and_one

procedure three_and_two
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (350, 250, 50, 50, brightblue)
        blues (2) := blues (2) + 1
        blues (6) := blues (6) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (350, 250, 50, 50, brightred)
        reds (2) := reds (2) + 1
        reds (6) := reds (6) + 1
    end if
end three_and_two

procedure three_and_three
    if count = 1 or count = 3 or count = 5 or count = 7 or count = 9 then
        drawfilloval (350, 350, 50, 50, brightblue)
        blues (1) := blues (1) + 1
        blues (6) := blues (6) + 1
        blues (8) := blues (8) + 1
    elsif count = 2 or count = 4 or count = 6 or count = 8 then
        drawfilloval (350, 350, 50, 50, brightred)
        reds (1) := reds (1) + 1
        reds (6) := reds (6) + 1
        reds (8) := reds (8) + 1
    end if
end three_and_three


loop
    mousewhere (x, y, button)

    if button = 1 and x >= 100 and x <= 200 and y >= 100 and y <= 200 then
        one_and_one
    elsif button = 1 and x >= 100 and x <= 200 and y >= 200 and y <= 300 then
        one_and_two
    elsif button = 1 and x >= 100 and x <= 200 and y >= 300 and y <= 400 then
        one_and_three
    elsif button = 1 and x >= 200 and x <= 300 and y >= 100 and y <= 200 then
        two_and_one
    elsif button = 1 and x >= 200 and x <= 300 and y >= 200 and y <= 300 then
        two_and_two
    elsif button = 1 and x >= 200 and x <= 300 and y >= 300 and y <= 400 then
        two_and_three
    elsif button = 1 and x >= 300 and x <= 400 and y >= 100 and y <= 200 then
        three_and_one
    elsif button = 1 and x >= 300 and x <= 400 and y >= 200 and y <= 300 then
        three_and_two
    elsif button = 1 and x >= 300 and x <= 400 and y >= 300 and y <= 400 then
        three_and_three
    else
        put "Choose a box"
    end if

    if button = 1 then
        delay (500)
        count := count + 1
    end if

    exit when count = 11
    locate (1, 1)
    put "X coodinate at ", x
    locate (2, 1)
    put "Y coordinte at ", y

    if blues (1) = 3 or blues (2) = 3 or blues (3) = 3 or blues (4) = 3 or blues (5) = 3 or blues (6) = 3 or blues (7) = 3 or blues (8) = 3 then
        locate (28, 5)
        put "Blue Wins!!"
        locate (3, 1)
        put " "
        exit
    elsif reds (1) = 3 or reds (2) = 3 or reds (3) = 3 or reds (4) = 3 or reds (5) = 3 or reds (6) = 3 or reds (7) = 3 or reds (8) = 3 then
        locate (28, 5)
        put "Red Wins!!!"
        locate (3, 1)
        put " "
        exit
    elsif count = 10 then
        locate (28, 5)
        put "Draw!"
        locate (3, 1)
        put " "
        exit
    end if
end loop

Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Wed Apr 05, 2006 9:38 pm   Post subject: (No subject)

Nice work Very Happy I remember there was some uber efficient way to code Tic Tac Toe in like < 50 lines. It might be in one of the stickies, I'll try and post a link in a bit. One thing I noticed is: You can place a red on top of a blue, and vice versa. That is to say, if I click on one location, then click on it again, the next piece will be placed there as well. If I do this a couple times, it even names a winner.

Instead of using coding like:

click
delay
action

consider:

code:

If button = 1 then
    loop
        mousewhere(x,y,button)
        exit when button = 0
    end loop
end if


This makes it so no matter how long they hold the mouse down, there will be no negative reprocussions.

Other than that, nice work. Definetly beats my first Tic Tac Toe game (By a long shot Razz)
NikG




PostPosted: Thu Apr 06, 2006 10:23 am   Post subject: (No subject)

Quote:
consider:

If button = 1 then
loop
mousewhere(x,y,button)
exit when button = 0
end loop
end if

This makes it so no matter how long they hold the mouse down, there will be no negative reprocussions.

Interesting suggestion, TheOneTrueGod, but I'm confused.
You helped me fix that kind of a bug in a much better way for my City Defender.

If you remember, you suggested a variable called OldButton, which should be set to button before each Mouse.Where and a check that OldButton is not equal Button.
code:
OldButton := Button
Mouse.Where (x,y,Button)

if Button=1 and oldButton not = 1 then
  %...
end if

This also prevents errors from users holding the mouse down for too long without the usage of an extra loop. Smile

Edit: oh yeah, great first game ohgeez_
Delos




PostPosted: Thu Apr 06, 2006 10:55 am   Post subject: (No subject)

Why reinvent the wheel? Aside from the learning that you'll get it you do it well...

Look up Mouse.Moved() and Mouse.ButtonWait()...they'll make your life a little easier, if not more variable...Laughing. Sorry, inside joke.
djlenny_3000




PostPosted: Thu Apr 06, 2006 1:18 pm   Post subject: (No subject)

very nice game! Smile

in my opinion very well done

try to make it so instead it draw an X trough the whole box or an O with a diameter of the box instead of circles

but very nice start
TheOneTrueGod




PostPosted: Fri Apr 07, 2006 6:22 am   Post subject: (No subject)

I don't know why, but I never got around to using the predefined turing functions. (Probably because my teacher hated them for no apparante reason)

The reason I gave two different ways to do it was because each was circumstantial. In NikG's game, you wanted stuff to happen while the user was holding down the mouse click. The way I provided would allow the program to run while the user still held the mouse button down.

In ohgeez_'s game, its much more plausible for the program to pause, and wait until the user stops pressing the button. It would be possible to do it the other way, but he would probably have to put in quite a few more checks scattered throughout the following lines:

code:
if button = 1 and x >= 100 and x <= 200 and y >= 100 and y <= 200 then
        one_and_one
    elsif button = 1 and x >= 100 and x <= 200 and y >= 200 and y <= 300 then
        one_and_two
    elsif button = 1 and x >= 100 and x <= 200 and y >= 300 and y <= 400 then
        one_and_three
    elsif button = 1 and x >= 200 and x <= 300 and y >= 100 and y <= 200 then
        two_and_one
    elsif button = 1 and x >= 200 and x <= 300 and y >= 200 and y <= 300 then
        two_and_two
    elsif button = 1 and x >= 200 and x <= 300 and y >= 300 and y <= 400 then
        two_and_three
    elsif button = 1 and x >= 300 and x <= 400 and y >= 100 and y <= 200 then
        three_and_one
    elsif button = 1 and x >= 300 and x <= 400 and y >= 200 and y <= 300 then
        three_and_two
    elsif button = 1 and x >= 300 and x <= 400 and y >= 300 and y <= 400 then
        three_and_three
    else
        put "Choose a box"
    end if
Clayton




PostPosted: Sat Apr 08, 2006 6:02 pm   Post subject: (No subject)

good game, as mentioned above you can draw over squares more than once, but other than that gj

kinda off topic but dont you think we should make a sticky for tic-tac-toe games and pong and stuff like that (common games that everyone does)
gogeunks1




PostPosted: Tue Jan 13, 2009 6:15 pm   Post subject: Re: tic tac toe

i dont get the part about the procedure and the bule (1) := blue (1) + 1
Sponsor
Sponsor
Sponsor
sponsor
gogeunks1




PostPosted: Tue Jan 13, 2009 6:15 pm   Post subject: Re: tic tac toe

can someone explain it to me???
Parker




PostPosted: Wed Jan 14, 2009 9:04 am   Post subject: RE:tic tac toe

It works, so that automatically makes it good Smile Some things you could improve on are :

- Keep blue and reds score
- Make X and O's because that what Tic Tac Toe is really about (lol)
- Ask if they want to play again (goes with score^^)
- You dont have to show the coordinates of the mouse on run screen.
chrisbrown




PostPosted: Wed Jan 14, 2009 9:49 am   Post subject: RE:tic tac toe

Quote:

It works, so that automatically makes it good

Enjoy that fallacy while it lasts...
Insectoid




PostPosted: Wed Jan 14, 2009 1:28 pm   Post subject: RE:tic tac toe

Parker, Windows 'works', but does that make it good? I'd say 85% at least of developers shun windows, the number is likely higher. Say 2 programs do exactly the same thing, written is the same language, but one runs 30% faster the other and takes only 80% the space. Which is better? In the real world, speed and efficiency (and sometimes clever marketing & contracts, in the case of one company I won't name but rhymes with licrohoft) are what own the industry. If the world was perfect (if only restaurants became famous for good quality food rather than giving toys to children, in the case of one company I won't name but rhymes with sick fondles).
Parker




PostPosted: Thu Jan 15, 2009 8:39 am   Post subject: RE:tic tac toe

I am trying to be nice, although it may not be a top of the line tic tac toe it still works. Therefore I am trying to give them positive feedback along with constructive critiscm.

PS: I like windows Very Happy
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: