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

Username:   Password: 
 RegisterRegister   
 Tic-Tac-Micro
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheZsterBunny




PostPosted: Mon May 10, 2004 8:26 pm   Post subject: Tic-Tac-Micro

I didn't want to do my english essay.

Tic-Tac-Toe in less than 50 lines. enjoy.

code:

setscreen ("graphics:150;150,nobuttonbar,title:Tic-Tac-Toe")
var board : array 1 .. 3, 1 .. 3 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
function win : boolean
    for i : 1 .. 3
        if board (i, 1) not= 0 and board (i, 1) = board (i, 2) and board (i, 1) = board (i, 3) then
            Draw.ThickLine ((i * 30) + 15, 115, (i * 30) + 15, 35, 3, red)
            result true
        end if
        if board (1, i) not= 0 and board (1, i) = board (2, i) and board (1, i) = board (3, i) then
            Draw.ThickLine (35, (i * 30) + 15, 115, (i * 30) + 15, 3, red)
            result true
        end if
    end for
    if board (2, 2) not= 0 and board (1, 1) = board (2, 2) and board (2, 2) = board (3, 3) then
        Draw.ThickLine (35, 35, 115, 115, 3, red)
        result true
    elsif board (2, 2) not= 0 and (board (1, 3) = board (2, 2) and board (2, 2) = board (3, 1)) then
        Draw.ThickLine (35, 115, 115, 35, 3, red)
        result true
    end if
    result false
end win
var mx, my, mb : int
drawbox (60, 30, 90, 120, 7)
drawbox (30, 60, 120, 90, 7)
drawbox (30, 30, 120, 120, 0)
var count := Rand.Int (1, 2)
loop
    mousewhere (mx, my, mb)
    if mx > 30 and mx < 120 and my > 30 and my < 120 and mb not= 0 then
        if board (floor (mx / 30), floor (my / 30)) = 0 then
            if count = 1 then
                drawoval ((floor (mx / 30) * 30) + 15, (floor (my / 30) * 30) + 15, 10, 10, 7)
                board (floor (mx / 30), floor (my / 30)) := 1
            elsif count = 2 then
                drawline ((floor (mx / 30) * 30) + 5, (floor (my / 30) * 30) + 5, (floor (mx / 30) * 30) + 25, (floor (my / 30) * 30) + 25, 7)
                drawline ((floor (mx / 30) * 30) + 5, (floor (my / 30) * 30) + 25, (floor (mx / 30) * 30) + 25, (floor (my / 30) * 30) + 5, 7)
                board (floor (mx / 30), floor (my / 30)) := 2
            end if
            count := (count mod 2) + 1
        end if
    end if
    loop
        mousewhere (mx, my, mb)
        exit when mb = 0
    end loop
    exit when win
end loop


-bunny
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon May 10, 2004 9:01 pm   Post subject: (No subject)

Well...that's impressive. <50 lines eh. Nice nice. Now...if only it would exit if one loses...

Ah well.

Have these:
+ bits.
awesomej01




PostPosted: Tue May 11, 2004 12:59 pm   Post subject: (No subject)

It doesn't close the window, that would make it 50 lines but good job.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: