作者在 2010-12-02 12:27:53 发布以下内容
部分主要代码:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int leftTime=30;//实现定时记录
int step;//实现等级记录
int n = 0;//实现记录分数
int score=450;//记录分数
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button11.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
if (leftTime > 9)
{
label4.Text = leftTime.ToString();
}
else
{
label4.Text = "0 " + leftTime.ToString();
}
if (leftTime == 0)
{
//倒计时到“00”,计时器停止
this.timer1.Stop();
this.timer2.Stop();
if (n > score)
{
label5.Text = "恭喜你!闯关成功!";
}
else
{
label5.Text = "对不起,闯关失败!重来?";
}
button11.Enabled = true;
this.Time.ComboBox.Enabled = true;
this.低级ToolStripMenuItem.Enabled = true;
this.高级ToolStripMenuItem.Enabled = true;
this.button1.Visible = false;
this.button3.Visible = false;
this.button2.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
//去做其他事情
//......
}
else
{
leftTime--;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Random r = new Random();
int i = r.Next(1, 9);
if (i == 1)
{
this.button1.Visible = true;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
if (i == 2)
{
this.button1.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button2.Visible = true;
this.button6.Visible = true;
}
if (i == 3 )
{
this.button1.Visible = false;
this.button2.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button3.Visible = true;
this.button7.Visible = true;
}
if (i == 4)
{
this.button4.Visible = true;
this.button8.Visible = true;
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button9.Visible = false;
}
if (i == 5)
{
this.button1.Visible = true;
this.button5.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
if (i == 6)
{
this.button4.Visible = true;
this.button9.Visible = true;
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
}
if (i == 7)
{
this.button2.Visible = true;
this.button7.Visible = true;
this.button1.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
if (i == 8)
{
this.button6.Visible =true;
this.button8.Visible = true;
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button7.Visible = false;
this.button9.Visible = false;
}
if (i == 9)
{
this.button1.Visible = true;
this.button3.Visible = true;
this.button2.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
}
//
//游戏开始
//按钮事件
private void button10_Click(object sender, EventArgs e)
{
this.低级ToolStripMenuItem.Enabled = false;
this.高级ToolStripMenuItem.Enabled = false;
this.Time.ComboBox.Enabled = false;
label2.Visible = true;
if (step == 1)
{
timer1.Interval = 10000;
}
else if (step == 2)
{
timer1.Interval = 650;
}
timer1.Enabled = true;
this.button10.Enabled = false;
this.button11.Enabled = false;
this.timer1.Start();
this.timer2.Start();
}
private void button1_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button1.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button2.Visible = false;
}
private void button3_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button3.Visible = false;
}
private void button4_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button4.Visible = false;
}
private void button5_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button5.Visible = false;
}
private void button6_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button6.Visible = false;
}
private void button7_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button7.Visible = false;
}
private void button8_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button8.Visible = false;
}
private void button9_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button9.Visible = false;
}
//
//游戏再来一次事件
//
private void button11_Click(object sender, EventArgs e)
{
label2.Visible = true;
leftTime= 30;
this.timer1.Enabled = true;
this.Time.ComboBox.Enabled = false;
this.低级ToolStripMenuItem.Enabled = false;
this.高级ToolStripMenuItem.Enabled = false;
if (step == 1)
{
timer1.Interval = 1000;
score = 460;
}
else if (step == 2)
{
timer1.Interval =650;
score = 300;
}
this.label2.Text = "0";
n = 0;
this.label5.Text = "";
this.timer1.Start();
this.timer2.Start();
this.button10.Enabled = false;
this.button11.Enabled = false;
}
//
//游戏开始下拉框事件
//
private void 游戏开始ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.label2.Visible = true;
this.button10.Enabled = false;
this.button11.Enabled = false;
this.Time.ComboBox.Enabled = false;
this.低级ToolStripMenuItem.Enabled = false;
this.高级ToolStripMenuItem.Enabled = false;
if (leftTime == 0)
{
this.label5.Text = "";//提示信息
this.label2.Text = "0";
n = 0;
/*if(低级ToolStripMenuItem.Selected==true)
{
//step = 1;
timer1.Interval = 10000;
}
else if (高级ToolStripMenuItem.Selected == true)
{
//step = 2;
timer1.Interval = 650;
}*/
if (Time.SelectedIndex == 0)
{
leftTime = 30;
if (低级ToolStripMenuItem.Selected == true)
{
//step = 1;
timer1.Interval = 10000;
score = 450;
}
else if (高级ToolStripMenuItem.Selected == true)
{
//step = 2;
timer1.Interval = 650;
score = 300;
}
else
{
score = 450;
}
}
else if (Time.SelectedIndex == 1)
{
leftTime = 40;
if (低级ToolStripMenuItem.Selected == true)
{
//step = 1;
timer1.Interval = 10000;
score = 600;
}
else if (高级ToolStripMenuItem.Selected == true)
{
//step = 2;
timer1.Interval = 650;
score = 450;
}
else
{
score = 450;
}
}
else if (Time.SelectedIndex == 2)
{
leftTime = 50;
if(低级ToolStripMenuItem.Selected==true)
{
//step = 1;
timer1.Interval = 10000;
score = 750;
}
else
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int leftTime=30;//实现定时记录
int step;//实现等级记录
int n = 0;//实现记录分数
int score=450;//记录分数
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button11.Enabled = false;
}
private void timer2_Tick(object sender, EventArgs e)
{
if (leftTime > 9)
{
label4.Text = leftTime.ToString();
}
else
{
label4.Text = "0 " + leftTime.ToString();
}
if (leftTime == 0)
{
//倒计时到“00”,计时器停止
this.timer1.Stop();
this.timer2.Stop();
if (n > score)
{
label5.Text = "恭喜你!闯关成功!";
}
else
{
label5.Text = "对不起,闯关失败!重来?";
}
button11.Enabled = true;
this.Time.ComboBox.Enabled = true;
this.低级ToolStripMenuItem.Enabled = true;
this.高级ToolStripMenuItem.Enabled = true;
this.button1.Visible = false;
this.button3.Visible = false;
this.button2.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
//去做其他事情
//......
}
else
{
leftTime--;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Random r = new Random();
int i = r.Next(1, 9);
if (i == 1)
{
this.button1.Visible = true;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
if (i == 2)
{
this.button1.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button2.Visible = true;
this.button6.Visible = true;
}
if (i == 3 )
{
this.button1.Visible = false;
this.button2.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
this.button3.Visible = true;
this.button7.Visible = true;
}
if (i == 4)
{
this.button4.Visible = true;
this.button8.Visible = true;
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button9.Visible = false;
}
if (i == 5)
{
this.button1.Visible = true;
this.button5.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
if (i == 6)
{
this.button4.Visible = true;
this.button9.Visible = true;
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
}
if (i == 7)
{
this.button2.Visible = true;
this.button7.Visible = true;
this.button1.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
if (i == 8)
{
this.button6.Visible =true;
this.button8.Visible = true;
this.button1.Visible = false;
this.button2.Visible = false;
this.button3.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button7.Visible = false;
this.button9.Visible = false;
}
if (i == 9)
{
this.button1.Visible = true;
this.button3.Visible = true;
this.button2.Visible = false;
this.button4.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
this.button7.Visible = false;
this.button8.Visible = false;
this.button9.Visible = false;
}
}
//
//游戏开始
//按钮事件
private void button10_Click(object sender, EventArgs e)
{
this.低级ToolStripMenuItem.Enabled = false;
this.高级ToolStripMenuItem.Enabled = false;
this.Time.ComboBox.Enabled = false;
label2.Visible = true;
if (step == 1)
{
timer1.Interval = 10000;
}
else if (step == 2)
{
timer1.Interval = 650;
}
timer1.Enabled = true;
this.button10.Enabled = false;
this.button11.Enabled = false;
this.timer1.Start();
this.timer2.Start();
}
private void button1_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button1.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button2.Visible = false;
}
private void button3_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button3.Visible = false;
}
private void button4_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button4.Visible = false;
}
private void button5_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button5.Visible = false;
}
private void button6_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button6.Visible = false;
}
private void button7_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button7.Visible = false;
}
private void button8_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button8.Visible = false;
}
private void button9_Click(object sender, EventArgs e)
{
n = n + 10;
this.label2.Text = n.ToString();
this.button9.Visible = false;
}
//
//游戏再来一次事件
//
private void button11_Click(object sender, EventArgs e)
{
label2.Visible = true;
leftTime= 30;
this.timer1.Enabled = true;
this.Time.ComboBox.Enabled = false;
this.低级ToolStripMenuItem.Enabled = false;
this.高级ToolStripMenuItem.Enabled = false;
if (step == 1)
{
timer1.Interval = 1000;
score = 460;
}
else if (step == 2)
{
timer1.Interval =650;
score = 300;
}
this.label2.Text = "0";
n = 0;
this.label5.Text = "";
this.timer1.Start();
this.timer2.Start();
this.button10.Enabled = false;
this.button11.Enabled = false;
}
//
//游戏开始下拉框事件
//
private void 游戏开始ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.label2.Visible = true;
this.button10.Enabled = false;
this.button11.Enabled = false;
this.Time.ComboBox.Enabled = false;
this.低级ToolStripMenuItem.Enabled = false;
this.高级ToolStripMenuItem.Enabled = false;
if (leftTime == 0)
{
this.label5.Text = "";//提示信息
this.label2.Text = "0";
n = 0;
/*if(低级ToolStripMenuItem.Selected==true)
{
//step = 1;
timer1.Interval = 10000;
}
else if (高级ToolStripMenuItem.Selected == true)
{
//step = 2;
timer1.Interval = 650;
}*/
if (Time.SelectedIndex == 0)
{
leftTime = 30;
if (低级ToolStripMenuItem.Selected == true)
{
//step = 1;
timer1.Interval = 10000;
score = 450;
}
else if (高级ToolStripMenuItem.Selected == true)
{
//step = 2;
timer1.Interval = 650;
score = 300;
}
else
{
score = 450;
}
}
else if (Time.SelectedIndex == 1)
{
leftTime = 40;
if (低级ToolStripMenuItem.Selected == true)
{
//step = 1;
timer1.Interval = 10000;
score = 600;
}
else if (高级ToolStripMenuItem.Selected == true)
{
//step = 2;
timer1.Interval = 650;
score = 450;
}
else
{
score = 450;
}
}
else if (Time.SelectedIndex == 2)
{
leftTime = 50;
if(低级ToolStripMenuItem.Selected==true)
{
//step = 1;
timer1.Interval = 10000;
score = 750;
}
else
WinForm | 阅读 905 次
文章评论,共0条