今天练习突发奇想做个颜色游戏
就类似这种的
然后这是我写的代码,有点不完善:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 颜色游戏
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void Chang()
{
Random random = new Random();
Form1 form = new Form1();
int num = random.Next(4);
int one = random.Next(3);
int two = random.Next(3);
int three = random.Next(3);
int four = random.Next(3);
#region 背景颜色变换
switch (num)
{
case 0:
palAll.BackColor = Color.Red;
break;
case 1:
palAll.BackColor = Color.Green;
break;
case 2:
palAll.BackColor = Color.Blue;
break;
case 3:
palAll.BackColor = Color.Yellow;
break;
}
#endregion
#region 红色按钮
switch (one)
{
case 0:
btnRed.ForeColor = Color.Yellow;
break;
case 1:
btnRed.ForeColor = Color.Green;
break;
case 2:
btnRed.ForeColor = Color.Blue;
break;
}
#endregion
#region 绿色按钮
switch (two)
{
case 0:
btnGreen.ForeColor = Color.Yellow;
break;
case 1:
btnGreen.ForeColor = Color.Red;
break;
case 2:
btnGreen.ForeColor = Color.Blue;
break;
}
#endregion
#region 蓝色按钮
switch (three)
{
case 0:
btnBlue.ForeColor = Color.Yellow;
break;
case 1:
btnBlue.ForeColor = Color.Green;
break;
case 2:
btnBlue.ForeColor = Color.Red;
break;
}
#endregion
#region 黄色按钮
switch (four)
{
case 0:
btnYellow.ForeColor = Color.Blue;
break;
case 1:
btnYellow.ForeColor = Color.Green;
break;
case 2:
btnYellow.ForeColor = Color.Red;
break;
}
#endregion
}
private void btnRed_Click(object sender, EventArgs e)
{
if (palAll.BackColor != Color.Red)
{
MessageBox.Show("选择错误");
}
else
{
Chang();
}
}
private void btnGreen_Click(object sender, EventArgs e)
{
if (palAll.BackColor != Color.Green)
{
MessageBox.Show("选择错误");
}
else
{
Chang();
}
}
private void btnBlue_Click(object sender, EventArgs e)
{
if (palAll.BackColor != Color.Blue)
{
MessageBox.Show("选择错误");
}
else
{
Chang();
}
}
private void btnYellow_Click(object sender, EventArgs e)
{
if (palAll.BackColor != Color.Yellow)
{
MessageBox.Show("选择错误");
}
else
{
Chang();
}
}
private void btnStart_Click(object sender, EventArgs e)
{
Chang();
}
private void btuOrg_Click(object sender, EventArgs e)
{
this.Close();
}
}
}