Exemplo 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);
        }
Exemplo 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);
                }
            }
        }
Exemplo 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);
                    }
                }
            }
        }
Exemplo 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);
                    }
                }
            }
        }
Exemplo n.º 5
0
        static void InitGame(Tetromino.Shape next)
        {
            string temp;

            if (enableChars)
            {
                temp = "☻♥♫";
            }

            else
            {
                temp = "█";
            }

            // colours which are below 7 are all dark colours
            piece     = new Tetromino(next, temp[r.Next(temp.Length)], enableColour ? (ConsoleColor)r.Next(9, 16) : ConsoleColor.Gray);
            piece.x   = FIELD_WIDTH - 1 >> 1;
            nextPiece = (Tetromino.Shape)r.Next(7);
            DrawNextPiece();
        }