A
B
C
Ç
D
E
F
G
Ğ
H
I
İ
J
K
L
M
N
O
P
R
S
Ş
T
U
Ü
V
Y
Z
Q
W
X
+ İçerik Ekle
TicTacToe
TicTacToe

TicTacToe
visual basicte yapılan bir oyun
Option Explicit
Dim StartSquare As Integer, EndSquare As Integer, Direction As Integer
Dim XO(2) As String
Dim Blank As Integer
Dim CaseCounter As Integer
Dim XsInARow As Integer, OsInARow As Integer
Dim HumanPlayingAsX As Boolean
Dim HumanMovedAlready As Boolean, CompMovedAlready As Boolean
Dim GameOver As Boolean
Dim SquareValue(8) As Integer
Dim RandChoice(8) As Integer
Dim WinLine As Integer
Dim TieGame As Boolean
Dim strCPU As String
Dim strHuman As String


Private Sub About_Click()
MsgBox "Professional bir yazılımcı olmadığım için elimden geldiğince bugları kapatabildim programı geliştirmek isteyenler bana ulaşabilir açık kaynak kodlarını verebilirim  By Antimodes", vbOKOnly



Unload Me
End Sub

Private Sub Command1_Click()
MsgBox "Renkler arada karışıo (: , sonuç belirlendiğinde oynamaya devam edebiliyorsunuz (: ama bunlar rahatsız edici seviyede değil..!"
End Sub

"This program was created by Antimodes

Dim Index As Integer

Cls
Randomize


For Index = 0 To 8
Square(Index).Caption = ""
SquareValue(Index) = 0
Next Index

For Index = 0 To 7
Win(Index).Visible = False
Next Index



If HumanX.Value = 1 Then
    HumanPlayingAsX = True
    strCPU = "O"
    strHuman = "X"
Else
    HumanPlayingAsX = False
    strCPU = "X"
    strHuman = "O"
End If


HumanMovedAlready = False
CompMovedAlready = False

HumanX.Visible = True
HumanFirst.Visible = True
HumanFirst.Value = 1
Call IntelligenceLevelCase

GameOver = False
TieGame = False


PlayAgain.Caption = "Yeni oyun"

End Sub


Private Sub Square_Click(Index As Integer)
Dim Flash100 As Integer


If Square(Index).Caption = "" And HumanMovedAlready = False Then
    HumanMovedAlready = True
    Square(Index).Caption = strHuman
    Call CheckForWin
    
    If GameOver = False Then
        Call CheckForCatsGame
        Call ComputerTurn
    End If
    

Else
    Beep
    For Flash100 = 1 To 100
        Me.BackColor = RGB(Int(256 * Rnd), Int(256 * Rnd), Int(256 * Rnd))
        Me.BackColor = "&H00C0FFFF"
    Next Flash100
End If
End Sub




Private Sub HumanFirst_Click()

If HumanFirst.Value = 1 Then
    HumanMovedAlready = False
Else
    HumanMovedAlready = True
    Cls
    Call ComputerTurn
End If
End Sub


Private Sub HumanX_Click()
If HumanX.Value = 1 Then
    HumanPlayingAsX = True
    strCPU = "O"
    strHuman = "X"
Else
    HumanPlayingAsX = False
    strCPU = "X"
    strHuman = "O"
End If

End Sub


Private Sub Intelligence_Change()
Dim Red As Integer, Green As Integer, Blue As Integer


Red = (Intelligence.Value / Intelligence.Max) * 255
Green = 0
Blue = (1 / Intelligence.Value) * 255
Level.ForeColor = RGB(Red, Green, Blue)
Call IntelligenceLevelCase
End Sub


Private Sub PlayAgain_Click()
Dim Index As Integer
Dim OldColor As String
OldColor = Square(0).BackColor
    For Index = 0 To 7
        Square(Index).BackColor = Square(Index + 1).BackColor
    Next Index
Square(8).BackColor = OldColor


Form_Load
End Sub


Private Sub Quit_Click()
Unload Me
End Sub


Private Sub XWins()
Call GameIsOver
MsgBox ("X Kazandı!")
End Sub


Private Sub OWins()
GameOver = True
Call GameIsOver
MsgBox ("O Kazandı!")
End Sub


Private Sub CatsGame()
TieGame = True
Call GameIsOver
MsgBox ("Oyun berabere !")
End Sub


Private Sub GameIsOver()
GameOver = True
PlayAgain.Caption = "Tekrar oynamak istermisiniz ?"
Beep
If TieGame = False Then Win(CaseCounter).Visible = True
End Sub


Private Sub BoardCheck()


Select Case CaseCounter
              
    Case 0
        StartSquare = 0
        EndSquare = 2
        Direction = 1
    Case 1
        StartSquare = 3
        EndSquare = 5
        Direction = 1
    Case 2
        StartSquare = 6
        EndSquare = 8
        Direction = 1
            
    Case 3
        StartSquare = 0
        EndSquare = 6
        Direction = 3
    Case 4
        StartSquare = 1
        EndSquare = 7
        Direction = 3
    Case 5
        StartSquare = 2
        EndSquare = 8
        Direction = 3
            

    Case 6
        StartSquare = 0
        EndSquare = 8
        Direction = 4
    Case 7
        StartSquare = 2
        EndSquare = 6
        Direction = 2
End Select
End Sub


Private Sub XOSelect(XOSquare)

Select Case XOSquare
    Case 1
        XO(0) = "X"
        XO(1) = "X"
        XO(2) = ""
        Blank = EndSquare
    Case 2
        XO(0) = "X"
        XO(1) = ""
        XO(2) = "X"
        Blank = StartSquare + Direction
    Case 3
        XO(0) = ""
        XO(1) = "X"
        XO(2) = "X"
        Blank = StartSquare
    Case 4
        XO(0) = "O"
        XO(1) = "O"
        XO(2) = ""
        Blank = EndSquare
    Case 5
        XO(0) = "O"
        XO(1) = ""
        XO(2) = "O"
        Blank = StartSquare + Direction
    Case 6
        XO(0) = ""
        XO(1) = "O"
        XO(2) = "O"
        Blank = StartSquare
End Select
End Sub


Private Sub IntelligenceLevelCase()
    Select Case Intelligence.Value
        Case 1
            Level.Caption = "Bebekle"
        Case 2
            Level.Caption = "Çocukla"
        Case 3
            Level.Caption = "Gençle"
        Case 4
            Level.Caption = "Yetiskinle"
        Case 5
            Level.Caption = "Yasliyla ( tavsiye etmem )   :)"
    End Select
End Sub


Private Sub CheckForCatsGame()

Dim Index As Integer
Dim Space As Integer

For Index = 0 To 8
    If Square(Index).Caption = "" Then Space = Space + 1
Next Index

If Space = 0 Then
    Call CatsGame
End If
End Sub


Private Sub SpecialAI()
Dim MiddleSideSquare As Integer
Dim Index As Integer




If (Square(0).Caption = strHuman And Square(8).Caption = strHuman) _
Or (Square(2).Caption = strHuman And Square(6).Caption = strHuman) Then
    
    For Index = 1 To 7 Step 2
        SquareValue(Index) = 10
    Next Index
    
End If



  
If Square(1).Caption = strHuman And Square(5).Caption = strHuman Then
    SquareValue(6) = 0
End If
    
If Square(5).Caption = strHuman And Square(7).Caption = strHuman Then
    SquareValue(0) = 0
End If
    
If Square(3).Caption = strHuman And Square(7).Caption = strHuman Then
    SquareValue(2) = 0
End If
    
If Square(1).Caption = strHuman And Square(3).Caption = strHuman Then
    SquareValue(8) = 0
End If




If Intelligence.Value > 4 Then
    For Index = 1 To 7 Step 2
        If Square(Index).Caption = strHuman Then
            MiddleSideSquare = MiddleSideSquare + 1
        End If
    Next Index
    
    If MiddleSideSquare = 1 Then
        If Square(1).Caption = strHuman Then
            SquareValue(0) = 10
            SquareValue(2) = 10
        End If
        
        If Square(3).Caption = strHuman Then
            SquareValue(0) = 10
            SquareValue(6) = 10
        End If
        
        If Square(5).Caption = strHuman Then
            SquareValue(2) = 10
            SquareValue(8) = 10
        End If
        
        If Square(7).Caption = strHuman Then
            SquareValue(6) = 10
            SquareValue(8) = 10
        End If
    End If
End If

End Sub


Private Sub CheckForWin()
Dim Index As Integer

If HumanX.Visible = True Then Call RemoveOptions

CaseCounter = 0
While CaseCounter < 8
                
    Call BoardCheck
        XsInARow = 0
        OsInARow = 0
    
    For Index = StartSquare To EndSquare Step Direction
        If Square(Index).Caption = "X" Then XsInARow = XsInARow + 1
        If Square(Index).Caption = "O" Then OsInARow = OsInARow + 1
    Next Index
    
If XsInARow = 3 Then Call XWins
If OsInARow = 3 Then Call OWins
      
CaseCounter = CaseCounter + 1
Wend
End Sub

    

Private Sub RemoveOptions()
    HumanX.Visible = False
    HumanFirst.Visible = False
End Sub

Private Sub CompAI()

Dim XOSquare As Integer
Dim Index As Integer
Dim Space As Integer

For Index = 0 To 8
    If Square(Index).Caption = "" Then
        If Index Mod 2 = 0 Then
            SquareValue(Index) = 5
                Else
            SquareValue(Index) = 1
        End If
    Else

        SquareValue(Index) = 0
    End If
Next Index


For Index = 0 To 8
    If Square(Index).Caption = "" Then Space = Space + 1
Next Index

If Space = 6 And Intelligence.Value > 3 Then
    Call SpecialAI
End If

CaseCounter = 0
XOSquare = 1

If Intelligence.Value > 1 Then
    If Square(4).Caption = "" Then
        SquareValue(4) = 10
    End If


    While CaseCounter < 8



    Call BoardCheck
    CaseCounter = CaseCounter + 1
        
        For XOSquare = 1 To 6
        Call XOSelect(XOSquare)

            If Square(StartSquare).Caption = XO(0) And _
            Square(StartSquare + Direction).Caption = XO(1) And _
            Square(EndSquare).Caption = XO(2) Then


                If HumanPlayingAsX = True Then
                    If XOSquare <= 3 Then
                        If Intelligence.Value > 2 And SquareValue(Blank) < 999 Then
                            SquareValue(Blank) = 500
                        End If
                    Else
                        If Intelligence.Value > 1 Then
                            SquareValue(Blank) = 999
                        End If
                    End If
                    

                Else
                    If XOSquare <= 3 Then
                        If Intelligence.Value > 1 Then
                            SquareValue(Blank) = 999
                        End If
                    Else
                        If Intelligence.Value > 2 And SquareValue(Blank) < 999 Then
                            SquareValue(Blank) = 500
                        End If
                    End If
                End If
            End If
        Next XOSquare
    Wend
End If


End Sub


Private Sub CompSquareSelection()
Dim Index As Integer
Dim HighVal As Integer
Dim Counter As Integer
Dim FinalChoice As Integer

Counter = 0
HighVal = 0
For Index = 0 To 8
If SquareValue(Index) = HighVal Then
    RandChoice(Counter) = Index
    Counter = Counter + 1
End If

If SquareValue(Index) > HighVal Then
    HighVal = SquareValue(Index)
    For Counter = 1 To 8
    RandChoice(Counter) = 0
    Next Counter
    RandChoice(0) = Index
    Counter = 1
End If
Next Index


Index = Int(Rnd * Counter)
Square(RandChoice(Index)).Caption = strCPU
HumanMovedAlready = False
End Sub


Private Sub ComputerTurn()

If GameOver = False Then
    Call CompAI
    Call CompSquareSelection
    Call CheckForWin
    Call CheckForCatsGame
End If

End Sub




brush




  Ad Soyad
  Yorum