VictoryConditions   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 32.14%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 18
eloc 29
c 2
b 0
f 0
dl 0
loc 60
rs 10
ccs 9
cts 28
cp 0.3214

3 Methods

Rating   Name   Duplication   Size   Complexity  
A moreDamage() 0 13 6
A eliminateSecondTeam() 0 13 6
A firstTeamSurvives() 0 13 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
{
13
    use \Nette\StaticClass;
14
15
    /**
16
     * Evaluate winner of combat
17
     * The team which dealt more damage after round limit, wins
18
     * If all members of one team are eliminated before that, the other team wins
19
     */
20
    public static function moreDamage(CombatBase $combat): int
21
    {
22 1
        $result = 0;
23 1
        if ($combat->round <= $combat->roundLimit) {
24 1
            if (!$combat->team1->hasAliveMembers()) {
25
                $result = 2;
26 1
            } elseif (!$combat->team2->hasAliveMembers()) {
27 1
                $result = 1;
28
            }
29 1
        } elseif ($combat->round > $combat->roundLimit) {
30 1
            $result = ($combat->team1Damage > $combat->team2Damage) ? 1 : 2;
31
        }
32 1
        return $result;
33
    }
34
35
    /**
36
     * Evaluate winner of combat
37
     * Team 1 wins only if they eliminate all opponents before round limit
38
     */
39
    public static function eliminateSecondTeam(CombatBase $combat): int
40
    {
41
        $result = 0;
42
        if ($combat->round <= $combat->roundLimit) {
43
            if (!$combat->team1->hasAliveMembers()) {
44
                $result = 2;
45
            } elseif (!$combat->team2->hasAliveMembers()) {
46
                $result = 1;
47
            }
48
        } elseif ($combat->round > $combat->roundLimit) {
49
            $result = (!$combat->team2->hasAliveMembers()) ? 1 : 2;
50
        }
51
        return $result;
52
    }
53
54
    /**
55
     * Evaluate winner of combat
56
     * Team 1 wins if at least 1 of its members is alive after round limit
57
     */
58
    public static function firstTeamSurvives(CombatBase $combat): int
59
    {
60
        $result = 0;
61
        if ($combat->round <= $combat->roundLimit) {
62
            if (!$combat->team1->hasAliveMembers()) {
63
                $result = 2;
64
            } elseif (!$combat->team2->hasAliveMembers()) {
65
                $result = 1;
66
            }
67
        } elseif ($combat->round > $combat->roundLimit) {
68
            $result = ($combat->team1->hasAliveMembers()) ? 1 : 2;
69
        }
70
        return $result;
71
    }
72
}
73