好的我的程序我试图得到它,以便当我按下我的程序按键并说我按L并且它在4x4 2d阵列中移动并且我到达我在阵列上指定为P的坑我希望它知道它击中了P并且打印出你有一个坑,或者如果我到达它在阵列上有G的地方我希望它打印出来你已经找到了金币。任何帮助表示赞赏。
using System;
namespace DragonCave
{
public struct DragonPlayer
{
public int X, Y;
public string CurrentMove;
}
public class DragonGameboard
{
public string[,] GameboardArray;
public DragonPlayer Player;
private Random r;
public DragonGameboard(){
GameboardArray = new string[4,4];
Player.CurrentMove = "";
r = new Random();
Player.X = r.Next(0, 4);
Player.Y = r.Next(0, 4);
GenerateRandomBoard();
}
private void GenerateRandomBoard()
{
//Put a dot in every spot
int row;
int col;
for (row = 0; row < 4; row++)
{
for (col = 0; col < 4; col++)
{
Console.Write(GameboardArray[row, col] = ".");
}
//Console.WriteLine();
}
//Randomly Places the entrance, dragon, pit and gold.
GameboardArray[r.Next(0,4), r.Next(0, 4)] = "E";
GameboardArray[r.Next(0,4), r.Next(0,4)] = "D";
GameboardArray[r.Next(0, 4), r.Next(0, 4)] = "P";
GameboardArray[r.Next(0, 4), r.Next(0, 4)] = "P";
GameboardArray[r.Next(0, 4), r.Next(0, 4)] = "P";
GameboardArray[r.Next(0, 4), r.Next(0, 4)] = "G";
}
public void PrintBoard()
{
int row;
int col;
for (row = 0; row < 4; row++)
{
for (col = 0; col < 4; col++)
{
Console.Write(GameboardArray[row, col] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("Cheat you are in" + Player.X + "," + Player.Y);
//fill with room numbers
}
public void ProcessMove(string move)
{
switch (move)
{
case "F":
Console.WriteLine("You chose forward");
break;
case "L":
Player.X--;
Player.Y--;
//Console.WriteLine("You chose Left");
Console.WriteLine("A Breeze is in the air");
break;
case "R":
Player.X++;
Player.Y++;
if (GameboardArray)
Console.WriteLine("You chose Right");
break;
case "G":
Console.WriteLine("You chose Grab gold");
break;
case "S":
Console.WriteLine("You chose Shoot arrow");
break;
case "C":
Console.WriteLine("You chose Climb");
break;
case "Q":
Console.WriteLine("You chose Quit");
break;
case "X":
Console.WriteLine("You chose Cheat");
PrintBoard();
break;
default:
Console.WriteLine("Invalid move!!!!!!!!!!1");
break;
}
}
}
答案 0 :(得分:0)
只需检查GameboardArray [player.x,player.y]中的字符串是什么。
public void ProcessTileEvent()
{
if( Player.X >= 0 && Player.X < 4 && Player.Y >= 0 && Player.Y < 4 )
{
switch( GameboardArray[Player.X, Player.Y] )
{
case "G":
Console.WriteLine( "You found gold!" );
break;
case "P":
Console.WriteLine( "You fell in a pit!" );
break;
}
}
}
你可能希望每次玩家移动时都这样做。