Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // function that prints a random number from 1 - 50.
- function printRandomNumber() {
- srand(time());
- $randomNum = rand(1, 50);
- echo "Random number: " . $randomNum . PHP_EOL;
- }
- // function that calculates the area of a rectangle.
- function calculateRectangleArea($length, $width) {
- return $length * $width;
- }
- // function that applies a speed boost.
- function applySpeedBoost(&$speed) {
- $speed *= 1.1; // I increased the speed by 10%
- }
- // function that simulates health regeneration.
- function regenerateHealth(&$health, $maxHealth) {
- // Add 5 health points (up to maxHealth)
- $health = ($health + 5 <= $maxHealth) ? $health + 5 : $maxHealth;
- }
- // function that calculates experience points.
- function calculateExperience($level) {
- // Simple formula (you can customize this)
- return $level * 100;
- }
- // define structure for inventory items.
- class Item {
- public $name;
- public $quantity;
- public function __construct($name, $quantity) {
- $this->name = $name;
- $this->quantity = $quantity;
- }
- }
- // function that adds an item to a player's inventory.
- function addItemToInventory(&$inventory, $itemName, $quantity) {
- $inventory[] = new Item($itemName, $quantity);
- }
- // define the structure for loot items.
- class LootItem {
- public $name;
- public $dropChance; // chance of (0.0 to 1.0)
- public function __construct($name, $dropChance) {
- $this->name = $name;
- $this->dropChance = $dropChance;
- }
- }
- // function that simulates loot drops.
- function simulateLootDrop() {
- srand(time());
- $randomNum = (float)rand() / (float)getrandmax(); // between 0 and 1
- $lootTable = [
- new LootItem("Health Potion", 0.3),
- new LootItem("Gold Coin", 0.6),
- new LootItem("Rare Sword", 0.1)
- ];
- foreach ($lootTable as $item) {
- if ($randomNum < $item->dropChance) {
- echo "Loot dropped: " . $item->name . PHP_EOL;
- break;
- }
- }
- }
- printRandomNumber();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement