c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;
网吧充值系统
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。。。。
.
2.。。。
推箱子
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");
} }
}
}
c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;的更多相关文章
- OC推箱子
#include<stdio.h> #include<stdlib.h> int main(void) { char sr;//存储用户输入的指令 //绘制地图 char a[ ...
- hdu.1254.推箱子(bfs + 优先队列)
推箱子 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- c++、c实现推箱子小游戏
经过四次的修改和优化,终于将推箱子这个游戏完整的写出来了,今天就像大家分享一下这个游戏的编写. 这个游戏界面的编写总的来说不困难,主要是推动箱子的算法. (1)利用数组和windows api 即可写 ...
- [HDU 1254] 推箱子
推箱子 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- HDU_1254——推箱子,两次BFS
这题做的一把鼻涕一把泪,果断考虑不周555 Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱 ...
- 【面试笔试算法】Program 5 : 推箱子 (网易游戏笔试题)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 推箱子是一款经典游戏.如图所示,灰色格子代表不能通过区域,蓝色方格是箱子,黑色圆形代表玩家,含有圆点的格子代表目标点. 规 ...
- 推箱子 (hdu1254)(bfs双重广搜)
推箱子 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission ...
- HDU 1254 推箱子(BFS)
Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不 ...
- HDU1254 推箱子(BFS) 2016-07-24 14:24 86人阅读 评论(0) 收藏
推箱子 Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推 ...
随机推荐
- [转载]Android核心分析
2013-12-19 15:44:03 转载自: http://blog.csdn.net/column/details/androidcore.html 很好的文章,阅读请跳转到转载链接,转载备以后 ...
- win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面
错误一: HTTP Error 500.19 - Internal Server Error配置错误: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定是默认设置的 (ov ...
- URAL 1519 基础插头DP
题目大意: 给定一个图,一部分点'*'作为障碍物,求经过所有非障碍点的汉密尔顿回路有多少条 基础的插头DP题目,对于陈丹琦的论文来说我觉得http://blog.sina.com.cn/s/blog_ ...
- [处理器、单片机]ARM
1.ARM简介: ARM是Advanced RISC Machines的缩写.1985年4月26日,第一个ARM原型在英国剑桥的Acorn计算机有限公司诞生,由美国加州San Jose VLSI技术公 ...
- @ResultMapping注解
@RequestMapping注解1.url映射放在方法上:@RequestMapping("/itemsEdit")2.窄化url请求映射放在类上,定义根路径,url就变成根路径 ...
- Project和Module的介绍
Project 和 Module 介绍 这两个概念是 IntelliJ IDEA 的必懂知识点之一,请务必要学会. 如果你是 Eclipse 用户,并且已经看了上面给的链接,那 IntelliJ ID ...
- iphone获取当前磁盘信息
获取iphone磁盘总大小.已使用空间.空闲空间 [代码]悦德财富:https://www.yuedecaifu.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
- js对象的定义及处理
一,概述 在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类.Hashtable类等等. 目前在Javascrip ...
- 详解模块定义(.def)文件
一个完整的Windows应用程序(C++程序)通常由五种类型的文件组成:源程序文件,头文件,资源描述文件,项目文件,模块定义文件.本文主要讲解模块定义文件. 模块定义 (.def)文件为链接器提供有关 ...
- RFIDler:一款定义RFID的读、写、仿真器的开源软件
很多类似于RFID这样的技术看起来都很神秘,实际上他是依赖于很多物理学原理的,比如”电磁感应原理”.是的,这些现象产生的各种信号足以令人发狂,看完这些模拟模拟信号后,我忽然发现二进制信息多么干净美丽. ...