1、Directory 操作文件夹
CreateDirectory 创建文件夹
Delete 删除文件夹
Move 剪切文件夹
GetFiles 获得指定的目录下所有文件的全路径
GetDirectory 获得指定目录下所有文件夹的全路径
2、WebBrowser浏览器控件
url
3、ComboBox下拉框控件
DropDownstyle:控制下拉框的外观样式
4、心算闯关。
核心业务代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form8 : Form
{
public Form8()
{
InitializeComponent();
}
private void Form8_Load(object sender, EventArgs e)
{
AllVisible();
}
public void AllVisible() {
IblNum1.Visible = false;
IblDo.Visible = false;
IblNum2.Visible = false;
IblTo.Visible = false;
IblNum3.Visible = false;
IblTips.Visible = false;
IblTimeShow.Visible = false;
IblTimeNumber.Visible = false;
IblLifeShow.Visible = false;
IblLifeNumber.Visible = false;
IblAnswer.Visible = false;
TxtAnswer.Visible = false;
}
float CountNumber;
int Score = 0;//分数
int LifeNumber = 0;//生命值
private void BtnStarOrsub_Click(object sender, EventArgs e)
{
IblNum1.Visible = true;
IblDo.Visible = true;
IblNum2.Visible = true;
IblTo.Visible = true;
IblNum3.Visible = true;
IblTips.Visible = true;
IblTimeShow.Visible = true;
IblTimeNumber.Visible = true;
IblLifeShow.Visible = true;
IblLifeNumber.Visible = true;
IblAnswer.Visible = true;
TxtAnswer.Visible = true;
string Text = TxtAnswer.Text;
Console.WriteLine(Text);
if (BtnStarOrsub.Text == "开始游戏")
{
BtnStarOrsub.Text = "提交答案";
AllUpdate();
}
if (TxtAnswer.Text == "")
{
return;
}
if (TxtAnswer.Text == CountNumber.ToString())
{
MessageBox.Show("恭喜你答对了");
TxtAnswer.Clear();
AllUpdate();
Score++;
}
else
{
MessageBox.Show("你答错了");
TxtAnswer.Clear();
AllUpdate();
LifeNumber = Convert.ToInt32(IblLifeNumber.Text);
LifeNumber--;
IblLifeNumber.Text = LifeNumber.ToString();
if (LifeNumber == 0)
{
MessageBox.Show("游戏结束,你本次得分:{0}", Score.ToString());
AllVisible();
BtnStarOrsub.Text = "游戏开始";
}
}
}
public void AllUpdate() {
int Num1 = RandomNum(0, 101);
Thread.Sleep(200);
int Num2 = RandomNum(0, 101);
int caozuo = RandomNum(0, 4);
CountNumber = Count(Num1, Num2, caozuo);//四则运算结果
IblNum1.Text = Num1.ToString();
IblNum2.Text = Num2.ToString();
}
public float Count(int a, int b, int caozuo) {
float count = 0F;
switch (caozuo)
{
case 0: count = a + b;IblDo.Text = "+"; break;
case 1: count = a - b; IblDo.Text = "-"; break;
case 2: count = a * b; IblDo.Text = "*"; break;
case 3: count = a / b; IblDo.Text = "/"; break;
default:
break;
}
return count;
}
public int RandomNum(int a, int b) {
Random r = new Random();
return r.Next(a, b);
}
}
}