Exemplo n.º 1
0
        protected Figure ExecuteCommand(Commander.CommandType command, Figure figure, PlayingField playingField)
        {
            switch (command)
            {
                case Commander.CommandType.A:
                    figure = figure.ShiftXLeft();
                    break;
                case Commander.CommandType.D:
                    figure = figure.ShiftXRight();
                    break;
                case Commander.CommandType.S:
                    figure = figure.ShiftYDown();
                    break;
                case Commander.CommandType.Q:
                    figure = figure.RotateCounterClockwise();
                    break;
                case Commander.CommandType.E:
                    figure = figure.RotateClockwise();
                    break;
                case Commander.CommandType.P:
                    var fieldOut = playingField.Field.Select(row => row.ToArray()).ToArray();
                    foreach (var cell in figure.Cells)
                        fieldOut[cell.ProjectionY][cell.ProjectionX] = PlayingField.StateCoord.CurrentFigure;

                    foreach (var row in fieldOut)
                    {
                        foreach (var cell in row)
                            Console.Write
                            (
                                cell == PlayingField.StateCoord.Free ? '.' :
                                cell == PlayingField.StateCoord.Busy ? '#' : '*'
                            );
                        Console.Write(Environment.NewLine);
                    }
                    break;
            }

            if (СheckCollision(figure, playingField))
                throw new CollisionException();

            return figure;
        }
Exemplo n.º 2
0
 public PlayingEngine(PlayingField playingField, Figure[] figurs, Commander commander)
 {
     _playingField = playingField;
     _commander = commander;
     _figurs = figurs.ToImmutableArray();
 }