Example #1
0
void Player::Act(Directions input_dir)
{
	Field *currentField = _position;
	Field *nextField = currentField;
	Field *targetField = GetTargetField();
	Battlefield *btl = _game->GetBattlefield();
	nextField = btl->GetNextField(currentField, input_dir);

	if (nextField != nullptr) //if we're moving somewhere
	{
		if (nextField == targetField) //where our target is
		{
			btl->Fight(this, targetField->GetEnemy(), true); //Kill'em!
			if ( HaveTarget() ) btl->CalculateNextFight(); //if enemy still alive
		}
		else //if target was somewhere else
		{
			SetTargetField(nullptr); //forget about it

			if (nextField->HaveEnemy()) 
			{
				SetTargetField(nextField); // select new target if any
				btl->CalculateNextFight();
			}

			else if (nextField->HavePowerup())
			{
				_game->GetDisplay()->SendEvent( TakePowerup(nextField) );
			}

			else
			{
				_position = nextField; //if there's no enemy - move there and look around
				LookAround();
			}
		}
	}
}