Grey Screen Tic-Tac-Toe

Hello. I have been programming for almost a year, though recently I got Allegro 5 for game-making. I wrote a program using Allegro for Tic-Tac-Toe and I can't find what's wrong. At the risk of looking like a terrible debugger, I have been searching for about 2 months, though not constantly. I use Code::Blocks 10.05 and Windows Vista if those matter.

Here's what happens. I will hit compile, and it will load, another window will open (the game window), but it will turn grey and say:

Tic-Tac-Toe.exe has stopped working
A problem caused the program to stop working correctly.
Windows will close the program and notify you if a solution is available.

Unquote. If anyone has dealt with a similar problem, please help. I have taken out empty lines to save space, leaving 243 lines. Please excuse the size, as I am quite a novice at graphics.

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include <allegro5/allegro5.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_primitives.h>
float FPS=1.0;
bool done=false;
ALLEGRO_TIMER* timer=NULL;
ALLEGRO_EVENT_QUEUE* event_queue=NULL;
ALLEGRO_DISPLAY* display=NULL;
void init(void)
{
    if (!al_init())
    {
        done=true;
    }
    if (!al_install_keyboard())
    {
        done=true;
    }
    if (!al_install_mouse())
    {
        done=true;
    }
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    display = al_create_display(625, 625);
    if (!display)
    {
        done=true;
    }
    al_clear_to_color(al_map_rgb(255,255,255));
    timer = al_create_timer(FPS);
    if(!timer)
    {
        done=true;
        al_destroy_display(display);
    }
    event_queue = al_create_event_queue();
    if (!event_queue)
    {
        done=true;
        al_destroy_timer(timer);
        al_destroy_display(display);
    }
if (event_queue) {
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_mouse_event_source());
    al_register_event_source(event_queue, al_get_display_event_source(display));
}
}
void delete_stuff(void)
{
    if (timer)
        al_destroy_timer(timer);
    if (display)
        al_destroy_display(display);
    if (event_queue)
        al_destroy_event_queue(event_queue);
}
void game_loop(void)
{
    if (!done)
    {
    char TL='a';
    char T='b';
    char TR='c';
    char L='d';
    char M='e';
    char R='f';
    char BL='g';
    char B='h';
    char BR='i';
    int turn = 1;
    bool redraw=false;
    ALLEGRO_COLOR black = al_map_rgb(0, 0, 0);
    al_set_target_bitmap(al_get_backbuffer(display));
    al_draw_line(201, 1, 201, 601, black, 5.0);
    al_draw_line(401, 1, 401, 601, black, 5.0);
    al_draw_line(1, 201, 601, 401, black, 5.0);
    al_draw_line(1, 201, 601, 401, black, 5.0);
    al_flip_display();
    while (!done) {
        if (turn==1)
            turn=2;
        else if (turn==2)
            turn=1;
        ALLEGRO_EVENT ev;
        al_wait_for_event(event_queue, &ev);
        if (ev.type == ALLEGRO_EVENT_TIMER)
        {
            redraw=true;
        }
        else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        break;
        else if (ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
        if (ev.mouse.x > 0 && ev.mouse.x < 200 &&
            ev.mouse.y > 0 && ev.mouse.y < 200) {
            if (turn==1) {
            al_draw_line(1, 1, 201, 201, black, 3);
            al_draw_line(201, 1, 1, 201, black, 3);
            TL='x';
            }
            else if (turn==2) {
            al_draw_circle(101, 101, 100, black, 5);
            TL='o';
            }
            }
        else if (ev.mouse.x > 200 && ev.mouse.x < 400 &&
            ev.mouse.y > 0 && ev.mouse.y < 200) {
            if (turn==1) {
            al_draw_line(201, 1, 401, 201, black, 3);
            al_draw_line(201, 201, 401, 1, black, 3);
            T='x';
            }
            else if (turn==2) {
            al_draw_circle(301, 101, 100, black, 5);
            T='o';
            }
            }
        else if (ev.mouse.x > 400 && ev.mouse.x < 600 &&
            ev.mouse.y > 0 && ev.mouse.y < 200) {
            if (turn==1) {
            al_draw_line(401, 1, 601, 201, black, 3);
            al_draw_line(401, 201, 601, 1, black, 3);
            TR='x';
            }
            else if (turn==2) {
            al_draw_circle(501, 101, 100, black, 5);
            TR='o';
            }
            }
        else if (ev.mouse.x > 0 && ev.mouse.x < 200 &&
            ev.mouse.y > 200 && ev.mouse.y < 400) {
            if (turn==1) {
            al_draw_line(1, 201, 201, 401, black, 3);
            al_draw_line(201, 201, 1, 401, black, 3);
            L='x';
            }
            else if (turn==2) {
            al_draw_circle(101, 301, 100, black, 5);
            L='o';
            }
            }
        else if (ev.mouse.x > 200 && ev.mouse.x < 400 &&
            ev.mouse.y > 200 && ev.mouse.y < 400) {
            if (turn==1) {
            al_draw_line(201, 201, 401, 401, black, 3);
            al_draw_line(201, 401, 401, 201, black, 3);
            M='x';
            }
            else if (turn==2) {
            al_draw_circle(301, 301, 100, black, 5);
            M='o';
            }
            }
        else if (ev.mouse.x > 400 && ev.mouse.x < 600 &&
            ev.mouse.y > 200 && ev.mouse.y < 400) {
            if (turn==1) {
            al_draw_line(401, 201, 601, 401, black, 3);
            al_draw_line(401, 401, 601, 201, black, 3);
            R='x';
            }
            else if (turn==2) {
            al_draw_circle(501, 301, 100, black, 5);
            R='o';
            }
            }
        else if (ev.mouse.x > 0 && ev.mouse.x < 200 &&
            ev.mouse.y > 400 && ev.mouse.y < 600) {
            if (turn==1) {
            al_draw_line(1, 401, 201, 601, black, 3);
            al_draw_line(401, 401, 201, 601, black, 3);
            BL='x';
            }
            else if (turn==2) {
            al_draw_circle(101, 501, 100, black, 5);
            BL='o';
            }
            }
        else if (ev.mouse.x > 200 && ev.mouse.x < 400 &&
            ev.mouse.y > 400 && ev.mouse.y < 600) {
            if (turn==1) {
            al_draw_line(201, 401, 401, 601, black, 3);
            al_draw_line(201, 601, 401, 401, black, 3);
            B='x';
            }
            else if (turn==2) {
            al_draw_circle(301, 501, 100, black, 5);
            B='o';
            }
            }
        else if (ev.mouse.x > 400 && ev.mouse.x < 600 &&
            ev.mouse.y > 400 && ev.mouse.y < 600) {
            if (turn==1) {
            al_draw_line(401, 401, 601, 601, black, 3);
            al_draw_line(401, 601, 601, 401, black, 3);
            BR='x';
            }
            else if (turn==2) {
            al_draw_circle(501, 501, 100, black, 5);
            BR='o';
            }
            }
        }
        if ((TL==T&&T==TR)||
            (L==M&&M==R)||
            (BL==B&&B==BR)||
            (TL==L&&L==BL)||
            (T==M&&M==B)||
            (TR==R&&R==BR)||
            (TL==M&&M==BR)||
            (TR==M&&M==BL)) {
            if (turn==1) {
            al_show_native_message_box(al_get_current_display(),
                                 "X WON!",
                                 "Congratulations!",
                                 "The winner is X!",
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
            break;
            }
            else if (turn==2) {
            al_show_native_message_box(al_get_current_display(),
                                 "O WON!",
                                 "Congratulations!",
                                 "The winner is O!",
                                 NULL, ALLEGRO_MESSAGEBOX_ERROR);
            break;
            }
            }

        if (redraw == true)
        {
            redraw=false;
            al_flip_display();
        }
    }
}
}
int main(int argc, char** argv)
{
    init();
    game_loop();
    delete_stuff();
    return 0;
}
Topic archived. No new replies allowed.