private void PlayingField_MouseDown(object sender, MouseEventArgs e) { /* * Looking back over this part of the code, I couldn't help but feel like... * this isn't elegant. This is crude. As an advanced-level programmer, we don't ever * want to settle for crude. We want elegance. We want our code to be sublime. * // First Row * if (e.X < (PlayingField.Width / 3) && e.Y < (PlayingField.Height / 3)) * { * if (theGrid[0, 0] == null) * theGrid[0, 0] = MyTurn; * else return; * } * if (e.X > (PlayingField.Width / 3) && e.X < (2 * PlayingField.Width / 3) && * e.Y < (PlayingField.Height / 3)) * { * if (theGrid[0, 1] == null) * theGrid[0, 1] = MyTurn; * else return; * } * if (e.X > (2 * PlayingField.Width / 3) && e.Y < (PlayingField.Height / 3)) * { * if (theGrid[0, 2] == null) * theGrid[0, 2] = MyTurn; * else return; * } * * // Second Row * if (e.X < (PlayingField.Width / 3) && e.Y > (PlayingField.Height / 3) && * e.Y < (2 * PlayingField.Height / 3)) * { * if (theGrid[1, 0] == null) * theGrid[1, 0] = MyTurn; * else return; * } * if (e.X > (PlayingField.Width / 3) && e.X < (2 * PlayingField.Width / 3) && * e.Y > (PlayingField.Height / 3) && e.Y < (2 * PlayingField.Height / 3)) * { * if (theGrid[1, 1] == null) * theGrid[1, 1] = MyTurn; * else return; * } * if (e.X > (2 * PlayingField.Width / 3) && e.Y > (PlayingField.Height / 3) && * e.Y < (2 * PlayingField.Height / 3)) * { * if (theGrid[1, 2] == null) * theGrid[1, 2] = MyTurn; * else return; * } * * // Third Row * if (e.X < (PlayingField.Width / 3) && e.Y > (2 * PlayingField.Height / 3)) * { * if (theGrid[2, 0] == null) * theGrid[2, 0] = MyTurn; * else return; * } * if (e.X > (PlayingField.Width / 3) && e.X < (2 * PlayingField.Width / 3) && * e.Y > (2 * PlayingField.Height / 3)) * { * if (theGrid[2, 1] == null) * theGrid[2, 1] = MyTurn; * else return; * } * if (e.X > (2 * PlayingField.Width / 3) && e.Y > (2 * PlayingField.Height / 3)) * { * if (theGrid[2, 2] == null) * theGrid[2, 2] = MyTurn; * else return; * } */ // OH // IT GOT FANCY // FANCY AF if (theGrid[(e.Y / (PlayingField.Height / 3)), (e.X / (PlayingField.Width / 3))] == null) { theGrid[(e.Y / (PlayingField.Height / 3)), (e.X / (PlayingField.Width / 3))] = MyTurn; } else { return; } PlayingField.Refresh(); MyTurn = !MyTurn; // Let the other person play! pickingO.Enabled = false; pickingX.Enabled = false; WinCondition(); }
private void Form1_Resize(object sender, EventArgs e) { PlayingField.Width = 420 + Math.Min(this.Width - initialWidth, this.Height - initialHeight); PlayingField.Height = 420 + Math.Min(this.Width - initialWidth, this.Height - initialHeight); PlayingField.Refresh(); }