Example #1
0
/**
  * Zeitablauf: Alle Figuren bewegen.
  */
void GameController::nextTick() {
	if(this->state == Starting)
	{
		this->ticks--;
		if(this->ticks == 0)
			this->setState(Playing);
	}
	else if(this->state == LevelOver)
	{
		this->ticks--;
		if(this->ticks == 0)
		{
			if(this->field->nextLevel())
			{
				this->setState(Starting);
			}
			else
			{
				this->setState(GameOver);
			}
		}
	}
	else if(this->state == Playing)
	{
		if (ghostStateHarmless) {
			if (--ghostHarmlessTicks <= 0) {
				ghostStateHarmless = false;
			}
		}

		for (std::vector<Figure*>::iterator iter = this->figures.begin(); iter != this->figures.end(); ++iter ) {
			// Die Figur darf noch nicht tot sein.
			Figure* figure = *iter;
			if (figure->getState() != Dead) {
				figure->nextTick();
				handleCollisionWithPacman(figure);
			}
		}

		if(this->foodCount == 0)
		{
			this->setState(LevelOver);
		}

		if(pacman->getState() == Dead)
		{
			if(--this->lives == 0)
			{
				this->state = GameOver;
			}
			else
			{
				for (std::vector<Figure*>::iterator iter = this->figures.begin(); iter != this->figures.end(); ++iter ) {
					// Die Figur darf noch nicht tot sein.
					Figure* figure = *iter;
					if (figure->getState() != Dead) {
						figure->reset();
					}
				}
				pacman->reset();
				this->setState(Starting);
			}
		}
	}
}