Adds the possibility to serialize a battle state for saving it
This commit is contained in:
@@ -91,6 +91,35 @@ class BattleTest extends CoreModelTestCase
|
||||
$this->assertTrue($character->isAlive() xor $monster->isAlive());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a fight can happen if it is serialized between each round.
|
||||
*/
|
||||
public function testFairBattleWithSerializationBetweenRounds()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
|
||||
$character = $em->getRepository(Character::class)->find(1);
|
||||
$monster = $em->getRepository(Monster::class)->find(1);
|
||||
|
||||
$battle = new Battle($this->getMockGame($character), $character, $monster);
|
||||
$battle = $battle->serialize();
|
||||
|
||||
for ($n = 0; $n < 99; $n++) {
|
||||
$battle = Battle::unserialize($this->getMockGame($character), $character, $battle);
|
||||
|
||||
$battle->fightNRounds(1);
|
||||
|
||||
if ($battle->isOver()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$battle = $battle->serialize();
|
||||
}
|
||||
|
||||
$this->assertTrue($battle->isOver());
|
||||
$this->assertTrue($battle->getPlayer()->isAlive() xor $battle->getMonster()->isAlive());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a fight which the player has to win (lvl 100 vs lvl 1)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user