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

Username:   Password: 
 RegisterRegister   
 Using the mouse
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheFerret




PostPosted: Sun Mar 14, 2004 1:47 pm   Post subject: Using the mouse

I am making a chess program and was going to use the keyboard to move the pieces but I think it is too complicated and I am going to use the mouse but I am not sure how to do it, I want the person to click the piece and then click on a open square and move the guy there but I do not know how to get the second click to work...
Sponsor
Sponsor
Sponsor
sponsor
jonos




PostPosted: Sun Mar 14, 2004 1:52 pm   Post subject: (No subject)

well you put your mousewhere(x, y, button) in a loop.

then when button = 1 (the user presses a mouse button), check if they are in a square where there is a chess peice.

if that is true, then make anotehr loop in the if statement you made above, and use mousewhere, and keep checking if the user has pressed a button, then when a button is pressed, check with an if statement it is in an unoccupied square and if it is a legal move, and if it is, move the chess peice and exit the loop.

it may sound complicated, but once you get everything together it will make sense. im sure there's an easier way but thats what i would do.
Cervantes




PostPosted: Sun Mar 14, 2004 1:54 pm   Post subject: (No subject)

if youre using mousewhere it should work fine. However, if you are using mousewhere in combination with boolean variables (such as, if btn = 1 then button_pressed := true) then you may have forgot to set it back to false.

Anyways, post the code or just the necessary piece of it and we'll take a look Smile

BTW, I think using the arrow keys would be easier. Well, maybe not for knights Confused
jonos




PostPosted: Sun Mar 14, 2004 1:57 pm   Post subject: (No subject)

you could also make it easier and do coordinates like the setting in chessmaster, but thats not as fun. it would be really easy though...
Cervantes




PostPosted: Sun Mar 14, 2004 2:03 pm   Post subject: (No subject)

Sometimes the coolest programs are the simplest ones (Mostly here I'm referring to games, such as Space Invaders, pong, connect 4). However, chess I think is kinda the opposite. Since chess is a simple game to begin with and entering coords is no fun, you gotta make it look nice. It would be very cool if you could make it like this:

you select a unit by holding the mousebutton down, while the mouse is on him. Then you move the mouse around and when its a valid square for that unit to move to, it highlights the squares that that unit would take. It would be even cooler if you could animate the unit while he moves along that path.

But that's all for later, if you even want to do that. First do the basics and get the game working.
TheFerret




PostPosted: Sun Mar 14, 2004 2:12 pm   Post subject: (No subject)

I made everything into a zip becasue there is like 12 .bmps... I have tried co-ods but it would get very confusing coding it...


chespics.zip
 Description:
Here it is

Download
 Filename:  chespics.zip
 Filesize:  146.56 KB
 Downloaded:  246 Time(s)

Cervantes




PostPosted: Sun Mar 14, 2004 2:24 pm   Post subject: (No subject)

having a ton of if statements like that for moving the pieces is very unefficient.
You should have a 2D array to store the positions of all the pieces. When the user inputs a coordinate (A2, for example) it checks that there is a piece at A2 and that it belongs to the correct player. Then you enter another coord and it checks if that piece can actually move there.

2D arrays... It's the way to go with these kind of board games.
TheFerret




PostPosted: Sun Mar 14, 2004 2:31 pm   Post subject: (No subject)

And how would I do the 2D array...
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Mar 14, 2004 2:33 pm   Post subject: (No subject)

you would go to [Turing Tutorials] and look up a tutorial or two
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TheFerret




PostPosted: Sun Mar 14, 2004 2:38 pm   Post subject: (No subject)

I mean how would I get to move the pieces of it and tell if a piece is in a square...
Paul




PostPosted: Sun Mar 14, 2004 3:12 pm   Post subject: (No subject)

Fill the 2 D array with the pieces, like if at the start, the variable piece(1,1) would be filled with a black/white rook.
TheFerret




PostPosted: Sun Mar 14, 2004 3:31 pm   Post subject: (No subject)

So I would have something like this
code:
var board:array 1..8,1..8 of int

board(1,1):=whtrook
board(1,2):=whtkni
board(1,3):=whtbis
board(1,4):=whtkin
%and so on
But how would you move the pieces...
Tony




PostPosted: Sun Mar 14, 2004 3:35 pm   Post subject: (No subject)

if pawn move from (4,2) to (4,4) then

board(4,4):=board(4,2)
board(4,2):="" %nothing in this spot

it would be easier if you write a function to just swap the two values. Just watch out for the case where you take out the opponent's piece, it has to disappear first
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TheFerret




PostPosted: Sun Mar 14, 2004 6:23 pm   Post subject: (No subject)

When I try to run
code:
if move =1213 then

    board (1, 2) := board (1, 3)
    board (1, 2) := "" %nothing in this spot
it says Assigned value is the wrong type and highlights the ""...
Tony




PostPosted: Sun Mar 14, 2004 6:59 pm   Post subject: (No subject)

Shocked
maybe you should work on something simpler Laughing
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 3  [ 35 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: