Thursday, July 9, 2009

C language experts.......plzz help..?

i want to create "tic tac toe" game in c language.....with mouse programming





now could anyone plzz help me......how shud i begin....plzz give me a logic.........


problem is dat in a "tic tac toe" game without mouse......i can simply ask user to enter row and column of the matirx....and hence can be easily done..





now with mouse programing...the main problem is how implement the co-ordinate of mouse.......to a matrix..





as i dont kwn grphics in c...i just want to make a basic simple game with two user.....


so plzz tell me how to take input via mouse and set a value in matrix,clicked by player.....plzz dont include graphic in it.....as it would become difficult for me to understand

C language experts.......plzz help..?
Typically you would use a framework of some sort. Which framework is dependent on your development tools and platform. I don't believe your question is for C language experts (which I am not), but rather for C programmers who have experience with mouse inputs.





I think it would be helpful to know what C complier / libraries you are using and on which platform (OS) you are targeting before you will get any helpful advice.
Reply:You don't say which system you use (Linux, Windows,...) so I will give you generalities:





You will need to have an event loop that receives the mouse events and then perform some operation when the mouse event occurs.





And then map the mouse coordinates to your TIC TAC TOE grid. Example: suppose the "client" part (i.e. the part where you draw) of you window is 300 pixels / 300 pixels, you Will get the correct Tic Tac Toe grid coordinate by using mouse.X/100 and mouse.Y/100





But don't try to do this without a tool giving you support for GUI programing (Personally I use VISUAL C++ Studio express which is freely downloadable from Microsoft)
Reply:well I don't know how you plan on creating a tic tac toe game using a mouse if you don't plan on using a graphics library of some kind. I would recommend SDL as a good graphic library to learn and use if you change your mind on the graphics part. but as far as logic for the game an easy way to see if a square is clicked on would be using offset from where the user click from origin. The origin in computer programs is the top left corner of the program window so when the mouse is clicked the position can be gotten from the a function call which varies on the API your using. But you get the mouse coordinates and you see if they fall on your grid of 9 squares. so if the user clicks at (1,2) and your first box is at x = 3 y = 3 then if 1 your users x is less than 3 then boxes x and 2 the users y is less that 3 the boxes y then the user clicked in the first box and just repeat this offset for all the boxes


No comments:

Post a Comment