void PlayArea::Play(int level) { if (curPiece) { delete curPiece; curPiece = NULL; } if (nextPiece) { delete nextPiece; nextPiece = NULL; } srand((unsigned)time(NULL)); curPiece = new Piece; curPiece->map = this; curPiece->CreateRandomPiece(); nextPiece = new Piece; nextPiece->map = this; nextPiece->CreateRandomPiece(); parent->HandleEvent(*this, MyDialog::MSG_NEWPIECE); ClearPlayArea(); frameInterval = 550 - level*50; timer = al_create_timer(frameInterval / 1000.f); al_register_event_source(queue, (ALLEGRO_EVENT_SOURCE *) timer); al_start_timer(timer); playing = true; lines = 0; score = 0; parent->HandleEvent(*this, MyDialog::MSG_UPDATESCORE, lines, score); }
void PlayArea::MsgTimer(ALLEGRO_TIMER_EVENT *t) { Widget::MsgTimer(t); if (t->source == timer) { if (curPiece->MoveDown() == false) { DropCurrentPiece(); delete curPiece; curPiece = nextPiece; nextPiece = new Piece; nextPiece->map = this; nextPiece->CreateRandomPiece(); if (!curPiece->CanMoveDown()) { GameOver(); } else { parent->HandleEvent(*this, MyDialog::MSG_NEWPIECE); } } } }