Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Tic-Tac-Micro
Author Message
TheZsterBunny

Posted: 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

Delos

Posted: 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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 3 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: