Need a little help with checkers....
Author |
Message |
steve_k91
|
Posted: Sat Nov 27, 2004 4:42 pm Post subject: Need a little help with checkers.... |
|
|
Hey guys,
I'm doing a project for my Grade 10 compsci class and have to build checkers. ive got the board and the peices put on but i have no clue about how to move the peices... Heres what i have so far... any help you can give would b amazing.
code: | View.Set ("nocursor,graphics:400;400")
var board : array 1 .. 8, 1 .. 8 of int
% initialize array
for col : 1 .. 8
for row : 1 .. 8
board (col, row) := 0
end for
end for
proc displayboard
for decreasing row : 8 .. 1
for col : 1 .. 8
put board (col, row), " " ..
end for
put ""
end for
end displayboard
for row : 1 .. 8 by 2
board (row, 1) := 1
end for
for row : 2 .. 8 by 2
board (row, 2) := 1
end for
for row : 1 .. 8 by 2
board (row, 3) := 1
end for
for row : 2 .. 8 by 2
board (row, 6) := 2
end for
for row : 1 .. 8 by 2
board (row, 7) := 2
end for
for row : 2 .. 8 by 2
board (row, 8) := 2
end for
proc drawGridbs
Draw.FillBox (0, 0, 400, 400, 92)
for col : 0 .. 7
for row : 0 .. 7
Draw.FillBox (col * 50 + 2, row * 50 + 2, col * 50 + 49, row *
50 + 49, black)
end for
end for
end drawGridbs
proc drawGridrs
for col : 0 .. 7 by 2
for row : 0 .. 7 by 2
Draw.FillBox (col * 50 + 2, row * 50 + 2, col * 50 + 49, row *
50 + 49, red)
for col1 : 1 .. 7 by 2
for row1 : 1 .. 7 by 2
Draw.FillBox (col1 * 50 + 2, row1 * 50 + 2, col1 *
50 + 49, row1 * 50 + 49, red)
end for
end for
end for
end for
end drawGridrs
proc drawpieces
var clr : int % disck colour
for col : 1 .. 8
for row : 1 .. 8
if board (col, row) = 1 then % red disk
Draw.FillOval (col * 50 - 25, (row - 1) * 50 + 25, 20, 20,
blue)
end if
if board (col, row) = 2 then % black disk
Draw.FillOval (col * 50 - 25, (row - 1) * 50 + 25, 20, 20,
green)
end if
%draw disk
end for
end for
end drawpieces
drawGridbs
drawGridrs
drawpieces
%displayboard |
thanks again guys |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Delos
|
Posted: Sat Nov 27, 2004 5:06 pm Post subject: (No subject) |
|
|
Ok, you seem to have the right idea regarding array usage. Now you need to find out a bit about Mouse. commands:
Mouse.Where()
Mouse.ButtonChoose()
etc etc.
Then you'll want to set up a nice procedure that allows the User to click on an individual tile, check to see what's in it, if it's a piece, allow for movement (i.e., clicking on another tile).
You'll want to look up types and records too, it will make using the tile concept a lot easier (basically you'll be packaging objects with varying, repeating characteristics together).
Records by Dodge |
|
|
|
|
|
Cervantes
|
Posted: Sat Nov 27, 2004 5:15 pm Post subject: (No subject) |
|
|
this thread might help, though it becomes useless once dodge starts worshipping Catalyst. |
|
|
|
|
|
steve_k91
|
Posted: Sat Nov 27, 2004 7:17 pm Post subject: (No subject) |
|
|
Thanks allot guys
ive figured out the procedure for that allows the User to click on an individual tile, check to see what's in it and if it's a piece, allow for movement.
but exactly how do i move it using the array? |
|
|
|
|
|
Cervantes
|
Posted: Sat Nov 27, 2004 7:28 pm Post subject: (No subject) |
|
|
well, if you've got the part to check if it's within movement distance:
code: |
board (NewPieceXAsDeterminedByTheMouse, NewPieceYAsDeterminedByTheMouse) := board (clickedPieceX, clickedPieceY)
board (clickedPieceX, clickedPieceY) := 0 %for empty
|
that's one way of doing it. |
|
|
|
|
|
SuperGenius
|
Posted: Sat Nov 27, 2004 11:09 pm Post subject: (No subject) |
|
|
you'll also have to check that they're not trying to move the checker off the edge of the board or that they are trying to move it to a square that already has a checker in it. One thing at a time though. |
|
|
|
|
|
wtd
|
Posted: Sat Nov 27, 2004 11:27 pm Post subject: (No subject) |
|
|
One thought... a square on the board can be either red or black. This could be represented by a boolean. Also, it can either be occupied or not. Another boolean.
code: | type Square :
record
black, occupied : boolean
end record
var board : array 1 .. 8, 1 .. 8 of Square
procedure initBoard
% code to set up the initial state of each square
end initBoard |
|
|
|
|
|
|
steve_k91
|
Posted: Sun Nov 28, 2004 1:24 pm Post subject: (No subject) |
|
|
thanks allot guys... that really helped... ill post the final program once im done |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|