Exemplo n.º 1
0
        protected override void Draw(GameTime gameTime)
        {
            switch (CurrentState)
            {
            case GameState.WelcomeScreen:
                GraphicsDevice.Clear(Color.White);
                spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, spriteScale);
                gameWorld.Draw(gameTime, spriteBatch);
                //tetrisGrid.Draw(gameTime, spriteBatch);
                spriteBatch.End();
                break;

            case GameState.StartScreen:
                GraphicsDevice.Clear(Color.White);
                spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, spriteScale);
                gameWorld.Draw(gameTime, spriteBatch);
                tetrisGrid.Draw(gameTime, spriteBatch);
                spriteBatch.End();
                break;

            case GameState.PlayScreen:
                GraphicsDevice.Clear(Color.White);
                spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, spriteScale);
                gameWorld.Draw(gameTime, spriteBatch);
                tetrisGrid.Draw(gameTime, spriteBatch);
                block.Draw(gameTime, spriteBatch);
                spriteBatch.End();
                break;
            }
        }
Exemplo n.º 2
0
 public void initalit()
 {
     pic_square.BackColor = gameFieldBgC;
     pic_line.BackColor   = gameFieldBgC;
     pic_J.BackColor      = gameFieldBgC;
     pic_L.BackColor      = gameFieldBgC;
     pic_T.BackColor      = gameFieldBgC;
     ipc_Z.BackColor      = gameFieldBgC;
     pic_S.BackColor      = gameFieldBgC;
     Application.DoEvents();
     //图片框1号:方块
     someBlock = new Block(new Point(35, 27), Block.BlockTypes.square);
     someBlock.Draw(pic_square.Handle);
     //图片框2号:直线
     someBlock = new Block(new Point(20, 35), Block.BlockTypes.line);
     someBlock.Draw(pic_line.Handle);
     //图片框3号:J
     someBlock = new Block(new Point(42, 20), Block.BlockTypes.J);
     someBlock.Draw(pic_J.Handle);
     //图片框4号:L
     someBlock = new Block(new Point(42, 20), Block.BlockTypes.L);
     someBlock.Draw(pic_L.Handle);
     //图片框5号:T
     someBlock = new Block(new Point(27, 27), Block.BlockTypes.T);
     someBlock.Draw(pic_T.Handle);
     //图片框6号:Z
     someBlock = new Block(new Point(27, 27), Block.BlockTypes.Z);
     someBlock.Draw(ipc_Z.Handle);
     //图片框7号:S
     someBlock = new Block(new Point(27, 27), Block.BlockTypes.S);
     someBlock.Draw(pic_S.Handle);
     Application.DoEvents();
 }
Exemplo n.º 3
0
 /*选择背景色*/
 private void p_backColor_Click(object sender, EventArgs e)
 {
     if (colorDialog1.ShowDialog() == DialogResult.OK)
     {
         pic_bgColor.BackColor = colorDialog1.Color;
     }
     pic_preView.Refresh();
     someBlock = new Block(new Point(45, 40), (Block.BlockTypes)currentBlock, pic_fgColor.BackColor, pic_bgColor.BackColor);
     someBlock.Draw(pic_preView.Handle);
 }
Exemplo n.º 4
0
        /*单击某个图片框*/
        private void pictureBox_Click(object sender, EventArgs e)
        {
            PictureBox send = (PictureBox)sender;

            currentBlock = int.Parse(send.Name.Substring(send.Name.Length - 1, 1));
            pic_preView.Refresh();
            pic_preView.BackColor = gameFieldBgC;
            Application.DoEvents();
            someBlock = new Block(new Point(45, 40), (Block.BlockTypes)currentBlock);
            someBlock.Draw(pic_preView.Handle);
            pic_fgColor.BackColor = GameField.BlockForeColor[currentBlock - 1];
            pic_bgColor.BackColor = GameField.BlockBackColor[currentBlock - 1];
        }
Exemplo n.º 5
0
 /*保存*/
 private void btn_save_Click(object sender, EventArgs e)
 {
     if (currentBlock != 0)
     {
         GameField.BlockForeColor[currentBlock - 1] = pic_fgColor.BackColor;
         GameField.BlockBackColor[currentBlock - 1] = pic_bgColor.BackColor;
         //重画预览框的图片
         someBlock = new Block(new Point(45, 40), (Block.BlockTypes)currentBlock);
         someBlock.Draw(pic_preView.Handle);
         //游戏设置改变
         GameField.isChanged = true;
     }
 }
Exemplo n.º 6
0
 /*重新开始一盘*/
 private void 重新开始ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     timer1.Stop();
     picBackGround.Refresh();                                               //刷新游戏区
     pic_preView.Refresh();                                                 //刷新预览区
     GameField.arriveBlock = new Square[GameField.width, GameField.height]; //清空所有小方块
     GameField.arrBitBlock = new int[GameField.height];
     score        = 0;                                                      //重新计算积分
     t_score.Text = "0";
     msg.SendToBack();                                                      //将提示窗口隐藏
     currentBlock = new Block(startLocation, Block.BlockTypes.undefined);
     currentBlock.Draw(GameField.winHandle);
     nextBlock = new Block(new Point(25, 25), Block.BlockTypes.undefined);
     nextBlock.Draw(pic_preView.Handle);
     开始ToolStripMenuItem.Enabled  = false;
     暂停ToolStripMenuItem1.Enabled = true;
     结束ToolStripMenuItem.Enabled  = true;
     stillRuning = true;
     timer1.Start();
 }
Exemplo n.º 7
0
 //开始游戏的方法
 private void beginGame()
 {
     msg.SendToBack();   //将提示窗口隐藏
     开始ToolStripMenuItem.Enabled  = false;
     暂停ToolStripMenuItem1.Enabled = true;
     结束ToolStripMenuItem.Enabled  = true;
     if (currentBlock == null)
     {
         //第一次开始
         currentBlock = new Block(startLocation, Block.BlockTypes.undefined);
         currentBlock.Draw(GameField.winHandle);
         nextBlock = new Block(new Point(25, 25), Block.BlockTypes.undefined);
         nextBlock.Draw(pic_preView.Handle);
         stillRuning = true;
         timer1.Start();
     }
     else
     {
         timer1.Enabled = true;
     }
 }
Exemplo n.º 8
0
 /*游戏时钟*/
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (!stillRuning)
     {
         return;
     }
     //检测是否还可以下移
     if (!currentBlock.down())
     {
         if (currentBlock.Top() == 0)
         {
             //如果到顶则游戏结束
             showMsg("Game Over!");
             stillRuning = false;
             timer1.Stop();
             return;
         }
         //否则计算分数并继续
         int eraseLines = GameField.CheckLines();
         if (eraseLines > 0)
         {
             score       += GameField.width * eraseLines;
             t_score.Text = score.ToString();
             picBackGround.Invalidate();
             Application.DoEvents();
             GameField.Redraw();
         }
         //产生下一个block
         currentBlock = new Block(startLocation, nextBlock.blockType);
         currentBlock.Draw(GameField.winHandle);
         pic_preView.Refresh();
         nextBlock = new Block(new Point(25, 25), Block.BlockTypes.undefined);
         nextBlock.Draw(pic_preView.Handle);
     }
     currentBlock.down();
 }
Exemplo n.º 9
0
 //Draw the whole map and the currently played block too
 public void Draw()
 {
     Map.Draw();
     CurrentBlock.Draw();
 }