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

36 lines
1.7 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
/**
* [Ex03 多態性の利便性 - Inventoryクラスによる消費アイテム管理]
*
* TODO:
* 1. common フォルダ内に、Inventory クラスを作成してください(ファイル名: Inventory.php)。
* - namespace は Common とする。
* - Inventory クラスの仕様:
* プロパティ: private $items (UsableInterface 型のオブジェクトを格納する配列)
* public function addItem(UsableInterface $item): void; // 配列にアイテムを追加する
* public function useAll(): string; // 配列内の各アイテムの useItem() の返り値を改行区切りで連結して返す
* public function getTotalEffect(): int; // 配列内の各アイテムの getAmount() の合計値を返す
*
* 2. 本ファイル内で、require_once を使い以下のファイルを読み込んでください:
* - common/UsableInterface.php
* - common/HealthPotion.php
* - common/ManaPotion.php
* - common/Bomb.php
* - common/Inventory.php
*
* 3. namespace を利用して、Common\Inventory, Common\HealthPotion, Common\ManaPotion, Common\Bomb クラスを使用してください。
*
* 4. Inventory クラスのインスタンスを生成し、以下のアイテムを追加してください:
* - HealthPotion (50)
* - ManaPotion (30)
* - Bomb (40)
* - さらに HealthPotion (20) を追加してもよい。
*
* 5. Inventory の useAll() メソッドを呼び出して、その結果を出力するとともに、
* getTotalEffect() メソッドの返り値(全アイテムの効果値の合計)も出力してください。
*
* ※このファイルには HTML を記述しないこと!
*/