# Microsoft Small Basic

Program Listing:
 Embed this in your website
JocXO()

' subrutina de desenare pentru X
Sub DeseneazaX
GraphicsWindow.PenWidth=10
GraphicsWindow.PenColor="Chocolate"
GraphicsWindow.DrawLine(10+posx,10+posy,190+posx,190+posy)
GraphicsWindow.DrawLine(190+posx,10+posy,10+posx,190+posy)
EndSub

' subrutina de desenare pentru 0
Sub Deseneaza0
GraphicsWindow.PenWidth=10
GraphicsWindow.BrushColor="SandyBrown"
GraphicsWindow.FillEllipse(10+posx,10+posy,180,180)
EndSub

Sub JocXO
GraphicsWindow.Width=600
GraphicsWindow.Height=600
GraphicsWindow.CanResize=0
GraphicsWindow.Title="X si 0"
GraphicsWindow.PenWidth=2
GraphicsWindow.PenColor="Wheat"
GraphicsWindow.DrawLine(0,200,600,200)
GraphicsWindow.DrawLine(0,400,600,400)
GraphicsWindow.DrawLine(200,0,200,600)
GraphicsWindow.DrawLine(400,0,400,600)
GraphicsWindow.MouseUp = Clickat
randulLui=1 'care pune X
terminat="nu"
For i=1 To 9
pozitii[i]=0
EndFor
EndSub

' subrutina pentru click pe tabla
Sub Clickat
If (terminat="nu") Then
x=GraphicsWindow.MouseX
y=GraphicsWindow.MouseY
coloana=Math.Floor(x/200)+1
linia=Math.Floor(y/200)+1
posx=(coloana-1)*200
posy=(linia-1)*200
If (pozitii[(linia-1)*3+coloana]=0) Then
If randulLui=1 Then
DeseneazaX()
randulLui=2
pozitii[(linia-1)*3+coloana]=1
Else
Deseneaza0()
randulLui=1
pozitii[(linia-1)*3+coloana]=2
EndIf
Sound.PlayClick()
Verificare()
Else
Sound.PlayBellRing()
EndIf
EndIf
EndSub

' subrutina pt verificarea situatiei pe tabla dupa click
Sub Verificare
If (pozitii[1]=pozitii[2]) And (pozitii[2]=pozitii[3]) And (pozitii[3]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(10,100,590,100)
terminat="da"
EndIf
If (pozitii[4]=pozitii[5]) And (pozitii[5]=pozitii[6]) And (pozitii[6]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(10,300,590,300)
terminat="da"
EndIf
If (pozitii[7]=pozitii[8]) And (pozitii[8]=pozitii[9]) And (pozitii[9]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(10,500,590,500)
terminat="da"
EndIf
If (pozitii[1]=pozitii[4]) And (pozitii[4]=pozitii[7]) And (pozitii[7]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(100,10,100,590)
terminat="da"
EndIf
If (pozitii[2]=pozitii[5]) And (pozitii[5]=pozitii[8]) And (pozitii[8]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(300,10,300,590)
terminat="da"
EndIf
If (pozitii[3]=pozitii[6]) And (pozitii[6]=pozitii[9]) And (pozitii[9]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(500,10,500,590)
terminat="da"
EndIf
If (pozitii[1]=pozitii[5]) And (pozitii[5]=pozitii[9]) And (pozitii[9]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(10,10,590,590)
terminat="da"
EndIf
If (pozitii[3]=pozitii[5]) And (pozitii[5]=pozitii[7]) And (pozitii[7]<>0) Then
GraphicsWindow.PenColor="Red"
GraphicsWindow.DrawLine(10,590,590,10)
terminat="da"
EndIf
If terminat="da" Then
Sound.PlayChime()
If randulLui=1 Then
GraphicsWindow.ShowMessage("A castigat 0","Final de joc")
Else
GraphicsWindow.ShowMessage("A castigat X","Final de joc")
EndIf
Else
cate=0
For i=1 To 9
If pozitii[i]<>0 Then
cate=cate+1
EndIf
EndFor
If cate=9 Then
Sound.PlayChime()
GraphicsWindow.ShowMessage("Oh, sunteti buni! Remiza!","Final de joc")
EndIf
EndIf
EndSub