Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $battles = [];
- while ($input != "Results") {
- $comand = explode(":", $input);
- switch ($comand[0]) {
- case"Add":
- $personName = $comand [1];
- $health = $comand [2];
- $energy = $comand [3];
- if (!key_exists($personName, $battles)) {
- $battles[$personName]['health'] = $health;
- $battles[$personName]['energy'] = $energy;
- }elseif (key_exists($personName, $battles)){
- $battles[$personName]['health'] += $health;
- }
- break;
- case"Delete":
- $personName = $comand [1];
- if ($personName == "All") {
- foreach ($battles as $key => $val) {
- unset($battles[$key]);
- }
- }
- if (key_exists($personName,$battles)) {
- unset($battles[$personName]);
- }
- break;
- case"Attack":
- // Attack:Clark:Mark:500
- $attackerName = $comand[1];
- $defenderName = $comand[2];
- $damage = $comand[3];
- if (key_exists($attackerName, $battles) && key_exists($defenderName, $battles)) {
- $battles[$defenderName]['health'] -= $damage;
- $battles[$attackerName]['energy'] -= 1;
- if ($battles[$defenderName]['health'] <= 0) {
- unset($battles[$defenderName]);
- echo "$defenderName was disqualified!\n";
- }
- if ($battles[$attackerName]['energy'] <= 0) {
- unset($battles[$attackerName]);
- echo "$attackerName was disqualified!\n";
- }
- }
- break;
- }
- $input = readline();
- }
- $count = count($battles);
- echo "People count: $count\n";
- ksort($battles);
- arsort($battles);
- foreach ($battles as $key => $val) {
- echo "$key - $val[health] - $val[energy]\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement