Last active
November 21, 2022 02:55
-
-
Save katsube/92ebd3b7a900aeb6e77cc1cbb5d0cf18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tarou = new User('太郎'); | |
$tarou->addExp(300); | |
// 現在のレベルを表示 ("太郎 Lv.4"と表示される) | |
printf("%s Lv.%d\n" | |
, $tarou->name | |
, $tarou->getLevel()); | |
/** | |
* ユーザークラス | |
*/ | |
class User{ | |
public $name; // 名前 ※外から参照可能 | |
private $exp; // 経験値 ※外から参照不可能 | |
/** | |
* コンストラクタ | |
*/ | |
function __construct($name, $exp=1){ | |
$this->name = $name; | |
$this->exp = $exp; | |
} | |
/** | |
* 経験値を加算する | |
*/ | |
function addExp($value){ | |
$this->exp += $value; | |
} | |
/** | |
* レベルを計算し返却する | |
*/ | |
// ★このあたりにメソッドを追加する★ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment