no message

This commit is contained in:
a-kizaki
2026-10-06 12:10:09 +09:00
commit 9c2090ffa2
156 changed files with 14850 additions and 0 deletions

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

View File

@@ -0,0 +1,23 @@
<?php
/**
* [Ex02 多態性の利便性 - 消費アイテムの一括処理]
*
* TODO:
* 1. 先ほど作成した Common\HealthPotion, Common\ManaPotion, Common\Bomb クラスを利用します。
*
* 2. 本ファイル内で、require_once を使い以下のファイルを読み込んでください:
* - common/UsableInterface.php
* - common/HealthPotion.php
* - common/ManaPotion.php
* - common/Bomb.php
*
* 3. namespace を利用して、各クラスを使用してください。
*
* 4. HealthPotion (50), ManaPotion (30), Bomb (40) の各インスタンスを生成し、1つの配列に格納してください。
*
* 5. 配列内の各アイテムについて、useItem() メソッドを呼び出し、その返り値を表示するとともに、
* 各アイテムの getAmount() メソッドを使って効果値を合計し、最終的な合計値も出力してください。
*
* ※このファイルには HTML を記述しないこと!
*/

View File

@@ -0,0 +1,35 @@
<?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 を記述しないこと!
*/

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>PHP 多態性問題 スタートページ</title>
<link href="../common/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>独習PHP第10章練習問題 <small>多態性の基本とその利便性</small></h1>
</div>
<div class="panel-group" id="accordion">
<!-- Ex01 -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex01.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex01: 基本的な多態性の利用(消費アイテムクラス)
</a>
<small>初級</small>
</h4>
</div>
</div>
<!-- Ex02 -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex02.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex02: 多態性の利便性を体感(配列で消費アイテムを一括処理)
</a>
<small>初級</small>
</h4>
</div>
</div>
<!-- Ex03 -->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a href="Ex03.php" target="_blank">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Ex03: Inventory クラスによる消費アイテム管理(現場寄り)
</a>
<small>上級</small>
</h4>
</div>
</div>
</div>
</div>
<!-- jQuery -->
<script src="../common/js/jquery-3.2.1.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="../common/js/bootstrap.min"></script>
</body>
</html>