Files
2026-10-06 12:10:09 +09:00

37 lines
1.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 を記述しないこと!
*/