Completed
Push — master ( 54fdf8...606b80 )
by Jakub
02:17
created

VictoryConditions::firstTeamSurvives()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 9
nc 6
nop 1
crap 42
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
/**
7
 * VictoryConditions
8
 *
9
 * @author Jakub Konečný
10
 */
11 1
class VictoryConditions {
12 1
  use \Nette\StaticClass;
13
  
14
  /**
15
   * Evaluate winner of combat
16
   * The team which dealt more damage after round limit, wins
17
   * If all members of one team are eliminated before that, the other team wins
18
   */
19
  public static function moreDamage(CombatBase $combat): int {
20 1
    $result = 0;
21 1
    if($combat->round <= $combat->roundLimit) {
22 1
      if(!$combat->team1->hasAliveMembers()) {
23
        $result = 2;
24 1
      } elseif(!$combat->team2->hasAliveMembers()) {
25 1
        $result = 1;
26
      }
27 1
    } elseif($combat->round > $combat->roundLimit) {
28 1
      $result = ($combat->team1Damage > $combat->team2Damage) ? 1 : 2;
29
    }
30 1
    return $result;
31
  }
32
  
33
  /**
34
   * Evaluate winner of combat
35
   * Team 1 wins only if they eliminate all opponents before round limit
36
   */
37
  public static function eliminateSecondTeam(CombatBase $combat): int {
38
    $result = 0;
39
    if($combat->round <= $combat->roundLimit) {
40
      if(!$combat->team1->hasAliveMembers()) {
41
        $result = 2;
42
      } elseif(!$combat->team2->hasAliveMembers()) {
43
        $result = 1;
44
      }
45
    } elseif($combat->round > $combat->roundLimit) {
46
      $result = (!$combat->team2->hasAliveMembers()) ? 1 : 2;
47
    }
48
    return $result;
49
  }
50
  
51
  /**
52
   * Evaluate winner of combat
53
   * Team 1 wins if at least 1 of its members is alive after round limit
54
   */
55
  public static function firstTeamSurvives(CombatBase $combat): int {
56
    $result = 0;
57
    if($combat->round <= $combat->roundLimit) {
58
      if(!$combat->team1->hasAliveMembers()) {
59
        $result = 2;
60
      } elseif(!$combat->team2->hasAliveMembers()) {
61
        $result = 1;
62
      }
63
    } elseif($combat->round > $combat->roundLimit) {
64
      $result = ($combat->team1->hasAliveMembers()) ? 1 : 2;
65
    }
66
    return $result;
67
  }
68
}
69
?>