Example #1
0
        private void lockActive()
        {
            isLocking = true;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (i + active.X < 22 && j + active.Y < 10 && i + active.X >= 0 && j + active.Y >= 0)
                    {
                        permaBlocked[i + active.X][j + active.Y] |= active.Blocking[i][j];
                        if (active.Blocking[i][j] && i + active.X >= 2)
                        {
                            permaColors[i + active.X - 2][j + active.Y] = active.Color;
                        }
                    }
                }
            }
            active    = next;
            next      = Tetromino.getRandom();
            ghost     = new Tetromino(active);
            active.X  = 0;
            active.Y  = 3;
            dueLock   = false;
            isLocking = false;

            for (int i = 2; i < 22; i++)
            {
                if (permaBlocked[i].All(x => x))
                {
                    for (int j = i; j > 0; j--)
                    {
                        permaBlocked[j] = permaBlocked[j - 1];
                        if (j >= 3)
                        {
                            permaColors[j - 2] = permaColors[j - 3];
                        }
                    }
                    permaBlocked[0] = new bool[10];
                    permaColors[0]  = new ConsoleColor?[10];
                }
            }

            var args = new TetrominoLockedEventArgs();

            args.Next = next;
            TetrominoLocked(this, args);
            if (permaBlocked[1].Any(x => x))
            {
                Environment.Exit(0);
            }
        }
Example #2
0
        private bool tryMove(int x, int y, Tetromino tet)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (tet.Blocking[i][j])
                    {
                        int translatedX = tet.X + i + x;
                        int translatedY = tet.Y + j + y;

                        if (occupied(translatedX, translatedY))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Example #3
0
        public TetrisField()
        {
            permaBlocked = new bool[22][];
            for (int i = 0; i < 22; i++)
            {
                permaBlocked[i] = new bool[10];
            }
            permaColors = new ConsoleColor?[20][];
            for (int i = 0; i < 20; i++)
            {
                permaColors[i] = new ConsoleColor?[10];
            }

            active = Tetromino.getRandom();
            next   = Tetromino.getRandom();
            ghost  = new Tetromino(active);

            HasChanged = true;
            active.X   = 0;
            active.Y   = 3;
        }
Example #4
0
        public void ProcessInput(UserInput input)
        {
            switch (input)
            {
            case UserInput.Down:
                if (tryMove(1, 0, active))
                {
                    active.X++;
                }
                break;

            case UserInput.Left:
                if (tryMove(0, -1, active))
                {
                    active.Y--;
                }
                break;

            case UserInput.Right:
                if (tryMove(0, 1, active))
                {
                    active.Y++;
                }
                break;

            case UserInput.Lock:
                while (tryMove(1, 0, active))
                {
                    active.X++;
                }
                lockActive();
                break;

            case UserInput.RotateClockwise:
                doRotate(false);
                break;

            case UserInput.RotateCClockwise:
                doRotate(true);
                break;

            case UserInput.Hold:
                if (hold == null)
                {
                    hold   = active;
                    active = next;
                    next   = Tetromino.getRandom();
                    TetrominoLockedEventArgs largs = new TetrominoLockedEventArgs();
                    largs.Next = next;
                    TetrominoLocked(this, largs);
                }
                else
                {
                    Tetromino temp = hold;
                    hold   = active;
                    active = temp;
                }
                ghost    = new Tetromino(active);
                active.X = 0;
                active.Y = 3;
                TetrominoHeldEventArgs args = new TetrominoHeldEventArgs();
                args.Hold = hold;
                TetrominoHeld(this, args);
                break;
            }
            dueLock = false;
            evaluateLock();
            HasChanged = true;
        }
Example #5
0
        private bool tryMove(int x, int y, Tetromino tet)
        {
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (tet.Blocking[i][j])
                    {
                        int translatedX = tet.X + i + x;
                        int translatedY = tet.Y + j + y;

                        if (occupied(translatedX, translatedY))
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
Example #6
0
        private void lockActive()
        {
            isLocking = true;
            for (int i = 0; i < 4; i++)
            {

                for (int j = 0; j < 4; j++)
                {
                    if (i + active.X < 22 && j + active.Y < 10 && i + active.X >= 0 && j + active.Y >= 0)
                    {
                        permaBlocked[i + active.X][j + active.Y] |= active.Blocking[i][j];
                        if (active.Blocking[i][j] && i + active.X >= 2)
                        {
                            permaColors[i + active.X - 2][j + active.Y] = active.Color;
                        }
                    }
                }
            }
            active = next;
            next = Tetromino.getRandom();
            ghost = new Tetromino(active);
            active.X = 0;
            active.Y = 3;
            dueLock = false;
            isLocking = false;

            for (int i = 2; i < 22; i++)
            {
                if (permaBlocked[i].All(x => x))
                {
                    for (int j = i; j > 0; j--)
                    {
                        permaBlocked[j] = permaBlocked[j - 1];
                        if (j >= 3)
                        {
                            permaColors[j - 2] = permaColors[j - 3];
                        }
                    }
                    permaBlocked[0] = new bool[10];
                    permaColors[0] =  new ConsoleColor?[10];
                }
            }

            var args = new TetrominoLockedEventArgs();
            args.Next = next;
            TetrominoLocked(this, args);
            if (permaBlocked[1].Any(x => x))
            {
                Environment.Exit(0);
            }
        }
Example #7
0
        public void ProcessInput(UserInput input)
        {
            switch (input)
            {
                case UserInput.Down:
                    if (tryMove(1, 0, active))
                    {
                        active.X++;
                    }
                    break;

                case UserInput.Left:
                    if (tryMove(0, -1, active))
                    {
                        active.Y--;
                    }
                    break;

                case UserInput.Right:
                    if (tryMove(0, 1, active))
                    {
                        active.Y++;
                    }
                    break;

                case UserInput.Lock:
                    while (tryMove(1, 0, active))
                    {
                        active.X++;
                    }
                    lockActive();
                    break;

                case UserInput.RotateClockwise:
                    doRotate(false);
                    break;

                case UserInput.RotateCClockwise:
                    doRotate(true);
                    break;

                case UserInput.Hold:
                    if (hold == null)
                    {
                        hold = active;
                        active = next;
                        next = Tetromino.getRandom();
                        TetrominoLockedEventArgs largs = new TetrominoLockedEventArgs();
                        largs.Next = next;
                        TetrominoLocked(this, largs);
                    }
                    else
                    {
                        Tetromino temp = hold;
                        hold = active;
                        active = temp;
                    }
                    ghost = new Tetromino(active);
                    active.X = 0;
                    active.Y = 3;
                    TetrominoHeldEventArgs args = new TetrominoHeldEventArgs();
                    args.Hold = hold;
                    TetrominoHeld(this, args);
                    break;
            }
            dueLock = false;
            evaluateLock();
            HasChanged = true;
        }
Example #8
0
        public TetrisField()
        {
            permaBlocked = new bool[22][];
            for (int i = 0; i < 22; i++)
            {
                permaBlocked[i] = new bool[10];
            }
            permaColors = new ConsoleColor?[20][];
            for (int i = 0; i < 20; i++)
            {
                permaColors[i] = new ConsoleColor?[10];
            }

            active = Tetromino.getRandom();
            next = Tetromino.getRandom();
            ghost = new Tetromino(active);

            HasChanged = true;
            active.X = 0;
            active.Y = 3;
        }
Example #9
0
 public Tetromino(Tetromino mother) // Ghost piece
 {
     this.Color  = ConsoleColor.Gray;
     this.mother = mother;
 }
Example #10
0
 // Ghost piece
 public Tetromino(Tetromino mother)
 {
     this.Color = ConsoleColor.Gray;
     this.mother = mother;
 }