Browse Source

[+] add poly

Artem Petrov 6 years ago
parent
commit
c5a448b4d1
5 changed files with 42 additions and 7 deletions
  1. 16 0
      Arbeiter.php
  2. 7 1
      Archer.php
  3. 5 4
      Barak.php
  4. 12 0
      RangeFireInterface.php
  5. 2 2
      index.php

+ 16 - 0
Arbeiter.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 10.07.18
+ * Time: 20:11
+ */
+
+class Arbeiter implements RangeFireInterface
+{
+
+    public function rangeFire(): void
+    {
+        echo 'range fire arbeiter';
+    }
+}

+ 7 - 1
Archer.php

@@ -7,12 +7,18 @@
  */
 
 include_once 'WarUnit.php';
+include_once 'RangeFireInterface.php';
 
-class Archer extends WarUnit
+class Archer extends WarUnit implements RangeFireInterface
 {
 
     public function fire($goal)
     {
 
     }
+
+    public function rangeFire(): void
+    {
+        echo 'range attack!!';
+    }
 }

+ 5 - 4
Barak.php

@@ -11,13 +11,14 @@ include_once 'Archer.php';
 
 class Barak
 {
-    public function buildUnit($unitType)
+    public function buildRangeUnit(string $unitType): RangeFireInterface
     {
-        if($unitType === 'Archer') {
+        if ($unitType === 'Archer') {
             return new Archer();
         }
-        if ($unitType === 'Guard') {
-            return new Guard();
+
+        if ($unitType === 'Arbeiter') {
+            return new Arbeiter();
         }
     }
 }

+ 12 - 0
RangeFireInterface.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 10.07.18
+ * Time: 20:08
+ */
+
+interface RangeFireInterface
+{
+    public function rangeFire(): void;
+}

+ 2 - 2
index.php

@@ -5,8 +5,8 @@ include_once 'Barak.php';
 
 $barak = new Barak();
 
-$unit = $barak->buildUnit('Archer');
+$unit = $barak->buildRangeUnit($_GET['unitType']);
 
-$unit->fire();
+$unit->rangeFire();
 
 var_dump($unit);