<?php
class GameObject {
protected $name;
protected $description;
public function __construct($name, $description) {
$this->name = $name;
$this->description = $description;
}
public function display() {
echo "\n Name: " . $this->name;
echo "\n Description: " . $this->description;
}
}
class Character extends GameObject {
private $url;
public function __construct($name, $description, $url) {
parent::__construct ($name, $description);
$this->url = $url;
}
public function display() {
parent::display ();
echo "\n Url: " . $this->url;
}
}
class Obstacle extends GameObject {
private $movable;
private $hittable;
public function __construct($name, $description, $movable, $hittable) {
parent::__construct ($name, $description);
$this->movable = $movable;
$this->hittable = $hittable;
}
public function display() {
parent::display ();
echo "\n Movable: " . $this->movable;
echo "\n Hittable: " . $this->hittable;
}
}
// Creating object array
$objects = array();
$objects['Mario'] = new Character(
'Mario',
'A short, pudgy, plumber who resides in the Mushroom Kingdom.',
' https://upload.wikimedia.org/wikipedia/en/9/99/MarioSMBW.png'
);
$objects['Luigi'] = new Character(
'Luigi',
'Younger brother of Mario.',
'https://upload.wikimedia.org/wikipedia/en/f/f1/LuigiNSMBW.png'
);
$objects['Bowser'] = new Character(
'Bowser',
'Bowser is the leader and most powerful of the turtle-like Koopa race.',
'https://upload.wikimedia.org/wikipedia/en/e/ec/Bowser_-_New_Super_Mario_Bros_2.png'
);
$objects['Coin'] = new Obstacle(
'Coin',
'Coins are added to each level, which reward an extra life.',
'No',
'Yes'
);
$objects['Brick'] = new Obstacle(
'Brick',
'Characters cannot get pass through the bricks.',
'No',
'No'
);
echo"\nSuperMario: Introduction of Game Objects \n";
$check = 'y';
while ($check == 'y'){
$searchObject = readline("\nEnter the name of the object: \n");
if (isset($objects[$searchObject])) {
$objects[$searchObject]->display();
} else {
echo "\n Sorry, object not found\n";
}
echo "\n";
$check=readline("Do you want to continue? (y/n): ");
}
?>
SuperMario: Introduction of Game Objects
Fatal error: Uncaught Error: Call to undefined function readline() in /in/JcJNT:76
Stack trace:
#0 {main}
thrown in /in/JcJNT on line 76
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
SuperMario: Introduction of Game Objects
Fatal error: Uncaught Error: Call to undefined function readline() in /in/JcJNT:76
Stack trace:
#0 {main}
thrown in /in/JcJNT on line 76
Process exited with code 255.
Output for 5.6.0 - 5.6.25
SuperMario: Introduction of Game Objects
Fatal error: Call to undefined function readline() in /in/JcJNT on line 76
Process exited with code 255.