Console.ForegroundColor = ConsoleColor.White(枚举类型);//设置前景色(输出的字)
Console.BackGroundColor = ConsoleColor.while;//设置背景颜色
Console,Clear();//清屏
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
public static int[] maingo = new int[100];
public static int[] playerPos = new int[2];
public static string[] playername = new string[2];
public static bool[] go = new bool[2];
/// <summary>
/// 主函数
/// </summary>
/// <param name="字符串变量"></param>
static void Main(string[] args)
{
gameshow();
Console.WriteLine("请输入玩家A的姓名");
playername[0] = Console.ReadLine();
Console.WriteLine("请输入玩家B的姓名");
playername[1] = Console.ReadLine();
Console.Clear();
gameshow();
mapinit();
drawMap();
while (playerPos[0] <= 99 || playerPos[1] <= 99)
{
Console.Clear();
gameshow();
mapinit();
drawMap();
game();
}
if (playerPos[0] > 99)
Console.WriteLine("玩家A胜利");
if (playerPos[1] > 99)
Console.WriteLine("玩家B胜利");
Console.ReadKey();
}
public static void gameshow()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("*************************************");
Console.WriteLine("****************飞行棋***************");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("*************************************");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("*************************************");
}
/// <summary>
/// 地图初始化
/// </summary>
/// <param name="a">赋值为1表示幸运标记</param>
/// <param name="b">赋值为2表示地雷</param>
/// <param name="c">赋值为三表示暂停</param>
/// <param name="d">赋值为四表示时间漩涡</param>
public static void mapinit()
{
int[] a = {6,24,25,45,36,84,88};
int[] b = { 66, 77, 99 };
int[] c= {11,22,33 };
int[] d = { 44,55,56,59};
for (int i = 0; i < a.Length; i++)
{
maingo[a[i]] = 1;
}
for (int i = 0; i < b.Length; i++)
{
maingo[b[i]] = 2;
}
for (int i = 0; i < c.Length; i++)
{
maingo[c[i]] = 3;
}
for (int i = 0; i < d.Length; i++)
{
maingo[d[i]] = 4;
}
}
/// <summary>
/// ref练习
/// </summary>
/// <param name="num"></param>
/// <param name="str"></param>
/// <param name="d1"></param>
/// <param name="b"></param>
//public static void CharReverse(ref int num, ref string str, ref double d1, ref bool b)
//{
// num += 500;
// str = "2222";
// d1 = 2.33333;
// b = true;
//}
//public static void TellStory(int number)
//{
// number++;
// Console.WriteLine("从前有座山");
// Console.WriteLine("山里有座庙");
// Console.WriteLine("庙里有个老和尚");
// Console.WriteLine("老和尚给小和尚讲故事");
// Console.WriteLine(number);
// if(number<10)
// TellStory(number);
//}
//public static int Parames(int b)
//{
// return b;
//}
//public static string Maxlength(string[] s1)
//{
// string maxstring = s1[0];
// for(int i=1;i<s1.Length;i++)
// {
// if(s1[i-1].Length<s1[i].Length)
// maxstring = s1[i];
// }
// return maxstring;
//}
//public static string[] revers(string[] a)
//{
// for (int i = 0; i < a.Length; i++)
// {
// char[] temp = a[i].ToCharArray();
// Array.Reverse(temp);
// a[i] = new string(temp);
// }
// return a;
//
/// <summary>
/// 画地图
/// </summary>
public static void drawMap()
{
for(int i =0;i<30;i++)
{
pos(i);
}
Console.WriteLine();
for (int i = 30; i < 35;i++ )
{
for (int j = 0; j < 29; j++)
{
Console.Write(" ");
}
pos(i);
Console.WriteLine();
}
for (int i = 64; i >=35; i--)
{
pos(i);
}
Console.WriteLine();
for (int i = 65; i < 70; i++)
{
pos(i);
Console.WriteLine();
}
for (int i = 70; i < 100; i++)
{
pos(i);
}
Console.WriteLine();
}
/// <summary>
/// 判断人物位置并且画图
/// </summary>
/// <param name="i"></param>
public static void pos(int i)
{
if (playerPos[0] == playerPos[1] && playerPos[0] == i)
Console.Write(">");
else if (playerPos[0] == i)
{
Console.Write("A");
}
else if (playerPos[1] == i)
{
Console.Write("B");
}
else
{
switch (maingo[i])
{
case 0: Console.Write("~"); break;
case 1: Console.Write("@"); break;
case 2: Console.Write("$"); break;
case 3: Console.Write("%"); break;
case 4: Console.Write("*"); break;
}
}
}
public static void game()
{
for (int j = 0; j < 2; j++)
{
Console.Clear();
gameshow();
mapinit();
drawMap();
if (!go[j])
{
go[j] = true;
continue;
}
Random r = new Random();
int i = r.Next(1, 7);
Console.WriteLine("按任意键开始掷骰子");
Console.ReadKey(true);
Console.WriteLine("玩家{0}扔出了{1}", playername[j], i);
Console.ReadKey(true);
Console.WriteLine("按任意键开始行动");
Console.ReadKey(true);
playerPos[j] += i;
posGO();
Console.WriteLine("玩家{0}行动完成", playername[j]);
Console.ReadKey(true);
if (playerPos[0] == playerPos[1])
{
Console.WriteLine("踩到玩家,踩玩家后退6格");
playerPos[j] -= 6;
Console.ReadKey();
}
else
{
switch (maingo[playerPos[j]])
{
case 1: playerPos[j]++; posGO(); break;
case 2: playerPos[j] -= 5; posGO(); break;
case 3: go[j] = false; break;
case 4: playerPos[j] += 10; posGO(); break;
}
}
}
}
/// <summary>
/// 判断位置是否越界
/// </summary>
public static void posGO()
{
if (playerPos[0] < 0)
{
playerPos[0] = 0;
}
if (playerPos[1] < 0)
{
playerPos[1] = 0;
}
if (playerPos[0] > 99)
{
playerPos[0] = 99;
}
if (playerPos[1] > 99)
{
playerPos[1] = 99;
}}
}
}
网友评论