no message
This commit is contained in:
36
Question15-Polymorphism/Ex01.php
Normal file
36
Question15-Polymorphism/Ex01.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* [Ex01 基本的な多態性 - 消費アイテムの利用]
|
||||
*
|
||||
* TODO:
|
||||
* 1. 以下の仕様に従って、common フォルダ内に各クラスファイルを作成してください。
|
||||
*
|
||||
* (1) インタフェース Common\UsableInterface を作成し、以下を定義する:
|
||||
* - public function useItem(): string;
|
||||
* - public function getAmount(): int;
|
||||
*
|
||||
* (2) Common\UsableInterface を実装するクラス Common\HealthPotion を作成する:
|
||||
* - コンストラクタでHP回復量(例: 50)を設定し、プロパティとして保持する。
|
||||
* - useItem() メソッドは「HealthPotion: You recover {amount} HP!」という文字列を返す。
|
||||
* - getAmount() メソッドは設定された HP 回復量を返す。
|
||||
*
|
||||
* (3) 同様に、Common\UsableInterface を実装するクラス Common\ManaPotion を作成する:
|
||||
* - コンストラクタでMP回復量(例: 30)を設定し、useItem() は「ManaPotion: You recover {amount} MP!」、
|
||||
* getAmount() はその数値を返す。
|
||||
*
|
||||
* (4) 同様に、Common\UsableInterface を実装するクラス Common\Bomb を作成する:
|
||||
* - コンストラクタでダメージ値(例: 40)を設定し、useItem() は「Bomb: You deal {amount} damage to all enemies!」、
|
||||
* getAmount() はその数値を返す。
|
||||
*
|
||||
* 2. 本ファイル内で、require_once を使い以下のファイルを読み込んでください:
|
||||
* - common/UsableInterface.php
|
||||
* - common/HealthPotion.php
|
||||
* - common/ManaPotion.php
|
||||
* - common/Bomb.php
|
||||
*
|
||||
* 3. namespace を利用して、Common\HealthPotion, Common\ManaPotion, Common\Bomb クラスを使用し、
|
||||
* それぞれのインスタンスを生成して、useItem() の返り値を出力してください。
|
||||
*
|
||||
* ※このファイルには HTML を記述しないこと!
|
||||
*/
|
||||
Reference in New Issue
Block a user