Exemple #1
0
        private void OnInputReceived(GameInputEventArgs gameInputEventArgs)
        {
            if (!AreCoordinatesValid(gameInputEventArgs))
            {
                return;
            }

            MoveEvaluationResult result = myScoreEvaluator.EvaluateScore(new ScoreEvaluationContext
            {
                CurrentColumn = myCurrentColumn,
                CurrentRow    = myCurrentRow,
                CurrentScore  = myScore,
                FieldMap      = myFieldMap,
                NextColumn    = myNextColumn,
                NextRow       = myNextRow,
                RouteMap      = myRouteMap,
            });

            if (result.IsMovePossible)
            {
                myScore = result.EvaluatedScore;

                myFieldMap[myCurrentRow][myCurrentColumn].IsActive = false;

                //After evaluation and scoring update the coordinates and display
                myCurrentColumn = myNextColumn;
                myCurrentRow    = myNextRow;

                myFieldMap[myCurrentRow][myCurrentColumn].IsActive = true;

                myDisplayAdapter.DisplayScore(myScore);

                myRouteMap.Steps.Add(new RouteMapEntry
                {
                    Column    = myCurrentColumn,
                    Row       = myCurrentRow,
                    MapEntity = myFieldMap[myCurrentRow][myCurrentColumn],
                    Score     = myScore
                });
            }

            if (result.IsGameWon)
            {
                myDisplayAdapter.DisplayScore(result.EvaluatedScore);
                myDisplayAdapter.DisplayMessage("You won!!");
                myGameOver = true;
                myGame.Reset();
                myKeyPressCommand.EnableEvents(false);
                return;
            }

            if (!myGameOver && myScore <= 0)
            {
                myDisplayAdapter.DisplayScore(0);
                myDisplayAdapter.DisplayMessage("Game Over, you lost!!!");
                myGameOver = true;
                myGame.Reset();
                myKeyPressCommand.EnableEvents(false);
            }
        }
Exemple #2
0
        private bool AreCoordinatesValid(GameInputEventArgs gameInputEventArgs)
        {
            myNextColumn = myCurrentColumn;
            myNextRow    = myCurrentRow;

            switch (gameInputEventArgs.Input)
            {
            case Key.Left:
                if (myCurrentColumn == 0)
                {
                    return(false);
                }
                else
                {
                    myNextColumn = myCurrentColumn - 1;
                    return(true);
                }
                break;

            case Key.Right:
                if (myCurrentColumn == myColumnsCount - 1)
                {
                    return(false);
                }
                else
                {
                    myNextColumn = myCurrentColumn + 1;
                    return(true);
                }
                break;

            case Key.Up:
                if (myCurrentRow == 0)
                {
                    return(false);
                }
                else
                {
                    myNextRow = myCurrentRow - 1;
                    return(true);
                }
                break;

            case Key.Down:
                if (myCurrentRow == myRowsCount - 1)
                {
                    return(false);
                }
                else
                {
                    myNextRow = myCurrentRow + 1;
                    return(true);
                }
                break;
            }
            return(false);
        }