c# Console app error [SOLVED]
Posted: Wed Mar 14, 2012 10:37 pm
So i'm writing a quick little console game for practice and basically what i want is:
when the player presses "d" they move right, "a" they move left, etc etc. here is the code i have right now
The two for loops are checking for the players position, and once they have the players position they are checking if they tile next to it is a "." or a blank tile. Once all of those things are true it writes the current player position to a "." and the tile next to it as a "P" for Player.
My only problem as of now is that once i press D it moves the player all the way to the edge of the screen and tries to write a "P" in a slot on the array that does not exist, thus giving me an error.
Also fyi if it helps the Tiles.gsTiles is the get/set method for a tile array i wrote in the tile class which is basically a 2 dimensional string array that holds the tile info that looks like:
when the player presses "d" they move right, "a" they move left, etc etc. here is the code i have right now
Code: Select all
cki = Console.ReadKey();
if (cki.Key == ConsoleKey.D)
{
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
if(Tiles.gsTiles[x , y] == "P" & Tiles.gsTiles[x + 1, y] == ".")
{
Tiles.gsTiles[x, y] = ".";
Tiles.gsTiles[x + 1, y] = "P";
Tiles.boardWrite();
}
}
}
}
My only problem as of now is that once i press D it moves the player all the way to the edge of the screen and tries to write a "P" in a slot on the array that does not exist, thus giving me an error.
Also fyi if it helps the Tiles.gsTiles is the get/set method for a tile array i wrote in the tile class which is basically a 2 dimensional string array that holds the tile info that looks like:
Code: Select all
static private string[,] tiles = new string[ 10, 10];
static public string[,] gsTiles
{
get { return tiles; }
set { tiles = value; }
}