1、画游戏头
2、初始化地图(加载地图所需要的资源)
3、画地图
4、玩游戏
游戏规则:
如果玩家A踩到了玩家B 玩家B退6格
踩到了地雷 退6格
踩到了时空隧道 进10格
踩到了幸运轮盘 1交换位置 2 轰炸对方 使对方退6格
踩到了暂停 暂停一回合
踩到了方块 神马都不干
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 飞行棋
{
classProgram
{
public static int[] Maps = new int[100];//存储地图的数组
public static int[] PlayerPos = newint[2];//PlayerPos1{0}A的坐标,PlayerPos{1}B的坐标
public static string[] PlayerName = new string[2];
public static bool [] Flags=new bool [2];
static void Main(string[] args)
{
GameHead();
#region 玩家输入
Console.WriteLine("请输入玩家A的姓名");
PlayerName[0]= Console.ReadLine();
while (PlayerName[0] == "")
{
Console.WriteLine("玩家A姓名不能为空,请重新输入!");
PlayerName[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名");
PlayerName[1] = Console.ReadLine();
while (PlayerName[1]==""||PlayerName [1]==PlayerName [0])
{
if (PlayerName[1]=="")
{
Console.WriteLine("玩家B姓名不能为空,请重新输入!");
PlayerName[1] = Console.ReadLine();
}
else
{
Console.WriteLine("玩家AB姓名不能重复,请重新输入!");
PlayerName[1] = Console.ReadLine();
}
}
#endregion
Console.Clear();
GameHead();
Console.WriteLine("游戏开始...");
Console.WriteLine("{0}玩家以A表示",PlayerName[0]);
Console.WriteLine("{0}玩家以B表示",PlayerName[1]);
InitialMap();
DrawMap();
#region 依据游戏规则开始
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},赢得了比赛", PlayerName[0],PlayerName[1]);
break;
}
if (Flags[1] == false)
{
PlayGame(1);
}
else
{
Flags[1] = false;
}
if (PlayerPos[0] >= 99)
{
Console.WriteLine("玩家{0}无耻的调戏了玩家{1},赢得了比赛", PlayerName[1],PlayerName[0]);
break;
}
}//while
#endregion
Win();
Console.ReadLine();
}
///
/// 画游戏头
///
public static void GameHead()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("*********************************");
Console.ForegroundColor =ConsoleColor.Green;
Console.WriteLine("***********飞行棋1.0*************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("*********************************");
}
///
/// 初始化地图
///
public static void InitialMap()
{
//我用0表示普通,显示给用户就是 □
//....1...幸运轮盘,显示组用户就◎
//....2...地雷,显示给用户就是 ☆
//....3...暂停,显示给用户就是 ▲
//....4...时空隧道,显示组用户就 卐
int[] Luckyturn = {6,23,40,55,69,83 };//幸运
for (int i = 0; i < Luckyturn.Length; i++)
{
Maps[Luckyturn[i]] = 1;
}
int[] LandMine = {5,13,17,33,38,50,64,80,91 };//地雷
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,90 };//时空隧道
for (int i = 0; i
{
Maps[TimeTunnel[i]] = 4;
}
}
///
/// 绘制地图
///
public static void DrawMap()
{
#region 画第一横行
for (int i = 0; i <=29; i++)
{
Console.Write(DrawStringMap(i));
}
Console.WriteLine();
#endregion
#region 画第一竖行
for (int i = 30; i <= 34; 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));
}
Console.WriteLine();
#endregion
#region 画第二竖行
for (int i = 65; i <=69; i++)
{
Console.WriteLine(DrawStringMap(i));
}
#endregion
#region 画第三横行
for (int i = 70; i <=99; i++)
{
Console.Write(DrawStringMap(i));
}
#endregion
}
///
/// 抽象出绘制地图的方法
///
///
/// str
public static string DrawStringMap(int i)
{
string str="";
if (PlayerPos[1] == PlayerPos[0] && PlayerPos[1] ==i)
{
Console.Write("<>");
}
else if (PlayerPos[0] == i)
{
Console.Write("A");//shift+空格切换全角/半角
}
else if (PlayerPos[1] == i)
{
Console.Write("B");
}
else
{
switch (Maps[i])
{
case 0:
Console.ForegroundColor = ConsoleColor.DarkGreen;
str="□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.DarkRed;
str="◎";
break;
case 2:
Console.ForegroundColor = ConsoleColor.DarkYellow;
str="☆";
break;
case 3:
Console.ForegroundColor = ConsoleColor.White;
str="▲";
break;
case 4:
Console.ForegroundColor = ConsoleColor.Blue;
str="卐";
break;
}//switch
}//else
return str;
}
///
/// 玩游戏的规则方法
///
public static void PlayGame(intplayerNumber)
{
#region 玩游戏
Random r = new Random();
int rNumber = r.Next(1, 7);
Console.WriteLine("玩家{0}按任意键开始:", PlayerName[playerNumber]);
Console.ReadKey(true);//按下的任意键不再控制台中显示
Console.WriteLine("玩家{0}掷出了{1}", PlayerName[playerNumber],rNumber);
PlayerPos[playerNumber] +=rNumber;
ChangePos();
Console.ReadKey(true);//按下的任意键不再控制台中显示
Console.WriteLine("玩家{0}按任意键开始行动", PlayerName[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("玩家{0}行动完了", PlayerName[playerNumber]);
Console.ReadKey(true);
if (PlayerPos[playerNumber] == PlayerPos[1 - playerNumber])
{
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}退六格",PlayerName[playerNumber], PlayerName[1 - playerNumber],PlayerName[1 - playerNumber]);
Console.ReadKey();
PlayerPos[1] -= 6;
ChangePos();
Console.WriteLine("玩家{0}退六格", PlayerName[1-playerNumber]);
Console.ReadKey();
}
else//玩家A没有踩到玩家B
{
switch (Maps[PlayerPos[playerNumber]])
{
case 0:
Console.WriteLine("玩家{0}踩到了方块,什么都不发生",PlayerName[playerNumber]);
Console.ReadKey(true);
break;
case 1:
Console.WriteLine("玩家{0}踩到了幸运轮盘,请选择 1-交换位置2-轰炸对方", PlayerName[playerNumber]);
string input = Console.ReadLine();
while (true)
{
if (input == "1")
{
Console.WriteLine("玩家{0}选择与玩家{1}交换位置", PlayerName[playerNumber],PlayerName[1 - playerNumber]);
int temp = PlayerPos[playerNumber];
PlayerPos[playerNumber] = PlayerPos[1 - playerNumber];
Console.ReadKey(true);
break;
}
else if (input == "2")
{
Console.WriteLine("玩家{0}选择轰炸对方", PlayerName[playerNumber]);
PlayerPos[1 - playerNumber] -= 6;
ChangePos();
Console.ReadKey(true);
break;
}
else
{
Console.WriteLine("输入有误请重新输入,1-交换位置 2-轰炸对方");
input = Console.ReadLine();
}
}
break;
case 2:
Console.WriteLine("玩家{0}踩到了地雷,退六格",PlayerName[playerNumber]);
PlayerPos[playerNumber] -= 6;
ChangePos();
Console.ReadKey(true);
break;
case 3:
Console.WriteLine("玩家{0}踩到了时空隧道,前进十格",PlayerName[playerNumber]);
PlayerPos[playerNumber] += 10;
ChangePos();
Console.ReadKey(true);
break;
case 4:
Console.WriteLine("玩家{0}踩到了暂停,暂停一局",PlayerName[playerNumber]);
Flags [playerNumber ]=true ;
Console.ReadKey(true);
break;
}
}
Console.Clear();//清屏
DrawMap();
#endregion
}
///
/// 当玩家坐标发生改变是保证玩家始终在地图上
///
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("■ ■■■■■■■■■●●");
Console.ResetColor();
}
}
}