编写一个飞行棋项目(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[100];
static int[] playpost = new int[]{0,0};
/// <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[] { 6, 12, 19, 28, 46, 66 };//幸运轮盘
int[] Landmine = new int[] { 45, 58, 62, 79, 88, 99 };//地雷
int[] Pause = new int[] { 33, 51, 68, 70, 80, 95 };//暂停
int[] Timeturn = new int[] { 25, 39, 47, 59, 71 };//时空隧道
for (int i = 0; i < luckkey.Length; i++)
{
int pos = luckkey[i];
map[pos] = 1;
}
for (int i = 0; i < Landmine.Length; i++)
{
int pos = Landmine [i];
map[pos] = 2;
}
for (int i = 0; i < Pause.Length; i++)
{
int pos = Pause [i];
map[pos] = 3;
}
for (int i = 0; i < Timeturn.Length; i++)
{
int pos = Timeturn [i];
map[pos] = 4;
}

}
/// <summary>
/// 判断AB的位置
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
static string panduan(int pos)
{
string result = "";
if (playpost[0] == pos && playpost[1] == pos)
{
Console.ForegroundColor = ConsoleColor.Red;
result = "<>";
}
else if (playpost[0] == pos)
{
Console.ForegroundColor = ConsoleColor.Red;
result = "Α";
}
else if (playpost[1] == pos)
{
Console.ForegroundColor = ConsoleColor.Red;
result = "Β";
}
else
{
switch (map[pos])
{
case 0:
result = "□"; break;
case 1:
Console.ForegroundColor = ConsoleColor.Yellow;
result = "◎"; break;
case 2:
Console.ForegroundColor = ConsoleColor.Green;
result = "※"; break;
case 3:
Console.ForegroundColor = ConsoleColor.DarkRed;
result = "▲"; break;
case 4:
Console.ForegroundColor = ConsoleColor.Blue;
result = "卍"; break;

}
}
return result;
}
/// <summary>
/// 绘制AB的位置,在地图上
/// </summary>
static void drawmap()
{
for (int i = 0; i <= 29; i++)
{
Console.Write(Program.panduan(i));

}
Console.WriteLine();
for (int i = 30; i <= 34; i++)
{
for (int j = 0; j < 29; j++)
{
Console.Write (" ");
}
Console.WriteLine(panduan(i));

}
for (int i = 64; i >= 35; i--)
{
Console.Write(panduan(i));
}
Console.WriteLine();
for (int i = 65; i <= 69; i++)
{
Console.WriteLine(panduan(i));
}
for (int i = 70; i <= 99; i++)
{
Console.Write(panduan(i));
}
Console.WriteLine();
}

/// <summary>
/// 作为玩家A和玩家B坐标越界的一个判断
/// </summary>
/// <param name="args"></param>
static void check()
{
for (int i = 0; i <= 1; i++)
{
if (playpost[i] > 99)
{
playpost[i] = 99;
}
else if (playpost[i] < 0)
{
playpost[i] = 0;
}
}
}
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 = 0;
string[] name = new string[2];//定义AB两玩家的名称(name[0]为A玩家name[1]为B玩家)
Program.Menus();//显示游戏名称
Console.WriteLine("请输入玩家A的名称:");
name[0] = Console.ReadLine();
//判断用户输入的内容是否为空
while (name[0] == "")
{
Console.WriteLine("玩家名称不能为空,请重新输入!");
name[0] = Console.ReadLine();
}
Console.WriteLine("请输入玩家B的名称:");
name[1] = Console.ReadLine();
//判断用户输入的内容是否为空或是否与玩家A的名称相同
while (name[1] == "" || name [1] == name [0])
{
if (name[1] == "")
{
Console.WriteLine("玩家名称不能为空,请重新输入!");
name[1] = Console.ReadLine();
}
else if (name[1] == name[0])
{
Console.WriteLine("玩家B的名称不能与玩家A的名称相同,请重新输入!");
name[1] = Console.ReadLine();
}
}
Console.Clear();
Program.Menus();
Console.WriteLine("对战开始!");
Console.WriteLine("{0}玩家使用A进行游戏", name[0]);
Console.WriteLine("{0}玩家使用B进行游戏", name[1]);
Console.WriteLine("当AB处在相同位置上时,显示<>");
Console.WriteLine("幸运轮盘◎ 炸弹※ 暂停▲ 时光隧道卍 ");
Console.WriteLine();
Program.chushiMap();
Program.drawmap();
Console.Clear();
Program.drawmap();
while(playpost [0] < 99 && playpost [1] < 99)
{
if (isstop[0] == false)
{
#region 玩家A之色子

Console.WriteLine("{0}按任意键开始游戏", name[0]);
Console.ReadKey(true);
step = random.Next(1, 7);
Console.WriteLine("{0}执出了:{1}", name[0], step);
Console.WriteLine("按任意键执行。。。。。");
Console.ReadKey(true);
playpost[0] += step;
Program.check();
if (playpost[0] == playpost[1])
{
playpost[1] = 0;
}
else
{
switch (map[playpost[0]])
{
case 0:
break;
case 1:
Console.Clear();
Program.drawmap();
Console.WriteLine("恭喜您!走到了幸运轮盘,请您选择您的幸运数(1-2):");
Console.WriteLine("---------------------------------------------------");
Console.WriteLine(" 1. 交换位置 2.轰炸对方 ");
int userselect = ReadInt(1, 2);
if (userselect == 1)
{
int temp = playpost[0];
playpost[0] = playpost[1];
playpost[1] = temp;
}
else
{
playpost[1] = playpost[1] - 6;
Program.check();
}
break;
case 2:
playpost[0] = playpost[0] - 6;
Program.check();
break;
case 3:
Console.Clear();
Program.drawmap();
isstop[0] = true;
msg = string.Format("{0}走到了地雷,暂停一次!", name[0]);
break;
case 4:
playpost[0] = playpost[0] + 10;
Program.check();
break;
}

}

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();

#endregion
}
else
{
isstop[0] = false;
}
if (playpost[0] >= 99)
{
break;
}
if (isstop[1] == false)
{
#region 玩家B之色子
Console.WriteLine("{0}按任意键开始游戏", name[1]);
Console.ReadKey(true);
step = random.Next(1, 7);
Console.WriteLine("{0}执出了:{1}", name[1], step);
Console.WriteLine("按任意键执行。。。。。");
Console.ReadKey(true);
playpost[1] += step;
Program.check();
if (playpost[0] == playpost[1])
{
playpost[0] = 0;
}
else
{
switch (map[playpost[1]])
{
case 0:
break;
case 1:
Console.Clear();
Program.drawmap();
Console.WriteLine("恭喜您!走到了幸运轮盘,请您选择您的幸运数(1-2):");
Console.WriteLine("---------------------------------------------------");
Console.WriteLine(" 1. 交换位置 2.轰炸对方 ");
int userselect = ReadInt(1, 2);
if (userselect == 1)
{
int temp = playpost[1];
playpost[1] = playpost[0];
playpost[0] = temp;
}
else
{
playpost[0] -= 6;
Program.check();
}
break;
case 2:
playpost[1] -= 6;
Program.check();
break;
case 3:
Console.Clear();
Program.drawmap();
isstop[1] = true;
msg = string.Format("{0}走到了地雷,暂停一次!", name[1]);
break;
case 4:
playpost[1] += 10;
Program.check();
break;
}
}

Console.WriteLine("{0}掷出了{1}", name[1], playpost[1]);
Console.WriteLine("*******************************************");
Console.WriteLine("{0}的位置{1}", name[1], playpost[1] + 1);
Console.WriteLine("{0}的位置{1}", name[0], playpost[0] + 1);
Console.Clear();
Program.chushiMap();
Program.drawmap();
#endregion
}
else
{
isstop[1] = false;
}
if (playpost[1] >= 99)
{
break;
}
}
if (playpost[0] >= 99)
{
Console.WriteLine("{0}玩家胜利", name[0]);
}
else
{
Console.WriteLine("{0}玩家胜利", name[1]);
}
Console.ReadKey();
}
}
}
时间: 2024-08-01 10:41:50

编写一个飞行棋项目(C#)遇到几个问题:的相关文章

局域网多人对战飞行棋的实现

在项目之间有段“空项期”,上个项目刚刚完成,下个项目还没落实,时间比较充裕.去年9月份就经历了这么一次短暂的“空项期”,那时偶还是一名前端工作者,C#使用起来毫不含糊,还自己整过一个类SCSF的MVP框架AngelFrame(详见之前博客:http://www.cnblogs.com/wgp13x/p/99c2adc52d8f0dff30a038841ac32872.html).在那段“空项期”之前,有位朋友托我做个小游戏,偶也满口的答应,只可惜之前项目太忙没时间做,就一直耽搁了,正好有这段“空

用Java语言编写一个简易画板

讲了三篇概博客的概念,今天,我们来一点实际的东西.我们来探讨一下如何用Java语言,编写一块简易的画图板. 一.需求分析 无论我们使用什么语言,去编写一个什么样的项目,我们的第一步,总是去分析这个项目需要满足怎样的需求. 那么,画板需要满足怎样的需要呢?换句话说,在画板上,我们应该赋予它什么功能呢?从我们熟悉的画板来看,我们需要实现诸如铅笔.橡皮.喷枪.刷子的功能,我们可以画出一些规则的图形,比如直线.矩形.圆.最好我们还能调整画笔的颜色和粗细.以上,我们希望的是,当我们点击一个按钮的时候,我们

C#基础:飞行棋游戏

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Pachee { class Program { #region 静态字段 // 关卡数量 public static int[] Maps = new int[100]; // 玩家坐标 public static int[] PlayerPos

007 飞行棋小项目

2016-01-16 1.画游戏头2.初始化地图(加载地图所需要的资源)将整数数组中的数字编程控制台中显示的特殊字符串的这个过程 就是初始化地图3.画地图 4.玩游戏 游戏规则:如果玩家A踩到了玩家B  玩家B退6格  踩到了地雷 退6格踩到了时空隧道 进10格踩到了幸运轮盘 1交换位置  2 轰炸对方 使对方退6格踩到了暂停  暂停一回合  踩到了方块  神马都不干 主要引用用的方法 1 Map[50] 2 if(map[40]==1) 3 { 4 Console.WriteLine("◎&q

从头开始编写一个Orchard网上商店模块(3) - 创建Orchard.Webshop模块项目

原文地址:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-3创建Orchard.Webshop模块项目 这是从头开始编写一个新的Orchard模块的教程的第3篇.对于本教程的概述,请参阅介绍. Orchard模块是一个真正的ASP.NET MVC的Area类库,同时遵循了ASP.NET MVC和Orchard的特定的规范.Orchard 规范提升了您的

C#面向过程项目之飞行棋

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 飞行棋Ver1._0 { class Program { //如果元素的值是0 代表这是1个普通 //1 幸运轮盘 ◎ //2 暂停 ▲ //3 地雷 ● //4. 时光隧道 卍 static int[] map = new int[100]; static int[] pos = new int[2];/

如何编写NopCommerce插件(一)建立一个MVC的项目

一.建立一个MVC的项目: 二.添加Description.txt文件 其中,Group表示插件是属于哪一组. FriendlyName:插件的名称 SystemName:插件的唯一标示 FileName:插件所在的dll 三.添加RouteProvider.cs文件 public partial class RouteProvider : IRouteProvider { public void RegisterRoutes(RouteCollection routes) { routes.M

飞行棋2.0--输完姓名后全自动,可修改为人机交互模式

1 // 2 // main.m 3 4 #import <Foundation/Foundation.h> 5 #import "GameController.h" 6 int main(int argc, const char * argv[]) 7 { 8 GameController *ctl = [GameController new]; 9 [ctl startGame]; 10 11 // GameMap *map = [GameMap new]; 12 //

纠正飞行棋的错误

错误1:在运行暂停功能时,这个暂停功能可以实现,但无法显示提示信息. 改正如下: case 3: Console.Clear(); Program.drawmap(); isstop[0] = true; Console .WriteLine ("{0}走到了暂停,暂停一次!", name[0]); Console.WriteLine("按任意键继续...");  Console.ReadKey(true); 原因:缺少Console.WriteLine("