C#飞行棋....
来源:互联网 发布:游民星空mac版游戏 编辑:程序博客网 时间:2024/05/22 10:50
没有使用面向对象的思想
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 骑士飞行棋
{
class Program
{
static int[] Map = new int[100];//初始化地图的数组
static int[] PlayerPos = { 0, 0 };//玩家位置初始化
static void Main(string[] args)
{
Random r = new Random();//r是产生随机数用的
int step = 0;//用于存放随机数
bool[] isStop = {false,false };//判断是否停下
string msg = "";//显示玩家当前信息
ShowUI();//显示游戏名称
string[] names = new string[2];//names[0]存贮玩家A的姓名,names[1]存贮玩家B的姓名
Console.WriteLine("请输入玩家A的姓名:");
names[0] = Console.ReadLine();
while (names[0] =="")//判断玩家A姓名是否为空
{
Console.WriteLine("玩家姓名不能为空,请重新输入:");
names[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的姓名:");
names[1] = Console.ReadLine();
while (names[1] == ""||names[1]==names[0])//判断玩家B的姓名是否为空且是否与A重名
{
if (names[1] == "")
{
Console.WriteLine("玩家姓名不能为空,请重新输入:");
}
if (names[1] == names[0])
{
Console.WriteLine("与玩家A重名,请重新输入:");
}
names[1] = Console.ReadLine();
}
Console.Clear();//清理屏幕
ShowUI();//显示游戏名
Console.WriteLine("玩家{0}的士兵用A",names[0]);
Console.WriteLine("玩家{0}的士兵用B", names[1]);
Console.WriteLine("如果玩家A的位置与B的位置相同,用<>表示");
InitialMap();//初始化地图
DrawMap();//绘制地图
//这个循环中让玩家A和玩家B轮流掷筛子.当玩家A或者玩家B的位置大于等于99时,游戏结束
while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
{
// 玩家A掷筛子
if (isStop[0] == false)
{
Console.WriteLine("{0}按任意键开始掷筛子", names[0]);
Console.ReadKey(true);
step = r.Next(1, 7);
Console.WriteLine("{0}掷出了{1}", names[0], step);
Console.WriteLine("按任意键开始行动......");
Console.ReadKey(true);
PlayerPos[0] = PlayerPos[0] + step;
CheckPos();
if (PlayerPos[0] == PlayerPos[1])//玩家A踩着玩家B
{
PlayerPos[1] = 0;
msg = string.Format("{0}踩到了{1},{1}退回原地", names[0], names[1], names[1]);
}
else
{ //没踩到
switch (Map[PlayerPos[0]])
{
case 0://普通 无效果
msg = "";
break;
case 1://幸运轮盘 选择
Console.Clear();
DrawMap();
Console.WriteLine("{0}走到了幸运轮盘,请选择运气......", names[0]);
Console.WriteLine("1---交换位置 2---轰炸敌方");
int userSelect = ReadInt(1, 2);
//while (userSelect != 1 || userSelect != 2)
//{
// Console.WriteLine("请重新输入1-2之间的整数:");
// userSelect = Convert.ToInt32(Console.ReadLine());
//}
if (userSelect == 1)
{
int temp = 0;
temp = PlayerPos[0];
PlayerPos[0] = PlayerPos[1];
PlayerPos[1] = temp;
msg = string.Format("{0}选择了与敌方交换位置", names[0]);
}
else
{
PlayerPos[1] = PlayerPos[1] - 6;
CheckPos();
msg = string.Format("{0}选择了轰炸敌方,{1}退六步", names[0], names[1]);
}
break;
case 2://地雷
PlayerPos[0] = PlayerPos[0] - 20;
CheckPos();
msg = string.Format("{0}踩到地雷退20步", names[0]);
break;
case 3://暂停
isStop[0] = true;
msg = string.Format("{0}走到暂停,暂停一次", names[0]);
break;
case 4://时光隧道
PlayerPos[0] = PlayerPos[0] + 10;
CheckPos();
msg = string.Format("{0}进入时光隧道,进十步", names[0]);
break;
}
}
Console.Clear();
GetMapString(PlayerPos[0]);
DrawMap();
if (msg != "")
{
Console.WriteLine(msg);
}
Console.WriteLine("{0}掷出了{1}", names[0], step);
Console.WriteLine("{0}的位置为{1}", names[0], PlayerPos[0] + 1);
Console.WriteLine("{0}的位置为{1}", names[1], PlayerPos[1] + 1);
//Console.WriteLine("{0}按任意键开始掷筛子......", names[1]);
}
else
{
isStop[0] = false;
}
if (PlayerPos[0] >= 99)
{
break;
}
if (isStop[1] == false)
{
// 玩家B掷筛子
Console.WriteLine("{0}按任意键开始掷筛子", names[1]);
Console.ReadKey(true);
step = r.Next(1, 7);
Console.WriteLine("{0}掷出了{1}", names[1], step);
Console.WriteLine("按任意键开始行动......");
Console.ReadKey(true);
PlayerPos[1] = PlayerPos[1] + step;
CheckPos();
if (PlayerPos[1] == PlayerPos[0])//玩家A踩着玩家B
{
PlayerPos[0] = 0;
msg = string.Format("{0}踩到了{1},{1}退回原地", names[1], names[0], names[0]);
}
else
{ //没踩到
switch (Map[PlayerPos[1]])
{
case 0://普通 无效果
msg = "";
break;
case 1://幸运轮盘 选择
Console.Clear();
DrawMap();
Console.WriteLine("{0}走到了幸运轮盘,请选择运气......", names[1]);
Console.WriteLine("1---交换位置 2---轰炸敌方");
int userSelect = ReadInt(1, 2);
//while (userSelect != 1 || userSelect != 2)
//{
// Console.WriteLine("请重新输入1-2之间的整数:");
// userSelect = Convert.ToInt32(Console.ReadLine());
//}
if (userSelect == 1)
{
int temp = 0;
temp = PlayerPos[1];
PlayerPos[1] = PlayerPos[0];
PlayerPos[0] = temp;
msg = string.Format("{0}选择了与敌方交换位置", names[1]);
}
else
{
PlayerPos[0] = PlayerPos[0] - 6;
}
break;
case 2://地雷
PlayerPos[1] = PlayerPos[1] - 20;
CheckPos();
msg = string.Format("{0}踩到地雷退20步", names[1]);
break;
case 3://暂停
break;
case 4://时光隧道
PlayerPos[1] = PlayerPos[1] + 10;
CheckPos();
msg = string.Format("{0}进入时光隧道,进十步", names[1]);
break;
}
}
Console.Clear();
GetMapString(PlayerPos[1]);
DrawMap();
if (msg != "")
{
Console.WriteLine(msg);
}
Console.WriteLine("{0}掷出了{1}", names[1], step);
Console.WriteLine("{0}的位置为{1}", names[0], PlayerPos[0] + 1);
Console.WriteLine("{0}的位置为{1}", names[1], PlayerPos[1] + 1);
//Console.WriteLine("{0}按任意键开始掷筛子......", names[1]);
}
else
{
isStop[1] = false;
}
}
Console.Clear();
ShowUI();
DrawMap();
if(PlayerPos[0]>=99)
{
Console.WriteLine("玩家{0}获取胜利!!!!!!!!!",names[0]);
}
else
{
Console.WriteLine("玩家{0}获取胜利!!!!!!!!!",names[1]);
}
Console.ReadKey();
}//游戏至此结束
static void ShowUI()//用于绘制飞行棋的名称
{
Console.WriteLine("***********************************************");
Console.WriteLine("* *");
Console.WriteLine("* 骑士飞行棋 *");
Console.WriteLine("* *");
Console.WriteLine("***********************************************");
}
static void InitialMap()
{
int[] luckyTurn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘 1
int[] landMain = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷 2
int[] pause = { 9, 27, 60, 93 };//暂停 3
int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时光隧道 4
for (int i = 0; i < luckyTurn.Length; i++)
{
int pos = luckyTurn[i];
Map[pos] = 1;
}
for (int i = 0; i < landMain.Length; i++)
{
Map[landMain[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;
}
}//初始化地图
static string GetMapString(int pos)//获得POS中的图案
{
string result = "";
if (PlayerPos[0] == pos && PlayerPos[1] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result="<>";
}
else if (PlayerPos[0] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result="A";
}
else if (PlayerPos[1] == pos)
{
Console.ForegroundColor = ConsoleColor.Yellow;
result="B";
}
else
{
switch (Map[pos])
{
case 0:
Console.ForegroundColor = ConsoleColor.White;
result="□";
break;
case 1:
Console.ForegroundColor = ConsoleColor.Green;
result="◎";
break;
case 2:
Console.ForegroundColor = ConsoleColor.Red;
result="★";
break;
case 3:
Console.ForegroundColor = ConsoleColor.DarkBlue;
result="▲";
break;
case 4:
Console.ForegroundColor = ConsoleColor.DarkMagenta;
result="卐";
break;
}
}
return result;
}
static void CheckPos()//进行玩家是否越界判断
{
for (int i = 0; i < 2;i++ )
{ if (PlayerPos[i] > 99)
{
PlayerPos[i] = 99;
}
if (PlayerPos[i] < 0)
{
PlayerPos[i] = 0;
}
}
}
static void DrawMap()
{
//输出图示
Console.WriteLine("图示:□普通 ◎幸运轮盘 ★地雷 ▲暂停 卐时光隧道");
//画地图 第一行:
for (int i = 0; i <= 29; i++)
{
Console.Write(GetMapString(i));
}
Console.WriteLine();
//绘制第一列
for (int i = 30; i <= 34; i++)
{
for (int j = 0; j <29; j++)
{
Console.Write(" ");
}
Console.WriteLine(GetMapString(i));
}
for (int i = 64; i > 34; i--)
{
Console.Write(GetMapString(i));
}
Console.WriteLine();
for (int i = 65; i <= 69; i++)
{
Console.WriteLine(GetMapString(i));
}
for (int i = 70; i <= 99; i++)
{
Console.Write(GetMapString(i));
}
Console.WriteLine();
Console.ResetColor();
}//绘制地图
static int ReadInt()
{
int i = ReadInt(int.MinValue, int.MaxValue);
return i;
}
static int ReadInt(int min, int max)
{
while (true)
{
try
{
int number = Convert.ToInt32(Console.ReadLine());
if (number < min || number > max)
{
Console.WriteLine("只能输入{0}-{1}之间的数", min, max);
continue;
}
return number;
}
catch
{
Console.WriteLine("只能输入数字,请重新输入");
}
}
}//介于1-2之间的判断
}
}
完成。。。。。
- C#飞行棋....
- 【C#】骑士飞行棋
- [C#]骑士飞行棋
- C#(经典)新手项目《骑士飞行棋 》
- C#/.net学习-7-飞行棋代码
- 飞行棋
- 飞行棋
- 飞行棋
- 飞行棋
- 骑士飞行棋C语言无指针版
- 开发一款C语言小游戏——骑士飞行棋
- C语言编写小游戏——骑士飞行棋
- C#——第1个:飞行棋项目
- C#,GDI+开发飞行仪表
- 飞行棋源代码
- 骑士飞行棋
- 骑士飞行棋
- 骑士飞行棋
- Oracle备份与恢复2
- struts2中后台代码操作cookie
- Qt基础——让使用Designer创建的UI也能自动适应窗口大小
- 在google地图上拖拽Marker事件
- hdu 1394
- C#飞行棋....
- Ragel的编译
- lucene3.6全文检索word2007
- 这段javascript真强悍
- Harfbuzz编译
- Qt再易主,将登陆三大阵营OS平台
- {{JS}}事件句柄
- Spring事务配置的五种方式及事务只读
- 网新恒天2011.9.21招聘会笔试题