I'm a newbie here and tried to write small TicTakToe game in SDL and c++.
I have stacked here once I call the "void get_player_move(void)" function. The purpose of the function is to recognize a mouse click and the place where the click has taken place and modify the value of a char matrix accordingly..
Im putting the function herewith for your kind attention..
/* Get player move */
void get_player_move(void)
{
SDL_Event event;
bool quit= false;
int x, y ;
while( quit == false ) {
if(event.type == SDL_MOUSEBUTTONDOWN){
if(event.button.button == SDL_BUTTON_LEFT){
//Get the mouse offsets
x = event.motion.x;
y = event.motion.y;
//Pressed on button 1..??
if( ( x > 0 ) && ( x < 50 ) && ( y > 0 ) && ( y < 50 ) ) {
matrix[0][0]='X';
}
//Pressed on button 2..??
if( ( x > 50 ) && ( x < 100) && ( y > 0 ) && ( y < 50 ) ) {
matrix[0][1]='X';
}
//Pressed on button 3..??
if( ( x > 100 ) && ( x < 150 ) && ( y > 0 ) && ( y < 50 ) ) {
matrix[0][2]='X';
}
//Pressed on button 4..??
if( ( x > 0 ) && ( x < 50 ) && ( y > 50 ) && ( y < 100 ) ) {
matrix[1][0]='X';
}
//Pressed on button 5..??
if( ( x > 50 ) && ( x < 100) && ( y > 50 ) && ( y < 100 ) ) {
matrix[1][1]='X';
}
//Pressed on button 6..??
if( ( x > 100 ) && ( x < 150 ) && ( y > 50 ) && ( y < 100 ) ) {
matrix[1][2]='X';
}
//Pressed on button 7..??
if( ( x > 0 ) && ( x < 50 ) && ( y > 100 ) && ( y < 150 ) ) {
matrix[2][0]='X';
}
//Pressed on button 8..??
if( ( x > 50 ) && ( x < 100) && ( y > 100 ) && ( y < 150 ) ) {
matrix[2][1]='X';
}
//Pressed on button 9..??
if( ( x > 100 ) && ( x < 150 ) && ( y > 100 ) && ( y < 150 ) ) {
matrix[2][2]='X';
}
}
//If the user has Xed out the window
if( event.type == SDL_QUIT ) {
//Quit the program
quit = true; }
}
}
}
But in the program it doesn't work properly and can anyone suggest any good way to capture this input in SDL other than this.. ??