Пример #1
0
        private void ReadNextTurns()
        {
            NextTurns = new TurnBlocks[8];

            for (int i = 0; i < 8; i++)
            {
                string[] inputs = _console.ReadLine().Split(' ');

                var color = new TurnBlocks
                {
                    Top    = inputs[0][0],
                    Bottom = inputs[1][0]
                };

                NextTurns[i] = color;
            }
        }
Пример #2
0
 public IBoard Play(TurnBlocks turnBlocks, int column, int rotation)
 {
     return(this);
 }
Пример #3
0
        public IBoard Play(TurnBlocks turnBlocks, int column, int rotation)
        {
            if (!IsValidPlay(column, rotation))
            {
                return(new InvalidBoard());
            }

            int[] columnTops = new int[6];

            for (int i = 0; i < 6; i++)
            {
                columnTops[i] = -1;
            }

            for (int i = 0; i < 12; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    if (_blocks[i][j].BlockType == '.')
                    {
                        columnTops[j] = i;
                    }
                }
            }

            var newBoard = new Board(BoardData);

            if (rotation == 0)
            {
                if (columnTops[column] == -1)
                {
                    return(new InvalidBoard());
                }
                if (columnTops[column + 1] == -1)
                {
                    return(new InvalidBoard());
                }

                newBoard._blocks[columnTops[column]][column].BlockType         = turnBlocks.Top;
                newBoard._blocks[columnTops[column + 1]][column + 1].BlockType = turnBlocks.Bottom;
            }

            if (rotation == 1)
            {
                var row = columnTops[column];
                if (row <= 0)
                {
                    return(new InvalidBoard());
                }

                newBoard._blocks[row][column].BlockType     = turnBlocks.Top;
                newBoard._blocks[row - 1][column].BlockType = turnBlocks.Bottom;
            }

            if (rotation == 2)
            {
                if (columnTops[column] == -1)
                {
                    return(new InvalidBoard());
                }
                if (columnTops[column - 1] == -1)
                {
                    return(new InvalidBoard());
                }

                newBoard._blocks[columnTops[column]][column].BlockType         = turnBlocks.Top;
                newBoard._blocks[columnTops[column - 1]][column - 1].BlockType = turnBlocks.Bottom;
            }

            if (rotation == 3)
            {
                var row = columnTops[column];
                if (row <= 0)
                {
                    return(new InvalidBoard());
                }

                newBoard._blocks[row][column].BlockType     = turnBlocks.Bottom;
                newBoard._blocks[row - 1][column].BlockType = turnBlocks.Top;
            }

            return(newBoard);
        }