Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace TicTacToeSimulation {
  12. public partial class Form1 : Form {
  13. public Form1() {
  14. InitializeComponent();
  15. }
  16.  
  17. private void ExitButton_Click(object sender, EventArgs e) {
  18. Close();
  19. }
  20. public int player = 2;
  21. public int turns = 0;
  22. public int s1 = 0;
  23. public int s2 = 0;
  24. public int sd = 0;
  25.  
  26. private void buttonClick(object sender, EventArgs e) {
  27. Button button = (Button)sender;
  28. if (button.Text == "")
  29. {
  30.  
  31. if (player % 2 == 0) {
  32. button.Text = "X";
  33. player++;
  34. turns++;
  35. } else {
  36. button.Text = "O";
  37. player++;
  38. turns++;
  39. }
  40. if (CheckDraw() == true) {
  41. MessageBox.Show("It's A Draw! New Game?");
  42. sd++;
  43. NewGame();
  44. }
  45. }
  46. }
  47.  
  48. private void Form1_Load(object sender, EventArgs e) {
  49. XWinsLabel.Text = "X: " + s1;
  50. OWinsLabel.Text = "O: " + s2;
  51. DrawsLabel.Text = "Draws: " + sd;
  52. }
  53. void NewGame()
  54. {
  55. player = 2;
  56. turns = 0;
  57. TopLeftButton.Text = TopCenterButton.Text = TopRightButton.Text = CenterLeftButton.Text = CenterButton.Text = CenterRightButton.Text = BottomLeftButton.Text = ButtomCenterButton.Text = ButtonRightButton.Text = "";
  58. }
  59.  
  60. private void NGButton_Click(object sender, EventArgs e) {
  61. NewGame();
  62. }
  63.  
  64. bool CheckDraw() {
  65. if (turns == 9)
  66. return true;
  67. else
  68. return false;
  69. }
  70. bool CheckWinner() {
  71. // Vertical
  72. if ((TopLeftButton.Text == TopCenterButton.Text) && (TopCenterButton.Text == TopRightButton.Text) && TopLeftButton.Text != "")
  73. return true;
  74. else if ((CenterLeftButton.Text == CenterButton.Text) && (CenterButton.Text == CenterRightButton.Text) && CenterLeftButton.Text != "")
  75. return true;
  76. else if ((BottomLeftButton.Text == ButtomCenterButton.Text) && (ButtomCenterButton.Text == ButtonRightButton.Text) && BottomLeftButton.Text != "")
  77. return true;
  78. // Horizontal
  79. if ((TopLeftButton.Text == CenterLeftButton.Text) && (CenterLeftButton.Text == BottomLeftButton.Text) && TopLeftButton.Text != "")
  80. return true;
  81. else if ((TopCenterButton.Text == CenterButton.Text) && (CenterButton.Text == ButtomCenterButton.Text) && TopCenterButton.Text != "")
  82. return true;
  83. else if ((TopRightButton.Text == CenterRightButton.Text) && (CenterRightButton.Text == ButtonRightButton.Text) && TopRightButton.Text != "")
  84. return true;
  85. // Diagonal
  86. if ((TopLeftButton.Text == CenterButton.Text) && (CenterButton.Text == ButtonRightButton.Text) && TopLeftButton.Text != "")
  87. return true;
  88. else if ((TopRightButton.Text == CenterButton.Text) && (CenterButton.Text == BottomLeftButton.Text) &&)
  89.  
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement