Exemplo n.º 1
0
        private void Start()
        {
            switch (TetrisManager.gameStatus)
            {
            //from default
            case 0:
                Sound.PlayRunning();
                TetrisManager.StartTetris();
                DisplayNextBlock();
                break;

            //from pause
            case 2:
                TetrisManager.RestartTetris();
                DisplayTetris();
                DisplayNextBlock();
                break;

            //from gameover
            case 3:
                TetrisManager.StartTetris();
                DisplayNextBlock();
                break;
            }
            tmrTetris.Enabled = true;
        }
Exemplo n.º 2
0
 private void MoveBlock(int row, int col)
 {
     if (TetrisManager.gameStatus == 1)
     {
         TetrisManager.MoveBlock(row, col);
         DisplayTetris();
     }
 }
Exemplo n.º 3
0
        public TetrisForm()
        {
            game  = null;
            time  = new Timer();
            ticks = 0;
            rand  = new Random();

            InitializeComponent();
        }
Exemplo n.º 4
0
 private void StartGame(object sender, EventArgs e)
 {
     Start.Visible  = false;
     Start.Enabled  = false;
     this.BackColor = Color.FromArgb(rand.Next(32, 220), rand.Next(32, 220), rand.Next(32, 220));
     game           = new TetrisManager(20, 300, 100);
     this.Invalidate();
     time.Start();
 }
Exemplo n.º 5
0
        private void Stop()
        {
            Sound.PlayOpening();
            TetrisManager.StopTetris();
            tmrTetris.Enabled = false;
            Graphics tetrisBoard = pnlTetris.CreateGraphics();

            tetrisBoard.Clear(Color.Black);
            tetrisBoard.DrawImage(Picture.start, 50, 200, 200, 200);
        }
Exemplo n.º 6
0
 private void Pause()
 {
     if (TetrisManager.gameStatus == 1)   //only works when the Tetris was running
     {
         Graphics tetrisBoard = pnlTetris.CreateGraphics();
         tetrisBoard.DrawImage(Picture.pause, 50, 220, 200, 150);
         TetrisManager.PauseTetris();
         tmrTetris.Enabled = false;
     }
 }
Exemplo n.º 7
0
        private void DropBlock()
        {
            if (TetrisManager.gameStatus == 1)
            {
                TetrisManager.DropBlock();
                DisplayTetris();

                new Thread(() => {
                    var c = new System.Windows.Media.MediaPlayer();
                    c.Open(new Uri(@"sounds/blockLanding.wav", UriKind.Relative));
                    c.Play();
                }).Start();
            }
        }
Exemplo n.º 8
0
        private void Run()
        {
            //prevent duplication of execution
            tmrTetris.Enabled = false;
            Graphics nextBlockBoard = pnlNextBlock.CreateGraphics();
            Graphics tetrisBoard    = pnlTetris.CreateGraphics();

            switch (TetrisManager.gameStatus)
            {
            //default
            case 0:
                tetrisBoard.DrawImage(Picture.start, 50, 200, 200, 200);
                ShowStatus();
                break;

            //running
            case 1:
                TetrisManager.ProgressTetris();
                DisplayTetris();
                ShowStatus();
                if (nextBlock != TetrisManager.nextBlock.Pattern)
                {
                    DisplayNextBlock();
                }
                tmrTetris.Enabled = true;       //continue Tetris
                break;

            //pausing
            case 2:
                break;

            //gameover
            case 3:
                tetrisBoard.DrawImage(Picture.gameOver, 50, 220, 200, 150);
                break;

            default:
                TetrisManager.gameStatus = 0;
                break;
            }
        }
Exemplo n.º 9
0
 private void RotateBlock()
 {
     TetrisManager.RotateBlock();
     DisplayTetris();
 }
Exemplo n.º 10
0
 private void Form1_Load(object sender, EventArgs e)
 {
     TetrisManager.InitializeTetris();
     Sound.PlayOpening();
 }