网吧充值系统
namespace ConsoleApplication1
{
class Program
{
struct huiyuan
{
public string name;
public string password;
public double yue;
}
static void Main(string[] aaa)
{
ArrayList Ul = new ArrayList();
while (true)
{
try
{
Console.WriteLine("请输入您要执行的操作:(1、会员管理\t2、充值管理)");
int x = Convert.ToInt32(Console.ReadLine());
m(x, Ul);
}
catch (Exception)
{ }
} }
static void m(int x, ArrayList al)
{
switch (x)
{
case :
Console.WriteLine("1、添加会员\t2、删除会员\t3、余额查询");
int xx = Convert.ToInt32(Console.ReadLine());
huiyuanfuwu(xx, al);
break;
case :
Console.WriteLine("1、充值服务\t2、扣费服务");
int xxx = Convert.ToInt32(Console.ReadLine());
chongzhiguanli(xxx, al);
break;
default:
break;
}
} static void chongzhiguanli(int x, ArrayList al)
{
switch (x)
{
case :
Console.Write("请输入要充值的用户名:");
string sname = Console.ReadLine();
foreach (huiyuan item in al)
{
if (item.name == sname)
{ Console.WriteLine("当前余额为:" + item.yue);
Console.Write("请输入充值金额:");
double m = Convert.ToInt32(Console.ReadLine());
chongzhi(m, al, sname);
break; }
}
break;
default:
break;
}
} static void chongzhi(double m, ArrayList al, string sname)
{
double x = ;//奖励金额 if (m >= && m < )
{
x = ;
}
else if (m >= && m < )
{
x = ;
}
else if (m >= && m < )
{
x = ;
}
else if (m >= && m < )
{
x = ;
}
else if (m >= && m < )
{
x = ;
}
else if (m >= )
{
x = m;
}
else
{
x = ;
}
huiyuan temp = new huiyuan();
for (int i = ; i < al.Count; i++)
{
temp = ((huiyuan)al[i]);
if (temp.name == sname)
{ temp.yue += Convert.ToDouble(m + x);
Console.WriteLine("本次充值成功,充值金额为" + m + "。奖励金额为:" + x + ".充值后余额为:" + temp.yue);
al.Insert(i, temp);
al.RemoveAt(i + );
break;
} } }
static void huiyuanfuwu(int x, ArrayList al)
{
switch (x)
{
case :
huiyuan h = new huiyuan();
Console.Write("请输入用户名:");
h.name = Console.ReadLine();
Console.Write("请输入密码:");
h.password = Console.ReadLine();
h.yue = ;
al.Add(h);
break;
case :
Console.Write("请输入要删除的用户名:");
string dname = Console.ReadLine();
foreach (huiyuan item in al)
{
if (item.name == dname)
{
al.Remove(item);
Console.WriteLine("删除成功!");
break;
}
} break;
case :
Console.Write("请输入要查询的用户名:");
string sname = Console.ReadLine();
foreach (huiyuan item in al)
{
if (item.name == sname)
{ Console.WriteLine("当前余额为:" + item.yue);
}
}
break;
default:
break;
}
} }
}

简易的闹钟

namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
DateTime a = DateTime.Now;//定义一个新datetime类型变量并赋值为系统现在的时间
DateTime nz=Convert.ToDateTime("2015-4-13 17:30");定义并赋值一个datetime
while (true)
{
a = a.AddMinutes();//a每次增加1分钟
if (nz.ToShortTimeString().Equals(a.ToShortTimeString()))//系统时间每次增加1分钟后如果等于设定的时间
{
Console.WriteLine(a + "起床啦!");
Console.Write("是否关闭闹钟?Y/N");
string s = Console.ReadLine();
if (s=="y.ToUpper()")
{
break;
}
else
{
nz = nz.AddMinutes();如果不关闭,则闹钟累加5分钟后,系统时间再累加直到与nz相同,循环。。。。。。
}
}
} }
}
}

出租车计费

namespace ConsoleApplication23
{
class Program
{
static void Main(string[] args)
{
while (true)
{
double i,l, m1 = ,m2=1.2,m3=1.5,m4=2.4;
Console.Write("请输入坐车距离:");
i = Convert.ToDouble(Console.ReadLine());
if (i>&&i<=)
{
Console.WriteLine("您的行车费用为:"+m1);
}
else if (i>&&i<=)
{
l = m1 + (i - ) * m2;
Console.WriteLine("您的行车费用为:" + l);
}
else if (i>)
{
l = m1 + m4 + (i - ) * m3;
Console.WriteLine("您的行车费用为:" + l);
}
else
{
Console.WriteLine("您的输入有误!");
}
} }
}
}

简单计算器:

namespace 第一次
{
class Program
{
static void Main(string[] args)
{double a, b;
//做一个简单的计算器
while (true)
{ Console.WriteLine("加法:");
Console.Write("请输入第一个数:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入第二个数:");
b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("结果为:"+(a+b));
Console.WriteLine("减法:");
Console.Write("请输入第一个数:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入第二个数:");
b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("结果为:" + (a - b));
Console.WriteLine("乘法:");
Console.Write("请输入第一个数:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入第二个数:");
b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("结果为:" + (a * b));
Console.WriteLine("除法:");
Console.Write("请输入第二个数:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("请输入第二个数:");
b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("结果为:" + (a / b));
} }
}
}

对战游戏;

namespace ConsoleApplication5
{ class Program
{
struct player
{
public string name;
public int hp;
public int attack;
public int defend;
public int quick;
public WuGong WG;
}
struct WuGong
{
public string name;
public int atk;
} static void Main(string[] args)
{ Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
player p1 = new player();
player p2 = new player();
Random r = new Random(); //生成两个玩家
Console.Write("请输入第一个战士的名字:");
p1.name = Console.ReadLine();
Console.Write("请输入第二个战士的名字:");
p2.name = Console.ReadLine();
//生成血量
p1.hp = r.Next(, ) + ;//初始血量
p2.hp = r.Next(, ) + ;
//生成攻防
p1.attack = r.Next(, ) + ;
p2.attack = r.Next(, ) + ;
p1.defend = r.Next(, ) + ;
p2.defend = r.Next(, ) + ;
//生成身法-敏捷度
p1.quick = r.Next();
p2.quick = r.Next(); Console.WriteLine("玩家:" + p1.name + " 血量:" + p1.hp + "\t攻击力:" + p1.attack
+ "\t物防:" + p1.defend + " 敏捷度:" + p1.quick);
Console.WriteLine("VS");
Console.WriteLine("玩家:" + p2.name + " 血量:" + p2.hp + "\t攻击力:" + p2.attack
+ "\t物防:" + p2.defend + " 敏捷度:" + p2.quick);
Console.WriteLine("点击任意键开始游戏.....");
Console.ReadKey(); while (true)
{
// 得出最后结果,跳出循环
if (p1.hp <= && p2.hp <= )
{
Console.WriteLine(p1.name + "与" + p2.name + "同归于尽!");
Console.ReadLine();
break;
}
if (p1.hp <= )
{
Console.WriteLine(p2.name + "把" + p1.name + "KO..");
Console.ReadLine();
break;
}
if (p2.hp <= )
{
Console.WriteLine(p1.name + "把" + p2.name + "KO..");
Console.ReadLine();
break;
} //对战 WuGong[] wg = new WuGong[];
//gongfu(wg);
wg[].name = "降龙十八掌";
wg[].atk = ; wg[].name = "打狗棒法";
wg[].atk = ; wg[].name = "独孤九剑";
wg[].atk = ;
//大招
int dz1 = r.Next();//大招随机
if (dz1 >= ) //从1到9的随机数里 取8和9 有20%的几率用大招。
{
Random x = new Random();
int a = x.Next(, );
int dx1 = r.Next();//声明 掉血 变量
int gj1 = r.Next() - ;//为了浮动 P2的 攻击力;
int fy1 = r.Next() - ;//为了浮动 P1的防御力;
dx1 = ((dx1 + wg[a].atk) - (p1.defend + fy1)) < ? : ((dx1 + wg[a].atk) - (p1.defend + fy1));
//为了防止掉血 出现负值
p1.hp -= dx1;
if (p1.hp < )
{
p1.hp = ;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(p2.name + "使用大招 " + wg[a].name + " 攻击,对" + p1.name + "造成" + dx1 + "的伤害。"); }
else //平常招式
{
//躲闪
int sf1 = r.Next();//身法的随机数 if (p1.quick - sf1 >= )
{
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(p1.name + "躲闪" + p2.name + "的攻击");
}
else
{
int dx1 = r.Next();//声明 掉血 变量
int gj1 = r.Next() - ;//为了浮动 P2的 攻击力;
int fy1 = r.Next() - ;//为了浮动 P1的防御力;
dx1 = (dx1 + (p2.attack + gj1) - (p1.defend + fy1)) < ? : (dx1 + (p2.attack + gj1) - (p1.defend + fy1));
//为了防止掉血 出现负值
p1.hp -= dx1;
if (p1.hp < )
{
p1.hp = ;
}
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(p1.name + "使用普通攻击,对" + p2.name + "造成" + dx1 + "的伤害。");
}
}
//稍等一下
System.Threading.Thread.Sleep(); int dz2 = r.Next();
if (dz2 >= )
{
Random y = new Random();
int b = y.Next(, );
int dx2 = r.Next();
int gj2 = r.Next() - ;//为了浮动 P1的 攻击力;
int fy2 = r.Next() - ;//为了浮动 P2的防御力;
dx2 = ((dx2 + wg[b].atk) - (p2.defend + fy2)) < ? : ((dx2 + wg[b].atk) - (p2.defend + fy2));
//为了防止掉血 出现负值
p2.hp -= dx2;
if (p2.hp < )
{
p2.hp = ;
}
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(p1.name + "使用大招 " + wg[b].name + " 攻击,对" + p2.name + "造成" + dx2 + "的伤害。");
}
else
{
//躲闪
int sf2 = r.Next();
if (p2.quick - sf2 > sf2)
{
Console.ForegroundColor = ConsoleColor.Black;
Console.WriteLine(p2.name + "躲闪" + p1.name + "的攻击");
}
else
{
int dx2 = r.Next();
int gj2 = r.Next() - ;//为了浮动 P1的 攻击力;
int fy2 = r.Next() - ;//为了浮动 P2的防御力;
dx2 = (dx2 + (p1.attack + gj2) - (p2.defend + fy2)) < ? : (dx2 + (p1.attack + gj2) - (p2.defend + fy2));
//为了防止掉血 出现负值
p2.hp -= dx2;
if (p2.hp < )
{
p2.hp = ;
}
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(p2.name + "使用普通攻击,对" + p1.name + "造成" + dx2 + "的伤害。");
}
}
//稍等一下
System.Threading.Thread.Sleep();
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("玩家:" + p1.name + "\t血量:" + p1.hp + "\t");
Console.WriteLine("玩家:" + p2.name + "\t血量:" + p2.hp); }
} } }

等额本金法

  等额本金法最大的特点是每月的还款额不同,呈现逐月递减的状态;它是将贷款本金按还款的总月数均分,再加上上期剩余本金的利息,这样就形成月还款额,所以等额本金法第一个月的还款额最多 ,然后逐月减少,越还越少,计算公式为:

  每月还本付息金额=(本金/还款月数)+(本金-累计已还本金)×月利率

  每月本金=总本金/还款月数

  每月利息=(本金-累计已还本金)×月利率

还款总利息=(还款月数+1)*贷款额*月利率/2

  还款总额=(还款月数+1)*贷款额*月利率/2+贷款额

namespace ConsoleApplication28
{
class Program
{
static void Main(string[] args)
{
double m, n, d = 0.0655, e = 0.0405, x, y, z,p,q,h;
Console.Write("请选择房贷类型?A商业贷款;B公积金贷款:");
string a = Console.ReadLine();
if (a=="A")
{
Console.Write("请选择房贷期限?A10年;B20;年C30年 :");
string b = Console.ReadLine();
if (b=="A")
{
Console.Write("请输入贷款金额:");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个还款月:");
n = Convert.ToInt32(Console.ReadLine());
x = m / ;
y = x + (m-x)* (d/);
z = x + (m - (n - )*x) * (d / );
p = ( + ) * m * (d / ) / ;
q = p + m;
Console.WriteLine("您当前月份的还款金额为:" + z);
Console.WriteLine("您每期偿还的本金为:" + x);
Console.WriteLine("您的最大月供为:" + y);
Console.WriteLine("您应当还款的总利息为:" + p);
Console.WriteLine("您应当还款的总金额为:" + q);
for (int i = ; i < ; i++)
{
h = x + (m - i*x) * (d / );
Console.WriteLine("第"+(i+)+"还款:"+h+"当月偿还的利息为:"+(h-x)+"剩余本金为:"+(m-x*(i+))); } }
else if (b=="B")
{
Console.Write("请输入贷款金额:");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个还款月:");
n = Convert.ToInt32(Console.ReadLine());
x = m / ;
y = x + (m - x) * (d / );
z = x + (m - (n - ) * x) * (d / );
p = ( + ) * m * (d / ) / ;
q = p +m;
Console.WriteLine("您当前月份的还款金额为:" + z);
Console.WriteLine("您每期偿还的本金为:" + x);
Console.WriteLine("您的最大月供为:" + y);
Console.WriteLine("您应当还款的总利息为:" + p);
Console.WriteLine("您应当还款的总金额为:" + q);
for (int i = ; i < ; i++)
{
h = x + (m - i * x) * (d / );
Console.WriteLine("第" + (i + ) + "还款:" + h + "当月偿还的利息为:" + (h - x) + "剩余本金为:" + (m - x * (i + ))); } }
else if (b=="C")
{
Console.Write("请输入贷款金额:");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个还款月:");
n = Convert.ToInt32(Console.ReadLine());
x = m / ;
y = x + (m - x) * (d / );
z = x + (m - (n - ) * x) * (d / );
p = ( + ) * m * (d / ) / ;
q = p + m;
Console.WriteLine("您当前月份的还款金额为:" + z);
Console.WriteLine("您每期偿还的本金为:" + x);
Console.WriteLine("您的最大月供为:" + y);
Console.WriteLine("您应当还款的总利息为:" + p);
Console.WriteLine("您应当还款的总金额为:" + q);
for (int i = ; i < ; i++)//依次列出每个月应该还多少,利息多少,剩余多少,for循环
{
h = x + (m - i * x) * (d / );
Console.WriteLine("第" + (i + ) + "还款:" + h + "当月偿还的利息为:" + (h - x) + "剩余本金为:" + (m - x * (i + ))); }
}
else
{
Console.WriteLine("请您选择正确的代号!");
} }
else if (a=="B")
{
Console.Write("请选择房贷期限?A10年;B20;年C30年 :");
string b = Console.ReadLine();
if (b == "A")
{
Console.Write("请输入贷款金额:");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个还款月:");
n = Convert.ToInt32(Console.ReadLine());
x = m / ;
y = x + (m - x) * (e / );
z = x + (m - (n - ) * x) * (e / );
p = ( + ) * m * (e / ) / ;
q = p + m;
Console.WriteLine("您当前月份的还款金额为:" + z);
Console.WriteLine("您每期偿还的本金为:" + x);
Console.WriteLine("您的最大月供为:" + y);
Console.WriteLine("您应当还款的总利息为:" + p);
Console.WriteLine("您应当还款的总金额为:" + q);
for (int i = ; i < ; i++)
{
h = x + (m - i * x) * (e / );
Console.WriteLine("第" + (i + ) + "还款:" + h + "当月偿还的利息为:" + (h - x) + "剩余本金为:" + (m - x * (i + ))); } }
else if (b == "B")
{
Console.Write("请输入贷款金额:");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个还款月:");
n = Convert.ToInt32(Console.ReadLine());
x = m / ;
y = x + (m - x) * (e / );
z = x + (m - (n - ) * x) * (e / );
p = ( + ) * m * (e / ) / ;
q = p + m;
Console.WriteLine("您当前月份的还款金额为:" + z);
Console.WriteLine("您每期偿还的本金为:" + x);
Console.WriteLine("您的最大月供为:" + y);
Console.WriteLine("您应当还款的总利息为:" + p);
Console.WriteLine("您应当还款的总金额为:" + q);
for (int i = ; i < ; i++)
{
h = x + (m - i * x) * (e / );
Console.WriteLine("第" + (i + ) + "还款:" + h + "当月偿还的利息为:" + (h - x) + "剩余本金为:" + (m - x * (i + ))); }
}
else if (b == "C")
{
Console.Write("请输入贷款金额:");
m = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入第几个还款月:");
n = Convert.ToInt32(Console.ReadLine());
x = m / ;
y = x + (m - x) * (e / );
z = x + (m - (n - ) * x) * (e / );
p = ( + ) * m * (e / ) / ;
q = p + m;
Console.WriteLine("您当前月份的还款金额为:" + z);
Console.WriteLine("您每期偿还的本金为:" + x);
Console.WriteLine("您的最大月供为:" + y);
Console.WriteLine("您应当还款的总利息为:" + p);
Console.WriteLine("您应当还款的总金额为:" + q);
for (int i = ; i < ; i++)
{
h = x + (m - i * x) * (e / );
Console.WriteLine("第" + (i + ) + "还款:" + h + "当月偿还的利息为:" + (h - x) + "剩余本金为:" + (m - x * (i + ))); }
}
else
{
Console.WriteLine("请您选择正确的代号!");
}
}
else
{
Console.WriteLine("请您选择正确的代号!");
}
Console.Read();
}
}
}

随机生成10个不重复的50以内的整数

1。。。。

.c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;-LMLPHP

2.。。。

c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;-LMLPHP

 推箱子

namespace ConsoleApplication15//推箱子本质就是变量的相互替换,3个变量的循环赋值
{
class Program
{ static void Main(string[] args)
{
int x = , y = , i = ;
int[, ,] dt = new int[, , ] //定义一个二维数组用于接收地图
{
{
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,}
},
{
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,,,,,,,,,,,}
} };
try
{ while (true)
{
int temp = ; ConsoleKeyInfo s = Console.ReadKey(); //s用于接收用户输入的键
if (s.Key.ToString() == "DownArrow")
{
if (dt[i, x + , y] == )//如果小人的下一步是0(空格),则两个元素交换 (下同)
{ temp = dt[i, x, y];
dt[i, x, y] = dt[i, x + , y];
dt[i, x + , y] = temp;
x++;
}
else if (dt[i, x + , y] == && dt[i, x + , y] == )//如果小人的下一步是箱子,箱子的下一步是空格,则三个元素进行交换 (下同)
{ temp = dt[i, x + , y];
dt[i, x + , y] = dt[i, x + , y];
dt[i, x + , y] = temp;
temp = dt[i, x + , y];
dt[i, x + , y] = dt[i, x, y];
dt[i, x, y] = temp;
x++; }
else if (dt[i, x + , y] == && dt[i, x + , y]==) //如果小人的下面第二个元素是“★”
{ dt[i, x+, y ] = ; //让五角星变成箱子
dt[i, x+, y ] = ;// 让箱子变成小人
dt[i, x, y] = ; //让小人变成空格
temp = ; //给临时变量赋一个值作为跳出循环的条件
}
}
else if (s.Key.ToString() == "UpArrow")
{
if (dt[i, x - , y] == )
{ temp = dt[i, x - , y];
dt[i, x - , y] = dt[i, x, y];
dt[i, x, y] = temp;
x--;
}
else if (dt[i, x - , y] == && dt[i, x - , y] == )
{ temp = dt[i, x - , y];
dt[i, x - , y] = dt[i, x - , y];
dt[i, x - , y] = temp;
temp = dt[i, x, y];
dt[i, x, y] = dt[i, x - , y];
dt[i, x - , y] = temp;
x--; }
else if (dt[i, x - , y] == && dt[i, x - , y]==) //如果小人的下面第二个元素是“★”
{ dt[i, x - , y] = ; //让五角星变成箱子
dt[i, x - , y] = ;// 让箱子变成小人
dt[i, x, y] = ; //让小人变成空格
temp = ; //给临时变量赋一个值作为跳出循环的条件
}
}
else if (s.Key.ToString() == "LeftArrow")
{
if (dt[i, x, y - ] == )
{ temp = dt[i, x, y - ];
dt[i, x, y - ] = dt[i, x, y];
dt[i, x, y] = temp;
y--;
}
else if (dt[i, x, y - ] == && dt[i, x, y - ] == )
{ temp = dt[i, x, y - ];
dt[i, x, y - ] = dt[i, x, y - ];
dt[i, x, y - ] = temp;
temp = dt[i, x, y];
dt[i, x, y] = dt[i, x, y - ];
dt[i, x, y - ] = temp;
y--; }
else if (dt[i, x, y - ] == &&dt[i, x, y - ] == ) //如果小人的下面第二个元素是“★”
{ dt[i, x, y - ] = ; //让五角星变成箱子
dt[i, x, y - ] = ;// 让箱子变成小人
dt[i, x, y] = ; //让小人变成空格
temp = ; //给临时变量赋一个值作为跳出循环的条件
}
}
else if (s.Key.ToString() == "RightArrow")
{
if (dt[i, x, y + ] == )
{ temp = dt[i, x, y + ];
dt[i, x, y + ] = dt[i, x, y];
dt[i, x, y] = temp;
y++;
}
else if (dt[i, x, y + ] == && dt[i, x, y + ] == )
{ temp = dt[i, x, y + ];
dt[i, x, y + ] = dt[i, x, y + ];
dt[i, x, y + ] = temp;
temp = dt[i, x, y + ];
dt[i, x, y + ] = dt[i, x, y];
dt[i, x, y] = temp;
y++; }
else if (dt[i, x, y + ] == &&dt[i, x, y + ] == ) //如果小人的下面第二个元素是“★”而且小人下面第一个元素是
{ dt[i, x, y + ] = ; //让五角星变成箱子
dt[i, x, y + ] = ;// 让箱子变成小人
dt[i, x, y] = ; //让小人变成空格
temp = ; //给临时变量赋一个值作为跳出循环的条件
}
} Console.Clear(); //清屏 ditu(dt, i);// 调用ditu函数打印地图;一开始就从这里开始,前面没有打印地图。
if (temp == )// 跳出循环
{
Console.WriteLine("恭喜您过关了!");
Console.WriteLine("按任意键进入下一关!");
Console.ReadKey();
x = ; y = ;//初始化小人的位置
i++; } }
}
catch (Exception)
{ Console.WriteLine("暂时只有两张图!");
Console.ReadKey();
} } private static void ditu(int[, ,] dt, int i)
{ for (int j = ; j < ; j++)
{
for (int k = ; k < ; k++)
{ if (dt[i, j, k] == )
{
Console.Write(" ");
}
else if (dt[i, j, k] == )
{
Console.Write("■");
}
else if (dt[i, j, k] == )
{
Console.Write("□");
}
else if (dt[i, j, k] == )
{
Console.Write("★");
}
else if (dt[i, j, k] == )
{
Console.Write("♀");
} }
Console.Write("\n");
} }
}
}
04-23 14:55