Example #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);
            }
        }
Example #2
0
        private void OnInputReceived(GameInputEventArgs gameInputEventArgs)
        {
            if (!AreCoordinatesValid(gameInputEventArgs))
            {
                return;
            }

            //Do scoring
            //Evaluate what is th score
            //If possible to move ?
            //Yes
            //Is score > 0
            //YES


            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;

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

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

            if (!myGameOver && myScore <= 0)
            {
                myDisplayAdapter.DisplayScore(0);
                myDisplayAdapter.DisplayMessage("Game Over, you lost!!!");
                myGameOver = true;

                base.Stop();
            }
        }