C#飞行棋游戏
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace _05.飞行棋游戏
{
class Program
{
//用静态字段来模拟全局变量
static int[] Maps = new int[];
//声明一个静态数组来存储玩家A和玩家B的坐标
static int[] PlayerPos = new int[];
//存储两个玩家的姓名
static string[] PlayerNames = new string[]; static void Main(string[] args)
{
//1.画游戏头
//2.初始化地图(加载地图所需要的资源)
//将整数数组中的数字编成控制台中显示的特殊字符串的过程--初始化地图
//3.画地图
//4.玩游戏
GameShow();
#region 玩家姓名输入
Console.WriteLine("请输入玩家A的姓名");
PlayerNames[] = Console.ReadLine();
while (PlayerNames[] == "")
{
Console.WriteLine("玩家A的姓名不能为空,请重新输入");
PlayerNames[] = Console.ReadLine();
} Console.WriteLine("请输入玩家B的姓名");
PlayerNames[] = Console.ReadLine();
while (PlayerNames[] == "" || PlayerNames[] == PlayerNames[])
{
if (PlayerNames[] == "")
{
Console.WriteLine("玩家B的姓名不能为空,请重新输入");
PlayerNames[] = Console.ReadLine();
}
else
{
Console.WriteLine("玩家B的姓名不能和玩家A的姓名相同,请重新输入");
PlayerNames[] = Console.ReadLine();
}
}
#endregion //玩家输入姓名OK后,首先应该清屏
Console.Clear();//清屏
GameShow();
Console.WriteLine("{0}的士兵用A表示", PlayerNames[]);
Console.WriteLine("{0}的士兵用B表示", PlayerNames[]); InitailMap();
DrawMap(); //玩家A和玩家B都没到终点,游戏继续
while (PlayerPos[] < && PlayerPos[] < )
{
Console.WriteLine("{0}按任意键开始掷骰子", PlayerNames[]);
Console.ReadKey(true);
Console.WriteLine("{0}掷出了4",PlayerNames[]);
PlayerPos[] += ;
Console.ReadKey(true);
Console.WriteLine("{0}按任意键开始行动",PlayerNames[]);
Console.ReadKey(true);
Console.WriteLine("{0}行动完了",PlayerNames[]);
Console.ReadKey(true);
//玩家A有可能踩到了玩家B、方块、幸运轮盘、地雷、暂停、时空隧道
if (PlayerPos[]==PlayerPos[])
{
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退6格",PlayerNames[],PlayerNames[],PlayerNames[]);
PlayerPos[] -= ;
Console.ReadKey(true);
}
else//踩到关卡
{
//玩家坐标 switch (Maps[PlayerPos[]])//0 1 2 3 4
{
case :Console.WriteLine("玩家{0}踩到了方块,安全", PlayerNames[]);
Console.ReadKey(true);
break;
case :Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择:1--交换位置;2--轰炸对方退6格",PlayerNames[]);
string input = Console.ReadLine();
Console.ReadKey(true);
break;
}
}
} Console.ReadKey();
} /// <summary>
/// 画游戏头
/// </summary>
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("*************************************************************");
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("*************************************************************");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("*************************************************************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("**********************飞行棋游戏*****************************");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("*************************************************************");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("*************************************************************");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("*************************************************************");
} /// <summary>
/// 初始化地图
/// </summary>
public static void InitailMap()
{
int[] luckyturn = { , , , , , };//幸运轮盘○
for (int i = ; i < luckyturn.Length; i++)
{
Maps[luckyturn[i]] = ;
} int[] landMine = { , , , , , , , , };//地雷☆
for (int i = ; i < landMine.Length; i++)
{
Maps[landMine[i]] = ;
} int[] pause = { , , , };//暂停△
for (int i = ; i < pause.Length; i++)
{
Maps[pause[i]] = ;
} int[] timeTunnel = { , , , , , , };//时空隧道##
for (int i = ; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = ;
}
} /// <summary>
/// 画地图
/// </summary>
public static void DrawMap()
{
Console.WriteLine("图例:幸运轮盘:○ 地雷:☆ 暂停:△ 时空隧道:##"); //第一横行
for (int i = ; i < ; i++)
{
Console.Write(DrowStringMap(i));
} //画完第一横行后应该换行
Console.WriteLine(); //第一竖行
for (int i = ; i < ; i++)
{
for (int j = ; j <= ; j++)
{
Console.Write(" ");
}
Console.Write(DrowStringMap(i));
Console.WriteLine();
} //第一横行:倒序
for (int i = ; i >= ; i--)
{
Console.Write(DrowStringMap(i));
} //画完第二横行后应该换行
Console.WriteLine(); //第二竖行
for (int i = ; i <= ; i++)
{
Console.WriteLine(DrowStringMap(i));
} //第二横行
for (int i = ; i <= ; i++)
{
Console.Write(DrowStringMap(i));
} //画完最后一行应该换行
Console.WriteLine(); } /// <summary>
/// 从画地图方法中抽象出来的方法
/// </summary>
/// <param name="i">地图中的位置</param>
/// <returns>要打印的字符串</returns>
public static string DrowStringMap(int i)
{
//声明str接收要打印的值
string str = "";
//玩家A和玩家B的坐标相同,并且都在地图上,则画<>
if (PlayerPos[] == PlayerPos[] && PlayerPos[] == i)
{
str = "<>";
}
else if (PlayerPos[] == i)
{
str = "A";
}
else if (PlayerPos[] == i)
{
str = "B";
}
else
{
switch (Maps[i])
{
case :
Console.ForegroundColor = ConsoleColor.Yellow;
str = "□";
break;
case :
Console.ForegroundColor = ConsoleColor.Green;
str = "○";
break;
case :
Console.ForegroundColor = ConsoleColor.Red;
str = "☆";
break;
case :
Console.ForegroundColor = ConsoleColor.Blue;
str = "△";
break;
case :
Console.ForegroundColor = ConsoleColor.DarkCyan;
str = "##";
break;
}
} return str;
}
}
}
C#飞行棋游戏的更多相关文章
- IT第十一天、第十二天、第十三天 - 数组的应用、飞行棋游戏的编写和总结
NIIT第十一天 上午 多维数组 1.数组是引用数据类型 排序 1.冒泡排序法 2.类冒泡排序法 下午 飞行棋游戏 1.项目策划 2.项目规则确认 3.项目模块确认 晚上 1.飞行棋游戏,项目框架的编 ...
- C#基础:飞行棋游戏
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- c#控制台玩飞行棋游戏
using System; namespace Game{ class Program { //用静态字段模拟全局变量 public static int[] Maps = new int[100]; ...
- hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 浙江工商大学15年校赛E题 无邪的飞行棋 【经典背包】
无邪的飞行棋 Time Limit 1s Memory Limit 64KB Judge Program Standard Ratio(Solve/Submit) 15.38%(4/26) Descr ...
- C#小程序呢飞行棋设计分析
C#小程序飞行棋,程序效果图 1.设计分析 这个程序界面大致分为四部分: ① 最上面游戏名字界面 ②信息提示区 ③游戏界面区 ④游戏操作提示区 2.分区设计实现 一.游戏界面显示区,由于只需要显示出图 ...
- 骑士飞行棋 C#代码详解
最近看见一个骑士飞行棋的小游戏代码,感觉这个代码中将大多数C#的基础知识都运用到了,是一个新手检验学习成果的有效方法,特此将这个代码整理一遍.这是一个控制台程序.这是代码下载地址,代码中的注释非常详细 ...
- 编写一个飞行棋项目(C#)遇到几个问题:
在写程序中遇到如下问题:如果有人知道,请您一定要指点迷津.小白. 1.在运行暂停功能时,这个暂停功能可以实现,但是无法显示提示信息. case 3: Console.Clear(); Program. ...
- C#基础篇六飞行棋
飞行棋业务:我们要能够让2个玩家 在地图上 按照游戏规则 进行游戏 玩家类 变量:玩家位置,玩家名称,玩家标识,玩家是否在陷阱中 方法:投骰子,移动 地图类 变量:地图数据数组 方法:初始化地图数据, ...
随机推荐
- html5本地存储之localstorage 、本地数据库、sessionStorage简单使用示例
这篇文章主要介绍了html5本地存储的localstorage .本地数据库.sessionStorage简单使用示例,需要的朋友可以参考下 html5的一个非常cool的功能,就是web stora ...
- JSP 调试
要测试/调试一个JSP或servlet程序总是那么的难.JSP和Servlets程序趋向于牵涉到大量客户端/服务器之间的交互,这很有可能会产生错误,并且很难重现出错的环境. 接下来将会给出一些小技巧和 ...
- MVC 后台调用JS
示例控制器: public ActionResult Index() { ViewBag.js = "<script type='text/java ...
- iOS Layout机制相关方法
iOS Layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size - (void)sizeToFit ——————- - (void)layoutSubview ...
- linux中的redis缓存服务器
Linux中的Redis缓存服务器 一.Redis基础部分: 1.redis介绍与安装比mysql快10倍以上 *****************redis适用场合**************** 1 ...
- LeetCode OJ:House Robber II(房屋窃贼II)
After robbing those houses on that street, the thief has found himself a new place for his thievery ...
- 通过ping 主机名,或者主机名对应的IP地址
通过ping 主机名,或者主机名对应的IP地址: 如下图: 懵了吧? 但是你用 ping 主机名 -4
- JavaWeb过滤器——登录过滤
一般来说简单且常用的过滤器使用方法,我觉得除了配置字符编码的过滤之外就是登录器的过滤了 登录过滤器的主要过程可以 一句话来概括:首先在登录的时候把指定好的标志放在session中,操作过滤的时候根据s ...
- web服务器无法显示font-awesome字体图标
今天遇到了在本地运行网页 一切调用的额font的小图标都OK的,但是把网页发布到tomcat服务器上面就不行了 之后百度了下,找到了解决方法,遂记录下,方法如下: 在web.xml 文件中加上: &l ...
- 利用 squid 反向代理提高网站性能(转载)
本文在介绍 squid 反向代理的工作原理的基础上,指出反向代理技术在提高网站访问速度,增强网站可用性.安全性方面有很好的用途.作者在具体的实验环境下,利用 DNS 轮询和 Squid 反向代理技术, ...