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
Step: 1
It seems like there are a few issues in your code Lets address them 1 Logic in MoveToRoom Your logic ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started