another Tic Tac Toe game problem.

determining a tie in tic tac toe

Page 1 of 1

1 Replies - 1248 Views - Last Post: 26 November 2008 - 10:09 AM Rate Topic: -----

#1 Awdel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-November 08

another Tic Tac Toe game problem.

Posted 26 November 2008 - 09:55 AM

Alright. So I was asked to make a tic tac toe game in class, and I am having trouble trying to get a tie game to work. I am pretty new at Visual Basic. I've only been at it about 3 weeks. but here is my code so far.

Public Class frmGame
	Dim a As New Integer		'changes to new integers
	Dim btn As New Button

	Private Sub Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, Btn7.Click, btn8.Click, btn9.Click
		btn = sender
		Select Case a
			Case 1
				If btn.Text = " " Then				  'Player X's Turn
					a = 2
					lblTurn.Text = "Player O's Turn"
					btn.Text = "X"

				End If
			Case 2
				If btn.Text = " " Then				  'Player O's Turn
					a = 1
					lblTurn.Text = "Player X's Turn"
					btn.Text = "O"
				End If

		End Select

		'X Lines-----------------------------------------------------------------


		If btn1.Text = "X" And btn2.Text = "X" And btn3.Text = "X" Then	 'If a line = X then X Wins
			lblWinner.Text = "X Wins"
		End If

		If btn4.Text = "X" And btn5.Text = "X" And btn6.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If Btn7.Text = "X" And btn8.Text = "X" And btn9.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If btn1.Text = "X" And btn4.Text = "X" And Btn7.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If btn2.Text = "X" And btn5.Text = "X" And btn8.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If btn3.Text = "X" And btn6.Text = "X" And btn9.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If btn1.Text = "X" And btn5.Text = "X" And btn9.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If btn3.Text = "X" And btn5.Text = "X" And Btn7.Text = "X" Then
			lblWinner.Text = "X Wins"
		End If

		If lblWinner.Text = "X Wins" Then				'Disables Buttons if X Wins
			lblTurn.Text = ""
			btn1.Enabled = False
			btn2.Enabled = False
			btn3.Enabled = False
			btn4.Enabled = False
			btn5.Enabled = False
			btn6.Enabled = False
			Btn7.Enabled = False
			btn8.Enabled = False
			btn9.Enabled = False

		End If


		'O Lines----------------------------------------------------------------------



		If btn1.Text = "O" And btn2.Text = "O" And btn3.Text = "O" Then	 'If a line = O then O Wins
			lblWinner.Text = "O Wins"
		End If

		If btn4.Text = "O" And btn5.Text = "O" And btn6.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If Btn7.Text = "O" And btn8.Text = "O" And btn9.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If btn1.Text = "O" And btn4.Text = "O" And Btn7.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If btn2.Text = "O" And btn5.Text = "O" And btn8.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If btn3.Text = "O" And btn6.Text = "O" And btn9.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If btn1.Text = "O" And btn5.Text = "O" And btn9.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If btn3.Text = "O" And btn5.Text = "O" And Btn7.Text = "O" Then
			lblWinner.Text = "O Wins"
		End If

		If lblWinner.Text = "O Wins" Then			'Disables buttons if O Wins
			lblTurn.Text = ""
			btn1.Enabled = False
			btn2.Enabled = False
			btn3.Enabled = False
			btn4.Enabled = False
			btn5.Enabled = False
			btn6.Enabled = False
			Btn7.Enabled = False
			btn8.Enabled = False
			btn9.Enabled = False
		End If

		If btn1.Text = "X" or btn.1.text = "0" Then
		ElseIf btn2.Text = "X" Or btn2.Text = "O" Then
		ElseIf btn3.Text = "X" Or btn3.Text = "O" Then
		ElseIf btn4.Text = "X" Or btn4.Text = "O" Then
		ElseIf btn5.Text = "X" Or btn5.Text = "O" Then
		ElseIf btn6.Text = "X" Or btn6.Text = "O" Then
		ElseIf Btn7.Text = "X" Or Btn7.Text = "O" Then
		ElseIf btn8.Text = "X" Or btn8.Text = "O" Then
		ElseIf btn9.Text = "X" Or btn9.Text = "O" Then
			lblWinner.Text = "Tie"
		End If




	End Sub

	Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
		btn1.Text = " "		 'Starts out Buttons/Squares as Blank spaces
		btn2.Text = " "
		btn3.Text = " "
		btn4.Text = " "
		btn5.Text = " "
		btn6.Text = " "
		Btn7.Text = " "
		btn8.Text = " "
		btn9.Text = " "
		btn1.Enabled = True		 ' Enables the buttons to be pressed
		btn2.Enabled = True
		btn3.Enabled = True
		btn4.Enabled = True
		btn5.Enabled = True
		btn6.Enabled = True
		Btn7.Enabled = True
		btn8.Enabled = True
		btn9.Enabled = True
		lblTurn.Text = "Player X's Turn"
		a = 1
		lblWinner.Text = " "




	   
		
	End Sub
End Class


I know this won't work, but can't figure out what will

If btn1.Text = "X" or btn.1.text = "0" Then
		ElseIf btn2.Text = "X" Or btn2.Text = "O" Then
		ElseIf btn3.Text = "X" Or btn3.Text = "O" Then
		ElseIf btn4.Text = "X" Or btn4.Text = "O" Then
		ElseIf btn5.Text = "X" Or btn5.Text = "O" Then
		ElseIf btn6.Text = "X" Or btn6.Text = "O" Then
		ElseIf Btn7.Text = "X" Or Btn7.Text = "O" Then
		ElseIf btn8.Text = "X" Or btn8.Text = "O" Then
		ElseIf btn9.Text = "X" Or btn9.Text = "O" Then
			lblWinner.Text = "Tie"
		End If


Is This A Good Question/Topic? 0
  • +

Replies To: another Tic Tac Toe game problem.

#2 jjsaw5  Icon User is offline

  • I must break you
  • member icon

Reputation: 90
  • View blog
  • Posts: 3,060
  • Joined: 04-January 08

Re: another Tic Tac Toe game problem.

Posted 26 November 2008 - 10:09 AM

I would like to direct youto the 10 pages of results of all the "Tic Tac Toe" threads that have been started here. Maybe you can find some help on one of these threads.


HERE
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1