예제 #1
0
        //public override void changeView(TetrisModel model) 多型覆蓋
        public override void changeView(TetrisModel model)
        {
            gg.Visible = false;
            m_Graphics.Graphics.Clear(Color.White);
            DrawGameField();
            bool[,] board = model.getBoard();
            TetrisBlock current_block = model.getBlock();

            for (int i = 0; i < 22; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (board[i, j])
                    {
                        DrawBlock(cadeBluebrush, azurePen, i, j);
                    }
                }
            }

            for (int i = 0; i < 4; i++)
            {
                DrawBlock(brush, azurePen, current_block.get_CurrentX() + current_block.get_X(i), current_block.get_CurrentY() + current_block.get_Y(i));
            }
            m_Graphics.Render();
            score.Text = model.getScore().ToString();
            if (model.GameOver())
            {
                gg.Visible = true;
            }
        }
예제 #2
0
        //public override void changeView(TetrisModel model) 多型覆蓋
        public override void changeView(TetrisModel model)
        {
            m_Graphics.Graphics.Clear(Color.Black);
            drawBackGround();
            bool[,] board = model.getBoard();
            TetrisBlock current_block = model.getBlock();


            //取得 GameOver 狀態,並決定是否顯示文字
            if (model.GameOver())
            {
                LbGO.Visible   = true;
                LbGO2.Visible  = true;
                iTime          = 0;
                sTimer.Enabled = false;
            }
            else
            {
                LbGO.Visible  = false;
                LbGO2.Visible = false;
            }

            for (int i = 0; i < 22; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (board[i, j])
                    {
                        drawBlock(whitePen, i, j);
                    }
                }
            }

            for (int i = 0; i < 4; i++)
            {
                drawBlock(bleakPen, current_block.get_CurrentX() + current_block.get_X(i), current_block.get_CurrentY() + current_block.get_Y(i));
            }
            m_Graphics.Render();
            Score.Text = "Score: " + model.getScore().ToString();
        }
예제 #3
0
        //public override void changeView(TetrisModel model) 多型覆蓋
        public override void changeView(TetrisModel model)
        {
            m_Graphics.Graphics.Clear(Color.SkyBlue);
            drawBackGround();
            mymodel       = model;
            bool[,] board = model.getBoard();
            TetrisBlock current_block = model.getBlock();

            if (current_block.getBlockShape() != TetrisBlock.Blocks.No_shape)
            {
                for (int i = 0; i < 22; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (board[i, j])
                        {
                            drawBlock(board_Pen, board_brush, i, j);
                        }
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    drawBlock(current_Pen, current_brush, current_block.get_CurrentX() + current_block.get_X(i), current_block.get_CurrentY() + current_block.get_Y(i));
                }

                m_Graphics.Render();
                //m_Graphics.Dispose();
                scoreBox.Text = model.getScore().ToString();
            }

            if (mymodel.GameOver())
            {
                Gameover gameover_form = new Gameover();
                gameover_form.Show(this);
            }
        }
예제 #4
0
        //public override void changeView(TetrisModel model) 多型覆蓋
        public override void changeView(TetrisModel model)
        {
            if (model.GameOver())
            {
                time = 0;
                viewTimer.Stop();
                button1.Text = "restart";
            }
            my_Graphics.Graphics.Clear(Color.White);
            drawBackGround();
            bool[,] board = model.getBoard();
            TetrisBlock current_block = model.getBlock();

            for (int i = 0; i < 22; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (board[i, j])
                    {
                        drawBlock(blackBrush, blackPen, i, j);
                    }
                }
            }


            int  depth = 0;
            bool add   = true;

            while (add)
            {
                depth++;
                for (int i = 0; i < 4; i++)
                {
                    //System.Diagnostics.Debug.WriteLine(current_block.get_X(i) + depth);
                    int h = current_block.get_X(i) + depth;
                    if (h < 0)
                    {
                        h = 0;
                    }
                    if (h > 21)
                    {
                        h = 21;
                    }
                    if (board[h, current_block.get_CurrentY() + current_block.get_Y(i)])
                    {
                        add = false;
                    }
                }
                if (depth > 21)
                {
                    break;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                while (current_block.get_X(i) + depth > 22)
                {
                    depth--;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (!model.GameOver())
                {
                    drawBlock(whiteBrush, redPen, current_block.get_X(i) + depth - 1, current_block.get_CurrentY() + current_block.get_Y(i));
                }
                if (!model.GameOver())
                {
                    drawBlock(yellowBrush, redPen, current_block.get_CurrentX() + current_block.get_X(i), current_block.get_CurrentY() + current_block.get_Y(i));
                }
            }
            my_Graphics.Render();
            score.Text    = "Score: " + model.getScore().ToString();
            viewTime.Text = "Time: " + time.ToString();
        }
예제 #5
0
        public override void changeView(TetrisModel model)
        //public void changeView(TetrisModel model)
        {
            if (!model.GameOver())
            {
                m_Graphics.Graphics.Clear(Color.WhiteSmoke);
                drawBackGround();
                bool[,] board = model.getBoard();
                TetrisBlock current_block = model.getBlock();

                //draw bottom blocks
                for (int i = 0; i < (int)constant.BOARD_HEIGHT; i++)
                {
                    for (int j = 0; j < (int)constant.BOARD_WIDTH; j++)
                    {
                        if (board[i, j])
                        {
                            drawBlock(blackPen, i, j);
                        }
                    }
                }


                int shape = (int)current_block.getBlockShape();

                //draw predict blocks
                //find distance from falling block to exist blocks
                SolidBrush blockBrush    = chooseBrushColor(shape);
                int        fallingHeight = -1;
                bool       findHeight    = false;
                while (!findHeight)
                {
                    fallingHeight++;
                    for (int i = 0; i < 4; i++)
                    {
                        if (current_block.get_CurrentX() + current_block.get_X(i) + fallingHeight < (int)constant.BOARD_HEIGHT)
                        {
                            if (board[current_block.get_CurrentX() + current_block.get_X(i) + fallingHeight, current_block.get_CurrentY() + current_block.get_Y(i)])
                            {
                                findHeight = true;
                                if (fallingHeight != 0)
                                {
                                    fallingHeight--;
                                }
                                break;
                            }
                        }
                        else
                        {
                            findHeight = true;
                            if (fallingHeight != 0)
                            {
                                fallingHeight--;
                            }
                            break;
                        }
                    }
                }
                //draw
                for (int i = 0; i < 4; i++)
                {
                    drawPredictBlock(blockBrush, current_block.get_CurrentX() + current_block.get_X(i) + fallingHeight, current_block.get_CurrentY() + current_block.get_Y(i));
                }

                //draw falling blocks
                Pen blockPen = choosePenColor(shape);
                for (int i = 0; i < 4; i++)
                {
                    drawBlock(blockPen, current_block.get_CurrentX() + current_block.get_X(i), current_block.get_CurrentY() + current_block.get_Y(i));
                }
                m_Graphics.Render();
                //m_Graphics.Dispose();
                Score.Text = model.getScore().ToString();
            }
            else
            {
                GameOver();
            }
        }