Esempio n. 1
0
        static bool DoesPieceFit(sbyte posX, sbyte posY, ref short rotation)
        {
            for (byte x = 0; x < Tetromino.LENGTH; ++x)
            {
                for (byte y = 0; y < Tetromino.LENGTH; ++y)
                {
                    var pieceIndex  = Tetromino.GetIndexByRotation(x, y, ref rotation);
                    var fieldIndexX = posX + x;
                    var fieldIndexY = posY + y;

                    if (fieldIndexY >= 0 && fieldIndexY < field.Height && fieldIndexX >= 0 && fieldIndexX < field.Width)
                    {
                        var fieldValue = field.GetGlyph((ushort)fieldIndexX, (ushort)fieldIndexY);

                        if (fieldValue != EMPTY && piece.Type[pieceIndex] != ' ')
                        {
                            return(false);
                        }
                    }

                    if (piece.Type[pieceIndex] != ' ' && (fieldIndexX >= field.Width || fieldIndexX < 0))
                    {
                        return(false);
                    }

                    if (piece.Type[pieceIndex] != ' ' && fieldIndexY >= field.Height)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        static void DrawNextPiece()
        {
            byte posX = NEXT_POS_X + 1, posY = NEXT_POS_Y + 1;
            var  nextTetrad = new Tetromino(nextPiece);

            for (byte x = 0; x < Tetromino.LENGTH; ++x)
            {
                for (byte y = 0; y < Tetromino.LENGTH; ++y)
                {
                    Painting.brush = nextTetrad.Type[Tetromino.GetIndexByRotation(x, y, ref piece.rotation)];
                    Painting.DrawCell((short)(posX + x), (short)(posY + y), nextTetrad.Colour);
                }
            }
        }
Esempio n. 3
0
        static void LockPiece(ref Tetromino piece, ComplexConsoleImage field)
        {
            for (byte x = 0; x < Tetromino.LENGTH; ++x)
            {
                for (byte y = 0; y < Tetromino.LENGTH; ++y)
                {
                    var c = piece.Type[Tetromino.GetIndexByRotation(x, y, ref piece.rotation)];

                    if (c != ' ')
                    {
                        field[(ushort)(piece.x + x), (ushort)(piece.y + y)] = piece.Colour;
                        field.SetGlyph((ushort)(piece.x + x), (ushort)(piece.y + y), c);
                    }
                }
            }
        }
Esempio n. 4
0
        static void DrawPiece(ref Tetromino piece)
        {
            for (byte x = 0; x < Tetromino.LENGTH; ++x)
            {
                for (byte y = 0; y < Tetromino.LENGTH; ++y)
                {
                    var c = piece.Type[Tetromino.GetIndexByRotation(x, y, ref piece.rotation)];

                    if (c != ' ')
                    {
                        Painting.brush = c;
                        Painting.DrawCell((short)(piece.x + x + 1), (short)(piece.y + y + 1), piece.Colour);
                    }
                }
            }
        }