public static void SkipEmptyTiles(EngineParserState state)
 {
     while (!state.Position.IsFinished && state[state.Position].Type == EngineGlyphType.Nothing)
     {
         state.Position.MoveForward();
     }
 }
        public static void PerformOperation(EngineParserState state)
        {
            switch (state.LastOperator)
            {
            case EngineOperatorType.NoOperator:
                state.LastNumberGroup = state.CurrentNumberGroup;
                break;

            case EngineOperatorType.Addition:
                state.LastNumberGroup += state.CurrentNumberGroup;
                break;

            case EngineOperatorType.Subtraction:
                state.LastNumberGroup -= state.CurrentNumberGroup;
                break;

            case EngineOperatorType.Multiplication:
                state.LastNumberGroup *= state.CurrentNumberGroup;
                break;

            case EngineOperatorType.Division:
                state.LastNumberGroup = (int)Math.Floor((double)state.LastNumberGroup / state.CurrentNumberGroup);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            state.CurrentNumberGroup = 0;
            state.LastOperator       = EngineOperatorType.NoOperator;
        }
        public static EngineTile Raycast(EngineParserState state, ParserPosition startPosition, EngineDirection direction)
        {
            var currentPosition = startPosition.Position;

            currentPosition = new Point(currentPosition.X + direction.X, currentPosition.Y + direction.Y);
            while (state.IsValidPosition(currentPosition))
            {
                var tile = state[currentPosition];

                if (tile.Type != EngineGlyphType.Nothing)
                {
                    return(tile);
                }

                currentPosition = new Point(currentPosition.X + direction.X, currentPosition.Y + direction.Y);
            }

            return(null);
        }
Exemplo n.º 4
0
 public EngineParser(EngineTile[,] tiles)
 {
     Tiles        = CloneTiles(tiles);
     _state       = new EngineParserState(this, Tiles);
     _tileParsers = new Dictionary <EngineGlyphType, Action <EngineParserState, EngineTile> > {
         { EngineGlyphType.Nothing, StateParser_Nothing.ParseTile },
         { EngineGlyphType.ActionMoveN, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveNE, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveE, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveSE, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveS, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveSW, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveW, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionMoveNW, StateParser_Action.ParseTile },
         { EngineGlyphType.ActionSpecial, StateParser_Action.ParseTile },
         { EngineGlyphType.NumeralOne, StateParser_Numeral.ParseTile },
         { EngineGlyphType.NumeralTwo, StateParser_Numeral.ParseTile },
         { EngineGlyphType.NumeralFour, StateParser_Numeral.ParseTile },
         { EngineGlyphType.NumeralEight, StateParser_Numeral.ParseTile },
         { EngineGlyphType.OperationMultiplier, StateParser_Multiply.ParseTile },
         { EngineGlyphType.OperationSubtract, StateParser_Subtract.ParseTile },
         { EngineGlyphType.ModifierInvert, StateParser_Invert.ParseTile },
         { EngineGlyphType.ModifierIgnore, StateParser_Ignore.ParseTile },
         { EngineGlyphType.SpecialCameleonN, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonNE, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonE, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonSE, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonS, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonSW, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonW, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.SpecialCameleonNW, StateParser_Cameleon.ParseTile },
         { EngineGlyphType.Bomb, StateParser_Bomb.ParseTile },
         { EngineGlyphType.SlicerStart, StateParser_Slicer.ParseTile },
         { EngineGlyphType.SlicerEnd, StateParser_Slicer.ParseTile }
     };
 }