userdefined.cs
来自「扫雷源代码,能智能形成堆栈与线程技术应用,是个很有用的游戏开发软件」· CS 代码 · 共 93 行
CS
93 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MineSweeping
{
//自定义游戏窗体
public partial class UserDefined : Form
{
public System.Windows.Forms.Form mainform;
int[] array = new int[3];
public UserDefined()
{
InitializeComponent();
}
//判断input字符串是否为有效数字输入,如果有效并且在min 和max范围内则返回input对应INT32数字
private int Judge(string input, int min, int max)
{
//判断是否为有效数字
bool confirm = true;
foreach (char ch in input)
{
if (!char.IsNumber(ch))
{
confirm = false;
break;
}
}
if (confirm == false)
return 0;
//confirm为false表示含有非数字字符,返回0
//如果输入正确,将string 转化为int,返回其值
else
{
try
{
//如果num在min和max之间,返回num,否则根据情况返回min或max
int num = System.Int32.Parse(input);
if (num < min)
return min;
else if ((num >= min) && (num <= max))
return num;
else
return max;
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
return 0;
}
}
}
//showSelf函数,通过引用实现参数的传递
public static bool ShowSelf(IWin32Window parent, Point location, ref int width, ref int height, ref int mile)
{
bool result;
UserDefined u = new UserDefined();
//以当前游戏参数初始化textBox
u.textBox1.Text = height.ToString();
u.textBox2.Text = width.ToString();
u.textBox3.Text = mile.ToString();
u.Location = location;
//如果对话框结果为OK,改变游戏参数
if (u.ShowDialog(parent) == DialogResult.OK)
{
if(u.Judge(u.textBox2.Text, 9, 30)!=0)
width = u.Judge(u.textBox2.Text, 9, 30);
if(u.Judge(u.textBox1.Text, 9, 24)!=0)
height = u.Judge(u.textBox1.Text, 9, 24);
if(u.Judge(u.textBox3.Text, 10, (width - 1) * (height - 1))!=0)
mile = u.Judge(u.textBox3.Text, 10, (width - 1) * (height - 1));
result = true;
}
else
result = false;
//垃圾处理
u.Dispose();
u = null;
return result;
}
//
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?