using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace planeChess
{
class Program
{
/*
* 1. 地图 第一横行 从1 到 15 ~30 随机一个数,表示第一行多少个格子
第二竖列 从上面的最后一个开始~35 之间 随机一个数 表示第二竖列 多少个格子
第三横行 从上面的最后一个开始~65 之间 随机一个数 表示第三横行多少个格子
第四竖列 从上面的最后一个开始~70 之间 随机一个数 表示第四竖列 多少个格子
最后横行 打完100 个格子.
2.100 个格子中 随机设置 9个地雷 7个幸运轮盘 4个暂停 7个时空隧道
注意: 地雷要布置在第6格之后, 如果布置的特殊符号已经存在,则重新随机设置
如果A 玩家最后又3步,但投出 5步 则 退回2步.
3.玩家必须100整才能赢得胜利!
* */
//logo
static void logo()
{
Console.WriteLine("*****************************************");
Console.WriteLine("** **");
Console.WriteLine("** 骑 士 飞 行 棋 **");
Console.WriteLine("** **");
Console.WriteLine("*****************************************");
}
//录入玩家名字
static string[] playName()
{
string[] players = new string[2];
Console.Write("请输入A玩家的名字:");
players[0] = Console.ReadLine();
//判断是否为空
while (players[0].Trim() == "")
{
Console.Write("输入不能为空,重新输入A:");
players[0] = Console.ReadLine();
}
Console.Write("请输入B玩家的名字:");
players[1] = Console.ReadLine();
while (true)
{
if (players[1].Trim() == "")
{
Console.Write("输入不能为空,重新输入B:");
players[1] = Console.ReadLine();
}
//AB玩家名字不能相同
else if (players[0].Trim() == players[1].Trim())
{
Console.Write("AB不能相同,重新输入B:");
players[1] = Console.ReadLine();
}
else
break;
}
players[0] = players[0].Trim();
players[1] = players[1].Trim();
return players;
}
//地图
static void map(int[] num,int[]countRan)
{
int i = 1, nbspTemp1 = 0, nbspTemp2 = 0;
if (countRan[0] > countRan[2] - countRan[1])
nbspTemp2 = countRan[0] + countRan[1] - countRan[2];
else
nbspTemp1 = countRan[2] - countRan[1] - countRan[0];
Console.WriteLine("□:普通 ◎:幸运轮盘 ★:地雷 △:暂停 ※:时空隧道");
for (int j = 0; j < nbspTemp1; j++)
Console.Write(" ");
while (i <= countRan[0])
{
mapImage(i, num);
i++;
}
Console.WriteLine();
while (i <= countRan[1])
{
for (int j = 0; j < countRan[0] + nbspTemp1 - 1; j++)
Console.Write(" ");
mapImage(i, num);
Console.WriteLine();
i++;
}
i = countRan[2];
for (int j = 0; j < nbspTemp2; j++)
Console.Write(" ");
while (i > countRan[1])
{
mapImage(i, num);
i--;
}
Console.WriteLine();
i = countRan[2] + 1;
while (i <= countRan[3])
{
for (int j = 0; j < nbspTemp2; j++)
Console.Write(" ");
mapImage(i, num);
Console.WriteLine();
i++;
}
for (int j = 0; j < nbspTemp2; j++)
Console.Write(" ");
while (i < 101)
{
mapImage(i, num);
i++;
}
Console.WriteLine();
}
//特殊符号处理
static void mapImage(int i, int[] num)
{
if (num[0] == num[1] && num[0] == i)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.Write("<>");
}
else if (num[0] == i)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("A");
}
else if (num[1] == i)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("B");
}
else if (plays[i - 1] == 1)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("★");
}
else if (plays[i - 1] == 2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("◎");
}
else if (plays[i - 1] == 3)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.Write("△");
}
else if (plays[i - 1] == 4)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("※");
}
else
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("□");
}
}
//生成随机特殊符号
static void ranImage(int number,int index,int n)
{
int count;
for (int i = 0; i < number; i++)
{
count=ran.Next(index,99);
if (plays[count] == 0)
plays[count] = n;
}
}
static int[] plays;
static Random ran = new Random();
static void Main(string[] args)
{
//定义玩家名字数组
string[] players;
//定义玩家步数
int[] num = new int[2] { 1, 1 };
//100个格子
plays = new int[100];
//控制台窗口宽度设置
Console.WindowWidth = 100;
#region 生成随机拐点
int[] countRan = new int[4];
countRan[0] = ran.Next(15, 31);
countRan[1] = ran.Next(countRan[0] + 1, 36);
countRan[2] = ran.Next(countRan[1] + 1, 66);
countRan[3] = ran.Next(countRan[2] + 1, 71);
#endregion
#region 随机生成特殊符号
ranImage(9, 6, 1);//9:个数 6:从第6个之后随机 1:地雷
ranImage(7, 1, 2);//7:个数 1:从第6个之后随机 2:幸运轮盘
ranImage(4, 1, 3);//4:个数 1:从第6个之后随机 3:暂停
ranImage(7, 1, 4);//7:个数 1:从第6个之后随机 4:时空隧道
#endregion
#region clearOne
//调用logo
logo();
//获取玩家名字
players=playName();
Console.Clear();
#endregion
#region clearTwo
logo();
Console.WriteLine("对战开始......");
Console.WriteLine("{0}用A表示", players[0]);
Console.WriteLine("{0}用B表示", players[1]);
Console.WriteLine("如果AB在同一个位置用<>表示");
Console.ReadLine();
Console.Clear();
#endregion
#region 打印地图
map(num, countRan);
#endregion
#region 掷骰子
//count:获取随机数
//temp:当遇到幸运转盘时,实现玩家位置交换功能
//oldPlays:记录当前plays[i]的值,为下次循环做准备
int isOne = 0, count, temp, oldPlays = 0;
bool isTrue = true;
while (true)
{
Console.WriteLine("玩家{0},按任意键掷骰子......", players[isOne]);
Console.ReadKey(true);
count = ran.Next(1, 7);
Console.WriteLine("玩家{0}掷出了{1},按任意键行动......", players[isOne], count);
Console.ReadKey(true);
if (num[isOne] + count > 100)
num[isOne] = 200 - num[isOne] - count;
else if (num[isOne] + count == 100)
{
Console.Clear();
num[isOne] += count;
map(num, countRan);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("玩家{0}获胜", players[isOne]);
break;
}
else
num[isOne] += count;
newPlays: Console.Clear();
//判断当前的玩家是否与之前一个玩家重叠
if (isOne == 0 && num[isOne] != 1)
{
if (num[isOne] == num[isOne + 1])
{
map(num, countRan);
Console.WriteLine("{0}踩到了{1},{1}退回原点", players[isOne], players[isOne + 1], players[isOne + 1]);
Console.WriteLine("按任意键继续......");
Console.ReadKey(true);
num[isOne + 1] = 1;
Console.Clear();
map(num, countRan);
}
}
else
{
if (num[isOne] == num[isOne - 1])
{
map(num, countRan);
Console.WriteLine("{0}踩到了{1},{1}退回原点", players[isOne], players[isOne - 1], players[isOne - 1]);
Console.WriteLine("按任意键继续......");
Console.ReadKey(true);
num[isOne - 1] = 1;
Console.Clear();
map(num, countRan);
}
}
Console.Clear();
if (plays[num[isOne] - 1] == 1)
{
map(num, countRan);
Console.WriteLine("玩家{0}踩中了地雷,后退6步", players[isOne]);
Console.ReadKey(true);
Console.Clear();
num[isOne] -= 6;
map(num, countRan);
//判断-6后的plays[i]的值是否为特殊符号的值
goto newPlays;
}
else if (plays[num[isOne] - 1] == 2)
{
map(num, countRan);
Console.WriteLine("玩家{0}来到了幸运转盘,选择1:前进6步,选择2:交换位置", players[isOne]);
string choice = Console.ReadLine();
while (true)
{
if (choice.Trim() == "")
{
Console.Write("输入不能为空,重新输入:");
choice = Console.ReadLine();
}
else if (choice.Trim() == "1")
{
Console.Clear();
if (num[isOne] + 6 > 100)
num[isOne] = 194 - num[isOne];
else if (num[isOne] + 6 == 100)
{
Console.Clear();
num[isOne] += count;
map(num, countRan);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("玩家{0}获胜", players[isOne]);
break;
}
else
{
num[isOne] += 6;
//判断+6后的plays[i]的值是否为特殊符号的值
goto newPlays;
}
map(num, countRan);
break;
}
else if (choice.Trim() == "2")
{
Console.Clear();
//temp:当遇到幸运转盘时,实现玩家位置交换功能
if (isOne == 0)
{
temp = num[isOne];
num[isOne] = num[isOne + 1];
num[isOne + 1] = temp;
}
else
{
temp = num[isOne];
num[isOne] = num[isOne - 1];
num[isOne - 1] = temp;
}
map(num, countRan);
}
else
{
Console.WriteLine("输入错误,请输入1或者2!!!");
Console.Write("重新输入:");
choice = Console.ReadLine();
}
}
Console.WriteLine("按任意键继续......");
Console.ReadKey(true);
}
else if (plays[num[isOne] - 1] == 3)
{
Console.Clear();
map(num, countRan);
Console.WriteLine("玩家{0}暂停一局", players[isOne]);
}
else if (plays[num[isOne] - 1] == 4)
{
Console.Clear();
map(num, countRan);
Console.WriteLine("玩家{0}来到时空隧道,前进10步", players[isOne]);
Console.WriteLine("按任意键继续......");
Console.ReadKey(true);
Console.Clear();
if (num[isOne] + 10 > 100)
{
num[isOne] = 190 - num[isOne];
map(num, countRan);
}
else if (num[isOne] + 10 == 100)
{
num[isOne] += 10;
map(num, countRan);
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("玩家{0}获胜", players[isOne]);
break;
}
else
{
num[isOne] += 10;
map(num, countRan);
//判断+10后的plays[i]的值是否为特殊符号的值
goto newPlays;
}
}
else
map(num, countRan);
if (oldPlays == 3 && plays[num[isOne] - 1] != 3)
{
if (isOne == 1 && isTrue)
{
isOne = 0;
isTrue = false;
}
else if (isOne == 0 && isTrue)
{
isOne = 1;
isTrue = false;
}
else
isTrue = true;
}
else
isTrue = true;
//oldPlays:记录当前plays[i]的值,为下次循环做准备
oldPlays = plays[num[isOne] - 1];
isOne++;
if (isOne > 1)
isOne = 0;
}
#endregion
Console.ReadLine();
}
}
}
飞行棋java 飞行棋情侣版
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章