• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#推箱子游戏&对战游戏

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

推箱子游戏提纲,只有向右向上的操作,向左向下同理,后期需完善。

  1 namespace 推箱子
  2 {
  3     class Program
  4     {
  5         static void Main(string[] args)
  6         {
  7             //小人初始位置的索引
  8             int x = 1;
  9             int y = 8;
 10 
 11             int end1x = 7;
 12             int end1y = 1;
 13 
 14             #region 画地图
 15             string[,] map = new string[10, 10] {
 16             {" "," ","","","","","","","",""},
 17             {" "," ",""," "," "," "," ",""," ",""},
 18             {"","",""," "," "," "," "," "," ",""},
 19             {""," "," "," "," "," "," "," "," ",""},
 20             {""," "," "," "," "," "," "," "," ",""},
 21             {""," "," ",""," "," "," "," "," ",""},
 22             {""," "," "," "," "," ","","","",""},
 23             {""," "," "," "," "," ",""," "," "," "},
 24             {"",""," "," "," "," ",""," "," "," "},
 25             {"","","","","","",""," "," "," "},
 26             };
 27             #endregion
 28 
 29             while (true)
 30             {
 31                 Console.Clear();//清空掉所有已经打印的内容
 32                 #region 打印地图
 33                 for (int i = 0; i < 10; i++)
 34                 {
 35                     for (int j = 0; j < 10; j++)
 36                     {
 37                         Console.Write(map[i, j]);
 38                     }
 39                     Console.WriteLine();
 40                 }
 41                 #endregion
 42 
 43                 if (map[end1y, end1x] == "")
 44                 {
 45                     Console.WriteLine("恭喜过关");
 46                     break;
 47                 }
 48 
 49                 ConsoleKeyInfo key = Console.ReadKey();
 50                 //向上
 51                 if (key.Key.ToString() == "UpArrow")
 52                 {
 53                     //小人当前的位置与要去的下一步位置内容互换
 54                     if (map[y - 1, x] == "")//如果小人的下一步是墙,什么都不干
 55                     {
 56                     }
 57                     else //小人的下一步不是墙
 58                     {
 59                         if (map[y - 1, x] == "" && map[y - 2, x] != "")
 60                         {
 61                             if (map[y - 2, x] == "")
 62                             {
 63                                 //箱子的下一步是目标点,让箱子填满目标点
 64                                 map[y - 2, x] = "";
 65                                 map[y - 1, x] = " ";
 66                                 string temp = map[y, x];
 67                                 map[y, x] = map[y - 1, x];
 68                                 map[y - 1, x] = temp;
 69                                 y--;//真正改变小人的位置
 70                             }
 71                             else if (map[y - 2, x] == " ")
 72                             {
 73                                 //推着箱子走,箱子的下一步是空地才可以走
 74                                 //先让箱子和箱子的下一步互换
 75                                 string temp = map[y - 1, x];
 76                                 map[y - 1, x] = map[y - 2, x];
 77                                 map[y - 2, x] = temp;
 78                                 temp = map[y, x];
 79                                 map[y, x] = map[y - 1, x];
 80                                 map[y - 1, x] = temp;
 81                                 y--;//真正改变小人的位置
 82                             }
 83                         }
 84                         else if (map[y - 1, x] == " ")
 85                         {
 86                             //正常行走
 87                             string temp = map[y, x];
 88                             map[y, x] = map[y - 1, x];
 89                             map[y - 1, x] = temp;
 90                             y--;//真正改变小人的位置
 91                         }
 92                     }
 93                 }
 94                 //向下
 95                 else if (key.Key.ToString() == "DownArrow")
 96                 {
 97                     string temp = map[y, x];
 98                     map[y, x] = map[y + 1, x];
 99                     map[y + 1, x] = temp;
100                     y++;//真正改变小人的位置
101                 }
102                 //向左
103                 else if (key.Key.ToString() == "LeftArrow")
104                 {
105                     string temp = map[y, x];
106                     map[y, x] = map[y, x - 1];
107                     map[y, x - 1] = temp;
108                     x--;//真正改变小人的位置
109                 }
110                 //向右
111                 else if (key.Key.ToString() == "RightArrow")
112                 {
113                     //小人当前的位置与要去的下一步位置内容互换
114                     if (map[y, x + 1] == "")//如果小人的下一步是墙,什么都不干
115                     {
116                     }
117                     else //小人的下一步不是墙
118                     {
119                         if (map[y, x + 1] == "" && map[y, x + 2] != "")
120                         {
121                             //先让箱子和箱子的下一步互换
122                             string temp = map[y, x + 1];
123                             map[y, x + 1] = map[y, x + 2];
124                             map[y, x + 2] = temp;
125                             temp = map[y, x];
126                             map[y, x] = map[y, x + 1];
127                             map[y, x + 1] = temp;
128                             x++;//真正改变小人的位置
129                         }
130                         else if (map[y, x + 1] == " ")
131                         {
132                             //正常行走
133                             string temp = map[y, x];
134                             map[y, x] = map[y, x + 1];
135                             map[y, x + 1] = temp;
136                             x++;//真正改变小人的位置
137                         }
138                     }
139                 }
140             }
141 
142 
143             //是否胜利
144 
145             Console.ReadKey();
146             Console.ReadKey();
147         }
148     }
149 }

 对战游戏提纲,简单从操作:

  1 namespace 对战游戏2._0
  2 {
  3     class Program
  4     {
  5         public struct ZhanShi
  6         {
  7             public string MingZi;
  8             public int GongJi;
  9             public int XueLiang;
 10         }
 11 
 12         public struct JiNeng
 13         {
 14             public string MingCheng;
 15             public double ShangHai;
 16         }
 17 
 18         public struct WuQi
 19         {
 20             public string MingCheng;
 21             public int GongJiLi;
 22         }
 23 
 24 
 25         static void Main(string[] args)
 26         {
 27             Random ran = new Random();
 28 
 29             #region 技能生成
 30             ArrayList JiNengMen = new ArrayList();
 31             JiNeng jn1 = new JiNeng();
 32             jn1.MingCheng = "降龙十八掌";
 33             jn1.ShangHai = 2;
 34             JiNeng jn2 = new JiNeng();
 35             jn2.MingCheng = "佛山无影脚";
 36             jn2.ShangHai = 1.5;
 37             JiNeng jn3 = new JiNeng();
 38             jn3.MingCheng = "如来神掌";
 39             jn3.ShangHai = 3;
 40             JiNengMen.Add(jn1);
 41             JiNengMen.Add(jn2);
 42             JiNengMen.Add(jn3);
 43             #endregion
 44 
 45             #region 生成武器库
 46             WuQi wq1 = new WuQi();
 47             wq1.MingCheng = "树枝";
 48             wq1.GongJiLi = 50;
 49             WuQi wq2 = new WuQi();
 50             wq2.MingCheng = "菜刀";
 51             wq2.GongJiLi = 200;
 52             WuQi wq3 = new WuQi();
 53             wq3.MingCheng = "圣剑";
 54             wq3.GongJiLi = 500;
 55             #endregion
 56 
 57             #region 创建战士
 58             ZhanShi zs1 = new ZhanShi();
 59             Console.Write("请输入第一个战士的姓名:");
 60             zs1.MingZi = Console.ReadLine();
 61             zs1.GongJi = ran.Next(100, 201);
 62             zs1.XueLiang = ran.Next(2000, 4000);
 63             //100  10以下 圣剑  11~40 菜刀  41~90 树枝  91~100啥也没有
 64             int HDWQ = ran.Next(1, 101);
 65             if (HDWQ <= 10)
 66             {
 67                 Console.WriteLine(zs1.MingZi + "获得了武器:" + wq3.MingCheng);
 68                 zs1.GongJi += wq3.GongJiLi;
 69             }
 70             else if (HDWQ <= 40)
 71             {
 72                 Console.WriteLine(zs1.MingZi + "获得了武器:" + wq2.MingCheng);
 73                 zs1.GongJi += wq2.GongJiLi;
 74             }
 75             else if (HDWQ <= 90)
 76             {
 77                 Console.WriteLine(zs1.MingZi + "获得了武器:" + wq1.MingCheng);
 78                 zs1.GongJi += wq1.GongJiLi;
 79             }
 80             else
 81             {
 82                 Console.WriteLine("嘿嘿嘿,啥也木有哇!");
 83             }
 84             Console.WriteLine("第一个战士:" + zs1.MingZi + ",攻击力:" + zs1.GongJi + ",血量:" + zs1.XueLiang);
 85 
 86             ZhanShi zs2 = new ZhanShi();
 87             Console.Write("请输入第二个战士的姓名:");
 88             zs2.MingZi = Console.ReadLine();
 89             zs2.GongJi = ran.Next(100, 201);
 90             zs2.XueLiang = ran.Next(500, 2000);
 91 
 92             HDWQ = ran.Next(1, 101);
 93             if (HDWQ <= 10)
 94             {
 95                 Console.WriteLine(zs2.MingZi + "获得了武器:" + wq3.MingCheng);
 96                 zs2.GongJi += wq3.GongJiLi;
 97             }
 98             else if (HDWQ <= 40)
 99             {
100                 Console.WriteLine(zs2.MingZi + "获得了武器:" + wq2.MingCheng);
101                 zs2.GongJi += wq2.GongJiLi;
102             }
103             else if (HDWQ <= 90)
104             {
105                 Console.WriteLine(zs2.MingZi + "获得了武器:" + wq1.MingCheng);
106                 zs2.GongJi += wq1.GongJiLi;
107             }
108             else
109             {
110                 Console.WriteLine("嘿嘿嘿,啥也木有哇!");
111             }
112 
113 
114             Console.WriteLine("第二个战士:" + zs2.MingZi + ",攻击力:" + zs2.GongJi + ",血量:" + zs2.XueLiang);
115             #endregion
116 
117             Console.WriteLine("请按任意键开始战斗!!!");
118             Console.ReadKey();
119 
120             Console.ForegroundColor = ConsoleColor.White;
121             //对打
122             while (true)
123             {
124                 int ShangHai = 0;
125 
126                 #region 第一个战士攻击
127                 int SYJN = ran.Next(1, 11);
128                 if (SYJN <= 3)
129                 {
130                     JiNeng jn = (JiNeng)JiNengMen[ran.Next(0, JiNengMen.Count)];
131                     ShangHai = Convert.ToInt32(Program.PuTongGongJi(zs1.GongJi) * jn.ShangHai);
132                     zs2.XueLiang = zs2.XueLiang - ShangHai;
133 
134                     Console.ForegroundColor = ConsoleColor.Green;
135                     Console.WriteLine(zs1.MingZi + "" + zs2.MingZi + " 发动了☆☆☆" + jn.MingCheng + "☆☆☆,造成了" + ShangHai + "点伤害, " + zs2.MingZi + " 剩余" + zs2.XueLiang + "点血量!");
136                     Console.WriteLine();
137                     System.Threading.Thre 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#调用系统API内核简单样例发布时间:2022-07-10
下一篇:
C#xmlhttp发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap