C# 推箱子游戏&对战游戏
推箱子游戏提纲,只有向右向上的操作,向左向下同理,后期需完善。
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;
}
}
}
C# 推箱子游戏&对战游戏的更多相关文章
- C++学习(九)(C语言部分)之 项目 推箱子游戏
游戏制作 推箱子 步骤分析 1.模板 2.模板分析 组成元素: 空地 墙 人 目的地 箱子 背景 3.如何操作 通过WASD键盘操作人,推着箱子,到达目的地,游戏结束,如果箱子卡在死角则游戏失败 4. ...
- 推箱子 BFS
[编程题] 推箱子 大家一定玩过“推箱子”这个经典的游戏.具体规则就是在一个N*M的地图上,有1个玩家.1个箱子.1个目的地以及若干障碍,其余是空地.玩家可以往上下左右4个方向移动,但是不能移动出地图 ...
- c#部分---网吧充值系统;简易的闹钟;出租车计费;简单计算器;对战游戏;等额本金法计算贷款还款利息等;随机生成10个不重复的50以内的整数;推箱子;
网吧充值系统namespace ConsoleApplication1 { class Program { struct huiyuan { public string name; public st ...
- VS 游戏:推箱子&对战游戏
推箱子 //只做了两关 class Program { static void Main(string[] args) { ; ; ; ; ; ; ; #region 地图绘制 , , ] { { { ...
- c语言游戏推箱子
前两天做了推箱子小游戏,看似简单的一个小游戏背后却 有巨大的秘密,这秘密就是一大堆逻辑. 自从学习了函数过后,的确是解决了很多问题,而且调用很方便,尽管我现在都不是很会调用. 写完一个函数,准备测试一 ...
- JavaScript写一个小乌龟推箱子游戏
推箱子游戏是老游戏了, 网上有各种各样的版本, 说下推箱子游戏的简单实现,以及我找到的一些参考视频和实例: 推箱子游戏的在线DEMO : 打开 如下是效果图: 这个拖箱子游戏做了移动端的适配, 我使用 ...
- 用C#制作推箱子小游戏
思路分析: 一.制作一个地图 二.地图中放置墙.箱子.人.目标等 三.让小人动起来完成推箱子动作 游戏制作: 1.按照上述地图制作一个地图 (12行×13列) 地图可以看做是行和列组成的,即可以看做 ...
- [转]Flash ActionScript2.0面向对象游戏开发-推箱子
本文转自:http://www.alixixi.com/Dev/W3C/Flash/2007/2007070868666.html 概述: Flash ActionScript2.0是一种面向对向的编 ...
- c++、c实现推箱子小游戏
经过四次的修改和优化,终于将推箱子这个游戏完整的写出来了,今天就像大家分享一下这个游戏的编写. 这个游戏界面的编写总的来说不困难,主要是推动箱子的算法. (1)利用数组和windows api 即可写 ...
随机推荐
- FreeRTOS 任务与调度器(2)
在上一篇我们介绍了FreeRTOS任务的一些基本操作和功能,今天我们会介绍一个很好很强大的功能——任务通知 任务通知可以在不同任务之间传递信息,它可以取代二值信号量.计数信号量.事件标志组.深度为1的 ...
- Name方法
重命名磁盘文件.目录或文件夹. 语法 Name 旧路径名称 As 新路径名称 “Name”**** 语句语法包含以下部分: 部分 说明 旧路径名称 必需. 字符串表达式,指定现有的文件名和位置;可能包 ...
- Centos下分布式跟踪工具Pinpoint的完整部署记录
一.Pinpoint简单介绍Pinpoint是一款对Java编写的大规模分布式系统的APM工具,有些人也喜欢称呼这类工具为调用链系统.分布式跟踪系统.一般来说,前端向后台发起一个查询请求,后台服务可能 ...
- android studio报Resolved versions for app (26.1.0) and test app (27.1.1)differ. 错误的解决办法
https://blog.csdn.net/qq_36636969/article/details/80278150
- 跟踪分析Linux内核的启动过程--实验报告 分析 及知识重点
跟踪分析Linux内核的启动过程 攥写人:杨光 学号:20135233 ( *原创作品转载请注明出处*) ( 学习课程:<Linux内核分析>MOOC课程http://mooc.stud ...
- Linux内核总结博客 20135332武西垚
http://www.cnblogs.com/wuxiyao/p/5220677.htmlhttp://www.cnblogs.com/wuxiyao/p/5247571.htmlhttp://www ...
- 开源通用爬虫框架YayCrawler-框架的运行机制
这一节我将向大家介绍一下YayCrawler的运行机制,首先允许我上一张图: 首先各个组件的启动顺序建议是Master.Worker.Admin,其实不按这个顺序也没关系,我们为了讲解方便假定是这个启 ...
- 常用的查询DOM的方法
查询body的方法=========== document.body // document.getElementsTagname("body")[0]; 查询html的方法=== ...
- java中的随机数Random
java中一般有两种随机数,一个是Math中random()方法,一个是Random类. 一.Math.random() : 随即生成0<x<1的小数 实例:如何写,生成随机生成 ...
- [CB]IPv6 在中国 - 大规模部署进行中 进展明显
IPv6 在中国 - 大规模部署进行中 进展明显 2019年02月04日 08:21 3078 次阅读 稿源:solidot 0 条评论 中国有着世界上最大的网民人口,但它的 IPv6 普及度却处于世 ...