2: noughts n crosses

Intro

Tic Tac Toe is an old game. Players alternately get Xs or Os in their button. The first one to complete 3 in a row wins.

It requires a 3×3 button control array.

Form:

  • A button array of 9 buttons inside a flow layout panel.
  • a boolean as to which is the current player (text is filled in the buttons accordingly)
  • Each time a button is clicked, check if known solutions are matched / its a draw

Solutions:

  • Solution is an array of 3 integers (button indexes) which have to be  for a player to win.
  • There are 8 possibilities (1,2,3 / 2,5,8 / 1,5,9 etc)
  • A winner is the text which is same in the 3 positions of a solution (and not equal to blank).
  • since button text is a UI function and Solutions is a class unaware of windows.forms.button, we pass textOf(i) as a function which returns buttons[i].text

See tabs overleaf for the code or browse.

Form

Solutions

Screen

 

Leave a Comment