<?php
header("Content-Type: text/plain; charset=utf-8"); class Game
{
public $hero;
public $monsters;
public $gold=0;
public function __construct($monsters, $items)
{
$this->hero = new Hero($items);
$this->monsters = $monsters;
}
public function getKillMonster()
{
$monsters = $this->monsters; //копия переменной монстров
for ($i = 1; $i <= $this->monsters; $i++)
{
$items = $this->hero->items;
$typeOfNewItem = mt_rand(1, count($items)); //генерация номера слота выпавшего предмета $oldItem = $this->hero->getOldItem($typeOfNewItem); //уровень старого предмета
$newItem = mt_rand (1, ($oldItem +1)); //генерация илвл нового предмета if ($newItem >= $oldItem)
{
$this->hero->getChangeItem($typeOfNewItem, $newItem); //замена старого предмета новым
$this->gold += $oldItem; //продажа старого предмета
} else {
$this->gold += $newItem; //продажа нового предмета, так как он хуже старого
}
$monsters--;
}
$this->monsters = $monsters; // количество монстров оставшихся в живых
}
}
class Hero
{
public function __construct($k)
{
for ($i = 1; $i <= $k; $i++)
{
$item = new Item($i);
$items[] = $item;
}
$this->items = $items;
}
public function getOldItem($numberItem)//взять илвл старого предмета данного слота
{
foreach ($this->items as $item) // перебор, чтобы добраться до нужного предмета
{
if ($item->slot == $numberItem) //проверка на подходящий слот
{
return $item->itemLvl; //возвращение уровня предмета
}
}
}
public function getChangeItem($numberItem, $itemLvl) //замена старого предмета новым
{
foreach ($this->items as $item) // перебор, чтобы добраться до нужного предмета
{
if ($item->slot == $numberItem) //проверка на подходящий слот
{
$item->itemLvl = $itemLvl; //присвоение нового уровня предмета
}
}
}
}
class Item
{
public $slot;
public $itemLvl=1;
public function __construct($slot)
{
return $this->slot = $slot;
}
}
function getGame($n, $k)
{
$game = new Game ($n, $k);
return $game;
}
$game = getGame(5, 2);
$game->getKillMonster();
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoIlVURi04Iik7CmNsYXNzIEdhbWUgCnsKCXB1YmxpYyAkaGVybzsKCXB1Y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