public Form1() { InitializeComponent(); helper = new TicTacToeHelper(boardLength, winLength); //longer text because i had some weird issues with shorter one not accurately //depicting the length of the text lWidth = TextRenderer.MeasureText("n n n n n n n n n ", label5.Font).Width / 9; lHeight = TextRenderer.MeasureText("n", label5.Font).Height; StringBuilder label5builder = new StringBuilder(); for (int i = 0; i < helper.BoardLength; i++) { for (int k = 0; k < helper.BoardLength; k++) { label5builder.Append("n "); } label5builder.Append('\n'); } label5.Text = label5builder.ToString(); ShowWinString(); }
//this function asks the helper about the game state void ShowGameState() { //first we need to convert the text to a form that the helper understands char[] text = label5.Text.ToCharArray(); List <TicTacToeFieldState> board = new List <TicTacToeFieldState>(); for (int i = 0; i < text.Length; i++) { try { TicTacToeFieldState fieldState = TicTacToeHelper.GetFieldFromChar(text[i]); board.Add(fieldState); } catch { } } //get the game state TicTacToeGameState gameState = helper.CheckGameState(board.ToArray()); if (gameState == TicTacToeGameState.Continuable) { label7.Text = "game is continuable."; } else if (gameState == TicTacToeGameState.Tied) { label7.Text = "game is tied."; } else if (gameState == TicTacToeGameState.XWon) { label7.Text = "x has won the game."; } else if (gameState == TicTacToeGameState.OWon) { label7.Text = "o has won the game."; } }