Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. $input = readline();
  3. $battles = [];
  4. while ($input != "Results") {
  5. $comand = explode(":", $input);
  6. switch ($comand[0]) {
  7. case"Add":
  8. $personName = $comand [1];
  9. $health = $comand [2];
  10. $energy = $comand [3];
  11. if (!key_exists($personName, $battles)) {
  12. $battles[$personName]['health'] = $health;
  13. $battles[$personName]['energy'] = $energy;
  14. }elseif (key_exists($personName, $battles)){
  15. $battles[$personName]['health'] += $health;
  16. }
  17. break;
  18. case"Delete":
  19. $personName = $comand [1];
  20. if ($personName == "All") {
  21. foreach ($battles as $key => $val) {
  22. unset($battles[$key]);
  23. }
  24. }
  25. if (key_exists($personName,$battles)) {
  26. unset($battles[$personName]);
  27. }
  28. break;
  29. case"Attack":
  30. // Attack:Clark:Mark:500
  31. $attackerName = $comand[1];
  32. $defenderName = $comand[2];
  33. $damage = $comand[3];
  34. if (key_exists($attackerName, $battles) && key_exists($defenderName, $battles)) {
  35. $battles[$defenderName]['health'] -= $damage;
  36. $battles[$attackerName]['energy'] -= 1;
  37. if ($battles[$defenderName]['health'] <= 0) {
  38. unset($battles[$defenderName]);
  39. echo "$defenderName was disqualified!\n";
  40. }
  41. if ($battles[$attackerName]['energy'] <= 0) {
  42. unset($battles[$attackerName]);
  43. echo "$attackerName was disqualified!\n";
  44. }
  45. }
  46. break;
  47. }
  48. $input = readline();
  49. }
  50. $count = count($battles);
  51. echo "People count: $count\n";
  52. ksort($battles);
  53. arsort($battles);
  54. foreach ($battles as $key => $val) {
  55. echo "$key - $val[health] - $val[energy]\n";
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement