Posted: 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...
Posted: 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.
Posted: 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
BTW, I think using the arrow keys would be easier. Well, maybe not for knights
Posted: 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...
Posted: 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.
Posted: 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...
Posted: 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.
Posted: Sun Mar 14, 2004 2:31 pm Post subject: (No subject)
And how would I do the 2D array...
Posted: Sun Mar 14, 2004 2:33 pm Post subject: (No subject)