Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // function that simulates a combat system.
- function simulateCombat($playerHealth, $enemyHealth) {
- srand(time());
- while ($playerHealth > 0 && $enemyHealth > 0) {
- $playerAttack = rand(1, 20);
- $enemyAttack = rand(1, 20);
- echo "Player attacks for " . $playerAttack . " damage!" . PHP_EOL;
- $enemyHealth -= $playerAttack;
- if ($enemyHealth <= 0) {
- echo "Enemy defeated! Player wins!" . PHP_EOL;
- break;
- }
- echo "Enemy counterattacks for " . $enemyAttack . " damage!" . PHP_EOL;
- $playerHealth -= $enemyAttack;
- if ($playerHealth <= 0) {
- echo "Player defeated! Enemy wins!" . PHP_EOL;
- break;
- }
- }
- }
- // function that generates random loot from treasure chests.
- function generateLoot($playerLuck) {
- srand(time());
- $lootValue = rand(0, 99);
- $actualLoot = $lootValue * $playerLuck / 100;
- echo "You found loot worth " . $actualLoot . " gold!" . PHP_EOL;
- }
- // define the structure for handling skill leveling.
- class Player {
- public $level;
- public $experience;
- public function __construct($level, $experience) {
- $this->level = $level;
- $this->experience = $experience;
- }
- }
- // player levels up!
- function levelUp($player) {
- $player->level++;
- $player->experience = 0;
- echo "Congratulations! You leveled up to level " . $player->level . "!" . PHP_EOL;
- }
- // function that simulates an enemy encounter.
- function enemyEncounter($enemyName, $enemyHealth) {
- echo "You encounter a " . $enemyName . "!" . PHP_EOL;
- echo "Enemy health: " . $enemyHealth . PHP_EOL;
- }
- $playerHealth = 100;
- $enemyHealth = 80;
- simulateCombat($playerHealth, $enemyHealth);
- $playerLuck = 75;
- generateLoot($playerLuck);
- $player = new Player(1, 0);
- $player->experience += 100;
- if ($player->experience >= 1000) {
- levelUp($player);
- }
- $enemyName = "Orc";
- $enemyHealth2 = 120;
- enemyEncounter($enemyName, $enemyHealth2);
- // tic tac toe
- $board = array_fill(0, 3, array_fill(0, 3, ' '));
- $board[1][1] = 'X';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement