소스 검색

[+] add game

Artem Petrov 6 년 전
커밋
94786b3117
6개의 변경된 파일131개의 추가작업 그리고 0개의 파일을 삭제
  1. 18 0
      Archer.php
  2. 23 0
      Barak.php
  3. 43 0
      Guard.php
  4. 23 0
      Swordsman.php
  5. 12 0
      WarUnit.php
  6. 12 0
      index.php

+ 18 - 0
Archer.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 06.07.18
+ * Time: 21:36
+ */
+
+include_once 'WarUnit.php';
+
+class Archer extends WarUnit
+{
+
+    public function fire($goal)
+    {
+
+    }
+}

+ 23 - 0
Barak.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 06.07.18
+ * Time: 21:47
+ */
+
+include_once 'Guard.php';
+include_once 'Archer.php';
+
+class Barak
+{
+    public function buildUnit($unitType)
+    {
+        if($unitType === 'Archer') {
+            return new Archer();
+        }
+        if ($unitType === 'Guard') {
+            return new Guard();
+        }
+    }
+}

+ 43 - 0
Guard.php

@@ -0,0 +1,43 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 06.07.18
+ * Time: 20:44
+ */
+
+include_once 'WarUnit.php';
+
+class Guard extends WarUnit
+{
+    protected const POWER = 10;
+
+    public $health;
+
+    public function __construct()
+    {
+        $this->health = 40;
+        $this->decreaseResources();
+        $this->playLoading();
+    }
+
+    private function decreaseResources()
+    {
+        echo '-20 золота<br>';
+    }
+
+    private function playLoading()
+    {
+        echo 'Playing guard loading<br>';
+    }
+
+    public function fire($ovtsa)
+    {
+        $ovtsa->health = $ovtsa->health - self::POWER;
+    }
+
+    public function selfCure()
+    {
+        $this->health = 40;
+    }
+}

+ 23 - 0
Swordsman.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 06.07.18
+ * Time: 20:45
+ */
+
+include_once 'Guard.php';
+
+class Swordsman extends Guard
+{
+    public function __construct($name)
+    {
+        parent::__construct($name);
+        $this->health = 50;
+    }
+
+    protected function playLoading()
+    {
+        echo 'Playing swordsman loading<br>';
+    }
+}

+ 12 - 0
WarUnit.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: artem
+ * Date: 06.07.18
+ * Time: 21:29
+ */
+
+abstract class WarUnit
+{
+    abstract function fire($goal);
+}

+ 12 - 0
index.php

@@ -0,0 +1,12 @@
+<?php
+
+
+include_once 'Barak.php';
+
+$barak = new Barak();
+
+$unit = $barak->buildUnit('Archer');
+
+$unit->fire();
+
+var_dump($unit);