Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Tic Tac Toe [winner]?


how can i get the winner of my a tic tac toe games? i'm using 9 lables on the game, so can i do something like:

If blah = "123" or 157" Then
Msgbox "Winner"
End If

But the question is, do I have to do and "If" statement for 123, 157, ect; to get the winner, or is there a quicker and shorter way?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Tic-Tac-Toe Winner?
Can anyone explain, how I can figuer out the winner of the game, meaning how would I know if the winner has gotten 3 in a row? ex: 1,5,9 are the winning squares..


1 2*3
4 5 6
7 8 9

x x o
o x o
x o x

Add To Winner Score
Im still working on a tic tac toe game but now iam using a control array to make it easier i have :X lables and O Lables with the indexes of 0-8 from left to right and command butons for each seperate lable with the same index's( like cmdX(0) cmdO(0) dof the first box) what i need to know is how do i have the game add to a winners score and then reset the form to play a new game without loseing the old score(s)?
Heeelp

cmdX(0) cmdO(0) cmdX(1) cmdO(1) cmdX(2) cmdO(2)
lblO(0) lblO(1) lblO(2)
lblX(0) lblX(1) lblX(2)

cmdX(3) cmdO(3) cmdX(4) cmdO(4) cmdX(5) cmdO(5)
lblO(3) lblO(4) lblO(5)
lblX(3) lblX(4) lblX(5)

cmdX(6) cmdO(6) cmdX(7) cmdO(7) cmdX(8) cmdO(8)
lblO(6) lblO(7) lblO(8)
lblX(6) lblX(7) lblX(8)

That is just a general picture of how it looks and the lables are actually on top of eachother both with the visible prop set as false and when a command button is pressed the(like if cmdX(1) were pressed cmdO(1)'s enabled prop would be set to false ) plz help

Help Deciding Winner
Ive been trying to code this game of Tic-Tac-Toe for a while and I need to decide when someone is the winner.
I havent much of an idea how to do this.
Could someone show me how I can do this. I have been trying a few ideas but have hit a brick wall, this is what I have done so far.

Code:
Option Explicit
Dim Player1 As Boolean
Dim Name1 As String
Dim Name2 As String






Private Sub cmdNought_Click(Index As Integer)
'Declare required storage
Dim WinPossible As Boolean
Dim Count As Integer

WinPossible = False
Call PlaceSymbol(Index)


picOutput.Cls

Do
If cmdNought(Count).Caption = cmdNought(Count + 1).Caption _
And cmdNought(Count).Caption = cmdNought(Count + 2).Caption Then
WinPossible = True
Count = Count + 3
Loop Until Count > 7
End If

If Player1 Then
picOutput.Print "Player two to go "
Else
picOutput.Print "Player one to go "
End If


End Sub

Private Sub cmdPlay_Click()
'Declare required storage
Dim Name1 As String
Dim Name2 As String

Do

'Require user to input their name
Name1 = InputBox("Please enter your name ", "Enter Name")

Name1 = UCase(Left(Name1, 1)) & LCase(Right(Name1, Len(Name1) - 1))

'Output player one's name
Loop Until Name1 > ""

picOutput.Print "Player one is "; ""; (Name1)


Do
Name2 = InputBox("Please enter your name ", "Enter Name")
Name2 = UCase(Left(Name2, 1)) & LCase(Right(Name2, Len(Name2) - 1))

Loop Until Name2 > ""

'Output player two's name

picOutput.Cls
picOutput.Print "Player two is "; ""; (Name2)

picOutput.Print "Player one "; (Name1); " to go first "

End Sub

Private Sub cmdQuit_Click()
' Terminate Application
End
End Sub

Private Sub cmdSquare_Click(Index As Integer)

Call PlaceSymbol(Index)

End Sub
Private Sub PlaceSymbol(SquareNumber As Integer)




'carry out players actions

If cmdNought(SquareNumber).Caption = "" Then

If Player1 Then
cmdNought(SquareNumber).Caption = "O"
Else

cmdNought(SquareNumber).Caption = "X"
End If

Player1 = Not Player1

End If

End Sub

Steve

Calculating The Winner
Could someone please help me. I am writing a program that will count the number of laps that a number of drivers have done. I am at the stage of now calculating who is placed where. I have six txt boxes containing the value of "Number of laps Completed". I have also got six lbl in which the names of the drives need to be placed.

Is there any quick or simple calculation that I can do, instead of using thousands of IF statements?

Thanking you in advanced......

Winner Gets A Cookie!
Hey... I have a sub here that's supposed to add code supplied from a server to a rich text box... which it does, however about every fifth line or after I enter a command or something it inserts a blank line for no reason I can find. Can someone please locate/tell me why?

code

Sub AddColText(ParseCol As String)

On Error Resume Next
Dim CcStart, CcEnd, cCode
Dim StartCcP, EndCcP, oldSel, OldLen ', LastColor

CcStart = (Chr(27) + "[")
'CcStart = ".["
CcEnd = "m"
'LastColor = RGB(255, 255, 255)

If ANSIstate.Value = 1 Then

Do
Textboxtmp.SelStart = Len(Textboxtmp.Text)
Textboxtmp.SelColor = DefaultMudColor
Textboxtmp.SelBold = False
Textboxtmp.SelUnderline = False
Textboxtmp.SelItalic = False


Textboxtmp.SelLength = 0

StartCcP = InStr(ParseCol, CcStart)
If StartCcP < 1 Then
Exit Do
End If

EndCcP = InStr(StartCcP, ParseCol, CcEnd)

If EndCcP < 1 Then
Exit Do
End If
cCode = Mid(ParseCol, StartCcP + Len(CcStart), 2)

If lastcolor = 1 Then
Textboxtmp.SelBold = True
ElseIf lastcolor = 4 Then
Textboxtmp.SelUnderline = True
ElseIf lastcolor = 2 Then
Textboxtmp.SelItalic = True
Else
Textboxtmp.SelColor = lastcolor
End If

Textboxtmp.SelText = Left(ParseCol, StartCcP - 1)
lastcolor = retColorCode(cCode)

ParseCol = Mid(ParseCol, EndCcP + 1)

'TextBox.SelStart = StartCcP
'TextBox.SelLength = 0 ' Len(TextBox.Text)

Loop
Else
Textboxtmp.SelStart = Len(Textboxtmp.Text)
Textboxtmp.SelColor = DefaultMudColor
Textboxtmp.SelBold = False
Textboxtmp.SelUnderline = False
Textboxtmp.SelItalic = False
Textboxtmp.SelLength = 0
End If

Textboxtmp.SelText = ParseCol
Textboxtmp.SelStart = Len(Textboxtmp.Text)

' TextBox.SelStart = oldSel
' TextBox.SelLength = OldLen

End Sub

Need Help Displaying The Winner In Tic Tac Toe Game
hi

i ve made tic tac toe game using command buttons has the board. im having trouble trying to figure out the winner to game. can u pls help me


vb Code:
Private Sub cmdPlayGround_Click(Index As Integer)    Static strPlayGround(2, 2) As String           ' Store players moves    Static strPlayer As String              ' O or X     If strPlayer = "" Then        strPlayer = "X"                     ' X goes first    End If     If cmdPlayGround(Index).Caption <> "" Then              ' Check for existing X or O        MsgBox "This square is already selected!"    Else        cmdPlayGround(Index).Caption = strPlayer            ' Show move        Call GamePlay(Index, strPlayer, strPlayGround())    ' Store move in strPlayGround()                If strPlayer = "X" Then                              ' Next player's turn                    strPlayer = "O"                Else                    strPlayer = "X"                End If    End IfEnd Sub Sub GamePlay(ByVal intIndex As Integer, ByVal strPlayer As String, ByRef strPlayGround() As String)           ' Moves made in each row    If intIndex <= 2 Then        strPlayGround(0, intIndex) = strPlayer      'first row    ElseIf intIndex <= 5 Then        strPlayGround(1, intIndex - 3) = strPlayer  'second row    Else        strPlayGround(2, intIndex - 6) = strPlayer  'third row    End IfEnd Sub Function IsWinner(ByRef strPlayGround() As String) As Boolean    Dim intRow As Integer, intCol As Integer    Dim blnMovesLeft As Boolean     IsWinner = False ' Check all rows    For intRow = 0 To 2                                                                                                                                                     If strPlayGround(intRow, 0) = strPlayGround(intRow, 1) And strPlayGround(intRow, 1) = strPlayGround(intRow, 2) And strPlayGround(intRow, 0) <> "" Then            IsWinner = True        End If    Next intRow ' Check all columns    For intCol = 0 To 2                                                                                                                                                     If strPlayGround(0, intCol) = strPlayGround(1, intCol) And strPlayGround(1, intCol) = strPlayGround(2, intCol) And strPlayGround(0, intCol) <> "" Then            IsWinner = True        End If    Next intCol ' Check one diagonal    If strPlayGround(0, 0) = strPlayGround(1, 1) And strPlayGround(1, 1) = strPlayGround(2, 2) And strPlayGround(0, 0) <> "" Then                                           IsWinner = True    End If ' Check other diagonal    If strPlayGround(0, 2) = strPlayGround(1, 1) And strPlayGround(1, 1) = strPlayGround(2, 0) And strPlayGround(0, 2) <> "" Then                                           IsWinner = True    End If ' Check for empty squares    blnMovesLeft = False                                    For intRow = 0 To 2        For intCol = 0 To 2            If strPlayGround(intRow, intCol) = "" Then                blnMovesLeft = True            End If        Next intCol    Next intRow        If Not blnMovesLeft Then        IsWinner = True    End IfEnd Function Sub NewGame(ByRef strPlayer As String, ByRef strPlayGround() As String, ByRef cmdTTTSquares As Object)    Dim intIndex As Integer, intRow As Integer, intCol As Integer     strPlayer = "X"                                 ' Player X starts     For intRow = 0 To 2                             ' Clear player moves        For intCol = 0 To 2            strPlayGround(intRow, intCol) = ""        Next intCol    Next intRow     For intIndex = 0 To 8                           ' Clears board        cmdTTTSquares(intIndex).Caption = ""    Next intIndexEnd Sub

Making A Winner In My Program
Hi im making a program in vb.net which is linked to a database, i have a group of users, and they have some numbers each, i want to be able to enter some numbers in text boxes and this checks them against their numbers and pulls out the matching users.

any idea how i would do this?

ive not done alot of programming in vb.net but i am keen to get started!!!

Thanks

Homer

We Have A Winner! (move To CHIT CHAT)
someone just one my vote for Best of the Forum


http://www.vbforums.com/showthread.p...hreadid=300821

OOPS - PLEASE MOVE TO CHIT CHAT. I COPIED THE ID, AND BROWSER DIDN'T GO BACK TO CHIT CHAT, AND WOULDN'T LET ME DELETE THE POST!

Shell Sort Challenge (25 Cents To Winner)
what you really need is pointers

i.e. a linked list of UDT's instead of an array then it would be easy

although perhaps you could use CopyMemory or someother memory API to do something similar?

Reference Vs Function Declares (Resolved Without A Clear Winner :D)
What is the difference between adding a reference to a dll and declaring functions in code? I know each function has to be declared individually, but why can't a reference be used instead?
Conversely, can a declare be used in place of a reference?

Setting Cards In A Rank To Declare Winner In A Card Game
I am writing a card game called Euchre in which trump changes from hearts, clubs, spades, and dimonds in no particular order. The Jack of the declared trump is the highest followed by the Jack of the same color then Ace, King, Queen, 10, and 9 of the chosen suit. Players declare trump before the game begins. My problem is when a person has played a card how do I compare the other players cards to decide who wins? Any suggestions would help thanks.

Copyright 2005-08 www.BigResource.com, All rights reserved