Checkers Movement
Author |
Message |
TaKer
|
Posted: Sun Jun 13, 2010 8:57 pm Post subject: Checkers Movement |
|
|
I am trying to make a checkers game. I have completed the board and pieces,but i cannot figure out how to make them move. I kno you need to use mousewhere.
Here is the code i have so far, i kno that it is inefficient. If anyone can help me get started by showing how to move 1 piece tha would be great.
Turing: |
setscreen ("graphics: 800;800")
%Coordinates for each black square on the board%
drawfillbox (maxx, 0, 0, maxy, red)
drawfillbox (0, 0, 100, 100, black)
drawfillbox (100, 100, 200, 200, black)
drawfillbox (200, 200, 300, 300, black)
drawfillbox (300, 300, 400, 400, black)
drawfillbox (400, 400, 500, 500, black)
drawfillbox (500, 500, 600, 600, black)
drawfillbox (600, 600, 700, 700, black)
drawfillbox (700, 700, 800, 800, black)
drawfillbox (200, 0, 300, 100, black)
drawfillbox (400, 0, 500, 100, black)
drawfillbox (600, 0, 700, 100, black)
drawfillbox (300, 200, 400, 100, black)
drawfillbox (500, 200, 600, 100, black)
drawfillbox (700, 200, 800, 100, black)
drawfillbox (400, 200, 500, 300, black)
drawfillbox (0, 200, 100, 300, black)
drawfillbox (0, 400, 100, 500, black)
drawfillbox (0, 600, 100, 700, black)
drawfillbox (700, 300, 800, 400, black)
drawfillbox (700, 500, 800, 600, black)
drawfillbox (600, 200, 700, 300, black)
drawfillbox (600, 400, 700, 500, black)
drawfillbox (500, 300, 600, 400, black)
drawfillbox (500, 700, 600, 800, black)
drawfillbox (300, 700, 400, 800, black)
drawfillbox (100, 700, 200, 800, black)
drawfillbox (100, 300, 200, 400, black)
drawfillbox (200, 400, 300, 500, black)
drawfillbox (100, 500, 200, 600, black)
drawfillbox (300, 500, 400, 600, black)
drawfillbox (200, 600, 300, 700, black)
drawfillbox (400, 600, 500, 700, black)
%Coordinates for each checkers piece, for black squares%
drawfilloval (50, 50, 50, 50, cyan)
drawfilloval (250, 50, 50, 50, cyan)
drawfilloval (450, 50, 50, 50, cyan)
drawfilloval (650, 50, 50, 50, cyan)
drawfilloval (150, 150, 50, 50, cyan)
drawfilloval (350, 150, 50, 50, cyan)
drawfilloval (550, 150, 50, 50, cyan)
drawfilloval (750, 150, 50, 50, cyan)
drawfilloval (250, 250, 50, 50, cyan)
drawfilloval (50, 250, 50, 50, cyan)
drawfilloval (450, 250, 50, 50, cyan)
drawfilloval (650, 250, 50, 50, cyan)
%Coordinates for each checker piece, for red squares%
drawfilloval (50, 750, 50, 50, magenta)
drawfilloval (250, 750, 50, 50, magenta)
drawfilloval (450, 750, 50, 50, magenta)
drawfilloval (650, 750, 50, 50, magenta)
drawfilloval (150, 650, 50, 50, magenta)
drawfilloval (350, 650, 50, 50, magenta)
drawfilloval (550, 650, 50, 50, magenta)
drawfilloval (750, 650, 50, 50, magenta)
drawfilloval (50, 550, 50, 50, magenta)
drawfilloval (250, 550, 50, 50, magenta)
drawfilloval (450, 550, 50, 50, magenta)
drawfilloval (650, 550, 50, 50, magenta)
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sun Jun 13, 2010 9:02 pm Post subject: RE:Checkers Movement |
|
|
You're going to need a procedure to draw the board, because you're going to be drawing it a lot.
You need an array to hold the coordinates of every checker. To move a checker, change its coordinate and redraw it. |
|
|
|
|
|
USEC_OFFICER
|
Posted: Sun Jun 13, 2010 9:38 pm Post subject: RE:Checkers Movement |
|
|
To move on piece, you have to add some variables, to add to the Draw.FillOvals to move them. |
|
|
|
|
|
TokenHerbz
|
Posted: Sun Jun 13, 2010 10:37 pm Post subject: RE:Checkers Movement |
|
|
Use a class, so much easier imo...
However, to move a piece the theory would be...
If mouse clicks then if mouse x,y are on a peice, then change peice x,y to new mouse location (depends if you wanna drag them or click/click) then do a check to see if its a valid move, if its not default the peice x,y and start again. if it is, confirm the move...
In all seriousness, Don't do this without knowing how to use more programming abilities.
might i suggest pong or astroids first!?! |
|
|
|
|
|
TaKer
|
Posted: Sun Jun 13, 2010 11:14 pm Post subject: RE:Checkers Movement |
|
|
Theres no choice as this is my summative for computer science... |
|
|
|
|
|
TokenHerbz
|
Posted: Mon Jun 14, 2010 12:18 am Post subject: RE:Checkers Movement |
|
|
well each peice needs its own chords so maybe use an array, since they are easy i'm sure you have learned them... and then you will have power to move each peice thats clicked on, checking threw the array and reassigning the values of the effected peice |
|
|
|
|
|
Cezna
|
Posted: Mon Jun 14, 2010 5:27 am Post subject: RE:Checkers Movement |
|
|
Instead of redrawing the board every time, you might want to draw it once at the beginning, take a picture of it with Pic.New, and then just redraw the picture.
TokenHerbz is right, you will need arrays for the co-ordinates, and you might be able to just simplify things with pictures for the pieces as well, using the same method as I explained for the board. |
|
|
|
|
|
yoursecretninja
|
Posted: Sat Jun 19, 2010 3:54 am Post subject: Re: Checkers Movement |
|
|
Also, instead of redrawing the board every time, try to redraw only the rectangle that bounds an area of the board that has been changed... in checkers, this will usually only be a small rectangle comprising two to four squares and will therefore significantly reduce the amount of computations required on average for each move. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|