/// <summary> /// Start new game /// </summary> private void OnNewGame() { if (gameMode == enGameMode.Socket_Create || gameMode == enGameMode.Socket_Connect) { byte[] message = new byte[256]; string incomingMsg; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Score?P1")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); P1.score = Convert.ToInt32(incomingMsg); message = new byte[256]; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Score?P2")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); P2.score = Convert.ToInt32(incomingMsg); } // Socket game mode control LabelRegulations(); Label[] allLabels = { lbl0, lbl1, lbl2, lbl3, lbl4, lbl5, lbl6, lbl7, lbl8 }; foreach (Label label in allLabels) { label.Text = null; label.BackColor = Color.LightGreen; } // Label reset switch (starting) { case enStarting.None: case enStarting.Player2: playerTurn = enPlayerTurn.Player1; starting = enStarting.Player1; ShowTurn(playerTurn.ToString()); break; case enStarting.Player1: playerTurn = enPlayerTurn.Player2; starting = enStarting.Player2; ShowTurn(playerTurn.ToString()); break; default: break; } if (gameMode == enGameMode.Timed) { timer.Start(); timer.Interval = 500; timer_countdown.Start(); timer_countdown.Interval = 1000; // timer settings pnlTime.Show(); } // Timed gamed control winner = enWinner.None; }
/// <summary> /// Constructor /// </summary> /// <param name="gameMode">Selected game mode</param> /// <param name="P1">Player1 information</param> /// <param name="P2">Player2 information</param> public frmGameForm(string gameMode, Player1 P1, Player2 P2) { InitializeComponent(); GameModeSelection(gameMode); this.P1 = P1; this.P2 = P2; starting = enStarting.None; if (this.gameMode == enGameMode.Socket_Create || this.gameMode == enGameMode.Socket_Connect) { lblNameDraw.Hide(); lblScoreDraw.Hide(); lblScoreP1.Hide(); lblScoreP2.Hide(); while (true) { byte[] message = new byte[256]; string incomingMsg; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Client?")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); if (incomingMsg == " C=2") { if (this.gameMode == enGameMode.Socket_Create) { message = new byte[256]; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Name?P2")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); this.P2.name = incomingMsg; message = new byte[256]; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Choice?P2")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); this.P2.choice = incomingMsg; } else if (this.gameMode == enGameMode.Socket_Connect) { message = new byte[256]; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Name?P1")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); this.P1.name = incomingMsg; message = new byte[256]; frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Choice?P1")); frmEntryForm.socket.Receive(message); incomingMsg = Edit_IncomingMessage(message); this.P1.choice = incomingMsg; if (incomingMsg == "X") { this.P2.choice = "O"; } else { this.P2.choice = "X"; } } else { } break; }//(Number of client = 2)? else { DialogResult dr; dr = MetroMessageBox.Show(this, "Waiting Player2", "", MessageBoxButtons.OKCancel, 100); if (dr == DialogResult.Cancel) { this.Close(); break; } } } }// Socket game mode control lblNameP1.Text = P1.name; lblNameP2.Text = P2.name; lblChoiceP1.Text = P1.choice; lblChoiceP2.Text = P2.choice; OnNewGame(); }