private void btnStart_Click(object sender, EventArgs e) { if (!playing) { RestartGame(); first = r.Next(0, 2); lbPlayFirst.Text = "Prvi igra -> " + first; playing = true; if (first == 0) { PCplay = true; PCtimer.Start(); } else { PCplay = false; } lbTurn.Text = "{ " + ((first == 0) ? "Računar" : "Čovek") + " igra prvi }"; } }
private void XorO_Click(object sender, EventArgs e) { Button b = (Button)sender; if (b.Text == "" && playing && !PCplay) { b.Text = (first == 0) ? "O" : "X"; lbTurn.Text = "{ " + ((!PCplay) ? "Računar" : "Čovek") + " je na potezu }"; availableButtons.Remove(b); if (CheckForWin(matrixOfButtons, false)) { playing = false; lbTurn.Text = "{ " + ((PCplay) ? "Računar" : "Čovek") + " je pobedio }"; wait(waitTime); if (new CustomDialog("Pobedio je " + ((PCplay) ? "Računar" : "Čovek") + "\n\nRestartovati igru?", "Pobeda").ShowDialog() == DialogResult.Yes) { RestartGame(); } return; } if (availableButtons.Count == 0) { lbTurn.Text = "{ Nerešeno }"; playing = false; allButtons.ForEach(btn => btn.Enabled = false); wait(waitTime); if (new CustomDialog("Nerešeno\n\nRestartovati igru?", "Nerešeno").ShowDialog() == DialogResult.Yes) { RestartGame(); } return; } PCplay = true; PCtimer.Start(); } }