using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace feixingqi
{
class Program
{
//静态字段模仿全局变量 地图
public static int[] Maps = new int[100];
//声明数组存储玩家的坐标
public static int[] PlayerPos = new int[2];
//声明玩家的姓名
public static string[] PlayerNames = new string[2];
//两个为玩家的标记
public static bool[] Flags = new bool[2];
//主方法
static void Main(string[] args)
{
//游戏标题
GameShow();
//输入玩家姓名
#region 输入玩家姓名
Console.WriteLine("请输入玩家A的姓名:");
PlayerNames[0] = Console.ReadLine();
while (PlayerNames[0] == "") {
Console.WriteLine("玩家A的姓名不能为空,请重新输入:");
PlayerNames[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名:");
PlayerNames[1] = Console.ReadLine();
while (PlayerNames[1] == ""||PlayerNames[1]==PlayerNames[0])
{
if (PlayerNames[1] == "")
{
Console.WriteLine("玩家B的姓名不能为空,请重新输入:");
PlayerNames[1] = Console.ReadLine();
}
else {
Console.WriteLine("玩家B的姓名不能与玩家A的相同,请重新输入:");
PlayerNames[1] = Console.ReadLine();
}
}
#endregion
//玩家姓名输入完成后清屏
Console.Clear();
//重新显示游戏头部
GameShow();
Console.WriteLine("{0}的士兵为A",PlayerNames[0]);
Console.WriteLine("{0}的士兵为B", PlayerNames[1]);
//初始化地图
InitailMap();
//画地图
DrawMap();
while (PlayerPos[0]<99&&PlayerPos[1]<99) {
if (Flags[0] == false)
{
PlayGame(0);
}
else {
Flags[0] = false;
}
if (PlayerPos[0] >= 99) {
Console.WriteLine("玩家{0}无耻的赢了玩家{1}",PlayerNames[0],PlayerNames[1]);
break;
}
if (Flags[1] == false)
{
PlayGame(1);
}
else {
Flags[1] = false;
}
if (PlayerPos[0] >= 99)
{
Console.WriteLine("玩家{0}无耻的赢了玩家{1}", PlayerNames[1], PlayerNames[1]);
break;
}
}
Win();
Console.ReadKey();
}
//游戏头部
public static void GameShow()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("***********豆豆飞行棋V1.0************");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.White;
}
//初始化地图
public static void InitailMap() {
int[] luckyturn = { 6, 23, 40, 69, 83 };//幸运轮盘◎
for (int i = 0; i < luckyturn.Length; i++) {
Maps[luckyturn[i]] = 1;
}
int[] landMine = {5,13,17,33,38,50,64,80,94};//地雷☆
for (int i = 0; i < landMine.Length; i++)
{
Maps[landMine[i]] = 2;
}
int[] pause = { 9, 27, 60, 93 };//暂停▲
for (int i = 0; i < pause.Length; i++)
{
Maps[pause[i]] = 3;
}
int[] timeTunnel = { 20, 25, 45, 63, 72, 88 };//时空隧道卍
for (int i = 0; i < timeTunnel.Length; i++)
{
Maps[timeTunnel[i]] = 4;
}
}
//画地图
public static void DrawMap()
{
Console.WriteLine("图例:幸运轮盘:◎ 地雷:☆ 暂停:▲ 时空隧道:卍");
#region 第一行
for (int i=0;i<30;i++) {
Console.Write(DrawStringMap(i));
}
#endregion
//画完第一行换行
Console.WriteLine();
#region 第一列
for (int i = 30; i < 35; i++) {
for (int j = 0; j < 29; j++) {
Console.Write(" ");
}
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 第二行
for (int i = 64; i >= 35; i--)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
#region 第二列
for (int i = 65; i < 69; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 第三行
for (int i = 70; i < 100; i++)
{
Console.Write(DrawStringMap(i));
}
#endregion
Console.WriteLine();
}
//从画地图的方法里抽象出一个方法
public static string DrawStringMap(int i)
{
string str = "";
//如果玩家1的坐标和万家2的坐标相同都在地图上就画<>
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[1] == i)
{
str="<>";
}
else if (PlayerPos[0] == i)
{
//全角符号 shift+空格
str="A";
}
else if (PlayerPos[1] == i)
{
str="B";
}
else
{
switch (Maps[i])
{
case 0:
Console.ForegroundColor = ConsoleColor.Yellow;
str="□"; break;
case 1:
Console.ForegroundColor = ConsoleColor.Green;
str="◎"; break;
case 2:
Console.ForegroundColor = ConsoleColor.Red;
str="☆"; break;
case 3:
Console.ForegroundColor = ConsoleColor.Blue;
str="▲"; break;
case 4:
Console.ForegroundColor = ConsoleColor.DarkCyan;
str="卍"; break;
}
}
return str;
}
//玩游戏
public static void PlayGame(int playerNumber) {
//随机数骰子
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("玩家{0}按任意键开始掷骰子", PlayerNames[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}骰子出了{1}", PlayerNames[playerNumber], rNumber);
PlayerPos[playerNumber] += rNumber;
ChangePos();
Console.WriteLine("玩家{0}开始行动", PlayerNames[playerNumber]);
//玩家A可能踩到玩家B,方块,幸运轮盘,地雷,暂停,时空隧道
if (PlayerPos[playerNumber] == PlayerPos[1- playerNumber])
{
//玩家踩到玩家
Console.WriteLine("玩家{0}猜到了玩家{1},玩家{2}退六格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);
PlayerPos[1- playerNumber] -= 6;
Console.ReadKey(true);
}
else
{
//玩家踩到关卡
switch (Maps[PlayerPos[playerNumber]])
{
case 0:
Console.WriteLine("玩家{0}猜到了方块,什么都不做", PlayerNames[playerNumber]);
Console.ReadKey(true);
break;
case 1:
Console.WriteLine("玩家{0}猜到了幸运轮盘,请选择:1-交换位置,2-轰炸对方", PlayerNames[playerNumber]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("玩家{0}选择和玩家{1}交换位置", PlayerNames[playerNumber], PlayerNames[1- playerNumber]);
Console.ReadKey(true);
int tmp = PlayerPos[playerNumber];
PlayerPos[playerNumber] = PlayerPos[1- playerNumber];
PlayerPos[1- playerNumber] = tmp;
Console.WriteLine("交换完成!!!按任意键继续!!!");
Console.ReadKey(true);
break;
}
else if (input == "2")
{
Console.WriteLine("玩家{0}选择轰炸玩家{1},玩家{2}退6格", PlayerNames[playerNumber], PlayerNames[1- playerNumber], PlayerNames[1- playerNumber]);
Console.ReadKey(true);
PlayerPos[1- playerNumber] -= 6;
Console.WriteLine("玩家{0}退了6格", PlayerNames[1- playerNumber]);
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("只能输入1或2,1-交换位置,2-轰炸对方");
input = Console.ReadLine();
break;
}
}
break;
case 2:
Console.WriteLine("玩家{0}踩到了地雷,退6格", PlayerNames[playerNumber]);
PlayerPos[playerNumber] -= 6;
break;
case 3:
Flags[playerNumber] = true;
break;
case 4:
Console.WriteLine("玩家{0}踩到了时空隧道,前进10格", PlayerNames[playerNumber]);
PlayerPos[playerNumber] += 10;
Console.ReadKey(true);
break;
}
}
ChangePos();
Console.Clear();
DrawMap();
}
//做一个限定防止玩家跑出地图 当玩家坐标发生改变的时候调用
public static void ChangePos() {
if (PlayerPos[0] < 0) {
PlayerPos[0] = 0;
}
if (PlayerPos[0] >=99) {
PlayerPos[0] = 99;
}
if (PlayerPos[1] < 0)
{
PlayerPos[1] = 0;
}
if (PlayerPos[1] >= 99)
{
PlayerPos[1] = 99;
}
}
//胜利
public static void Win()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(" ◆ ");
Console.WriteLine(" ■ ◆ ■ ■ ");
Console.WriteLine(" ■■■■ ■ ■ ◆■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ◆ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■■■■■■ ■■■■■■■ ■ ■ ■ ");
Console.WriteLine(" ■■■■ ■ ■ ●■● ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ● ■ ● ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■■■■■■ ● ■ ● ■ ■ ■ ");
Console.WriteLine(" ■■■■ ■ ● ■ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ■ ■ ");
Console.WriteLine(" ■ ■ ■ ■ ● ■ ");
Console.WriteLine(" ■ ■■ ■■■■■■ ■ ● ● ");
}
}
}
飞行棋小游戏
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 本实例基于 React + ES6 + Webpack + Node 实现一个井字棋的小游戏,来进一步深刻理解 R...
- C语言是面向过程的,而C++是面向对象的。C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构。C程...