Guten Abend,
ich bin ein Anfänger in Visual Basic und habe mit Hilfe von Tutorials und dem Grundwissen schon ein erstes kleines Programm (eher Tic Tac Toe Spiel) programmiert. Ich weiß, wozu braucht man sowas, kann man doch einfach online Spielen.. Aber ich bin trotzdem noch stolz drauf, dass es mein erstes programmiertes Spiel ist.
Der Source-Code:
Code:
PublicClass Form1
Dim turn AsInteger
PrivateSub win()
If Button1.Text = "X"And Button2.Text = "X"And Button3.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
Call disablebuttons()
ElseIf Button1.Text = "X"And Button5.Text = "X"And Button9.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
ElseIf Button1.Text = "X"And Button4.Text = "X"And Button7.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
ElseIf Button2.Text = "X"And Button5.Text = "X"And Button8.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
ElseIf Button3.Text = "X"And Button6.Text = "X"And Button9.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
ElseIf Button4.Text = "X"And Button5.Text = "X"And Button6.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
ElseIf Button7.Text = "X"And Button8.Text = "X"And Button9.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
ElseIf Button3.Text = "X"And Button5.Text = "X"And Button7.Text = "X"Then
MsgBox("Spieler X hat gewonnen !")
Label5.Text += 1
EndIf
If Button1.Text = "O"And Button2.Text = "O"And Button3.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
Call disablebuttons()
ElseIf Button1.Text = "O"And Button5.Text = "O"And Button9.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
ElseIf Button1.Text = "O"And Button4.Text = "O"And Button7.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
ElseIf Button2.Text = "O"And Button5.Text = "O"And Button8.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
ElseIf Button3.Text = "O"And Button6.Text = "O"And Button9.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
ElseIf Button4.Text = "O"And Button5.Text = "O"And Button6.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
ElseIf Button7.Text = "O"And Button8.Text = "O"And Button9.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
ElseIf Button3.Text = "O"And Button5.Text = "O"And Button7.Text = "O"Then
MsgBox("Spieler O hat gewonnen !")
Label6.Text += 1
Call disablebuttons()
EndIf
EndSub
PrivateSub disablebuttons()
Button1.Enabled = (False)
Button2.Enabled = (False)
Button3.Enabled = (False)
Button4.Enabled = (False)
Button5.Enabled = (False)
Button6.Enabled = (False)
Button7.Enabled = (False)
Button8.Enabled = (False)
Button9.Enabled = (False)
EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If turn = 1 Then
Button1.Text = "O"
Label1.Text = "X"
Else
Button1.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button1.Enabled = False
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If turn = 1 Then
Button2.Text = "O"
Label1.Text = "X"
Else
Button2.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button2.Enabled = False
EndSub
PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If turn = 1 Then
Button3.Text = "O"
Label1.Text = "X"
Else
Button3.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button3.Enabled = False
EndSub
PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If turn = 1 Then
Button4.Text = "O"
Label1.Text = "X"
Else
Button4.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button4.Enabled = False
EndSub
PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If turn = 1 Then
Button5.Text = "O"
Label1.Text = "X"
Else
Button5.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button5.Enabled = False
EndSub
PrivateSub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If turn = 1 Then
Button6.Text = "O"
Label1.Text = "X"
Else
Button6.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button6.Enabled = False
EndSub
PrivateSub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If turn = 1 Then
Button7.Text = "O"
Label1.Text = "X"
Else
Button7.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button7.Enabled = False
EndSub
PrivateSub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If turn = 1 Then
Button8.Text = "O"
Label1.Text = "X"
Else
Button8.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button8.Enabled = False
EndSub
PrivateSub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If turn = 1 Then
Button9.Text = "O"
Label1.Text = "X"
Else
Button9.Text = "X"
Label1.Text = "O"
EndIf
turn += 1
If turn > 2 Then
turn = 1
EndIf
Call win()
Button9.Enabled = False
EndSub
PrivateSub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Button1.Text = ""
Button1.Enabled = True
Button2.Text = ""
Button2.Enabled = True
Button3.Text = ""
Button3.Enabled = True
Button4.Text = ""
Button4.Enabled = True
Button5.Text = ""
Button5.Enabled = True
Button6.Text = ""
Button6.Enabled = True
Button7.Text = ""
Button7.Enabled = True
Button8.Text = ""
Button8.Enabled = True
Button9.Text = ""
Button9.Enabled = True
EndSub
EndClass
Download-Link: http://rapidshare.com/files/436357541/TicTacToe.exe
Hoffe es funktioniert auch bei euch richtig
Schöne Grüße