在这部分代码中是一个错误。它说
“运行时检查失败 #3 - 变量 'direct' 正在使用而未初始化。”
我该如何解决这个错误?
bool loop=true;
int direct;
al_install_keyboard();
ALLEGRO_TIMER *timer = al_create_timer (0.4);
ALLEGRO_EVENT_QUEUE *keystroke = al_create_event_queue();
al_register_event_source(keystroke ,al_get_keyboard_event_source() );
al_register_event_source (keystroke , al_get_timer_event_source(timer));
al_start_timer(timer);
do{
ALLEGRO_EVENT input;
al_wait_for_event(keystroke , &input );
if (input.type == ALLEGRO_EVENT_KEY_DOWN){
switch(input.keyboard.keycode){
case ALLEGRO_KEY_DOWN: direct=DOWN; break;
case ALLEGRO_KEY_UP : direct=UP;break;
case ALLEGRO_KEY_LEFT: direct=LEFT;break;
case ALLEGRO_KEY_RIGHT: direct=RIGHT;break;
case ALLEGRO_KEY_ESCAPE: loop= false;
}
}
if(input.type==ALLEGRO_EVENT_TIMER){
switch(direct){
case DOWN: moove_snake(DOWN) ; break;
case UP: moove_snake(UP) ; break;
case LEFT: moove_snake(LEFT) ; break;
case RIGHT: moove_snake(RIGHT) ; break;
}
}
}while (loop);