/*游戏时钟*/ 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(); } if (score > 100) { timer1.Interval = (int)speeds.slow; label7.Text = "Level2"; } if (score > 200) { timer1.Interval = (int)speeds.quick; label7.Text = "Level3"; } if (score > 300) { timer1.Interval = (int)speeds.quicker; label7.Text = "Level4"; } if (score > 400) { timer1.Interval = (int)speeds.quickest; label7.Text = "Level5"; } //产生下一个block currentBlock = new Block(startLocation, nextBlock.blockType); currentBlock.Draw(GameField.winHandle); pic_preView.Refresh(); nextBlock = new Block(new Point(80, 50), Block.BlockTypes.undefined); nextBlock.Draw(pic_preView.Handle); } currentBlock.down(); }
/*选择前景色*/ private void p_foreColor_Click(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.OK) { p_foreColor.BackColor = colorDialog1.Color; } pic_preView.Refresh(); someBlock = new Block(new Point(45, 40), (Block.BlockTypes)currentBlock, p_foreColor.BackColor, p_backColor.BackColor); someBlock.Draw(pic_preView.Handle); }
/*单击某个图片框*/ 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); p_foreColor.BackColor = GameField.BlockForeColor[currentBlock-1]; p_backColor.BackColor = GameField.BlockBackColor[currentBlock-1]; }
/*单击某个图片框*/ 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); p_foreColor.BackColor = GameField.BlockForeColor[currentBlock - 1]; p_backColor.BackColor = GameField.BlockBackColor[currentBlock - 1]; }
//保存 private void button1_Click(object sender, EventArgs e) { if (currentBlock != 0) { GameField.BlockForeColor[currentBlock - 1] = p_foreColor.BackColor; GameField.BlockBackColor[currentBlock - 1] = p_backColor.BackColor; //Form1.ActiveForm.Refresh(); //重画预览框的图片 someBlock = new Block(new Point(45, 40), (Block.BlockTypes)currentBlock); someBlock.Draw(pic_preView.Handle); //游戏设置改变 GameField.isChanged = true; } }
/*重新开始一盘*/ 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(80, 50), Block.BlockTypes.undefined); nextBlock.Draw(pic_preView.Handle); 开始ToolStripMenuItem.Enabled = false; 暂停ToolStripMenuItem1.Enabled = true; 结束ToolStripMenuItem.Enabled = true; stillRuning = true; timer1.Start(); }
//开始游戏的方法 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(80, 50), Block.BlockTypes.undefined); nextBlock.Draw(pic_preView.Handle); stillRuning = true; timer1.Start(); } else { timer1.Enabled = true; } }
public void initalit() { pictureBox1.BackColor = gameFieldBgC; pictureBox2.BackColor = gameFieldBgC; pictureBox3.BackColor = gameFieldBgC; pictureBox4.BackColor = gameFieldBgC; pictureBox5.BackColor = gameFieldBgC; pictureBox6.BackColor = gameFieldBgC; pictureBox7.BackColor = gameFieldBgC; Application.DoEvents(); //图片框1号:方块 someBlock = new Block(new Point(35, 27), Block.BlockTypes.square); someBlock.Draw(pictureBox1.Handle); //图片框2号:直线 someBlock = new Block(new Point(20, 35), Block.BlockTypes.line); someBlock.Draw(pictureBox2.Handle); //图片框3号:J someBlock = new Block(new Point(42, 20), Block.BlockTypes.J); someBlock.Draw(pictureBox3.Handle); //图片框4号:L someBlock = new Block(new Point(42, 20), Block.BlockTypes.L); someBlock.Draw(pictureBox4.Handle); //图片框5号:T someBlock = new Block(new Point(27, 27), Block.BlockTypes.T); someBlock.Draw(pictureBox5.Handle); //图片框6号:Z someBlock = new Block(new Point(27, 27), Block.BlockTypes.Z); someBlock.Draw(pictureBox6.Handle); //图片框7号:S someBlock = new Block(new Point(27, 27), Block.BlockTypes.S); someBlock.Draw(pictureBox7.Handle); Application.DoEvents(); }
/*游戏时钟*/ 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(80, 50), Block.BlockTypes.undefined); nextBlock.Draw(pic_preView.Handle); } currentBlock.down(); }
/*选择背景色*/ private void p_backColor_Click(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.OK) p_backColor.BackColor = colorDialog1.Color; pic_preView.Refresh(); someBlock = new Block(new Point(45, 40), (Block.BlockTypes)currentBlock, p_foreColor.BackColor, p_backColor.BackColor); someBlock.Draw(pic_preView.Handle); }