编写一个飞行棋项目(C#)遇到几个问题:
在写程序中遇到如下问题:如果有人知道,请您一定要指点迷津。小白。
1.在运行暂停功能时,这个暂停功能可以实现,但是无法显示提示信息。
case 3:
Console.Clear();
Program.drawmap();
isstop[0] = true;
msg = string.Format("{0}走到了地雷,暂停一次!", name[0]);
break;
2.下面这行代码没有效果:(我换了一下console.clear()的位置不行,但去掉可以实现,但是也没有清屏了。)
Console.WriteLine("{0}掷出了{1}", name[0], playpost[0]);
Console.WriteLine("*******************************************");
Console.WriteLine("{0}的位置{1}", name[0], playpost[0] + 1);
Console.WriteLine("{0}的位置{1}", name[1], playpost[1] + 1);
Console.Clear();
Program.chushiMap();
Program.drawmap();
3.玩家走不出去,就算位置大于99了,还是会返回,走不到终点。(我没有设置位置必须为99才胜利的要求)。
完整代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace 骑士飞行棋
{
class Program
{
static int[] map = new int[];
static int[] playpost = new int[]{,};
/// <summary>
/// 界面函数
/// </summary>
static void Menus()
{
Console.WriteLine("\t************************************************\t");
Console.WriteLine("\t* *\t");
Console.WriteLine("\t* 骑 士 飞 行 棋 *\t");
Console.WriteLine("\t************************************************\t");
}
/// <summary>
/// 地图
/// </summary>
static void chushiMap()
{ int[] luckkey = new int[] { , , , , , };//幸运轮盘
int[] Landmine = new int[] { , , , , , };//地雷
int[] Pause = new int[] { , , , , , };//暂停
int[] Timeturn = new int[] { , , , , };//时空隧道
for (int i = ; i < luckkey.Length; i++)
{
int pos = luckkey[i];
map[pos] = ;
}
for (int i = ; i < Landmine.Length; i++)
{
int pos = Landmine [i];
map[pos] = ;
}
for (int i = ; i < Pause.Length; i++)
{
int pos = Pause [i];
map[pos] = ;
}
for (int i = ; i < Timeturn.Length; i++)
{
int pos = Timeturn [i];
map[pos] = ;
} }
/// <summary>
/// 判断AB的位置
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
static string panduan(int pos)
{
string result = "";
if (playpost[] == pos && playpost[] == pos)
{
Console.ForegroundColor = ConsoleColor.Red;
result = "<>";
}
else if (playpost[] == pos)
{
Console.ForegroundColor = ConsoleColor.Red;
result = "Α";
}
else if (playpost[] == pos)
{
Console.ForegroundColor = ConsoleColor.Red;
result = "Β";
}
else
{
switch (map[pos])
{
case :
result = "□"; break;
case :
Console.ForegroundColor = ConsoleColor.Yellow;
result = "◎"; break;
case :
Console.ForegroundColor = ConsoleColor.Green;
result = "※"; break;
case :
Console.ForegroundColor = ConsoleColor.DarkRed;
result = "▲"; break;
case :
Console.ForegroundColor = ConsoleColor.Blue;
result = "卍"; break; }
}
return result;
}
/// <summary>
/// 绘制AB的位置,在地图上
/// </summary>
static void drawmap()
{
for (int i = ; i <= ; i++)
{
Console.Write(Program.panduan(i)); }
Console.WriteLine();
for (int i = ; i <= ; i++)
{
for (int j = ; j < ; j++)
{
Console.Write (" ");
}
Console.WriteLine(panduan(i)); }
for (int i = ; i >= ; i--)
{
Console.Write(panduan(i));
}
Console.WriteLine();
for (int i = ; i <= ; i++)
{
Console.WriteLine(panduan(i));
}
for (int i = ; i <= ; i++)
{
Console.Write(panduan(i));
}
Console.WriteLine();
} /// <summary>
/// 作为玩家A和玩家B坐标越界的一个判断
/// </summary>
/// <param name="args"></param>
static void check()
{
for (int i = ; i <= ; i++)
{
if (playpost[i] > )
{
playpost[i] = ;
}
else if (playpost[i] < )
{
playpost[i] = ;
}
}
}
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之间的数字,从新输入!");
continue;
}
return number;
}
catch
{
Console.WriteLine("只能输入数字,从新输入!");
}
} }
/// <summary>
/// 主函数
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
string msg = "";
Random random = new Random();
bool[] isstop = { false, false };//定义一个布尔类型,false表示运行、true表示暂停
int step = ;
string[] name = new string[];//定义AB两玩家的名称(name[0]为A玩家name[1]为B玩家)
Program.Menus();//显示游戏名称
Console.WriteLine("请输入玩家A的名称:");
name[] = Console.ReadLine();
//判断用户输入的内容是否为空
while (name[] == "")
{
Console.WriteLine("玩家名称不能为空,请重新输入!");
name[] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的名称:");
name[] = Console.ReadLine();
//判断用户输入的内容是否为空或是否与玩家A的名称相同
while (name[] == "" || name [] == name [])
{
if (name[] == "")
{
Console.WriteLine("玩家名称不能为空,请重新输入!");
name[] = Console.ReadLine();
}
else if (name[] == name[])
{
Console.WriteLine("玩家B的名称不能与玩家A的名称相同,请重新输入!");
name[] = Console.ReadLine();
}
}
Console.Clear();
Program.Menus();
Console.WriteLine("对战开始!");
Console.WriteLine("{0}玩家使用A进行游戏", name[]);
Console.WriteLine("{0}玩家使用B进行游戏", name[]);
Console.WriteLine("当AB处在相同位置上时,显示<>");
Console.WriteLine("幸运轮盘◎ 炸弹※ 暂停▲ 时光隧道卍 ");
Console.WriteLine();
Program.chushiMap();
Program.drawmap();
Console.Clear();
Program.drawmap();
while(playpost [] < && playpost [] < )
{
if (isstop[] == false)
{
#region 玩家A之色子 Console.WriteLine("{0}按任意键开始游戏", name[]);
Console.ReadKey(true);
step = random.Next(, );
Console.WriteLine("{0}执出了:{1}", name[], step);
Console.WriteLine("按任意键执行。。。。。");
Console.ReadKey(true);
playpost[] += step;
Program.check();
if (playpost[] == playpost[])
{
playpost[] = ;
}
else
{
switch (map[playpost[]])
{
case :
break;
case :
Console.Clear();
Program.drawmap();
Console.WriteLine("恭喜您!走到了幸运轮盘,请您选择您的幸运数(1-2):");
Console.WriteLine("---------------------------------------------------");
Console.WriteLine(" 1. 交换位置 2.轰炸对方 ");
int userselect = ReadInt(, );
if (userselect == )
{
int temp = playpost[];
playpost[] = playpost[];
playpost[] = temp;
}
else
{
playpost[] = playpost[] - ;
Program.check();
}
break;
case :
playpost[] = playpost[] - ;
Program.check();
break;
case :
Console.Clear();
Program.drawmap();
isstop[] = true;
msg = string.Format("{0}走到了地雷,暂停一次!", name[]);
break;
case :
playpost[] = playpost[] + ;
Program.check();
break;
} } Console.WriteLine("{0}掷出了{1}", name[], playpost[]);
Console.WriteLine("*******************************************");
Console.WriteLine("{0}的位置{1}", name[], playpost[] + );
Console.WriteLine("{0}的位置{1}", name[], playpost[] + );
Console.Clear();
Program.chushiMap(); Program.drawmap(); #endregion
}
else
{
isstop[] = false;
}
if (playpost[] >= )
{
break;
}
if (isstop[] == false)
{
#region 玩家B之色子
Console.WriteLine("{0}按任意键开始游戏", name[]);
Console.ReadKey(true);
step = random.Next(, );
Console.WriteLine("{0}执出了:{1}", name[], step);
Console.WriteLine("按任意键执行。。。。。");
Console.ReadKey(true);
playpost[] += step;
Program.check();
if (playpost[] == playpost[])
{
playpost[] = ;
}
else
{
switch (map[playpost[]])
{
case :
break;
case :
Console.Clear();
Program.drawmap();
Console.WriteLine("恭喜您!走到了幸运轮盘,请您选择您的幸运数(1-2):");
Console.WriteLine("---------------------------------------------------");
Console.WriteLine(" 1. 交换位置 2.轰炸对方 ");
int userselect = ReadInt(, );
if (userselect == )
{
int temp = playpost[];
playpost[] = playpost[];
playpost[] = temp;
}
else
{
playpost[] -= ;
Program.check();
}
break;
case :
playpost[] -= ;
Program.check();
break;
case :
Console.Clear();
Program.drawmap();
isstop[] = true;
msg = string.Format("{0}走到了地雷,暂停一次!", name[]);
break;
case :
playpost[] += ;
Program.check();
break;
}
} Console.WriteLine("{0}掷出了{1}", name[], playpost[]);
Console.WriteLine("*******************************************");
Console.WriteLine("{0}的位置{1}", name[], playpost[] + );
Console.WriteLine("{0}的位置{1}", name[], playpost[] + );
Console.Clear();
Program.chushiMap();
Program.drawmap();
#endregion
}
else
{
isstop[] = false;
}
if (playpost[] >= )
{
break;
}
}
if (playpost[] >= )
{
Console.WriteLine("{0}玩家胜利", name[]);
}
else
{
Console.WriteLine("{0}玩家胜利", name[]);
}
Console.ReadKey();
}
}
}
编写一个飞行棋项目(C#)遇到几个问题:的更多相关文章
- C#基础:飞行棋游戏
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 用Java语言编写一个简易画板
讲了三篇概博客的概念,今天,我们来一点实际的东西.我们来探讨一下如何用Java语言,编写一块简易的画图板. 一.需求分析 无论我们使用什么语言,去编写一个什么样的项目,我们的第一步,总是去分析这个项目 ...
- IT第十一天、第十二天、第十三天 - 数组的应用、飞行棋游戏的编写和总结
NIIT第十一天 上午 多维数组 1.数组是引用数据类型 排序 1.冒泡排序法 2.类冒泡排序法 下午 飞行棋游戏 1.项目策划 2.项目规则确认 3.项目模块确认 晚上 1.飞行棋游戏,项目框架的编 ...
- 从头开始编写一个Orchard网上商店模块(3) - 创建Orchard.Webshop模块项目
原文地址:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-par ...
- JAVA WEB快速入门之从编写一个基于SpringBoot+Mybatis快速创建的REST API项目了解SpringBoot、SpringMVC REST API、Mybatis等相关知识
JAVA WEB快速入门系列之前的相关文章如下:(文章全部本人[梦在旅途原创],文中内容可能部份图片.代码参照网上资源) 第一篇:JAVA WEB快速入门之环境搭建 第二篇:JAVA WEB快速入门之 ...
- 作业二:个人编程项目——编写一个能自动生成小学四则运算题目的程序
1. 编写一个能自动生成小学四则运算题目的程序.(10分) 基本要求: 除了整数以外,还能支持真分数的四则运算. 对实现的功能进行描述,并且对实现结果要求截图. 本题发一篇随笔,内容包括: 题 ...
- C#面向过程项目之飞行棋
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 飞行棋V ...
- CSharpGL(34)以从零编写一个KleinBottle渲染器为例学习如何使用CSharpGL
CSharpGL(34)以从零编写一个KleinBottle渲染器为例学习如何使用CSharpGL +BIT祝威+悄悄在此留下版了个权的信息说: 开始 本文用step by step的方式,讲述如何使 ...
- 网络爬虫:使用Scrapy框架编写一个抓取书籍信息的爬虫服务
上周学习了BeautifulSoup的基础知识并用它完成了一个网络爬虫( 使用Beautiful Soup编写一个爬虫 系列随笔汇总 ), BeautifulSoup是一个非常流行的Python网 ...
随机推荐
- css布局-多行文字垂直居中
方法一: 代码: <style> *{padding: ;margin:;font-size: 12px;} div{float: left;width: 200px;height:200 ...
- Python中下划线---完全解读
Python 用下划线作为变量前缀和后缀指定特殊变量 _xxx 不能用'from module import *'导入 __xxx__ 系统定义名字 __xxx 类中的私有变量名 核心风格:避免用下划 ...
- debugger 调试的一些经验
1. 如果没有firebug , 可以用firebug-lite.js 内嵌的调试方式. 2. console.log 不是所有浏览器都支持console.log 在IE或者没有调试窗口的浏览器中,c ...
- jquery.cookie实战用法详细解析
Cookie是由服务器端生成,发送给User-Agent(一般是浏览器),浏览器会将Cookie的key/value保存到某个目录下的文本文件内,下次请求同一网站时就发送该Cookie给服务器(前提是 ...
- eclipse调试找不到源解决办法
eclipse调试时有时显示找不到源码,首先得确定代码没问题 这是eclipse没有发现工程源码,解决办法是 右键工程>>Debug As >> Debug configura ...
- FMS+NGINX打造高带宽利用率的流媒体(音频+视频)环境
fms自身已经拥有了httpd,用来给客户端访问用,例如通过http的音频播放.众所周知,非专业的httpd自然有不专业之处,例如我遇到的情况就是经常http服务假死,或者在访问量庞大的时候会无缘无故 ...
- vue初探
vue初探 很多同学一定都听过MVVM.组件.数据绑定之类的专业术语,而vue框架正是这样的一种框架.vue的作用是:通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件. 第一部分:vue介 ...
- 玩转微信小程序
原文链接 2007 年 1 月 9 号,苹果一代在功能机盛行的年代中出世. 2017 年 1 月 9 号,微信小程序在重型app风靡的压力下上线. 苹果的出世掀起了互联网一波又一波的浪潮,而微信小程序 ...
- linux开机自启动服务优化设置命令
1.设置成英文字符,避免出现乱码[root@xuegod62 ~]# LANG=en2.两种配置linux开机自启动服务命令:1)[root@xuegod62 ~]# ntsysv2)[root@xu ...
- 深圳尚学堂:JavaScript的常见面试题
经常说编程是一门技术专业,在找工作时面试官肯定不止看你的面试能力,还要看你的专业知识掌握,他可能会让你做一个小的编程测试,或者说考察你的语法知识掌握,今天,总结了一些关于在JavaScript中常常会 ...