Ejemplo n.º 1
0
 private void MoveRobot(DirectionTypes directionType)
 {
     if (_puzzleReferee.CheckAction(_robotBrain.Position, directionType, ActionTypes.Move))
     {
         Point direction      = PuzzleReferee.ConvertToPoint(directionType);
         Point actionPosition = new Point(_robotBrain.Position.X + direction.X, _robotBrain.Position.Y + direction.Y);
         _robotBrain.Position = actionPosition;
     }
 }
Ejemplo n.º 2
0
        private void RobotBrain_ActionWanted(object sender, ActionWantedEventArgs e)
        {
            DirectionTypes actionDirection = e.Action.Direction;
            ActionTypes    actionType      = e.Action.Type;

            if (_puzzleReferee.CheckAction(_robotBrain.Position, actionDirection, actionType))
            {
                Point direction        = PuzzleReferee.ConvertToPoint(actionDirection);
                Point actionPosition   = new Point(_robotBrain.Position.X + direction.X, _robotBrain.Position.Y + direction.Y);
                int   stateChangeCount = 0;
                switch (actionType)
                {
                case ActionTypes.Move:
                    _robotBrain.Position = actionPosition;
                    break;

                case ActionTypes.MarkAsEmpty:
                    stateChangeCount = _puzzleBoard.SetState(actionPosition, PuzzleCellStateTypes.Empty).Count;
                    break;

                case ActionTypes.MarkAsFilled:
                    stateChangeCount = _puzzleBoard.SetState(actionPosition, PuzzleCellStateTypes.Filled).Count;
                    break;

                case ActionTypes.RemoveMarker:
                    stateChangeCount = _puzzleBoard.SetState(actionPosition, PuzzleCellStateTypes.NotMarked).Count;
                    break;
                }
                if (_puzzleBoard.IsWrong())
                {
                    _robotBrain.ActionFeedback -= 1000;
                }
                else if (_puzzleBoard.IsComplete())
                {
                    _robotBrain.ActionFeedback += 100;
                }
                else if (stateChangeCount > 0)
                {
                    _robotBrain.ActionFeedback += stateChangeCount;
                }
            }

            if (!_simulationRunsInBackground && _cbxAutoRefreshPlayground.Checked)
            {
                RefreshPlayGround();
                RecreateCells();
            }
        }
Ejemplo n.º 3
0
        private void BtnLoadPuzzle_Click(object sender, EventArgs e)
        {
            DialogLoadPuzzle loadDialog = new DialogLoadPuzzle();

            // ToDo: Replace static hard coded folder reference with relative path
            loadDialog.InitialDirectory = @"..\..\FillAPixRobot\Puzzles";
            if (loadDialog.ShowDialog() == DialogResult.OK)
            {
                _puzzleBoard = new PuzzleBoard(loadDialog.FileName);
                _robotBrain.Activate(new Point(0, 0), new Rectangle(new Point(0, 0), _puzzleBoard.Size));
                _puzzleReferee = new PuzzleReferee(_puzzleBoard);
            }
            _gbxRobot.Enabled           = _puzzleBoard != null;
            _btnRunInBackground.Enabled = _puzzleBoard != null;
            RefreshRobotSettings();
            RefreshPlayGround();
            RecreateCells();
        }
Ejemplo n.º 4
0
        private void DoStateAction(PuzzleCellStateTypes markerState)
        {
            if (_cbxDirectionTypes.SelectedIndex < 0)
            {
                return;
            }
            DirectionTypes directionType  = (DirectionTypes)_cbxDirectionTypes.SelectedItem;
            Point          direction      = PuzzleReferee.ConvertToPoint(directionType);
            Point          markerPosition = new Point(_robotBrain.Position.X + direction.X, _robotBrain.Position.Y + direction.Y);

            _puzzleBoard.SetState(markerPosition, markerState);

            if (_cbxAutoRefreshPlayground.Checked)
            {
                RefreshPlayGround();
                RecreateCells();
            }
        }