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

Username:   Password: 
 RegisterRegister   
 Help! Urgent! Chess!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DBeast




PostPosted: Mon Dec 09, 2002 9:12 pm   Post subject: Help! Urgent! Chess!

Ahhhhh

I've written a chess program (or tried to) =/
It features basic mouse commands to initiate the setup of the board, it loads a board (picture) and all the pieces in their corresponding coordinates. I've made tons of loops to try to move the pieces around with the mouse...the problem is, with all the procedures and loops, I'd have to write 64 seperate ones, which would overlap and kill each other.

I wanna know if there is an easier way to do this

Like...using only 1 procedure where it redraws the board everytime u click on a certain piece, the piece would be "attached" to your mouse and then when u click the spot where you want that piece to go, it would redraw again with the piece there in the right spot

Any help would be great! Smile
Sponsor
Sponsor
Sponsor
sponsor
krishon




PostPosted: Mon Dec 09, 2002 10:25 pm   Post subject: (No subject)

yo, derek, ur screwed...but newayz, do u have the pics of the different pieces??
krishon




PostPosted: Mon Dec 09, 2002 10:28 pm   Post subject: (No subject)

yo, its gonna be big, but u hafta write the procedure for each piece, like if one for a pond, one for a queen, a king, a bishop and wutever. Its the only way i can think of it. Confused
Tony




PostPosted: Mon Dec 09, 2002 11:10 pm   Post subject: (No subject)

Tony is here to save the day with his crazy VB procedure SKILLZ

Very Happy

anyway, you can have a single procedure for moving the piece, and 6 more (one for each piece type) to varify if new location is valid.

code:

proc Move(picID:int)
delay(1000)
loop
Mouse.Where(x,y,b)
Pic.Draw(picID,x,y,picMerge)
exit when b=1
end loop
end Move


Basically when you call this procedure, you pass the picture you want to "attach" to mouse in the parameter. It waits for 1 second to give you time to let go of the button as it will drop the picture as soon as you press the button again exit when b=1.

Here's a proc to verify the position of pawn

code:

proc Verify(type:string, oldX:int, oldY:int, newX:int,newY:int)
newX := floor(newX/10)
newY := floor (newY/10)
if type = "pawn" then
      if oldX = newX and newY = oldY + 1 or newY = oldY +2 then
%valid, keep it here
      else
%move invalid
newX:=oldX
newY:=oldY
     end id
end if
end Verify


Note: X,Y values are grid location on the board and 1,1 correspond to A1.

Thats why we use function NewX := floor(NewX/10) because the newX value is passed as a pixel location from the move proc. This way we find which grid it is, assuming each square is 10 pixels in size.

that oldY +1 and oldY +2 are possible movements of the piece (ether 1 or 2 up). Now you'd have to put more variables in there as you can move 2 up only if you never thouched this piece. And you can't go up if there's another piece there. You can also attack sideways (so its if newY = oldY + 1 and newX = oldX + 1 if attack is to the right).

I hope this helps. If you have more questions, post.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: