C#基础:飞行棋游戏
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace Pachee
{
class Program
{
#region 静态字段
// 关卡数量
public static int[] Maps = new int[];
// 玩家坐标
public static int[] PlayerPos = new int[];
// 玩家名称
public static string[] PlayerNames = new string[];
// 判断玩家是否暂停
public static bool[] Flags = new bool[];
#endregion /// <summary>
/// 输出游戏头
/// </summary>
public static void ShowGame()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("****************************");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("****************************");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("***C#基础练习:飞行棋项目***");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("****************************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("****************************");
}
/// <summary>
/// 接受用户输入的游戏名称,判断是否合法
/// </summary>
/// <returns>游戏名称</returns>
public static string[] InputPlayerNames()
{
PlayerNames[] = "";
PlayerNames[] = "";
Console.ForegroundColor = ConsoleColor.White;
while (PlayerNames[] == "")
{
Console.Write("Please enter the name of game A player: ");
PlayerNames[] = Console.ReadLine().Trim();
if (PlayerNames[] == "")
{
Console.WriteLine("A player name cannot be empty, please enter again.");
continue;
}
break;
}
while (PlayerNames[] == "" || PlayerNames[] == PlayerNames[])
{
Console.Write("Please enter the name of game B player: ");
PlayerNames[] = Console.ReadLine().Trim();
if (PlayerNames[] == "")
{
Console.WriteLine("B player name cannot be empty, please enter again.");
continue;
}
else if (PlayerNames[] == PlayerNames[])
{
Console.WriteLine("The player name cannot be the same as the player A B, please enter again.");
continue;
}
break;
}
return PlayerNames;
}
/// <summary>
/// 初始化地图,改变默认的地图坐标类型
/// 0:方块
/// 1:轮盘
/// 2:地雷
/// 3:暂停
/// 4:隧道
/// </summary>
public static void InitailMap()
{
#region 轮盘
int[] luckTrun = { , , , , , };
for (int i = ; i < luckTrun.Length; i++)
{
Maps[luckTrun[i]] = ;
}
#endregion #region 地雷
int[] landMine = { , , , , , , , , };
for (int i = ; i < landMine.Length; i++)
{
Maps[landMine[i]] = ;
}
#endregion #region 暂停
int[] pause = { , , , };
for (int i = ; i < pause.Length; i++)
{
Maps[pause[i]] = ;
}
#endregion #region 隧道
int[] timeTunnel = { , , , , , , };
for (int i = ; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = ;
}
#endregion
}
/// <summary>
/// 设定当前坐标的类型
/// </summary>
/// <param name="i">坐标</param>
/// <returns>坐标类型</returns>
public static string DrawStringMap(int i)
{
string str = null;
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.Blue;
str = "◎";
break;
case :
Console.ForegroundColor = ConsoleColor.Green;
str = "☆";
break;
case :
Console.ForegroundColor = ConsoleColor.Red;
str = "▲";
break;
case :
Console.ForegroundColor = ConsoleColor.Cyan;
str = "卐";
break;
}
}
return str;
}
/// <summary>
/// 生成所有坐标
/// </summary>
public static void DrawMap()
{
Console.WriteLine("Legend: LuckTrun<◎> landMine<☆> Pause<▲> timeTunnel<卐>"); #region 第一橫行
for (int i = ; i < ; i++)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion #region 第一竖行
for (int i = ; i < ; i++)
{
for (int j = ; j <= ; j++)
{
Console.Write(" ");
}
Console.Write(DrawStringMap(i));
Console.WriteLine();
}
#endregion #region 第二橫行
for (int i = ; i >= ; i--)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion #region 第二竖行
for (int i = ; i < ; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion #region 第三橫行
for (int i = ; i <= ; i++)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion
}
/// <summary>
/// 判断坐标是否超出范围
/// </summary>
public static void ChangePos()
{
#region Player A
if (PlayerPos[] < )
{
PlayerPos[] = ;
}
if (PlayerPos[] > )
{
PlayerPos[] = ;
}
#endregion #region Player B
if (PlayerPos[] < )
{
PlayerPos[] = ;
}
if (PlayerPos[] > )
{
PlayerPos[] = ;
}
#endregion
}
/// <summary>
/// 踩到轮盘时,选择功能
/// </summary>
/// <param name="input">玩家的选择</param>
/// <param name="player">玩家标示</param>
public static void PlayerSelect(string input, int player)
{
while (true)
{
if (input == "")
{
Console.WriteLine("Player {0} select and {1} swap places.", PlayerNames[player], PlayerNames[ - player]);
int temp = PlayerPos[player];
PlayerPos[player] = PlayerPos[ - player];
PlayerPos[ - player] = temp;
Console.WriteLine("Swap complete, press any key continue.");
Console.ReadKey(true);
break;
}
else if (input == "")
{
Console.WriteLine("Player {0} select bombing {1}, Player {2} back to 6.", PlayerNames[player], PlayerNames[ - player], PlayerNames[ - player]);
PlayerPos[ - player] -= ;
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("Can only select: 1--Swap places 2--bombing: ");
input = Console.ReadLine();
}
}
}
/// <summary>
/// 进行游戏
/// </summary>
/// <param name="player">玩家标示位</param>
public static void PlayGame(int player)
{
Random r = new Random();
int next = r.Next(, );
Console.WriteLine("{0} press any key to start rolling the dice.", PlayerNames[player]);
Console.ReadKey(true);
Console.WriteLine("{0} Throw out of {1}", PlayerNames[player], next);
PlayerPos[player] += next;
ChangePos();
Console.ReadKey(true);
Console.WriteLine("{0} press any key to start action.", PlayerNames[player]);
Console.ReadKey(true);
Console.WriteLine("{0} action complete.", PlayerNames[player]);
Console.ReadKey(true);
// Player A 有可能踩到: Player B、方块、轮盘、地雷、暂停、隧道
if (PlayerPos[player] == PlayerPos[ - player])
{
Console.WriteLine("Player {0} step on {1}, {2} back to 6.", PlayerNames[player], PlayerNames[ - player], PlayerNames[ - player]);
PlayerPos[ - player] -= ;
Console.ReadKey(true);
}
else
{
switch (Maps[PlayerPos[player]])
{
case :
Console.WriteLine("Player {0} step on Square, safe.", PlayerNames[player]);
Console.ReadKey(true);
break;
case :
Console.WriteLine("Player {0} step on a LuckTrun, please select: 1--Swap places 2--bombing: ", PlayerNames[player]);
string input = Console.ReadLine().Trim();
PlayerSelect(input, player);
Console.ReadKey(true);
break;
case :
Console.WriteLine("Player {0} step on a LandMine, back to 6", PlayerNames[player]);
PlayerPos[player] -= ;
Console.ReadKey(true);
break;
case :
Console.WriteLine("Player {0} step on a Pause, to suspend a round.", PlayerNames[player]);
Console.ReadKey(true);
Flags[player] = true;
break;
case :
Console.WriteLine("Player {0} step on a TimeTunnel, forward 10.", PlayerNames[player]);
PlayerPos[player] += ;
Console.ReadKey();
break;
}
}
ChangePos();
Console.Clear();
DrawMap();
}
static void Main(string[] args)
{
ShowGame();
InputPlayerNames();
Console.WriteLine("Player {0} is A.", PlayerNames[]);
Console.WriteLine("Player {0} is B.", PlayerNames[]);
InitailMap();
DrawMap(); while (PlayerPos[] < && PlayerPos[] < )
{
#region A
if (Flags[] == false)
{
PlayGame();
}
else
{
Flags[] = false;
}
#endregion
#region B
if (Flags[] == false)
{
PlayGame();
}
else
{
Flags[] = false;
}
#endregion
}
#region 判断玩家胜利 if (PlayerPos[] == )
{
Console.Clear();
Console.WriteLine("Player {0} Win.", PlayerNames[]);
}
if (PlayerPos[] == )
{
Console.Clear();
Console.WriteLine("Player {0} Win.", PlayerNames[]);
}
#endregion Console.ReadKey();
}
}
}
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#基础篇六飞行棋
飞行棋业务:我们要能够让2个玩家 在地图上 按照游戏规则 进行游戏 玩家类 变量:玩家位置,玩家名称,玩家标识,玩家是否在陷阱中 方法:投骰子,移动 地图类 变量:地图数据数组 方法:初始化地图数据, ...
- 骑士飞行棋 C#代码详解
最近看见一个骑士飞行棋的小游戏代码,感觉这个代码中将大多数C#的基础知识都运用到了,是一个新手检验学习成果的有效方法,特此将这个代码整理一遍.这是一个控制台程序.这是代码下载地址,代码中的注释非常详细 ...
- C#小程序呢飞行棋设计分析
C#小程序飞行棋,程序效果图 1.设计分析 这个程序界面大致分为四部分: ① 最上面游戏名字界面 ②信息提示区 ③游戏界面区 ④游戏操作提示区 2.分区设计实现 一.游戏界面显示区,由于只需要显示出图 ...
- HTML5+JS 《五子飞》游戏实现(三)页面和棋盘棋子
前面两节,我们已经对<五子飞>有个初步的认识,对走棋路线也有了基本的了解,现在里沃特继续跟大家分享HTML页面,另外把棋盘棋子也画出来. 演示地址:http://www.lyout.com ...
随机推荐
- javascript代码 调试方法
你的代码可能包含语法错误,逻辑错误,如果没有调试工具,这些错误比较难于发现. 通常,如果 JavaScript 出现错误,是不会有提示信息,这样你就无法找到代码错误的位置. 在程序代码中寻找错误叫做代 ...
- ARCGIS SDE空间化处理
在 Oracle 中,ST_Geometry 和 ST_Raster 的 SQL 函数使用通过 Oracle 的外部过程代理(即 extproc)访问的共享库.要将 SQL 和 ST_Geometry ...
- webView 自适应高度 document.body 属性
前段时间开发遇到webView 高度自适应问题,用最初的方法无效,找了些资料,记录下. 1.若网页中含有< !DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...
- (十四)Maven聚合与继承
1.Maven聚合 我们在平时的开发中,项目往往会被划分为好几个模块,比如common公共模块.system系统模块.log日志模块.reports统计模块.monitor监控模块等等.这时我们肯定会 ...
- c#批量插入数据库Demo
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- SQL server学习
慕课网sql server学习 数据库第一印象:desktop--web server--database server** 几大数据库:sql server.oracle database.DB2. ...
- 解决ie6下li左浮动文字换行的问题
问题: 使用li左浮动来自动换行,当父标签剩下宽度不够一个li的宽度时,在ie6中最后一个li中的文字出现换行 解决办法: ul{ white-space:nowrap;} /*强制文字不换行*/
- Linux系统下面挂载u盘
1.先插好u盘到Linux服务器,然后查看u盘挂载到哪个目录下面. [root@localhost ~]# /sbin/fdisk -l 2.挂载到u目录下面 [root@localhost ~]# ...
- 浏览器控制台js代码与后台不同步
原因:浏览器会缓存js 如果是将js代码直接通过<script>标签插入jsp页面中则不存在这个问题 在加载页面的时候会重新加载js代码 如果直接将js代码以文件的形式引入,那么每次在修改 ...
- php在5.5.0默认提供了Zend OPcache
eaccelerator无法兼容php5.5.0,好在php在5.5.0默认提供了Zend OPcache,所以一直习惯eaccelerator的朋友如果要升级到php5.5.0的话,可能要暂时和ea ...