Exemplo n.º 1
0
        private void ShowCurrentCorrectResult(MasterMindGameTurn gameTurn)
        {
            var correctResult = new StringBuilder();

            string[] result = new string[gameTurn.NumberLength];
            foreach (var item in gameTurn.CurrentCorrectPlayResult)
            {
                var value = item.Split(',')[0];
                var pos   = Convert.ToInt32(item.Split(',')[1]);
                result[pos] = value;
            }
            foreach (var item in result)
            {
                if (string.IsNullOrEmpty(item))
                {
                    correctResult.Append(_incorrectMark);
                }
                else
                {
                    correctResult.Append(item);
                }
            }
            gameTurn.CurrentCorrectPlayResultDisplay =
                correctResult.ToString();
            gameTurn.CurrentCorrectPlayResultInfoDisplay
                = _codeMaker.GetHintDetail(correctResult.ToString().Replace(_incorrectMark, "0"),
                                           gameTurn.ThisTurnAnswer);
        }
Exemplo n.º 2
0
        public void Excute(MasterMindGameTurn gameTurn)
        {
            bool iscorrect = true;

            if (_answerElementPosition?.Count > 0)
            {
                foreach (var item in _answerElementPosition)
                {
                    if (!gameTurn.CurrentPlayResult.Contains(item))
                    {
                        iscorrect = false;
                    }
                    else
                    {
                        if (!gameTurn.CurrentCorrectPlayResult.Contains(item))
                        {
                            gameTurn.CurrentCorrectPlayResult.Add(item);
                        }
                    }
                }
            }

            gameTurn.IsGuessAllTheNumber = iscorrect;

            if ((gameTurn.CurrentTries == gameTurn.MaxTries) || iscorrect)
            {
                gameTurn.ChangeState(new EndState());
            }

            ShowCurrentCorrectResult(gameTurn);
        }
Exemplo n.º 3
0
        public void Enter(MasterMindGameTurn gameTurn)
        {
            _answerElementPosition = new List <string>();
            var answerArray = gameTurn.ThisTurnAnswer.ToList();

            for (var i = 0; i < answerArray.Count; i++)
            {
                var pos = string.Format("{0},{1}", answerArray[i], i);
                _answerElementPosition.Add(pos);
            }
        }
Exemplo n.º 4
0
 public void Exit(MasterMindGameTurn gameTurn)
 {
     gameTurn.IsGameOver                          = false;
     gameTurn.IsGameFail                          = false;
     gameTurn.IsGuessAllTheNumber                 = false;
     gameTurn.IsOverMaxTries                      = false;
     gameTurn.CurrentTries                        = 0;
     gameTurn.CurrentCorrectPlayResult            = new List <string>();
     gameTurn.CurrentCorrectPlayResultDisplay     = string.Empty;
     gameTurn.CurrentCorrectPlayResultInfoDisplay = string.Empty;
     gameTurn.CurrentPlayResult                   = new List <string>();
 }
Exemplo n.º 5
0
 public void Enter(MasterMindGameTurn gameTurn)
 {
     try
     {
         _logger.Debug("Start game");
         this._codeMaker = new AutoCodeMaker();
         gameTurn.CurrentCorrectPlayResult = new List <string>();
         gameTurn.ThisTurnAnswer           = _codeMaker.GetAnswer(gameTurn.NumberLength);
         gameTurn.ThisTurnHints            = _codeMaker.GetHintsDetail(_codeMaker.GetHints(gameTurn.NumberLength,
                                                                                           gameTurn.HintCapacity, gameTurn.ThisTurnAnswer), gameTurn.ThisTurnAnswer);
     }
     catch (Exception ex)
     {
         _logger.Error(ex.ToString());
     }
 }
Exemplo n.º 6
0
 public void Excute(MasterMindGameTurn gameTurn)
 {
     try
     {
         if (gameTurn.CurrentTries > gameTurn.MaxTries)
         {
             gameTurn.IsOverMaxTries = true;
             gameTurn.ChangeState(new EndState());
         }
         else
         {
             gameTurn.ChangeState(new GuessState());
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex.ToString());
     }
 }
Exemplo n.º 7
0
 public void Exit(MasterMindGameTurn gameTurn)
 {
     return;
 }
Exemplo n.º 8
0
 public void Enter(MasterMindGameTurn gameTurn)
 {
     _logger.Debug("User start to try this game.");
     gameTurn.CurrentTries++;
 }
Exemplo n.º 9
0
 public void Excute(MasterMindGameTurn gameTurn)
 {
     return;
 }