예제 #1
0
        private void Init()
        {
            gr = this.CreateGraphics();
            height_in_cells = 24;
            width_in_cells  = 11;
            cell_size       = 20;
            menu            = new Label();
            menu.SetBounds(-10, 480, 237, 60);
            menu.BackColor = Color.Transparent;
            menu.Font      = new Font("Courier New", 12, FontStyle.Bold);
            menu.TextAlign = ContentAlignment.MiddleCenter;
            this.Controls.Add(menu);
            this.FormBorderStyle = FormBorderStyle.Fixed3D;
            this.Height          = 600;
            this.Width           = 237;
            this.Text            = "Tetris v.2.0";
            this.Font            = new Font("Courier New", 20, FontStyle.Bold);
            this.BackgroundImage = Image.FromFile(Environment.CurrentDirectory + @"\333.jpg");

            board   = new Board(height_in_cells, width_in_cells);
            current = new Tetromino();
            current.GetTetromino();

            game_timer = new Timer()
            {
                Interval = 1000,
                Enabled  = true
            };

            game_timer.Tick += DownShift;
            game_timer.Start();
            this.KeyDown       += MyForm_KeyDown;
            this.DoubleBuffered = true;
            this.Paint         += MyForm_Paint;
        }
예제 #2
0
 private bool CanMove(int x, int y, Tetromino tetromino)
 {
     foreach (Coordinates c in tetromino.pC)
     {
         if (c.pX + x <= 0)
         {
             return(false);
         }
         if (c.pX + x >= (width_in_cells - 1))
         {
             return(false);
         }
         if (c.pY + y < 0)
         {
             return(false);
         }
         if (board.field[c.pY, c.pX + x].BorderOrBlock)
         {
             return(false);
         }
         if (board.field[c.pY + y, c.pX].BorderOrBlock)
         {
             return(false);
         }
     }
     return(true);
 }
예제 #3
0
 private void BlockRestart()
 {
     foreach (Coordinates c in current.pC)
     {
         board.field[c.pY, c.pX].pCellkind = CellKind.Block;
     }
     board.ClearBoard();
     current = new Tetromino();
     current.GetTetromino();
 }
예제 #4
0
        public Tetromino CopyTetromino()
        {
            Tetromino copy = new Tetromino();

            copy.pTetris_type = this.pTetris_type;
            for (int i = 0; i < 4; i++)
            {
                copy.coordinates[i].pX = this.coordinates[i].pX;
                copy.coordinates[i].pY = this.coordinates[i].pY;
            }
            return(copy);
        }
예제 #5
0
        private void MoveDirection(Direction direction)
        {
            StopGame();
            int shift = 0;

            switch (direction)
            {
            case Direction.Left:
            case Direction.Right:
                shift = (direction == Direction.Left) ? -1 : 1;
                if (CanMove(shift, 0, current))
                {
                    for (int i = 0; i < 4; i++)
                    {
                        current.pC[i].pX += shift;
                    }
                }
                break;

            case Direction.Rotate:
                Tetromino rotated = current.CopyTetromino();
                rotated.Rotate();
                if (CanMove(shift, 0, rotated))
                {
                    current.Rotate();
                }
                break;

            case Direction.IDown:
                Down(true);
                break;

            case Direction.Down:
                Down();
                break;
            }
            this.Refresh();
        }