Computer Science Canada Tic Tac Toe |
Author: | jabar145 [ Tue Jan 19, 2010 5:51 pm ] |
Post subject: | Tic Tac Toe |
I am trying to get the mouse to register what box of the grid it is in; then paste a picture in that box. Code: 'This is the procedure to make the grid if it helps' procedure Grid var x1, y1, x2, y2 : int for row : 1 .. 4 for column : 1 .. 6 x1 := column * BOX_SIZE + 25 y1 := row * BOX_SIZE - 10 x2 := x1 + BOX_SIZE y2 := y1 + BOX_SIZE drawbox (x1, y1, x2, y2, black) end for end for end Grid |
Author: | TheGuardian001 [ Tue Jan 19, 2010 6:24 pm ] |
Post subject: | Re: Tic Tac Toe |
And what problem are you having with this? Oh, and chances are we'll need the full code, not just the one procedure (and images if there are any). |
Author: | jabar145 [ Tue Jan 19, 2010 9:14 pm ] |
Post subject: | Re: Tic Tac Toe |
I figured out most of it now, but having problems with the 6x4 grid. The program can create circles out side of the grid and I don't know how to fix this. Try clicking on the outside of the grid to see what I mean. (I only want the circles inside the grid space where I clicked.) I will just paste the code here. ------------------------------- import GUI View.Set ("nobuttonbar") setscreen ("graphics:max;max") const BOARD_SIZE := 6 const GRID_SIZE := 1 const BOX_SIZE := round (maxy / (GRID_SIZE + 5)) var x, y : int var picID : int var X, Y, button : int var column, row : int var ymouse, xmouse : int procedure Draw_Card (row, column : int) Draw.FillOval (row * BOX_SIZE + (BOX_SIZE div 2), column * BOX_SIZE + (BOX_SIZE div 2), 30, 60, brightblue) end Draw_Card procedure Grid % Procedure to make the grid var x1, y1, x2, y2 : int for row : 1 .. 4 for column : 1 .. 6 x1 := column * BOX_SIZE + 25 y1 := row * BOX_SIZE - 10 x2 := x1 + BOX_SIZE y2 := y1 + BOX_SIZE drawbox (x1, y1, x2, y2, black) end for end for end Grid %Game board creation drawfillbox (100, 76, 895, 600, brightred) drawbox (100, 76, 895, 600, brightblue) drawbox (100 + 1, 76 + 1, 895 + 1, 600 + 1, brightblue) drawbox (100 + 2, 76 + 2, 895 + 2, 600 + 2, brightblue) %----- Grid % Creates grid here var quitBtn : int := GUI.CreateButton (950, 665, 0, "Quit", GUI.Quit) loop Mouse.Where (x, y, button) Text.Locate (1, 1) if button = 0 then else ymouse := y xmouse := x for x_2 : 1 .. BOARD_SIZE + 1 if xmouse >= (x_2 * BOX_SIZE) and xmouse <= (xmouse * BOX_SIZE) + BOX_SIZE then row := x_2 end if end for for y_2 : 1 .. BOARD_SIZE + 1 if ymouse >= (y_2 * BOX_SIZE) and ymouse <= (ymouse * BOX_SIZE) + BOX_SIZE then column := y_2 end if end for put row put column Draw_Card (row, column) end if exit when GUI.ProcessEvent end loop quit |