Platforms to show: All Mac Windows Linux Cross-Platform
/Main/Web Edition Examples/TicTacToe game/TicTacToe game Web1
Function:
Required plugins for this example:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Web Edition Examples/TicTacToe game/TicTacToe game Web1
This example is the version from Thu, 6th Apr 2016.
Function:
Required plugins for this example:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Web Edition Examples/TicTacToe game/TicTacToe game Web1
This example is the version from Thu, 6th Apr 2016.
Project "TicTacToe game Web1.xojo_binary_project"
Class App Inherits WebApplication
EventHandler Sub Open()
dim leer as new Picture(100,100,32)
dim kreis as Picture = picture.Open(findFile("kreis.png"))
dim kreuz as Picture = picture.Open(findFile("kreuz.png"))
KreisPic = new WebPicture(kreis, picture.FormatPNG)
kreuzPic = new WebPicture(kreuz, picture.FormatPNG)
leerPic = new WebPicture(leer, picture.FormatPNG)
End EventHandler
Function FindFile(name as string) As FolderItem
// Look for file in parent folders from executable on
dim parent as FolderItem = app.ExecutableFile.Parent
while parent<>Nil
dim file as FolderItem = parent.Child(name)
if file<>Nil and file.Exists then
Return file
end if
parent = parent.Parent
wend
End Function
Property KreisPic As WebPicture
Property KreuzPic As WebPicture
Property LeerPic As WebPicture
End Class
Class Session Inherits WebSession
Const ErrorDialogCancel = "Do Not Send"
Const ErrorDialogMessage = "This application has encountered an error and cannot continue."
Const ErrorDialogQuestion = "Please describe what you were doing right before the error occurred:"
Const ErrorDialogSubmit = "Send"
Const ErrorThankYou = "Thank You"
Const ErrorThankYouMessage = "Your feedback helps us make improvements."
Const NoJavascriptInstructions = "To turn Javascript on, please refer to your browser settings window."
Const NoJavascriptMessage = "Javascript must be enabled to access this page."
End Class
Class WebPage1 Inherits WebPage
Control ImageView1 Inherits WebImageView
ControlInstance ImageView1 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 0
End EventHandler
End Control
Control ImageView2 Inherits WebImageView
ControlInstance ImageView2 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 1
End EventHandler
End Control
Control ImageView3 Inherits WebImageView
ControlInstance ImageView3 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 2
End EventHandler
End Control
Control ImageView4 Inherits WebImageView
ControlInstance ImageView4 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 3
End EventHandler
End Control
Control ImageView5 Inherits WebImageView
ControlInstance ImageView5 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 4
End EventHandler
End Control
Control ImageView6 Inherits WebImageView
ControlInstance ImageView6 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 5
End EventHandler
End Control
Control ImageView7 Inherits WebImageView
ControlInstance ImageView7 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 6
End EventHandler
End Control
Control ImageView8 Inherits WebImageView
ControlInstance ImageView8 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 7
End EventHandler
End Control
Control ImageView9 Inherits WebImageView
ControlInstance ImageView9 Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent)
Mensch 8
End EventHandler
End Control
Control Button1 Inherits WebButton
ControlInstance Button1 Inherits WebButton
EventHandler Sub Action()
neu
End EventHandler
End Control
Control Liste Inherits WebListBox
ControlInstance Liste Inherits WebListBox
End Control
Control Dialog11 Inherits WebDialog1
ControlInstance Dialog11 Inherits WebDialog1
End Control
EventHandler Sub Open()
felder.Append ImageView1
felder.Append ImageView2
felder.Append ImageView3
felder.Append ImageView4
felder.Append ImageView5
felder.Append ImageView6
felder.Append ImageView7
felder.Append ImageView8
felder.Append ImageView9
End EventHandler
Protected Sub Meldung(s as string)
Dialog11.Info.text = s
Dialog11.Show
End Sub
Protected Sub Mensch(n as integer)
if ende = false and feld(n)=0 then
felder(n).Picture = app.KreuzPic
feld(n)=1
message "Mensch nimm Feld "+str(n mod 3 + 1)+"/"+str(n\3+1)
bewertung
if punktemensch >=50 then
Message "Mensch gewinnt!"
Meldung "Sie haben gewonnen!"
ende = true
else
computerzug
bewertung
if punktecomputer >= 50 then
Message "Computer gewinnt!"
Meldung "Sie haben verloren!"
ende = true
end if
end if
end if
End Sub
Protected Sub Message(s as string)
Liste.InsertRow 0, s
End Sub
Protected Sub bewertung()
dim si(-1) as integer
punktemensch=0
punktecomputer=0
si.append feld(0)+feld(1)+feld(2)
si.append feld(3)+feld(4)+feld(5)
si.append feld(6)+feld(7)+feld(8)
si.append feld(0)+feld(4)+feld(8)
si.append feld(2)+feld(4)+feld(6)
si.append feld(0)+feld(3)+feld(6)
si.append feld(1)+feld(4)+feld(7)
si.append feld(2)+feld(5)+feld(8)
for n as integer = 0 to 7
Select case si(n)
case 0
punktemensch=punktemensch+1
punktecomputer=punktecomputer+1
case 1
punktemensch=punktemensch+2
case 2
punktemensch=punktemensch+4
case 3
punktemensch=punktemensch+50
case 5
punktecomputer=punktecomputer+2
case 10
punktecomputer=punktecomputer+4
case 15
punktecomputer=punktecomputer+50
end Select
next
End Sub
Protected Sub computerzug()
dim best as integer = 0
dim bp as integer = -1
dim frei as integer = freiefelder
if frei = 9 then
// computer starts
put 4
Return
end if
if frei = 1 then
// last field
putany
Return
end if
if frei = 0 then
// ended
Return
end if
// can computer win?
for i as integer = 0 to 8
if feld(i)=0 then
feld(i)=5
bewertung
if punktecomputer>49 then
put i
Return
end if
feld(i)=0
end if
next
// can human win?
for i as integer = 0 to 8
if feld(i)=0 then
feld(i)=1
bewertung
if punktemensch > 49 then
put i
Return
end if
feld(i)=0
end if
next
// see if human could win after our move
for i as integer = 0 to 8
if feld(i) = 0 then
for j as integer = 0 to 8
if i<>j and feld(j) = 0 then
feld(i)=5
feld(j)=1
bewertung
dim w as integer = punktecomputer-punktemensch
if (w>bp) then
bp=w
best=i
end if
feld(i)=0
feld(j)=0
end if
next
end if
next
if bp>=0 then
put(best)
else
putany
end if
End Sub
Protected Function freiefelder() As integer
dim j as integer
for i as integer = 0 to 8
if feld(i)=0 then
j = j + 1
end if
next
Return j
End Function
Protected Sub neu()
ende = false
for i as integer = 0 to 8
feld(i)=0
felder(i).Picture=app.LeerPic
next
punktemensch = 0
punktecomputer = 0
liste.DeleteAllRows
End Sub
Protected Sub put(n as integer)
feld(n)=5
felder(n).picture=app.KreisPic
Message "Computer nimmt Feld "+str(n mod 3 + 1)+"/"+str(n\3+1)
End Sub
Protected Sub putany()
static moves(-1) as integer = Array(4, 0, 2, 6, 8, 1, 3, 5, 7)
for n as integer = 0 to 8
dim j as integer = moves(n)
if feld(j)=0 then
put j
Return
end if
next
End Sub
Property Protected Felder() As WebImageView
Property Protected ende As Boolean
Property Protected feld(8) As Integer
Property Protected punktecomputer As Integer
Property Protected punktemensch As Integer
End Class
Class WebDialog1 Inherits WebDialog
Control Info Inherits WebLabel
ControlInstance Info Inherits WebLabel
End Control
Control Button1 Inherits WebButton
ControlInstance Button1 Inherits WebButton
EventHandler Sub Action()
self.Close
End EventHandler
End Control
End Class
End Project
See also:
- /Main/Web Edition Examples/Infos Web1
- /Main/Web Edition Examples/Infos Web2
- /Main/Web Edition Examples/Invisible FileUploader with Button Web1
- /Main/Web Edition Examples/Little database sample Web1
- /Main/Web Edition Examples/Music in Web App Web1
- /Main/Web Edition Examples/TicTacToe game/TicTacToe game Web2
- /Main/Web Edition Examples/WebApp with missing pictures Web1
- /Main/Web Loadbalancer Example/MyApp
The items on this page are in the following plugins: MBS Main Plugin.
Feedback: Report problem or ask question.