Game.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Created by IntelliJ IDEA.
  4. * User: solu
  5. * Date: 2019/3/1
  6. * Time: 5:03 PM
  7. */
  8. class Game {
  9. public function initHorse($horseNum) {
  10. $horseList = [];
  11. for ($i = 0; $i < $horseNum; $i++) {
  12. $horse = [
  13. "speed" => rand(20, 90), // 速度
  14. "jump" => rand(1, 90), // 跳跃
  15. "agility" => rand(1, 90), // 敏捷
  16. "luck" => rand(20, 90), // 幸运
  17. "volition" => rand(10, 90), // 意志
  18. ];
  19. foreach ($horse as $value) {
  20. $horse['ability'] += $value;
  21. }
  22. $horseList[] = $horse;
  23. }
  24. return $horseList;
  25. }
  26. public function initEvent($stageNum) {
  27. $list = [];
  28. for ($num = $stageNum; $num >= 1; $num--) {
  29. $numList = [];
  30. for ($i = 0; $i < 9; $i++) {
  31. // $numList[] = rand(0, 9);
  32. $numList[] = rand(0, 9);
  33. }
  34. $list[] = $numList;
  35. }
  36. return $list;
  37. }
  38. public static function getBufferSpeed($weatherNum, $eventNum, $horse) {
  39. $speed = $horse['speed'];
  40. // 0 属于正常跑
  41. // 1 ~ 3 属于 石头,靠跳跃 0.3
  42. // 4 ~ 6 属于 泥坑,靠敏捷 0.3
  43. // 7 ~ 9 属于 Buffer,靠幸运 0.3
  44. switch ($eventNum) {
  45. case 0:
  46. case 1:
  47. case 2:
  48. $speed *= $horse['jump'] / 100;
  49. break;
  50. case 4:
  51. case 5:
  52. case 6:
  53. $speed *= $horse['agility'] / 100;
  54. break;
  55. case 7:
  56. case 8:
  57. $speed += $horse['luck'] + 10;
  58. break;
  59. }
  60. // 0、1 属于 逆风、下雪,靠意志 0.2
  61. if ($weatherNum == 0 || $weatherNum == 1) {
  62. $speed *= $horse['volition'] / 100;
  63. }
  64. $speed = max($speed, 10);
  65. return $speed;
  66. }
  67. public static function getWeatherStr($weatherNum) {
  68. if ($weatherNum == 0) {
  69. return 'weather:wind, ';
  70. } else if ($weatherNum == 1) {
  71. return 'weather:snow, ';
  72. } else {
  73. return '';
  74. }
  75. }
  76. public static function getEventStr($eventNum) {
  77. switch ($eventNum) {
  78. case 0:
  79. case 1:
  80. case 2:
  81. return "event:石头, ";
  82. case 4:
  83. case 5:
  84. case 6:
  85. return "event:泥坑, ";
  86. case 7:
  87. case 8:
  88. return "event:加速, ";
  89. }
  90. return 'event:正常';
  91. }
  92. }