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

Username:   Password: 
 RegisterRegister   
 CHECKER GAME HELP! PLEASE!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
d3c0d3d




PostPosted: Mon Jan 12, 2004 7:23 pm   Post subject: CHECKER GAME HELP! PLEASE!

CAN ANYONE SHOW ME HOW TO PUT THE PIECES FOR THIS GAME?...YOU CAN SHOW ME HOW TO DO ONE...AND ILL DO THE REST..PLEASE AND THANKS! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
d3c0d3d




PostPosted: Mon Jan 12, 2004 7:24 pm   Post subject: (No subject)

here's how i started.

var winID : int := Window.Open ("graphics:400;400 , title:Checker Board")

%Checker Board_
for x : 1 .. 8
for y : 1 .. 8
drawfillbox (x * 50, y * 50 - 1, x * 50 - 50, y * 50 - 50, ((x+y*7) mod 2) * black)
end for
end for
Cervantes




PostPosted: Mon Jan 12, 2004 7:45 pm   Post subject: (No subject)

read up on the ever useful tool known as "arrays"
DanShadow




PostPosted: Mon Jan 12, 2004 7:46 pm   Post subject: (No subject)

You might do it the slow, but accu rate way like this:
code:

%Checker Board_
for x : 1 .. 8
    for y : 1 .. 8
        drawfillbox (x * 50, y * 50 - 1, x * 50 - 50, y * 50 - 50, ((x + y * 7) mod 2) * black)
    end for
end for
%------------------------------------------------------------------
%Checker (x,y) co-ordinates; Checker color; Checker selected (1=yes,0=no)
var checker_x, checker_y, checker_c, checker_s : array 1 .. 24 of int
%Makes all array variables equal to -20
for i : 1 .. 24
    checker_x (i) := -20
    checker_y (i) := -20
    if i < 13 then
        checker_c (i) := 12
    else
        checker_c (i) := 1
    end if
    checker_s (i) := 0
end for
checker_x (1) := 25
checker_y (1) := 25
checker_x (2) := 125
checker_y (2) := 25
checker_x (3) := 225
checker_y (3) := 25
checker_x (4) := 325
checker_y (4) := 24

proc drawCheckers
    for i : 1 .. 24
        Draw.FillOval (checker_x (i), checker_y (i), 20, 20, checker_c (i))
    end for
end drawCheckers

drawCheckers

I coded a program, where you can lift and move checkers...ill upload the code if I remember, heh. I hope this helps.
Andy




PostPosted: Mon Jan 12, 2004 8:01 pm   Post subject: (No subject)

caps are lame
McKenzie




PostPosted: Mon Jan 12, 2004 8:26 pm   Post subject: (No subject)

Dodge is right, nver type in ALL CAPS, it pisses people off. Thats not what you want when you're asking for help. Here we go anyways.

1. You want to use a 2-dim array to store the pieces
code:
var board : array 1..8,1..8 of int

2. Recognize that you are using 2 different coordinate systems. The screen coordinates and the board coordinates. I would suggest making 2 simple procedures to convert back and forth.
e.g.
code:
proc boardToScreen(bx,by:int, var sx,sy:int)
    sx:=bx * 50 + 25     % center of box for circles
    sy:=by * 50 + 25     % center of box for circles
end boardToScreen

3. Make a procedure to draw a piece given a boardx,boardy and a colour.
shorthair




PostPosted: Mon Jan 12, 2004 9:12 pm   Post subject: (No subject)

decode , to start if your not 2 sure ( im just guessing here ) how to use an array , then using a 2d array isnt where you should start , i mean sure you only asked us to get the peices on hte board , but to me thats the hardest part , the code for movent is easy , just some for loops and some if statements , read through the tutorials and you will find alot of learning help , you should learn how to use the arrays in many situations , dont just use the code but learn the code so you will remember what its used for, you probably have compsci exams coming up and knowing this can make things nice and easy when it comes to writing an exam, i just want to make sure your understanding the code , be sure to ask more detailed questions if you dont understang something.

Shorthair Very Happy Very Happy Glad to Help
DanShadow




PostPosted: Tue Jan 13, 2004 8:53 am   Post subject: (No subject)

Here is the code to move checkers:
code:

var cx, cy, cs : array 1 .. 10 of int
var x, y, b : int := 0
for i : 1 .. 10
    cx (i) := 0 + (i * 25)
    cy (i) := 10
    cs (i) := 0
end for


loop
    setscreen ("offscreenonly")
    View.Update
    mousewhere (x, y, b)
    Draw.FillBox (0, 0, maxx, maxy, 255)

    for i : 1 .. 10
        Draw.FillOval (cx (i), cy (i), 10, 10, 12)
        if (b = 1) and (x > cx (i) - 10 and x < cx (i) + 10) and (y > cy (i) - 10 and y < cy (i) + 10) then
            cs (i) := 1
        end if
        if (b = 1) and (cs (i) = 1) then
            loop
                setscreen ("offscreenonly")
                View.Update
                mousewhere (x, y, b)
                Draw.FillBox (0, 0, maxx, maxy, 255)
                for z : 1 .. 10
                    Draw.FillOval (cx (z), cy (z), 10, 10, 12)
                end for
                cx (i) := x
                cy (i) := y
                Draw.FillOval (cx (i), cy (i), 10, 10, 14)
                exit when b not= 1
            end loop
        end if
        if b not= 1 then
            cs (i) := 0
        end if
    end for
end loop

Enjoy! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: