'Gebeurtenis Afandelingen
Sub OnMouseDown
x = GraphicsWindow.MouseX
y = GraphicsWindow.MouseY
'Start het spel opnieuw
If x > 229 And x < 320 And y > 510 And y < 550 Then
Start()
EndIf
If beurt < 11 then
'kleurKiezen
If x >= 279 And x <= 330 And y >= 0 And y <= 510 then
KiesKleur()
ZetKleurMarker()
EndIf
'kleur plaatsen 25,0,204,510
If x >= 25 And x <= 229 And y >= (-51 + beurt * 51) And y <= (beurt * 51) then
'kleurKiezen
PlaatsPin()
EndIf
Else
GraphicsWindow.ShowMessage("Het spel is afgelopen", "Mastermind")
EndIf
EndSub
'plaats een pin
Sub PlaatsPin
if array.ContainsValue(aantalPinsGezet, GeselecteerdeKleur) Then
GraphicsWindow.ShowMessage("Deze kleur heb je al gebruikt", "mastermind")
else
'bepaal in welke kolom is geklikt
If GraphicsWindow.MouseX > 25 Then
kolom = 1
EndIf
If GraphicsWindow.MouseX > 76 Then
kolom = 2
EndIf
If GraphicsWindow.MouseX > 127 Then
kolom = 3
EndIf
If GraphicsWindow.MouseX > 178 Then
kolom = 4
EndIf
x = 25 + 5 + (kolom *51) - 51
y = 5 + beurt * 51 - 51
GraphicsWindow.BrushColor = GeselecteerdeKleur
GraphicsWindow.FillEllipse(x, y, 41,41)
aantalPinsGezet[kolom] = GeselecteerdeKleur
If Array.GetItemCount(aantalPinsGezet) = 4 Then
GraphicsWindow.Title = ""
'Controleer gezette pins
BerekenScore()
'Plaats resultaat van de beurt
If beurt = 11 then
GraphicsWindow.ShowMessage("ëinde van het spel", "Einde")
endif
EndIf
EndSub
'Kies een kleur
Sub KiesKleur
If Array.ContainsValue(PinKleur, GraphicsWindow.GetPixel(x,y)) then
GeselecteerdeKleur = GraphicsWindow.GetPixel(x,y)
GraphicsWindow.Title = GeselecteerdeKleur
EndIf
EndSub
'Plaats kleurMarker
Sub ZetKleurMarker
TekenVoorbeeldKleuren()
For i=1 To 6
If PinKleur[i] = GeselecteerdeKleur Then
x = 279
y = i * 51
GraphicsWindow.PenColor = "white"
GraphicsWindow.PenWidth = 4
GraphicsWindow.DrawEllipse(x+4, y+4-51, 43, 43)
EndIf
EndFor
EndSub
'Plaats het driehoek om aan te geven welke beurt
Sub ZetBeurMarker
TekenBeurtAanduiding()
x = 0
y = (51 * beurt) -51
'GraphicsWindow.Title = "y= " + y
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FillTriangle(x, y, x, y + 51, x + 25, y + 26)
EndSub
'Bereken de score van de beurt
Sub BerekenScore
For i=1 To 4
If aantalPinsGezet[i] = PinKleur[MasterMindCode[i]] Then
aantalKleurenGoedePlaats = aantalKleurenGoedePlaats + 1
Else
If Array.ContainsValue(aantalPinsGezet, PinKleur[MasterMindCode[i]] ) then
aantalKleurenGoed = aantalKleurenGoed + 1
EndIf
EndIf
EndFor
GraphicsWindow.Title = "kleurGoed:" + aantalKleurenGoed + " PlekGoed:" + aantalKleurenGoedePlaats
PlaatsScorePins()
If aantalKleurenGoedePlaats =4 Then
GraphicsWindow.ShowMessage("Gefeliciteerd! Je hebt de code geraden.", "Mastermind")
'Toon de geheime Mastermind code
TekenMastermindCode()
beurt = 11
EndIf
For i1 = 1 To 10 'teken de rijen
For i2 = 1 To 4 'teken de pinnetjes
GraphicsWindow.PenColor = "White"
GraphicsWindow.DrawEllipse(x+4, y+4, 43,43)
x = x + 51
EndFor
x = 25
y = y +51
EndFor
'Teken de voorbeeldkleuren
TekenVoorbeeldKleuren()
'Teken de voorbeeldkleuren
Sub TekenVoorbeeldKleuren
'Voorbeeldkleuren
GraphicsWindow.BrushColor = "DarkGray"
GraphicsWindow.FillRectangle(279,0,50,510)
x = 279
y = 0
For i = 1 To 6
GraphicsWindow.BrushColor = PinKleur[i]
GraphicsWindow.fillEllipse(x+4, y+4, 43,43)
y = y + 51
EndFor
EndSub
Sub TekenBeurtAanduiding
'BeurtAanduiding
GraphicsWindow.BrushColor = "Silver"
GraphicsWindow.FillRectangle(0,0,25,570)
EndSub
Sub TekenMastermindCode
x = 25
y = 510
For i = 1 To 4 'teken de pinnetjes
GraphicsWindow.brushColor = PinKleur[MasterMindCode[i]]
GraphicsWindow.FillEllipse(x+4, y+8, 43,43)
x = x + 51
EndFor
EndSub
'pin 1
x = x + 7
y = y + 7
If aantalKleurenGoedePlaats > 0 Then
GraphicsWindow.BrushColor = "black"
GraphicsWindow.FillEllipse(x, y, 15, 15)
Else
GraphicsWindow.BrushColor = "white"
GraphicsWindow.FillEllipse(x, y, 15, 15)
EndIf
'pin 2
x = x + 25
If aantalKleurenGoedePlaats > 1 Then
GraphicsWindow.BrushColor = "black"
GraphicsWindow.FillEllipse(x, y, 15, 15)
Else
GraphicsWindow.BrushColor = "white"
GraphicsWindow.FillEllipse(x, y, 15, 15)
EndIf
'pin 3
If TotaalAantalPins > 2 then
x = x - 25
y = y + 25
If aantalKleurenGoedePlaats > 2 Then
GraphicsWindow.BrushColor = "black"
GraphicsWindow.FillEllipse(x, y, 15, 15)
Else
GraphicsWindow.BrushColor = "white"
GraphicsWindow.FillEllipse(x, y, 15, 15)
EndIf
EndIf
'pin 4
If TotaalAantalPins > 3 then
x = x + 25
If aantalKleurenGoedePlaats > 3 Then
GraphicsWindow.BrushColor = "black"
GraphicsWindow.FillEllipse(x, y, 15, 15)
Else
GraphicsWindow.BrushColor = "white"
GraphicsWindow.FillEllipse(x, y, 15, 15)
EndIf
EndIf
EndSub