using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace 飞行棋
{
class Program
{
public static string strformat = "";
public static int[] Map = new int[100];
public static int[] PlayerPos = new int[2];
public static string[] PlayerName = new string[2];
public static bool[] flags = new bool[] { false, false };
private static Timer tm;
static char[] S = new char[512];
static int n = 0;
static void Main(string[] args)
{
Console.SetWindowPosition(0,0);//设置控制台在屏幕中的位置
Console.SetWindowSize(80,36);//设置控制台宽度和高度
ShowUI();//显示游戏标题
InitMap();//初始化地图
PlayerName = Login();//用户登录
Console.Clear();//清屏
ShowUI();//显示游戏标题
Console.WriteLine("一场轰轰烈烈的爱情追逐战即将开始……\n");
Console.WriteLine("首先上场的是我们的萌妹纸 {0} 美女……\n",PlayerName[0]);
Console.WriteLine("紧随而来的是我们的帅小伙 {0} 帅哥……\n",PlayerName[1]);
DrawMap();
Console.WriteLine("按任意键开始爱情追逐!");
Console.ReadKey(true);
Console.Clear();
DrawMap();
Console.WriteLine("爱情追逐已经开始了……");
Console.WriteLine("毫无疑问,萌妹纸 {0} 先掷骰子!\n",PlayerName[0]);
//游戏过程
while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
{
//第一个问题,玩家的坐标大于99了,玩家显示的位置可能不在地图上
//判断 玩家每走一次,或者说涉及到坐标发生改变,就应该检查一下当前位置是否大于99
//第二个问题,玩家的坐标可能小于0
//第一个人掷骰子
if (flags[0] == false)
{
RowDo(0);
}
else
{
flags[0] = false;
}
//判断第一个人是否胜利
if(PlayerPos[0] == 99)
{
Win(0);
break;
}
//第二个人掷骰子
if (flags[1] == false)
{
RowDo(1);
}
else
{
flags[1] = false;
}
//判断第二个人是否胜利
if (PlayerPos[1] == 99)
{
Win(1);
break;
}
}
Console.Clear();
Console.ReadKey();
}
///
/// 游戏标题部分显示,封装为一个方法
///
public static void ShowUI()
{
Console.WriteLine("");
Console.WriteLine(" **************************************");
Console.WriteLine(" * *");
Console.Write(" * >>>>>> ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("情侣终极飞行棋");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(" <<<<<< *");
Console.WriteLine(" * *");
Console.WriteLine(" **************************************");
Console.WriteLine("");
Console.WriteLine("");
}
///
/// 初始化地图
/// 1:幸运轮盘 2、失之交臂 3、暂停一次 4、爱神丘比特
///
public static void InitMap()
{
//map数组中一共有100个元素,现在默认是每个元素里的值都是0
//让某些元素中的值发生变化
int[] luckyturn = new int[6]{ 6, 23, 40, 55, 69, 83 };//幸运轮盘
int[] landMine = new int[9] { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//失之交臂
int[] pause = new int[4] { 9, 27, 60, 93 };//暂停一次
int[] timeTunnel = new int[7] { 20, 25, 45, 63, 72, 88, 90 };//爱神丘比特
for (int i = 0; i < luckyturn.Length; i++)
{
Map[luckyturn[i]] = 1;
}
for (int i = 0; i < landMine.Length; i++)
{
Map[landMine[i]] = 2;
}
for (int i = 0; i < pause.Length; i++)
{
Map[pause[i]] = 3;
}
for (int i = 0; i < timeTunnel.Length; i++)
{
Map[timeTunnel[i]] = 4;
}
}
///
/// 画地图
///
public static void DrawMap()
{
Console.WriteLine("图例:幸运轮盘:◎ 失之交臂:☆ 暂停一次:▲ 爱神丘比特:卐\n");
Console.Write(" 起点-> ");
#region 画第一横行
DrawMapLeftToRight(0, 29);
#endregion
Console.WriteLine("");
#region 画第一竖列
for (int i = 30; i <= 34; i++)
{
for (int j = 0; j < 34; j++)
{
Console.Write(" ");
}
Console.WriteLine(DrawMapString(i));
}
#endregion
Console.Write(" ");
#region 画第二横行
for (int i = 64; i >= 35; i--)
{
Console.Write(DrawMapString(i));
}
#endregion
Console.WriteLine("");
#region 画第二竖列
for (int i = 65; i <= 69; i++)
{
Console.Write(" ");
Console.WriteLine(DrawMapString(i));
}
#endregion
Console.Write(" ");
#region 画第三横行
DrawMapLeftToRight(70, 99);
#endregion
Console.Write(" <-终点");
Console.WriteLine("\n");
}
///
/// 画地图显示图案
///
///
坐标
///
public static string DrawMapString(int pos)
{
string str = "";
if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
str = "爱";
}
else if (PlayerPos[0] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
str = "妻";
}
else if (PlayerPos[1] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
str = "夫";
}
else
{
switch (Map[pos])
{
case 0:
Console.ForegroundColor = ConsoleColor.White;
str = "□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Red;
str = "◎";
break;
case 2:
Console.ForegroundColor = ConsoleColor.DarkMagenta;
str = "☆";
break;
case 3:
Console.ForegroundColor = ConsoleColor.Cyan;
str = "▲";
break;
case 4:
Console.ForegroundColor = ConsoleColor.Blue;
str = "卐";
break;
}//end switch
}//end else
return str;
}
///
/// 从左到右画地图
///
///
开始坐标
///
结束坐标
public static void DrawMapLeftToRight(int left, int right)
{
for (int i = left; i <= right; i++)
{
Console.Write(DrawMapString(i));
}
}
///
/// 登录
///
///
登录用户
public static string[] Login()
{
string[] Player = new string[2];
Console.WriteLine("请输入萌妹纸的名字:");
do
{
Player[0] = Console.ReadLine();
if (Player[0] == "")
{
Console.WriteLine("难道是传说中的女王无名?还是老实交代妹纸的芳名吧……");
}
}while(Player[0] == "");
Console.WriteLine("请输入帅小伙的名字:");
Player[1] = Console.ReadLine();
while (Player[0] == Player[1] || Player[1] == "")
{
if (Player[0] == Player[1])
{
Console.WriteLine("你忍心和一个萌妹纸抢名字么?骚年,还是换个名字吧……");
}
else
{
Console.WriteLine("难道是传说中的土豪无名?骚年,还是老实交代自己的名字吧……");
}
Player[1] = Console.ReadLine();
}
return Player;
}
///
/// 判断用户输入的是不是规定范围内的数字
///
///
提示语
///
最小值
///
最大值
///
public static int ReadInt(string str,int min,int max)
{
//一、用户输入的如果不是数字就一直提醒输入
//二、用户输入的数字只能是1和2
while (true)
{
Console.WriteLine(str);
try
{
int num = Convert.ToInt32(Console.ReadLine());
if (num >= min && num <= max)
{
return num;
}
else
{
Console.WriteLine("输入的数字不在{0}和{1}之间,请重新输入……");
}
}
catch
{
Console.WriteLine("输入的不是数字,请重新输入……");
}
}
}
///
/// 移动位置
///
///
起点位置
///
终点位置
///
当前位置
///
移动步数
///
public static int Move(int start, int end, int pos, int move)
{
if(pos + move < start)
{
pos = start;
}
else if (pos + move > end)
{
pos = end;
}
else
{
pos = pos + move;
}
return pos;
}
///
/// 幸运轮盘判断
///
///
触发人
public static void LuckTurn(int pos)
{
int number = ReadInt(string.Format(" {0} 走到了幸运轮盘,1--你侬我侬,互换位置,2--咫尺天涯,送你回去", PlayerName[pos]), 1, 2);
if (number == 1)
{
//交换位置
int temp = PlayerPos[pos];
PlayerPos[pos] = PlayerPos[1 - pos];
PlayerPos[1 - pos] = temp;
Console.WriteLine(" {0} 对 {1} 使用了你侬我侬,两人交换位置。", PlayerName[pos], PlayerName[1 - pos]);
}
else
{
//退6步,需要判断退6步后是否超出起点
PlayerPos[1-pos] = Move(0, Map.Length - 1, PlayerPos[1 - pos], -6);
Console.WriteLine(" {0} 对 {1} 使用了咫尺天涯, {1} 退后六步。", PlayerName[pos], PlayerName[1 - pos], PlayerName[1 - pos]);
}
}
///
/// 检查位置是否越界
///
public static void CheckPos()
{
if (PlayerPos[0] > 99)
{
PlayerPos[0] = 99;
}
if (PlayerPos[1] > 99)
{
PlayerPos[1] = 99;
}
if (PlayerPos[0] < 0)
{
PlayerPos[0] = 0;
}
if (PlayerPos[1] < 0)
{
PlayerPos[1] = 0;
}
}
///
/// 掷骰子过程
///
///
当前玩家
public static void RowDo(int pos)
{
Random r = new Random();
int num = r.Next(1, 7);
Console.WriteLine(" {0} 按任意键掷骰子……",PlayerName[pos]);
Console.ReadKey(true);
Console.WriteLine(" {0} 掷出了{1}", PlayerName[pos], num);
Console.WriteLine(" {0} 按任意键开始行动……\n", PlayerName[pos]);
Console.ReadKey(true);
PlayerPos[pos] = Move(0, Map.Length - 1, PlayerPos[pos], num);
//判断两个玩家有没有谁踩到谁
if (PlayerPos[pos] == PlayerPos[1 - pos])
{
PlayerPos[1 - pos] = 0;
strformat = string.Format(" {1} 与 {0} 不期而遇, {0} 被 {1} 送回了原点",PlayerName[pos],PlayerName[1-pos],PlayerName[1-pos],PlayerName[pos]);
}
else
{
switch (Map[PlayerPos[pos]])
{
case 0:
strformat = string.Format(" {0} 行动完毕!",PlayerName[pos]);
break;
case 1:
LuckTurn(pos);
break;
case 2:
PlayerPos[pos] = Move(0, Map.Length - 1, PlayerPos[pos], -6);
strformat = string.Format(" {0} 与对方失之交臂,后退6步……", PlayerName[pos]);
break;
case 3:
flags[pos] = true;
strformat = string.Format(" {0} 陷入情网不能自拔,暂停一回合……", PlayerName[pos]);
break;
case 4:
PlayerPos[pos] = Move(0, Map.Length - 1, PlayerPos[pos], 10);
strformat = string.Format(" {0} 遇见了爱神丘比特,得到祝福,前进10步……", PlayerName[pos]);
break;
}
}
//重新画地图
Console.Clear();
DrawMap();
Console.WriteLine(strformat);
Console.WriteLine("");
}
public static void Win(int pos)
{
Console.Clear();
DrawMap();
//画心
int[] tab ={0,1,0,0,0,1,0,
1,0,1,0,1,0,1,
1,0,0,1,0,0,1,
1,0,0,0,0,0,1,
0,1,0,0,0,1,0,
0,0,1,0,1,0,0,
0,0,0,1,0,0,0,};
for (int i = 0; i < 49; i++)
{
if (i % 7 == 0)
{
Console.Write(" \n");
}
if (tab[i] == 0)
{
Console.Write(" ");//注意这里双引号之间有两个空格
}
else
{
Console.Write(" *");//注意这里*前有个空格
}
}
Console.WriteLine();
//按照一定的速率输出要显示的内容
S = "爱情,没有谁赢谁输,也无关对错,只要相伴走过一生,你也像我一样深深的眷恋。。。亲爱的,我爱你,我就是要好好的宠着你,养着你,让你任性,让你奢侈,让你无忧无虑的生活着。。。我爱你,亲爱的老婆。。。".ToCharArray();
tm = new System.Threading.Timer(new TimerCallback(timer_Elapsed), null, 0, 300);
Console.ReadLine();
}
private static void timer_Elapsed(object sender)
{
if (n < S.Count())
{
Console.Write(S[n]);
n++;
}
}
}
}