Exemple #1
0
 public void CheckIsDead(PlayerContext player)
 {
     if (FeatureEngine.Instance.CheckIsDead(player))
     {
         player.state = PlayerStateType.Dead;
     }
 }
 public CarManager FindCarManager(PlayerContext player)
 {
     CarManager result = null;
     if (_cars != null && _cars.ContainsKey(player.name))
     {
         result = _cars[player.name];
     }
     return result;
 }
Exemple #3
0
 public void BuildCar(PlayerContext player, Vector3 startPosition, Vector3 nextPosition)
 {
     _player = player;
     _spriteRenderer.color = _player.GetColor();
     var vectorRotation = this.ComputeRotation(startPosition, nextPosition);
     var rotation = new Quaternion(0, 0, 0, 1);
     rotation.eulerAngles = vectorRotation;
     this.transform.localRotation = rotation;
 }
Exemple #4
0
 public bool CheckIsDead(PlayerContext player)
 {
     bool result = false;
     if (player.features.tire < 0 || player.features.brake < 0 || player.features.body == 0 || player.features.motor == 0 || player.features.handling == 0)
     {
         result = true;
     }
     return result;
 }
Exemple #5
0
 public void UpdateDe(PlayerContext player)
 {
     if (player.state == PlayerStateType.RollDice)
     {
         this.LoadDeChoise(player);
     }
     else
     {
         this.ViewPlayer(player);
     }
 }
Exemple #6
0
 public bool ApplyBrokenEngine(PlayerContext player)
 {
     bool result = false;
     var blackDe = RaceEngine.Instance.BlackDice();
     if (blackDe <= 4)
     {
         player.features.motor = player.features.motor - 1;
         this.DisplayFeature(player);
         result = true;
     }
     return result;
 }
Exemple #7
0
 public bool ApplyClash(PlayerContext player)
 {
     bool result = false;
     var de = RaceEngine.Instance.BlackDice();
     if (de == 1)
     {
         player.features.handling = player.features.handling - 1;
         this.DisplayFeature(player);
         result = true;
     }
     return result;
 }
Exemple #8
0
 public void ApplyDangerousRoute(PlayerContext player, RouteResult route)
 {
     bool hasChange = false;
     foreach (var current in route.route.Where(c => c.isDangerous))
     {
         var de = RaceEngine.Instance.BlackDice();
         if (de <= 4)
         {
             player.features.handling = player.features.handling - 1;
             hasChange = true;
         }
     }
     if (hasChange)
     {
         this.DisplayFeature(player);
     }
 }
 public void SelectedPlayer(PlayerContext player)
 {
     foreach (var current in _players)
     {
         var button = current.Value.GetComponent<Button>();
         if (current.Key == player.name)
         {
             current.Value.localPosition = new Vector3(current.Value.localPosition.x, 2f, 0);
             button.colors = this.CreateColorBlock(new Color(1f, 1f, 1f, 1f));
         }
         else
         {
             current.Value.localPosition = new Vector3(current.Value.localPosition.x, 0, 0);
             button.colors = this.CreateColorBlock(new Color(200f / 255f, 200f / 255f, 200f / 255f, 128f / 255f));
         }
     }
 }
Exemple #10
0
        private void LoadDeChoise(PlayerContext player)
        {
            int min;
            int max;
            FeatureEngine.Instance.ComputeMinMaxGearbox(player, out min, out max);
            var gear = PlayerEngine.Instance.GetTurnHistories(player).Last().gear;
            var indexMin = min - 1;
            var indexMax = max - 1;

            DeManager selectedDe = null;
            var currentGear = gear != 0 ? gear : 1;
            for (int i = 0; i < 6; i++)
            {
                var currentDe = buttonDes[i];
                if (indexMin <= i && i <= indexMax)
                {
                    if (currentDe.gear == currentGear)
                    {
                        selectedDe = currentDe;
                    }
                    currentDe.LoadDe(true, gear, player.state == PlayerStateType.RollDice);
                }
                else
                {
                    currentDe.LoadDe(false, gear, player.state == PlayerStateType.RollDice);
                }
            }

            if (selectedDe != null)
            {
                RaceEngine.Instance.OnViewGear(selectedDe.gear, selectedDe.min, selectedDe.max);
            }

            isCancel = false;
            imageButtonPlay.color = playColor;
            textButtonPlay.UpdateResource("ButtonPlay");
            buttonPlay.interactable = true;
        }
        public void LoadPlayer(PlayerContext player, int index)
        {
            if (index == 0)
            {
                trophy.color = Config.TrophyColor.gold;
            }
            else if (index == 1)
            {
                trophy.color = Config.TrophyColor.silver;
            }
            else if (index == 2)
            {
                trophy.color = Config.TrophyColor.bronze;
            }
            position.text = (index + 1).ToString();

            if (index < 3)
            {
                position.gameObject.SetActive(false);
                trophy.gameObject.SetActive(true);
            }
            else
            {
                position.gameObject.SetActive(true);
                trophy.gameObject.SetActive(false);
            }
            playerImg.color = player.GetColor();
            name.text = player.name;
            best.text = player.turnHistories.Max(t => t.paths.SelectMany(p => p.Skip(1)).Count()).ToString();
            if (player.state == PlayerStateType.Finish)
            {
                turn.text = player.turnHistories.Skip(1).Count().ToString();
            }
            else
            {
                turn.text = ResourceEngine.Instance.GetResource("EndGameNA");
            }
        }
        public void LoadPlayer(PlayerContext player, int index)
        {
            _player = player;
            numberText.text = string.Format("{0}.", index + 1);
            nameText.text = player.name;
            playerImage.color = player.GetColor();
            if (player.qualification != null && player.qualification.state == QualificationStateType.Completed)
            {
                startQuanlification.gameObject.SetActive(false);
                resultContainer.gameObject.SetActive(true);
                turnText.text = (player.qualification.turnHistories.Count - 1).ToString();
                var duration = player.qualification.endDate - player.qualification.startDate;
                int totalMin = Mathf.FloorToInt((float)duration.TotalMinutes);
                durationText.text = string.Format(ResourceEngine.Instance.GetResource("QualificationDurationMinute"), totalMin);
                penaltyText.text = player.qualification.outOfBend.ToString();
                totalText.text = player.qualification.total.ToString();
            }
            else
            {
                startQuanlification.gameObject.SetActive(true);

                var imageStartQuanlification = startQuanlification.GetComponent<Image>();
                var textStartQuanlification = startQuanlification.GetComponentInChildren<Text>();
                if (player.qualification == null || player.qualification.state == QualificationStateType.NoPlay)
                {
                    imageStartQuanlification.color = startColor;
                    textStartQuanlification.text = ResourceEngine.Instance.GetResource("StartQualificationButton");
                }
                else
                {
                    imageStartQuanlification.color = continueColor;
                    textStartQuanlification.text = ResourceEngine.Instance.GetResource("ContinueQualificationButton");
                }

                resultContainer.gameObject.SetActive(false);
            }
        }
Exemple #13
0
        public void ComputeMinMaxGearbox(PlayerContext player, out int min, out int max)
        {
            var gear = PlayerEngine.Instance.GetTurnHistories(player).Last().gear;
            if (ContextEngine.Instance.gameContext.state == GameStateType.Race)
            {
                min = gear - 1;
                if (player.features.gearbox > 0 && player.features.brake > 0 && player.features.motor > 0)
                {
                    min -= 3;
                }
                else if (player.features.gearbox > 0 && player.features.brake > 0)
                {
                    min -= 2;
                }
                else if (player.features.gearbox > 0)
                {
                    min -= 1;
                }
                max = gear + 1;
            }
            else
            {
                min = gear - 1 - 3;
                max = gear + 1;
            }

            if (min < 1)
            {
                min = 1;
            }
            if (max > 6)
            {
                max = 6;
            }
        }
Exemple #14
0
 public void ApplyRoute(PlayerContext player, RouteResult route)
 {
     player.features = this.ComputeRoute(player, route);
     player.qualification.outOfBend = player.features.outOfBend;
     this.DisplayFeature(player);
 }
Exemple #15
0
        public IndexDataSource GetCurrentIndex(PlayerContext player)
        {
            IndexDataSource result = null;
            HistoryContext history = null;
            if (player.currentTurn != null && player.currentTurn.paths.Any())
            {
                history = player.currentTurn;
            }
            else
            {
                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    if (player.qualification != null)
                    {
                        history = player.qualification.turnHistories.Last();
                    }
                }
                else
                {
                    history = player.turnHistories.Last();
                }
            }

            if (history != null && history.paths.Any())
            {
                result = history.paths.Last().Last();
            }

            return result;
        }
Exemple #16
0
 public List<HistoryContext> GetTurnHistories(PlayerContext player)
 {
     List<HistoryContext> result = null;
     if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
     {
         if (player.qualification != null)
         {
             result = player.qualification.turnHistories;
         }
     }
     else
     {
         result = player.turnHistories;
     }
     return result;
 }
Exemple #17
0
 public void ApplyDemotion(PlayerContext player, int gear)
 {
     player.features = this.ComputeDemotion(player, gear);
     this.DisplayFeature(player);
 }
Exemple #18
0
 private PlayerContext FindNextPlayer(PlayerContext player)
 {
     PlayerContext result = null;
     int currentIndex = int.MaxValue;
     for (int i = 0; i < ContextEngine.Instance.gameContext.players.Count; i++)
     {
         var current = ContextEngine.Instance.gameContext.players[i];
         if (current == player)
         {
             currentIndex = i;
         }
         else if (current.IsPlayable() && currentIndex < i)
         {
             result = current;
             break;
         }
     }
     return result;
 }
Exemple #19
0
        public void LoadPlayers(List<PlayerContext> players)
        {
            var starts = BoardEngine.Instance.GetStartCase();

            for (int i = 0; i < players.Count; i++)
            {
                var player = players[i];
                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    if (player.qualification == null)
                    {
                        player.qualification = new QualificationPlayerContext();
                        player.qualification.state = QualificationStateType.NoPlay;
                        player.state = PlayerStateType.Waiting;
                    }
                    if (player.qualification.turnHistories.Count == 0)
                    {
                        var startCase = starts[0];
                        var history = new HistoryContext();
                        history.paths = new List<List<IndexDataSource>>() { new List<IndexDataSource>() { startCase.itemDataSource.index } };
                        player.qualification.turnHistories.Add(history);
                        player.qualification.startDate = DateTime.UtcNow;
                        player.qualification.state = QualificationStateType.Playing;
                    }
                }
                else
                {
                    if (!player.turnHistories.Any())
                    {
                        var startCase = starts[i];
                        var history = new HistoryContext();
                        history.paths = new List<List<IndexDataSource>>() { new List<IndexDataSource>() { startCase.itemDataSource.index } };
                        player.turnHistories.Add(history);
                        player.state = PlayerStateType.Waiting;
                        player.lap = -1;
                    }
                }
            }

            if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
            {
                _currentPlayer = players.First();
                if (_currentPlayer.state == PlayerStateType.Waiting)
                {
                    _currentPlayer.currentTurn = new HistoryContext();
                    _currentPlayer.state = PlayerStateType.RollDice;
                }
            }
            else
            {
                _currentPlayer = players.FirstOrDefault(p => p.IsPlayable() && p.state != PlayerStateType.Waiting);
            }

            carLayoutManager.BuildCars(players);
            playerPanelManager.BuildPlayers(players);

            if (_currentPlayer == null)
            {
                this.NextPlayer();
            }
            else
            {
                this.SelectedPlayerView(_currentPlayer);
            }
        }
Exemple #20
0
 private FeatureContext ComputeDemotion(PlayerContext player, int targetGear)
 {
     FeatureContext result = player.features.Clone();
     if (ContextEngine.Instance.gameContext.state == GameStateType.Race)
     {
         var previousGear = PlayerEngine.Instance.GetTurnHistories(player).Last().gear;
         var gearDif = previousGear - targetGear;
         if (gearDif >= 4)
         {
             result.gearbox = player.features.gearbox - 1;
             result.brake = player.features.brake - 1;
             result.motor = player.features.motor - 1;
         }
         else if (gearDif == 3)
         {
             result.gearbox = player.features.gearbox - 1;
             result.brake = player.features.brake - 1;
         }
         else if (gearDif == 2)
         {
             result.gearbox = player.features.gearbox - 1;
         }
     }
     return result;
 }
Exemple #21
0
        public void NextPlayer()
        {
            PlayerContext nextPlayer = null;
            if (_currentPlayer != null)
            {
                var history = this.GetTurnHistories(_currentPlayer).Last();
                var fullPath = history.paths.SelectMany(p => p.Select(i => i)).ToList();
                if (history.outOfBend > 0 && _currentPlayer.features.tire == 0 && fullPath.Count > 1)
                {
                    var carManager = carLayoutManager.FindCarManager(_currentPlayer);
                    var previousCase = BoardEngine.Instance.GetCase(fullPath[fullPath.Count - 2]);
                    carManager.ReturnCar(previousCase.transform.position);
                    history.gear = 0;
                }
                nextPlayer = this.FindNextPlayer(_currentPlayer);
            }

            if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
            {
                _currentPlayer.currentTurn = new HistoryContext();
                _currentPlayer.state = PlayerStateType.RollDice;
                this.SelectedPlayerView(_currentPlayer);
            }
            else
            {
                var playablePlayer = ContextEngine.Instance.gameContext.players.Count(p => p.IsPlayable());
                if (playablePlayer > 1)
                {
                    if (nextPlayer == null)
                    {
                        ContextEngine.Instance.gameContext.players = this.OrderedPlayerTurn();
                        var test = ContextEngine.Instance.gameContext.players.Count(p => p.IsPlayable());
                        if (ContextEngine.Instance.gameContext.players.Count(p => p.IsPlayable()) > 1)
                        {
                            ContextEngine.Instance.gameContext.turn++;
                            nextPlayer = ContextEngine.Instance.gameContext.players.FirstOrDefault(p => p.IsPlayable());
                        }
                    }

                    nextPlayer.currentTurn = new HistoryContext();
                    nextPlayer.state = PlayerStateType.RollDice;
                    _currentPlayer = nextPlayer;
                    this.SelectedPlayerView(_currentPlayer);
                }
                else
                {
                    RaceEngine.Instance.OnEndGame();
                }
            }
        }
Exemple #22
0
 public void WarningDemotion(PlayerContext player, int gear)
 {
     this.DisplayFeature(player);
     var features = this.ComputeDemotion(player, gear);
     featurePanelManager.WarningFeature(ContextEngine.Instance.gameContext.state, player.features, features);
 }
Exemple #23
0
 public void WarningRoute(PlayerContext player, RouteResult route)
 {
     this.DisplayFeature(player);
     var features = this.ComputeRoute(player, route);
     featurePanelManager.WarningFeature(ContextEngine.Instance.gameContext.state, player.features, features);
 }
Exemple #24
0
 public void DisplayFeature(PlayerContext player)
 {
     var currentCase = BoardEngine.Instance.GetCase(PlayerEngine.Instance.GetCurrentIndex(player));
     var currentStop = 0;
     var maxStop = 0;
     if (currentCase.bendDataSource != null)
     {
         maxStop = currentCase.bendDataSource.stop;
         if (currentCase.bendDataSource.name == player.lastBend)
         {
             currentStop = player.stopBend;
         }
     }
     featurePanelManager.UpdateFeature(ContextEngine.Instance.gameContext.state, player.features, currentStop, maxStop);
 }
Exemple #25
0
 public void PlayerDead(PlayerContext player)
 {
     if (player.state == PlayerStateType.Dead)
     {
         var carManager = carLayoutManager.FindCarManager(player);
         carManager.Dead();
         var target = BoardEngine.Instance.GetCase(this.GetCurrentIndex(player));
         RaceEngine.Instance.AddDangerousCase(target);
     }
 }
Exemple #26
0
        public void SelectedPlayerView(PlayerContext playerContext)
        {
            RaceEngine.Instance.CleanCurrent();
            if (_previousViewPlayer != null)
            {
                var previousTurnHistories = this.GetTurnHistories(_previousViewPlayer);
                var previousHistory = previousTurnHistories.Last();
                if (previousHistory.paths.Any())
                {
                    BoardEngine.Instance.CleanRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), _previousViewPlayer.GetColor());
                }
            }
            var turnHistories = this.GetTurnHistories(playerContext);
            if (_previousViewPlayer == null || _previousViewPlayer.name != playerContext.name)
            {
                Vector3 previousPoint;
                var car = carLayoutManager.FindCarManager(playerContext);
                if (turnHistories.Any())
                {
                    CaseManager previousCase = BoardEngine.Instance.GetCase(turnHistories.Last().paths.First().First());
                    previousPoint = previousCase.transform.position;
                }
                else
                {
                    previousPoint = car.transform.position;
                }
                cameraManager.UpdateZoomPosition(car.transform.position, previousPoint);
            }

            _previousViewPlayer = playerContext;
            playerPanelManager.SelectedPlayer(playerContext);
            FeatureEngine.Instance.DisplayFeature(playerContext);
            dePanelManager.UpdateDe(playerContext);
            if (playerContext.state == PlayerStateType.RollDice)
            {
                int gear = turnHistories.Last().gear;
                if (gear <= 0)
                {
                    gear = 1;
                }
                var de = dePanelManager.buttonDes[gear - 1];
                RaceEngine.Instance.OnViewGear(gear, de.min, de.max);
            }
            else if (playerContext.state == PlayerStateType.ChoseRoute)
            {
                var gear = playerContext.currentTurn.gear;
                RaceEngine.Instance.OnViewRollDice(gear, playerContext.currentTurn.de);
            }
            else if (playerContext.state == PlayerStateType.Aspiration)
            {
                RaceEngine.Instance.OnAspiration(true);
            }
            else if (playerContext.state == PlayerStateType.StandOut)
            {
                RaceEngine.Instance.OnStandOut();
            }

            if (turnHistories.Count > 1)
            {
                var previousHistory = turnHistories.Last();
                if (previousHistory.paths.Count > 0)
                {
                    BoardEngine.Instance.DrawRoute(previousHistory.paths.SelectMany(p => p.Select(i => BoardEngine.Instance.GetCase(i))).ToList(), playerContext.GetColor());
                }
            }
        }
Exemple #27
0
        public SearchRouteResult FindRoutes(PlayerContext player, int min, int max)
        {
            SearchRouteResult result = new SearchRouteResult();
            var context = new SearchRouteContext();
            context.bendName = player.lastBend;
            context.bendStop = player.stopBend;
            context.min = min;
            context.max = max;
            context.tire = player.features.tire;
            context.playerIndex = player.index;
            context.isLastLap = ContextEngine.Instance.gameContext.totalLap - player.lap <= 1;
            List<CaseManager> baseRoute = new List<CaseManager>();
            var currentIndex = PlayerEngine.Instance.GetCurrentIndex(player);
            baseRoute.Add(boardManager.FindCaseManager(currentIndex));
            this.SearchRoutes(result, context, baseRoute, 0, 0, 0, 0);

            return result;
        }
Exemple #28
0
        private FeatureContext ComputeRoute(PlayerContext player, RouteResult route)
        {
            bool isEnd = false;
            var hasFinishCase = BoardEngine.Instance.ContainsFinishCase(route.route.Select(r => r.itemDataSource.index));
            if (hasFinishCase)
            {
                if (ContextEngine.Instance.gameContext.state == GameStateType.Qualification)
                {
                    isEnd = true;
                }
                else if (player.lap + 1 == ContextEngine.Instance.gameContext.totalLap)
                {
                    isEnd = true;
                }
            }

            var features = player.features;
            if (!isEnd)
            {
                features = this.ComputeOutOfBend(player.features, route.nbOutOfBend);
                var nbCase = route.route.Count - 1;
                var de = 0;
                if (player.state == PlayerStateType.Aspiration)
                {
                    de = 3;
                }
                else if (player.state == PlayerStateType.StandOut)
                {
                    de = nbCase;
                }
                else
                {
                    if (player.currentTurn != null)
                    {
                        de = player.currentTurn.de;
                    }
                    else
                    {
                        de = PlayerEngine.Instance.GetTurnHistories(player).Last().de;
                    }
                }
                features = this.ComputeUseBrake(features, de, route.isStandWay, nbCase);
            }
            return features;
        }
Exemple #29
0
 public void ComputeMinMaxUseBrake(PlayerContext player, int de, out int min, out int max)
 {
     if (player.state == PlayerStateType.ChoseRoute && ContextEngine.Instance.gameContext.state == GameStateType.Race)
     {
         if (player.features.brake >= 3)
         {
             if (player.features.tire >= 3)
             {
                 min = de - 6;
             }
             else if (player.features.tire == 2)
             {
                 min = de - 5;
             }
             else if (player.features.tire == 1)
             {
                 min = de - 4;
             }
             else
             {
                 min = de - 3;
             }
         }
         else if (player.features.brake == 2)
         {
             min = de - 2;
         }
         else if (player.features.brake == 1)
         {
             min = de - 1;
         }
         else
         {
             min = de;
         }
         if (min < 1)
         {
             min = 1;
         }
         max = de;
     }
     else
     {
         min = de;
         max = de;
     }
 }
Exemple #30
0
        private void ViewPlayer(PlayerContext player)
        {
            int gear = 0;
            if (player.state == PlayerStateType.Waiting || !player.IsPlayable())
            {
                gear = PlayerEngine.Instance.GetTurnHistories(player).Last().gear;
            }
            else
            {
                gear = player.currentTurn.gear;
            }
            for (int i = 0; i < 6; i++)
            {
                var currentDe = buttonDes[i];
                if (gear == i + 1)
                {
                    int de = 0;
                    if (player.state == PlayerStateType.Waiting || !player.IsPlayable())
                    {
                        de = PlayerEngine.Instance.GetTurnHistories(player).Last().de;
                    }
                    else
                    {
                        de = player.currentTurn.de;
                    }
                    currentDe.LoadDe(true, gear, player.state == PlayerStateType.RollDice, de);
                }
                else
                {
                    currentDe.LoadDe(false, gear, player.state == PlayerStateType.RollDice);
                }
                currentDe.SelectGear(gear);
            }

            if (player.state == PlayerStateType.Aspiration)
            {
                isCancel = true;
                imageButtonPlay.color = cancelColor;
                textButtonPlay.UpdateResource("ButtonCancel");
                buttonPlay.interactable = true;
            }
            else
            {
                isCancel = false;
                imageButtonPlay.color = playColor;
                textButtonPlay.UpdateResource("ButtonPlay");
                buttonPlay.interactable = false;
            }
        }