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#飞行棋游戏的更多相关文章

  1. IT第十一天、第十二天、第十三天 - 数组的应用、飞行棋游戏的编写和总结

    NIIT第十一天 上午 多维数组 1.数组是引用数据类型 排序 1.冒泡排序法 2.类冒泡排序法 下午 飞行棋游戏 1.项目策划 2.项目规则确认 3.项目模块确认 晚上 1.飞行棋游戏,项目框架的编 ...

  2. C#基础:飞行棋游戏

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. c#控制台玩飞行棋游戏

    using System; namespace Game{ class Program { //用静态字段模拟全局变量 public static int[] Maps = new int[100]; ...

  4. hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. 浙江工商大学15年校赛E题 无邪的飞行棋 【经典背包】

    无邪的飞行棋 Time Limit 1s Memory Limit 64KB Judge Program Standard Ratio(Solve/Submit) 15.38%(4/26) Descr ...

  6. C#小程序呢飞行棋设计分析

    C#小程序飞行棋,程序效果图 1.设计分析 这个程序界面大致分为四部分: ① 最上面游戏名字界面 ②信息提示区 ③游戏界面区 ④游戏操作提示区 2.分区设计实现 一.游戏界面显示区,由于只需要显示出图 ...

  7. 骑士飞行棋 C#代码详解

    最近看见一个骑士飞行棋的小游戏代码,感觉这个代码中将大多数C#的基础知识都运用到了,是一个新手检验学习成果的有效方法,特此将这个代码整理一遍.这是一个控制台程序.这是代码下载地址,代码中的注释非常详细 ...

  8. 编写一个飞行棋项目(C#)遇到几个问题:

    在写程序中遇到如下问题:如果有人知道,请您一定要指点迷津.小白. 1.在运行暂停功能时,这个暂停功能可以实现,但是无法显示提示信息. case 3: Console.Clear(); Program. ...

  9. C#基础篇六飞行棋

    飞行棋业务:我们要能够让2个玩家 在地图上 按照游戏规则 进行游戏 玩家类 变量:玩家位置,玩家名称,玩家标识,玩家是否在陷阱中 方法:投骰子,移动 地图类 变量:地图数据数组 方法:初始化地图数据, ...

随机推荐

  1. MongoDB3.xxx 用户创建

    启动MongoDB前需要关闭配置文件中的auth选项,否则不能创建用户 首先创建用户管理用户 use admin db.createUser({user:'admin',pwd:'123456', r ...

  2. python 爬虫005-爬虫实例

    实例一:扒取猫眼电影TOP100 的信息 #!/usr/bin/env python # -*- coding: utf-8 -*- """ 扒取猫眼电影TOP100 的 ...

  3. poj2187凸包最远点对

    暴力过了 #include<map> #include<set> #include<cmath> #include<queue> #include< ...

  4. 解决Mybatis配置ORM映射 时分秒都为0

    方法一: Date类型的类成员变量使用java.sql.Timestamp 方法二: Mybatis的映射配置javatype=Timestamp.class

  5. Angular开发实践(七): 跨平台操作DOM及渲染器Renderer2

    在<Angular开发实践(六):服务端渲染>这篇文章的最后,我们也提到了在服务端渲染中需要牢记的几件事件,其中就包括不要使用window. document. navigator等浏览器 ...

  6. bzoj1269

    题解: splay维护 只不过变成了字符串 代码: #include<bits/stdc++.h> using namespace std; +,BS= + ,BN= + ; ,head, ...

  7. Week08《Java程序设计》第八次学习总结

    Week08<Java程序设计>第八次学习总结 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 答: 2.书面作业 1. ArrayList代码分析 1.1 解 ...

  8. eclipse集群tomcat

    eclipse集群tomcat 1.  File -> new -> other 选择server. 2.  选择Apache下边对应的tomcat版本,配置tomcat名称即可.由于我本 ...

  9. react 问题

    安装依赖报错问题                                           可能需要按顺序安装,  不能cnpm npm 混合安装, 参考react项目入门 react an ...

  10. functools 和 itertools

    functools 补充 1 wraps 在编写装饰器时,在实现前加入 @functools.wraps(func) 可以保证装饰器不会对被装饰函数造成影响.wraps 保存被装饰函数的原信息 def ...