推箱子游戏提纲,只有向右向上的操作,向左向下同理,后期需完善。
namespace 推箱子
{
class Program
{
static void Main(string[] args)
{
//小人初始位置的索引
int x = ;
int y = ; int end1x = ;
int end1y = ; #region 画地图
string[,] map = new string[, ] {
{" "," ","■","■","■","■","■","■","■","■"},
{" "," ","■"," "," "," "," ","☆"," ","■"},
{"■","■","■"," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," ","■"},
{"■"," "," "," "," "," "," "," "," ","■"},
{"■"," "," ","□"," "," "," "," "," ","■"},
{"■"," "," "," "," "," ","■","■","■","■"},
{"■"," "," "," "," "," ","■"," "," "," "},
{"■","♀"," "," "," "," ","■"," "," "," "},
{"■","■","■","■","■","■","■"," "," "," "},
};
#endregion while (true)
{
Console.Clear();//清空掉所有已经打印的内容
#region 打印地图
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
Console.Write(map[i, j]);
}
Console.WriteLine();
}
#endregion if (map[end1y, end1x] == "★")
{
Console.WriteLine("恭喜过关");
break;
} ConsoleKeyInfo key = Console.ReadKey();
//向上
if (key.Key.ToString() == "UpArrow")
{
//小人当前的位置与要去的下一步位置内容互换
if (map[y - , x] == "■")//如果小人的下一步是墙,什么都不干
{
}
else //小人的下一步不是墙
{
if (map[y - , x] == "□" && map[y - , x] != "■")
{
if (map[y - , x] == "☆")
{
//箱子的下一步是目标点,让箱子填满目标点
map[y - , x] = "★";
map[y - , x] = " ";
string temp = map[y, x];
map[y, x] = map[y - , x];
map[y - , x] = temp;
y--;//真正改变小人的位置
}
else if (map[y - , x] == " ")
{
//推着箱子走,箱子的下一步是空地才可以走
//先让箱子和箱子的下一步互换
string temp = map[y - , x];
map[y - , x] = map[y - , x];
map[y - , x] = temp;
temp = map[y, x];
map[y, x] = map[y - , x];
map[y - , x] = temp;
y--;//真正改变小人的位置
}
}
else if (map[y - , x] == " ")
{
//正常行走
string temp = map[y, x];
map[y, x] = map[y - , x];
map[y - , x] = temp;
y--;//真正改变小人的位置
}
}
}
//向下
else if (key.Key.ToString() == "DownArrow")
{
string temp = map[y, x];
map[y, x] = map[y + , x];
map[y + , x] = temp;
y++;//真正改变小人的位置
}
//向左
else if (key.Key.ToString() == "LeftArrow")
{
string temp = map[y, x];
map[y, x] = map[y, x - ];
map[y, x - ] = temp;
x--;//真正改变小人的位置
}
//向右
else if (key.Key.ToString() == "RightArrow")
{
//小人当前的位置与要去的下一步位置内容互换
if (map[y, x + ] == "■")//如果小人的下一步是墙,什么都不干
{
}
else //小人的下一步不是墙
{
if (map[y, x + ] == "□" && map[y, x + ] != "■")
{
//先让箱子和箱子的下一步互换
string temp = map[y, x + ];
map[y, x + ] = map[y, x + ];
map[y, x + ] = temp;
temp = map[y, x];
map[y, x] = map[y, x + ];
map[y, x + ] = temp;
x++;//真正改变小人的位置
}
else if (map[y, x + ] == " ")
{
//正常行走
string temp = map[y, x];
map[y, x] = map[y, x + ];
map[y, x + ] = temp;
x++;//真正改变小人的位置
}
}
}
} //是否胜利 Console.ReadKey();
Console.ReadKey();
}
}
}
对战游戏提纲,简单从操作:
namespace 对战游戏2._0
{
class Program
{
public struct ZhanShi
{
public string MingZi;
public int GongJi;
public int XueLiang;
} public struct JiNeng
{
public string MingCheng;
public double ShangHai;
} public struct WuQi
{
public string MingCheng;
public int GongJiLi;
} static void Main(string[] args)
{
Random ran = new Random(); #region 技能生成
ArrayList JiNengMen = new ArrayList();
JiNeng jn1 = new JiNeng();
jn1.MingCheng = "降龙十八掌";
jn1.ShangHai = ;
JiNeng jn2 = new JiNeng();
jn2.MingCheng = "佛山无影脚";
jn2.ShangHai = 1.5;
JiNeng jn3 = new JiNeng();
jn3.MingCheng = "如来神掌";
jn3.ShangHai = ;
JiNengMen.Add(jn1);
JiNengMen.Add(jn2);
JiNengMen.Add(jn3);
#endregion #region 生成武器库
WuQi wq1 = new WuQi();
wq1.MingCheng = "树枝";
wq1.GongJiLi = ;
WuQi wq2 = new WuQi();
wq2.MingCheng = "菜刀";
wq2.GongJiLi = ;
WuQi wq3 = new WuQi();
wq3.MingCheng = "圣剑";
wq3.GongJiLi = ;
#endregion #region 创建战士
ZhanShi zs1 = new ZhanShi();
Console.Write("请输入第一个战士的姓名:");
zs1.MingZi = Console.ReadLine();
zs1.GongJi = ran.Next(, );
zs1.XueLiang = ran.Next(, );
//100 10以下 圣剑 11~40 菜刀 41~90 树枝 91~100啥也没有
int HDWQ = ran.Next(, );
if (HDWQ <= )
{
Console.WriteLine(zs1.MingZi + "获得了武器:" + wq3.MingCheng);
zs1.GongJi += wq3.GongJiLi;
}
else if (HDWQ <= )
{
Console.WriteLine(zs1.MingZi + "获得了武器:" + wq2.MingCheng);
zs1.GongJi += wq2.GongJiLi;
}
else if (HDWQ <= )
{
Console.WriteLine(zs1.MingZi + "获得了武器:" + wq1.MingCheng);
zs1.GongJi += wq1.GongJiLi;
}
else
{
Console.WriteLine("嘿嘿嘿,啥也木有哇!");
}
Console.WriteLine("第一个战士:" + zs1.MingZi + ",攻击力:" + zs1.GongJi + ",血量:" + zs1.XueLiang); ZhanShi zs2 = new ZhanShi();
Console.Write("请输入第二个战士的姓名:");
zs2.MingZi = Console.ReadLine();
zs2.GongJi = ran.Next(, );
zs2.XueLiang = ran.Next(, ); HDWQ = ran.Next(, );
if (HDWQ <= )
{
Console.WriteLine(zs2.MingZi + "获得了武器:" + wq3.MingCheng);
zs2.GongJi += wq3.GongJiLi;
}
else if (HDWQ <= )
{
Console.WriteLine(zs2.MingZi + "获得了武器:" + wq2.MingCheng);
zs2.GongJi += wq2.GongJiLi;
}
else if (HDWQ <= )
{
Console.WriteLine(zs2.MingZi + "获得了武器:" + wq1.MingCheng);
zs2.GongJi += wq1.GongJiLi;
}
else
{
Console.WriteLine("嘿嘿嘿,啥也木有哇!");
} Console.WriteLine("第二个战士:" + zs2.MingZi + ",攻击力:" + zs2.GongJi + ",血量:" + zs2.XueLiang);
#endregion Console.WriteLine("请按任意键开始战斗!!!");
Console.ReadKey(); Console.ForegroundColor = ConsoleColor.White;
//对打
while (true)
{
int ShangHai = ; #region 第一个战士攻击
int SYJN = ran.Next(, );
if (SYJN <= )
{
JiNeng jn = (JiNeng)JiNengMen[ran.Next(, JiNengMen.Count)];
ShangHai = Convert.ToInt32(Program.PuTongGongJi(zs1.GongJi) * jn.ShangHai);
zs2.XueLiang = zs2.XueLiang - ShangHai; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(zs1.MingZi + " 对 " + zs2.MingZi + " 发动了☆☆☆" + jn.MingCheng + "☆☆☆,造成了" + ShangHai + "点伤害, " + zs2.MingZi + " 剩余" + zs2.XueLiang + "点血量!");
Console.WriteLine();
System.Threading.Thread.Sleep();
}
else
{
Console.ForegroundColor = ConsoleColor.White;
ShangHai = Program.PuTongGongJi(zs1.GongJi);
zs2.XueLiang = zs2.XueLiang - ShangHai;
Console.WriteLine(zs1.MingZi + " 对 " + zs2.MingZi + " 发动了普通攻击,造成了" + ShangHai + "点伤害, " + zs2.MingZi + " 剩余" + zs2.XueLiang + "点血量!");
Console.WriteLine();
System.Threading.Thread.Sleep();
}
#endregion #region 第二个战士攻击
SYJN = ran.Next(, );
if (SYJN <= )
{
JiNeng jn = (JiNeng)JiNengMen[ran.Next(, JiNengMen.Count)];
ShangHai = Convert.ToInt32(Program.PuTongGongJi(zs2.GongJi) * jn.ShangHai);
zs1.XueLiang = zs1.XueLiang - ShangHai; Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(zs2.MingZi + " 对 " + zs1.MingZi + " 发动了☆☆☆" + jn.MingCheng + "☆☆☆,造成了" + ShangHai + "点伤害, " + zs1.MingZi + " 剩余" + zs1.XueLiang + "点血量!");
Console.WriteLine();
System.Threading.Thread.Sleep();
}
else
{
Console.ForegroundColor = ConsoleColor.White;
ShangHai = Program.PuTongGongJi(zs2.GongJi);
zs1.XueLiang = zs1.XueLiang - ShangHai; Console.WriteLine(zs2.MingZi + " 对 " + zs1.MingZi + " 发动了普通攻击,造成了" + ShangHai + "点伤害, " + zs1.MingZi + " 剩余" + zs1.XueLiang + "点血量!");
Console.WriteLine(); System.Threading.Thread.Sleep();
}
#endregion #region 判断胜负
if (zs1.XueLiang <= || zs2.XueLiang <= )
{
if (zs1.XueLiang <= && zs2.XueLiang <= )
{
Console.WriteLine("二位同归于尽了!!!");
}
else
{
if (zs1.XueLiang <= )
{
Console.WriteLine(zs2.MingZi + "获得了最终胜利!!!");
}
else
{
Console.WriteLine(zs1.MingZi + "获得了最终胜利!!!");
}
}
break;
}
#endregion
} Console.ReadKey();
} /// <summary>
/// 生成普通攻击的浮动攻击值
/// </summary>
/// <param name="a">普通攻击的基础攻击力</param>
/// <returns></returns>
public static int PuTongGongJi(int a)
{
int cc = ;
Random r = new Random();
int aa = r.Next(, );
int bb = r.Next(, );
if (bb == )
{
cc = a + aa;
}
else
{
cc = a - aa;
}
return cc;
}
}
}