<?php
/**
 * Created by IntelliJ IDEA.
 * User: solu
 * Date: 2019/3/1
 * Time: 5:03 PM
 */

class Game {

    public function initHorse($horseNum) {
        $horseList = [];
        for ($i = 0; $i < $horseNum; $i++) {
            $horse = [
                "speed" => rand(20, 90),    // 速度
                "jump" => rand(1, 90),      // 跳跃
                "agility" => rand(1, 90),   // 敏捷
                "luck" => rand(20, 90),     // 幸运
                "volition" => rand(10, 90), // 意志
            ];

            foreach ($horse as $value) {
                $horse['ability'] += $value;
            }

            $horseList[] = $horse;
        }

        return $horseList;
    }

    public function initEvent($stageNum) {
        $list = [];
        for ($num = $stageNum; $num >= 1; $num--) {
            $numList = [];
            for ($i = 0; $i < 9; $i++) {
//            $numList[] = rand(0, 9);
                $numList[] = rand(0, 9);
            }

            $list[] = $numList;
        }

        return $list;
    }


    public static  function getBufferSpeed($weatherNum, $eventNum, $horse) {
        $speed = $horse['speed'];

        // 0 属于正常跑
        // 1 ~ 3 属于 石头，靠跳跃 0.3
        // 4 ~ 6 属于 泥坑，靠敏捷 0.3
        // 7 ~ 9 属于 Buffer，靠幸运 0.3
        switch ($eventNum) {
            case 0:
            case 1:
            case 2:
                $speed *= $horse['jump'] / 100;
                break;
            case 4:
            case 5:
            case 6:
                $speed *= $horse['agility'] / 100;
                break;
            case 7:
            case 8:
                $speed += $horse['luck'] + 10;
                break;
        }

        // 0、1 属于 逆风、下雪，靠意志 0.2
        if ($weatherNum == 0 || $weatherNum == 1) {
            $speed *= $horse['volition'] / 100;
        }

        $speed = max($speed, 10);
        return $speed;
    }
    public static function getWeatherStr($weatherNum) {
        if ($weatherNum == 0) {
            return 'weather:wind, ';
        } else if ($weatherNum == 1) {
            return 'weather:snow, ';
        } else {
            return '';
        }
    }

    public static function getEventStr($eventNum) {
        switch ($eventNum) {
            case 0:
            case 1:
            case 2:
                return "event:石头, ";
            case 4:
            case 5:
            case 6:
                return "event:泥坑, ";
            case 7:
            case 8:
                return "event:加速, ";
        }

        return 'event:正常';
    }
}