Test Failed
Push — master ( 4204bb...4b507f )
by Jakub
02:18
created

VictoryConditions   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 18
eloc 29
c 1
b 0
f 0
dl 0
loc 56
ccs 8
cts 28
cp 0.2857
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A eliminateSecondTeam() 0 12 6
A firstTeamSurvives() 0 12 6
A moreDamage() 0 12 6
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
final class VictoryConditions {
12
  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 1
        $result = 2;
24 1
      } elseif(!$combat->team2->hasAliveMembers()) {
25 1
        $result = 1;
26
      }
27
    } elseif($combat->round > $combat->roundLimit) {
28
      $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
?>