my previous version had 9 buttons, created in the interface, and the only code i had was super simple code for the buttons if you clicked it.
now I'm trying to make a Tic Tac Toe game that creates when you start the game(all by code):
the 9 buttons as play field
1 button for a new game
and a scoring label.
my question is, i don't really know how to get the winning options,
i so far created the code that if you start the game, it will create 9 buttons(the play field)
the buttons are from a special class which knows when you press any button, which button it is( i tested it out with labels, it will say 1,1 or 2,3 etc.)
i created an integer named turn, which declares the turn.
if it's 0 then when you click any button, the text will change to X,
and if it's 1 the text will change to O
the integer cant be greater then 1, it will automatically return to 0.
but for the scoring, i don't know, what kind of code to create for this problem:
if you have 3 X's in a row, then the score for X should gain 1, sounds logical to me,
but i don't know how to create the code for it, so it will automatically see there are 3 X's or O's in a row
maybe someone knows the problem and can help me?
Public Class MainForm Public turn As Integer = 0 Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'creating buttons Call createbuttons() 'other code: 'like a New Game button 'Score counting 'Wich player begins 'Stuff like that End Sub Private Sub createbuttons() Dim sizo As New Size(25, 25) Dim loca As New Point(25, 25) For i As Integer = 1 To 3 For o As Integer = 1 To 3 Dim butto As New Buttonno butto.Location = loca butto.Size = sizo butto.arow = i butto.acollum = o Me.Controls.Add(butto) loca.X += 28 Next o loca.X -= 84 loca.Y += 28 Next i End Sub End Class
Extra button class:
Public Class Buttonno Inherits Button Public arow As Integer Public acollum As Integer Private Sub Buttonno_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click If MainForm.turn = 0 Then Me.Text = "X" MainForm.turn += 1 Me.Enabled = False If MainForm.turn > 1 Then MainForm.turn = 0 End If ElseIf MainForm.turn = 1 Then Me.Text = "O" MainForm.turn += 1 Me.Enabled = False If MainForm.turn > 1 Then MainForm.turn = 0 End If End If End Sub End Class