Computer Science Canada

tic-tac-toe

Author:  gta_master1987 [ Sat Jun 05, 2004 7:22 pm ]
Post subject:  tic-tac-toe

i have trouble drawing x and o on my board
here is my board:

colourback (black)
cls
drawbox (23, 122, 282, 382, white)

drawline (111, 123, 111, 381, white)
drawline (196, 123, 196, 381, white)
drawline (24, 211, 281, 211, white)
drawline (24, 301, 281, 301, white)

how can i draw x and o on this board?

Author:  Delos [ Sat Jun 05, 2004 8:10 pm ]
Post subject: 

1) Use [ code] tags.
2) Drawing commands can be used here.
Eg.
code:

drawline (100, 100, 200, 200, 12)
drawline (200, 100, 100, 200, 12)
% Will draw an 'X'.

drawoval (400, 100, 50, 50, 12)
% Will draw an 'O'.


In case you need to know, the syntax is:
drawline (startX, startY, endX, endY, colourRef)

drawoval (centreX, centreY, Xradius, yRadius, colourRef)

Author:  Cervantes [ Sat Jun 05, 2004 8:10 pm ]
Post subject: 

what have you tried so far??
maybe you could use Font.New to create a font, and Font.Draw or Draw.Text to draw an "x" or an "o" onto the board.

Author:  gta_master1987 [ Sun Jun 06, 2004 12:26 am ]
Post subject: 

i can draw the x and o but i can's place it one the board

Author:  Cervantes [ Sun Jun 06, 2004 7:36 am ]
Post subject: 

you can. its just difficult because of the placement of the board. It would be best if you had a constant for the width and the height of the grid, in pixels, called gridsize or something. then you can figure out everything by looking at what square it is in ((1,1), (2,3) etc.). then whenever you want to draw something you multiply the grid position by the gridsize.

Author:  bryan_magnum [ Thu Jun 10, 2004 10:00 pm ]
Post subject: 

Im tired now so this isnt much.
This just draws an X and an O anywhere if you right or left click
code:
Mouse.ButtonChoose ("multibutton")
var winID : int := Window.Open ("graphics:640;480")
var player1, player2 : string
var x, y, b : int := 0
var font : int := Font.New ("arial:30")
var left, middle, right : int

colourback (black)
cls
colour (0)
put "What is player 1 name?"
get player1 : *
colour (0)
put "What is player 2 name?"
get player2 : *

cls
drawbox (23, 122, 282, 382, white)
drawline (111, 123, 111, 381, white)
drawline (196, 123, 196, 381, white)
drawline (24, 211, 281, 211, white)
drawline (24, 301, 281, 301, white)
color (0)
locatexy (0,0)
put "Player1 = left click, Player2 = right click, Exit = Middle click"
loop
    mousewhere (x, y, b)
    left := b mod 10
    middle := (b - left) mod 100
    right := b - middle - left
    if left = 1 then
        Font.Draw ("X", x, y, font, 0)
    elsif right = 100 then
        Font.Draw ("O", x, y, font, 0)
    end if
    exit when middle = 10
end loop
Window.Close (winID)


: