C# 九宫格游戏
来源:互联网 发布:淘宝3c数码是哪个类目 编辑:程序博客网 时间:2024/04/29 03:26
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace qq
{
/// <summary>
/// 2 4 6 8 1 3 7 9 正确步骤
/// </summary>
public partial class Nine : Form
{
//点击次数计数器
int count = 0;
public Nine()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
bool result=false;
count++;
this.label2.Text = count.ToString();//在label2显示
String btnText = ((Button)sender).Text;
if (btnText.Equals("1"))
{
button1.BackColor = button1.BackColor == Color.Red ? Color.Yellow : Color.Red;
button2.BackColor = button2.BackColor == Color.Red ? Color.Yellow : Color.Red;
button4.BackColor = button4.BackColor == Color.Red ? Color.Yellow : Color.Red;
button5.BackColor = button5.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("2"))
{
button1.BackColor = button1.BackColor == Color.Red ? Color.Yellow : Color.Red;
button2.BackColor = button2.BackColor == Color.Red ? Color.Yellow : Color.Red;
button3.BackColor = button3.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("3"))
{
button2.BackColor = button2.BackColor == Color.Red ? Color.Yellow : Color.Red;
button3.BackColor = button3.BackColor == Color.Red ? Color.Yellow : Color.Red;
button5.BackColor = button5.BackColor == Color.Red ? Color.Yellow : Color.Red;
button6.BackColor = button6.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("4"))
{
button1.BackColor = button1.BackColor == Color.Red ? Color.Yellow : Color.Red;
button4.BackColor = button4.BackColor == Color.Red ? Color.Yellow : Color.Red;
button7.BackColor = button7.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("5"))
{
button2.BackColor = button2.BackColor == Color.Red ? Color.Yellow : Color.Red;
button4.BackColor = button4.BackColor == Color.Red ? Color.Yellow : Color.Red;
button5.BackColor = button5.BackColor == Color.Red ? Color.Yellow : Color.Red;
button6.BackColor = button6.BackColor == Color.Red ? Color.Yellow : Color.Red;
button8.BackColor = button8.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("6"))
{
button3.BackColor = button3.BackColor == Color.Red ? Color.Yellow : Color.Red;
button6.BackColor = button6.BackColor == Color.Red ? Color.Yellow : Color.Red;
button9.BackColor = button9.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("7"))
{
button4.BackColor = button4.BackColor == Color.Red ? Color.Yellow : Color.Red;
button5.BackColor = button5.BackColor == Color.Red ? Color.Yellow : Color.Red;
button7.BackColor = button7.BackColor == Color.Red ? Color.Yellow : Color.Red;
button8.BackColor = button8.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("8"))
{
button7.BackColor = button7.BackColor == Color.Red ? Color.Yellow : Color.Red;
button8.BackColor = button8.BackColor == Color.Red ? Color.Yellow : Color.Red;
button9.BackColor = button9.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
else if (btnText.Equals("9"))
{
button5.BackColor = button5.BackColor == Color.Red ? Color.Yellow : Color.Red;
button6.BackColor = button6.BackColor == Color.Red ? Color.Yellow : Color.Red;
button8.BackColor = button8.BackColor == Color.Red ? Color.Yellow : Color.Red;
button9.BackColor = button9.BackColor == Color.Red ? Color.Yellow : Color.Red;
}
result = button5.BackColor == Color.Yellow
&& button1.BackColor==Color.Red
&& button2.BackColor==Color.Red
&& button3.BackColor==Color.Red
&& button4.BackColor==Color.Red
&& button6.BackColor==Color.Red
&& button7.BackColor==Color.Red
&& button8.BackColor==Color.Red
&& button9.BackColor==Color.Red;
if (result)
{
MessageBox.Show("你赢了!!!!!!!!");
this.button10.Enabled = true;
setButton(false);
}
}
private void Nine_Load(object sender, EventArgs e)
{
setButton(false);
}
private void button10_Click(object sender, EventArgs e)
{
//自身不可用
this.button10.Enabled = false;
setButton(true);
//恢复按钮的背景颜色为初始颜色
this.button1.BackColor = Control.DefaultBackColor;
this.button2.BackColor = Control.DefaultBackColor;
this.button3.BackColor = Control.DefaultBackColor;
this.button4.BackColor = Control.DefaultBackColor;
this.button5.BackColor = Control.DefaultBackColor;
this.button6.BackColor = Control.DefaultBackColor;
this.button7.BackColor = Control.DefaultBackColor;
this.button8.BackColor = Control.DefaultBackColor;
this.button9.BackColor = Control.DefaultBackColor;
}
//设置按钮的交互状态,是否可用
public void setButton(bool en)
{
this.button1.Enabled = en;
this.button2.Enabled = en;
this.button3.Enabled = en;
this.button4.Enabled = en;
this.button5.Enabled = en;
this.button6.Enabled = en;
this.button7.Enabled = en;
this.button8.Enabled = en;
this.button9.Enabled = en;
}
}
}
- C# 九宫格游戏
- 九宫格游戏
- Android九宫格游戏
- 游戏中的九宫格算法
- 0326九宫格游戏下载+简单MVC
- [UnityUI]九宫格在游戏中的使用
- javascript九宫游戏代码
- 【开源】完美破解九宫格(数独)游戏
- Oracle Form写的九宫格游戏(Sudoku Game)
- C++ 完美破解九宫格(数独)游戏
- Sudoku Puzzles - 九宫格(数独)游戏
- 游戏开发九宫格战斗架构解析详解
- 九宫格练习 9*9数独游戏
- C++实现九宫格游戏人机对战
- 一段代码,求解数独(九宫格)游戏
- 九宫格
- 九宫格
- 九宫格
- Oracle数据库中的左连接与右连接【转】
- struts2上传文件类型限制
- Core Dump Management on the Solaris OS
- 在使用ajaxcontroltoolkit时出现 'SYS' 未定义
- 利用LD_PRELOAD发现程序潜在的问题
- C# 九宫格游戏
- VC++使用ADO连接SQL Server数据库
- struts2文件上传中,如何限制上传的文件类型
- wince 下cmd ping命令的执行
- 网站装饰品---地图,时钟
- 技巧: 使用truss、strace或ltrace诊断软件的"疑难杂症"
- 圆角图片制作
- 开源网站
- 一次解决系统性能的日记(Solaris8)