-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandlers.c
91 lines (78 loc) · 1.67 KB
/
handlers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*****************************************************************************
*
* lines -- a game
*
* (c) 1999 Albertas Agejevas <alga@pub.osf.lt>
*
* This program is free software. You can use it under the conditions of
* the GNU General Public Licence version 2
*
*
*****************************************************************************
*/
#include "handlers.h"
#include "rules.h"
#include "hiscore.h"
#include "lines.h"
#include <stdio.h>
void delete_event(GtkWidget *widget, GdkEvent *e, gpointer data)
{
gtk_main_quit();
}
void click(GtkWidget *widget, gpointer data)
{
int i,j;
static int second;
static int x1, y1, click_lock;
if(click_lock)
return;
i = (unsigned)data >> 16;
j = (unsigned)data & 0xFFFF;
/* is one ball selected yet ? */
if( !second ) {
if(!field[i][j]) {
/* if an empty square was pressed, we just
* pop it back
*/
click_lock = TRUE;
gtk_toggle_button_set_state(
GTK_TOGGLE_BUTTON(buttons[i][j]),
FALSE);
click_lock = FALSE;
return;
}
second = TRUE;
x1 = j;
y1 = i;
} else if (second) {
if(x1 == j && y1 == i) {
second = FALSE;
return;
}
click_lock = TRUE;
gtk_toggle_button_set_state(
GTK_TOGGLE_BUTTON(buttons[y1][x1]),
FALSE);
if(!field[i][j])
gtk_toggle_button_set_state(
GTK_TOGGLE_BUTTON(buttons[i][j]),
FALSE);
else {
x1 = j;
y1 = i;
click_lock = FALSE;
return;
}
click_lock = FALSE;
save_undo();
if( find_path(y1, x1, i, j) && !check_lines()) {
if (pop_new() == FALSE) {
game_over();
}
next_pop();
check_lines();
enable_undo(TRUE);
}
second = FALSE;
}
}