Zum Inhalt springen

Gambas: Spiele: Sprint Form1.class

Aus Wikibooks
PUBLIC z AS Integer 'Zähler für die Zahl der Züge
PUBLIC w AS String 'Variable wer aktuell an der Reihe ist X oder O

PUBLIC SUB Form_Open()
  ME.TEXT = "Sprint, wer setzt den letzten Stein. Ein Spiel für 2"
  ME.Center
  Button3_Click
END

SUB gewonnen()
  'nach jedem Setzen wird geprüft ob die Gewinnkriterien erfüllt sind
  DIM a AS Integer
  a = 0
  IF TextBox1.Text = "" THEN a = a + 1
  IF TextBox2.Text = "" THEN a = a + 1
  IF TextBox3.Text = "" THEN a = a + 1
  IF TextBox4.Text = "" THEN a = a + 1
  IF TextBox5.Text = "" THEN a = a + 1
  IF TextBox6.Text = "" THEN a = a + 1
  IF TextBox7.Text = "" THEN a = a + 1
  IF TextBox8.Text = "" THEN a = a + 1
  IF TextBox9.Text = "" THEN a = a + 1
  IF TextBox10.Text = "" THEN a = a + 1
  IF TextBox11.Text = "" THEN a = a + 1
  IF TextBox12.Text = "" THEN a = a + 1
  IF TextBox13.Text = "" THEN a = a + 1
  IF TextBox14.Text = "" THEN a = a + 1
  IF TextBox15.Text = "" THEN a = a + 1
  IF TextBox16.Text = "" THEN a = a + 1
  IF TextBox17.Text = "" THEN a = a + 1
  IF TextBox18.Text = "" THEN a = a + 1
  IF TextBox19.Text = "" THEN a = a + 1
  IF TextBox20.Text = "" THEN a = a + 1
  IF TextBox21.Text = "" THEN a = a + 1
  IF TextBox22.Text = "" THEN a = a + 1
  IF TextBox23.Text = "" THEN a = a + 1
  IF TextBox24.Text = "" THEN a = a + 1
  IF TextBox25.Text = "" THEN a = a + 1
  IF TextBox26.Text = "" THEN a = a + 1
  IF TextBox27.Text = "" THEN a = a + 1
  IF TextBox28.Text = "" THEN a = a + 1
  IF TextBox29.Text = "" THEN a = a + 1
  IF TextBox30.Text = "" THEN a = a + 1
  IF TextBox31.Text = "" THEN a = a + 1
  IF TextBox32.Text = "" THEN a = a + 1
  IF TextBox33.Text = "" THEN a = a + 1
  IF TextBox34.Text = "" THEN a = a + 1
  IF TextBox35.Text = "" THEN a = a + 1
  IF TextBox36.Text = "" THEN a = a + 1
  IF TextBox37.Text = "" THEN a = a + 1
  IF TextBox38.Text = "" THEN a = a + 1
  IF TextBox39.Text = "" THEN a = a + 1
  IF TextBox40.Text = "" THEN a = a + 1
  IF a = 0 THEN TextArea1.Text = w & " hat gewonnen"
END

SUB wechsel ()
  INC z
  IF z = 1 OR z = 3 OR z = 5 OR z = 7 OR z = 9 OR z = 11 OR z = 13 THEN 
    w = "X" 
    TextArea1.Text = "Am Zug ist O"
  ENDIF
  IF z = 2 OR z = 4 OR z = 6 OR z = 8 OR z = 10 OR z = 12 OR z = 14 THEN 
    w = "O"
    TextArea1.Text = "Am Zug ist X"
  ENDIF
  TextArea2.Text = "Zug " & Str(z)
END

PUBLIC SUB TextBox1_DblClick()
  IF TextBox1.Text = "" THEN
    wechsel
    TextBox1.Text = w
    TextBox2.Text = "B"
    TextBox3.Text = "B"
    gewonnen
  ELSE 
    TextArea1.Text = "Feld schon belegt"
  ENDIF 
END

PUBLIC SUB TextBox10_DblClick()
  IF TextBox10.Text = "" THEN
    wechsel
    TextBox10.Text = w
    TextBox2.Text = "B"
    TextBox3.Text = "B"
    TextBox4.Text = "B"
    TextBox9.Text = "B"
    TextBox11.Text = "B"
    TextBox15.Text = "B"
    TextBox16.Text = "B"
    TextBox17.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox11_DblClick()
  IF TextBox11.Text = "" THEN
    wechsel
    TextBox11.Text = w
    TextBox5.Text = "B"
    TextBox3.Text = "B"
    TextBox4.Text = "B"
    TextBox10.Text = "B"
    TextBox12.Text = "B"
    TextBox16.Text = "B"
    TextBox17.Text = "B"
    TextBox18.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox12_DblClick()
  IF TextBox12.Text = "" THEN
    wechsel
    TextBox12.Text = w
    TextBox4.Text = "B"
    TextBox5.Text = "B"
    TextBox6.Text = "B"
    TextBox13.Text = "B"
    TextBox11.Text = "B"
    TextBox17.Text = "B"
    TextBox18.Text = "B"
    TextBox19.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END 

PUBLIC SUB TextBox13_DblClick()
  IF TextBox13.Text = "" THEN
    wechsel
    TextBox13.Text = w
    TextBox7.Text = "B"
    TextBox5.Text = "B"
    TextBox6.Text = "B"
    TextBox12.Text = "B"
    TextBox14.Text = "B"
    TextBox20.Text = "B"
    TextBox18.Text = "B"
    TextBox19.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox14_DblClick()
  IF TextBox14.Text = "" THEN
    wechsel
    TextBox14.Text = w
    TextBox7.Text = "B"
    TextBox8.Text = "B"
    TextBox6.Text = "B"
    TextBox13.Text = "B"
    TextBox20.Text = "B"
    TextBox19.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox15_DblClick()
  IF TextBox15.Text = "" THEN
    wechsel
    TextBox15.Text = w
    TextBox9.Text = "B"
    TextBox10.Text = "B"
    TextBox16.Text = "B"
    TextBox22.Text = "B"
    TextBox21.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox16_DblClick()
  IF TextBox16.Text = "" THEN
    wechsel
    TextBox16.Text = w
    TextBox9.Text = "B"
    TextBox10.Text = "B"
    TextBox11.Text = "B"
    TextBox15.Text = "B"
    TextBox17.Text = "B"
    TextBox21.Text = "B"
    TextBox22.Text = "B"
    TextBox23.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox17_DblClick()
  IF TextBox17.Text = "" THEN
    wechsel
    TextBox17.Text = w
    TextBox12.Text = "B"
    TextBox10.Text = "B"
    TextBox11.Text = "B"
    TextBox16.Text = "B"
    TextBox18.Text = "B"
    TextBox24.Text = "B"
    TextBox22.Text = "B"
    TextBox23.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox18_DblClick()
  IF TextBox18.Text = "" THEN
    wechsel
    TextBox18.Text = w
    TextBox12.Text = "B"
    TextBox13.Text = "B"
    TextBox11.Text = "B"
    TextBox17.Text = "B"
    TextBox19.Text = "B"
    TextBox24.Text = "B"
    TextBox25.Text = "B"
    TextBox23.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox19_DblClick()
  IF TextBox19.Text = "" THEN
    wechsel
    TextBox19.Text = w
    TextBox12.Text = "B"
    TextBox13.Text = "B"
    TextBox14.Text = "B"
    TextBox18.Text = "B"
    TextBox20.Text = "B"
    TextBox24.Text = "B"
    TextBox25.Text = "B"
    TextBox26.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox2_DblClick()
  IF TextBox2.Text = "" THEN
    wechsel
    TextBox2.Text = w
    TextBox1.Text = "B"
    TextBox3.Text = "B"
    TextBox9.Text = "B"
    TextBox10.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox20_DblClick()
  IF TextBox20.Text = "" THEN
    wechsel
    TextBox20.Text = w
    TextBox13.Text = "B"
    TextBox14.Text = "B"
    TextBox19.Text = "B"
    TextBox25.Text = "B"
    TextBox26.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox21_DblClick()
  IF TextBox21.Text = "" THEN
    wechsel
    TextBox21.Text = w
    TextBox15.Text = "B"
    TextBox16.Text = "B"
    TextBox22.Text = "B"
    TextBox27.Text = "B"
    TextBox28.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox22_DblClick()
  IF TextBox22.Text = "" THEN
    wechsel
    TextBox22.Text = w
    TextBox15.Text = "B"
    TextBox16.Text = "B"
    TextBox17.Text = "B"
    TextBox23.Text = "B"
    TextBox21.Text = "B"
    TextBox27.Text = "B"
    TextBox28.Text = "B"
    TextBox29.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox23_DblClick()
  IF TextBox23.Text = "" THEN
    wechsel
    TextBox23.Text = w
    TextBox18.Text = "B"
    TextBox16.Text = "B"
    TextBox17.Text = "B"
    TextBox22.Text = "B"
    TextBox24.Text = "B"
    TextBox30.Text = "B"
    TextBox28.Text = "B"
    TextBox29.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox24_DblClick()
  IF TextBox24.Text = "" THEN
    wechsel
    TextBox24.Text = w
    TextBox18.Text = "B"
    TextBox19.Text = "B"
    TextBox17.Text = "B"
    TextBox23.Text = "B"
    TextBox25.Text = "B"
    TextBox30.Text = "B"
    TextBox31.Text = "B"
    TextBox29.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox25_DblClick()
  IF TextBox25.Text = "" THEN
    wechsel
    TextBox25.Text = w
    TextBox18.Text = "B"
    TextBox19.Text = "B"
    TextBox20.Text = "B"
    TextBox24.Text = "B"
    TextBox26.Text = "B"
    TextBox30.Text = "B"
    TextBox31.Text = "B"
    TextBox32.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox26_DblClick()
  IF TextBox26.Text = "" THEN
    wechsel
    TextBox26.Text = w
    TextBox19.Text = "B"
    TextBox20.Text = "B"
    TextBox25.Text = "B"
    TextBox31.Text = "B"
    TextBox32.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox27_DblClick()
  IF TextBox27.Text = "" THEN
    wechsel
    TextBox27.Text = w
    TextBox21.Text = "B"
    TextBox22.Text = "B"
    TextBox28.Text = "B"
    TextBox33.Text = "B"
    TextBox34.Text = "B"
    TextBox35.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox28_DblClick()
  IF TextBox28.Text = "" THEN
    wechsel
    TextBox28.Text = w
    TextBox21.Text = "B"
    TextBox22.Text = "B"
    TextBox23.Text = "B"
    TextBox27.Text = "B"
    TextBox29.Text = "B"
    TextBox34.Text = "B"
    TextBox35.Text = "B"
    TextBox36.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox29_DblClick()
  IF TextBox29.Text = "" THEN
    wechsel
    TextBox29.Text = w
    TextBox24.Text = "B"
    TextBox22.Text = "B"
    TextBox23.Text = "B"
    TextBox28.Text = "B"
    TextBox30.Text = "B"
    TextBox37.Text = "B"
    TextBox35.Text = "B"
    TextBox36.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox3_DblClick()
  IF TextBox3.Text = "" THEN
    wechsel
    TextBox3.Text = w
    TextBox1.Text = "B"
    TextBox2.Text = "B"
    TextBox4.Text = "B"
    TextBox9.Text = "B"
    TextBox10.Text = "B"
    TextBox11.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox30_DblClick()
  IF TextBox30.Text = "" THEN
    wechsel
    TextBox30.Text = w
    TextBox24.Text = "B"
    TextBox25.Text = "B"
    TextBox23.Text = "B"
    TextBox29.Text = "B"
    TextBox31.Text = "B"
    TextBox37.Text = "B"
    TextBox38.Text = "B"
    TextBox36.Text = "B"
    gewonnen
  ELSE
   TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox31_DblClick()
  IF TextBox31.Text = "" THEN
    wechsel 
    TextBox31.Text = w
    TextBox24.Text = "B"
    TextBox25.Text = "B"
    TextBox26.Text = "B"
    TextBox30.Text = "B"
    TextBox32.Text = "B"
    TextBox37.Text = "B"
    TextBox38.Text = "B"
    TextBox39.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox32_DblClick()
  IF TextBox32.Text = "" THEN
    wechsel
    TextBox32.Text = w
    TextBox25.Text = "B"
    TextBox26.Text = "B"
    TextBox31.Text = "B"
    TextBox38.Text = "B"
    TextBox39.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox33_DblClick()
  IF TextBox33.Text = "" THEN
    wechsel
    TextBox33.Text = w
    TextBox27.Text = "B"
    TextBox34.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox34_DblClick()
  IF TextBox34.Text = "" THEN
    wechsel
    TextBox34.Text = w
    TextBox28.Text = "B"
    TextBox27.Text = "B"
    TextBox33.Text = "B"
    TextBox35.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox35_DblClick()
  IF TextBox35.Text = "" THEN
    wechsel
    TextBox35.Text = w
    TextBox27.Text = "B"
    TextBox29.Text = "B"
    TextBox34.Text = "B"
    TextBox28.Text = "B"
    TextBox36.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox36_DblClick()
  IF TextBox36.Text = "" THEN
    wechsel
    TextBox36.Text = w
    TextBox28.Text = "B"
    TextBox30.Text = "B"
    TextBox37.Text = "B"
    TextBox35.Text = "B"
    TextBox29.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox37_DblClick()
  IF TextBox37.Text = "" THEN
    wechsel
    TextBox37.Text = w
    TextBox29.Text = "B"
    TextBox31.Text = "B"
    TextBox30.Text = "B"
    TextBox38.Text = "B"
    TextBox36.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox38_DblClick()
  IF TextBox38.Text = "" THEN
    wechsel
    TextBox38.Text = w
    TextBox30.Text = "B"
    TextBox32.Text = "B"
    TextBox37.Text = "B"
    TextBox31.Text = "B"
    TextBox39.Text = "B"
    TextBox40.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox39_DblClick()
  IF TextBox39.Text = "" THEN
    wechsel
    TextBox39.Text = w
    TextBox31.Text = "B"
    TextBox38.Text = "B"
    TextBox32.Text = "B"
    TextBox40.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox4_DblClick()
  IF TextBox4.Text = "" THEN
    wechsel
    TextBox4.Text = w
    TextBox3.Text = "B"
    TextBox5.Text = "B"
    TextBox10.Text = "B"
    TextBox11.Text = "B"
    TextBox12.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox40_DblClick()
  IF TextBox40.Text = "" THEN
    wechsel
    TextBox40.Text = w
    TextBox38.Text = "B"
    TextBox39.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox5_DblClick()
  IF TextBox5.Text = "" THEN
    wechsel
    TextBox5.Text = w
    TextBox4.Text = "B"
    TextBox6.Text = "B"
    TextBox13.Text = "B"
    TextBox11.Text = "B"
    TextBox12.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox6_DblClick()
  IF TextBox6.Text = "" THEN
    wechsel
    TextBox6.Text = w
    TextBox7.Text = "B"
    TextBox5.Text = "B"
    TextBox12.Text = "B"
    TextBox13.Text = "B"
    TextBox14.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox7_DblClick()
  IF TextBox7.Text = "" THEN
    wechsel
    TextBox7.Text = w
    TextBox6.Text = "B"
    TextBox8.Text = "B"
    TextBox13.Text = "B"
    TextBox14.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox8_DblClick()
  IF TextBox8.Text = "" THEN
    wechsel
    TextBox8.Text = w
    TextBox7.Text = "B"
    TextBox14.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END

PUBLIC SUB TextBox9_DblClick()
  IF TextBox9.Text = "" THEN
    wechsel
    TextBox9.Text = w
    TextBox2.Text = "B"
    TextBox3.Text = "B"
    TextBox10.Text = "B"
    TextBox15.Text = "B"
    TextBox16.Text = "B"
    gewonnen
  ELSE
    TextArea1.Text = "Schon belegt"
  ENDIF
END
 
PUBLIC SUB Button1_Click()
  DIM msg AS String
  msg = "Sprint: Spielregeln\n"
  msg = msg & "Mit der Maus markiert der erste Spieler ein freies Feld.\n"
  msg = msg & "Das Feld wird mit X gekennzeichnet.\n"
  msg = msg & "Die benachbarten Felder werden automatisch mit B belegt.\n"
  msg = msg & "Danach ist der Spielpartner dran.\n"
  msg = msg & "Er bekommt O zugeordnet und klickt ein freies Feld an.\n"
  msg = msg & "Gesetzt wird abwechselnd.\n"
  msg = msg & "Sieger ist, wer das letzte Zeichen einsetzen kann."
  Message.Info( msg ,"OK") 
END

PUBLIC SUB Button2_Click() 
  DIM msg AS String
  msg = "Fragen zum Spiel\n"
  msg = msg & "Gibt es ein Spiel mit weniger als 8 Zügen?\n"
  msg = msg & "Gibt es ein Spiel mit mehr als 13 Zügen?\n "
  msg = msg & "Gibt es für den Spieler, der beginnen darf,\n"
  msg = msg & "eine optimale Gewinnstrategie?\n"
  msg = msg & "Wo wurde dieses Spiel das erste Mal gespielt?\n"
  msg = msg & "Wo wurde dieses Spiel das erste Mal beschrieben?\n"
  msg = msg & "Antworten per email an: rho54@gmx.de"
  Message.Info( msg ,"OK") 
END

PUBLIC SUB Button3_Click()
  TextBox1.Text = ""
  TextBox2.Text = ""
  TextBox3.Text = ""
  TextBox4.Text = ""
  TextBox5.Text = ""
  TextBox6.Text = ""
  TextBox7.Text = ""
  TextBox8.Text = ""
  TextBox9.Text = ""
  TextBox10.Text = ""
  TextBox11.Text = ""
  TextBox12.Text = ""
  TextBox13.Text = ""
  TextBox14.Text = ""
  TextBox15.Text = ""
  TextBox16.Text = ""
  TextBox17.Text = ""
  TextBox18.Text = ""
  TextBox19.Text = ""
  TextBox20.Text = ""
  TextBox21.Text = ""
  TextBox22.Text = ""
  TextBox23.Text = ""
  TextBox24.Text = ""
  TextBox25.Text = ""
  TextBox26.Text = ""
  TextBox27.Text = ""
  TextBox28.Text = ""
  TextBox29.Text = ""
  TextBox30.Text = ""
  TextBox31.Text = ""
  TextBox32.Text = ""
  TextBox33.Text = ""
  TextBox34.Text = ""
  TextBox35.Text = ""
  TextBox36.Text = ""
  TextBox37.Text = ""
  TextBox38.Text = ""
  TextBox39.Text = ""
  TextBox40.Text = ""
  z = 0
  TextArea1.Text = "Am Zug ist X"
  TextArea2.Text = "Zug 0"
END

PUBLIC SUB Button4_Click()
  ME.Close
END