Question: I need assistance with my array as I am using it as a method, but it's not working. namespace CPT230Maze { public partial class Form1

I need assistance with my array as I am using it as a method, but it's not working.

namespace CPT230Maze { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) { txtx.Text = "0"; txty.Text = "0"; txtOutput.Text = "You are in a room with an exit to the North, South, East, and West." + " Get the right coordinates to exit the room by clicking the Action button."; }

private void MoveToRoom() {

string[,] getRooms = new string[4, 4] { {"North 0, -2", "North 0, -1", "North 0, 0", "North 0, 1"}, {"South 0, 1", "South 0, 0", "South 0, -1", "South 0, -2"}, {"East -2, 0", "East -1, 0", "East 0, 0", "East 1, 0"}, {"West 2, 0", "West 1, 0", "West 0, 0", "West -1, 0"},

}; if (getRooms.Length == 1) { for (int r = 0; r < getRooms.GetLength(0); r++) { for (int c = 0; c < getRooms.GetLength(1); c++) { txtOutput.Text = ("You are in room " + getRooms[r, c].ToString()); } }

} else if (getRooms.Length == 1) { for (int r = 1; r < getRooms.GetLength(0); r++) { for (int c = 1; c < getRooms.GetLength(1); c++) { txtOutput.Text = ("You are in room " + getRooms[r, c].ToString()); } } }

else if (getRooms.Length == 1) { for (int r = 2; r < getRooms.GetLength(0); r++) { for (int c = 2; c < getRooms.GetLength(1); c++) { txtOutput.Text = ("You are in room " + getRooms[r, c].ToString()); } } }

else if (getRooms.Length == 1) { for (int r = 3; r < getRooms.GetLength(0); r++) { for (int c = 3; c < getRooms.GetLength(1); c++) { txtOutput.Text = ("You are in room " + getRooms[r, c].ToString()); } } }

else { //Let's the player know they have made a wrong move WrongMove(); }

}

private void btnNorth_Click(object sender, EventArgs e) { int x = Convert.ToInt32(txtx.Text); int y = Convert.ToInt32(txty.Text);

if (x == 0 && y >= -3) { MoveToRoom(); btAction.Visible = true; } else { //Let's the player know they have made a wrong move WrongMove(); } }

private void btEast_Click(object sender, EventArgs e) { int x = Convert.ToInt32(txtx.Text); int y = Convert.ToInt32(txty.Text);

//starting from room 2, 0 if (x >= -3 && y == 0) { MoveToRoom(); btAction.Visible = true; } else {

//Let's the player know they have made a wrong move WrongMove(); } }

private void btSouth_Click(object sender, EventArgs e) { int x = Convert.ToInt32(txtx.Text); int y = Convert.ToInt32(txty.Text);

//starting from room 0, 1 //starting from room 0, -2 if (x == 0 && y <= 3) { MoveToRoom(); btAction.Visible = true; }

else {

//Let's the player know they have made a wrong move WrongMove(); } }

private void btWest_Click(object sender, EventArgs e) { int x = Convert.ToInt32(txtx.Text); int y = Convert.ToInt32(txty.Text);

//starting from room 1, 0 //starting from room 0, -2 if (x <= 3 && y == 0) { MoveToRoom(); btAction.Visible = true; } else {

//Let's the player know they have made a wrong move WrongMove();

} }

private void btAction_Click(object sender, EventArgs e) { int x = Convert.ToInt32(txtx.Text); int y = Convert.ToInt32(txty.Text); bool levelPull = Convert.ToBoolean(txtLever.Text); if (!levelPull && x == -1 && y == 0) { txtOutput.Text += " You were tricked. Hahahahaha! Play again!"; txtLever.Text = "true"; btAction.Visible = false;

}

else if (!levelPull && x == 1 && y == 0) { btAction.Text = "Exit"; MessageBox.Show("You chose correctly. You get to exit.", "YAHOO! (^_^) "); btAction.Visible = true; this.Close();

}

else {

txtOutput.Text = "Ooops! You were not chosen. Play again!"; btAction.Visible = false;

} }

private void WrongMove() { // let's the player know they need to start again MessageBox.Show("You can't go that way!", "Sorry, Dav, I can't do that."); btAction.Visible = true; }

private void textBox1_TextChanged(object sender, EventArgs e) {

}

private void txtx_TextChanged(object sender, EventArgs e) {

} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It seems like there are a few issues in your code Lets address them 1 Logic in MoveToRoom Your logic ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!