/// <summary> /// Нажатие на кнопку "Начать игру (один игрок)" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected internal void button1_Click(object sender, EventArgs e) { Mouse.mice.Clear(); GameForm game_form = new GameForm(); GameForm.current_mouse = 0; Mouse.Add(); game_form.Owner = this; game_form.ShowDialog(); }
private void StartBtn_Click(object sender, EventArgs e) { string name = NameTextBox.Text; int port = Convert.ToInt32(PortTextBox.Text); string server = ServerTextBox.Text; GameForm form = new GameForm(name, port, server); form.Show(); this.Hide(); }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Equals("")) { MessageBox.Show("Enter Player name here"); } else { GameForm gf = new GameForm(); GameForm.aiGame = true; gf.Show(); this.Hide(); } }
private void PlayButton_Click(object sender, EventArgs e) { if (PlayerXtextBox.Text.Equals("") || PlayerOtextBox.Text.Equals("")) { MessageBox.Show("Enter Player names here"); } else { GameForm gf = new GameForm(); GameForm.aiGame = false; gf.Show(); this.Hide(); } }
/// <summary> /// Нажатие на кнопку "Подключиться" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { IP_part1 = maskedTextBox1.Text; IP_part2 = maskedTextBox2.Text; IP_part3 = maskedTextBox3.Text; IP_part4 = maskedTextBox4.Text; string PORT_str = maskedTextBox5.Text; string IP; IP = IP_part1 + "." + IP_part2 + "." + IP_part3 + "." + IP_part4; // Формируем IP IP = IP.Replace(" ", ""); // Убираем оттуда пробелы, если они есть // Если IP введен в неверном формате if (IP_part1 == "" || IP_part2 == "" || IP_part3 == "" || IP_part4 == "" || PORT_str == "") { MessageBox.Show("Вы неверно ввели IP-адрес хоста"); } // Если IP введен в правильном формате else { int PORT = Convert.ToInt32(PORT_str.Replace(" ", "")); Ping Pinger = new Ping(); PingReply Reply = Pinger.Send(IP, 1); // Если соединение по выбранному IP существует, то устанавливаем его if (true || Reply.Status == IPStatus.Success) { MenuForm menu_form = Owner as MenuForm; menu_form.Hide(); // Скрываем форму с меню Server.IP = IP; // Передаем IP в модуль Server для отправки команд на сервер Server.PORT = PORT; // Передаем PORT в модуль Server для отправки команд на сервер Server.StartOfGame(); // Заходим на сервер и ожидаем начала игры GameForm game_form = new GameForm(); game_form.Owner = menu_form; // Задаем владельца формы с игрой game_form.Show(); // Если сформирована команда, то начинаем игру Close(); // Закрываем текущую форму } // Если соединения по выбранному IP не существует else { MessageBox.Show("Ошибка соединения с хостом"); } } }
public void detectHit(Point loc) { //check if the board is clicked log.Debug("check if the board is clicked"); if (loc.Y <= 500) { int x = 0; int y = 0; if (loc.X < 167) { x = 0; } else if (loc.X > 167 && loc.X < 334) { x = 1; } else if (loc.X > 334) { x = 2; } if (loc.Y < 167) { y = 0; } else if (loc.Y > 167 && loc.Y < 334) { y = 1; } else if (loc.Y > 334 && loc.Y < 500) { y = 2; } if (holders[x, y].getValue() == B && !isBoardFull()) { log.Debug("check player turn"); //it's X's turn if (movesMade % 2 == 0 && holders[x, y].getValue() == B) { GFX.drawX(new Point(x, y)); holders[x, y].setValue(X); if (detectRow()) { if (GameForm.aiGame == true) { MessageBox.Show("you have won, " + OnePlayerForm.getPlayerXValue()); } else if (GameForm.aiGame == false) { MessageBox.Show("you have won, " + TwoPlayersForm.getPlayerXValue()); } Xwins++; reset(); GFX.setUpCanvas(); } if (GameForm.getAIgame() && !detectRow() && !isBoardFull()) { Holder aiMove = ComputerLogic.determineAndPlaceMark(holders); GFX.drawO(aiMove.getLocation()); holders[aiMove.getLocation().X, aiMove.getLocation().Y].setValue(O); if (detectRow()) { MessageBox.Show("Compuetr has won"); Owins++; reset(); GFX.setUpCanvas(); } movesMade++; playersTurn = X; } playersTurn = O; } else { GFX.drawO(new Point(x, y)); holders[x, y].setValue(O); if (detectRow()) { MessageBox.Show("you have won, " + TwoPlayersForm.getPlayerOValue()); Owins++; reset(); GFX.setUpCanvas(); } playersTurn = X; } movesMade++; } if (isBoardFull()) { MessageBox.Show("It is tie, Play again"); reset(); GFX.setUpCanvas(); } } }
private void Menu_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up) { if (PM2.GetY() == 303) { PM2.SetY(503); } else { PM2.SetY(PM2.GetY() - 50); } } if (e.KeyCode == Keys.Down) { if (PM2.GetY() == 503) { PM2.SetY(303); } else { PM2.SetY(PM2.GetY() + 50); } } if (e.KeyCode == Keys.Enter) { if (PM2.GetY() == 303) { Animation.Stop(); Visible = false; GameForm gf = new GameForm(); gf.ShowDialog(); gf.Close(); Animation.Start(); Visible = true; TopMost = true; Focus(); } if (PM2.GetY() == 353) { MenuState = 2; Animation.Stop(); grfx.DrawImage(Properties.Resources.MenuHelp, -10, 0, Width, Height - 50); } if (PM2.GetY() == 403) { MenuState = 2; Animation.Stop(); HighScore hs = new HighScore(); hs.ShowDialog(); hs.Close(); Animation.Start(); } if (PM2.GetY() == 453) { MenuState = 2; Animation.Stop(); grfx.DrawImage(Properties.Resources.MenuAbout, -10, 0, Width, Height - 50); } if (PM2.GetY() == 503) { Application.Exit(); } } if (e.KeyCode == Keys.Escape) { if (MenuState == 1) { Application.Exit(); } else { Animation.Start(); MenuState = 1; grfx.DrawImage(Properties.Resources.Menu, -10, 0, Width, Height - 50); } } }