[B2d] Quiz-Grundgerüst

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

SpionAtom

Betreff: [B2d] Quiz-Grundgerüst

BeitragMo, Apr 10, 2006 23:53
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich brauch was für mein Ego Twisted Evil . Und da ich kein Feedback zu meinem Quiz bekam (weils zu gut versteckt war), spendiere ich ihm einen neuen Eintrag im Codearchiv. Fragen sind am Ende des Quelltextes als Data-Anhang und können beliebig erweitert werden. Außerdem sind die Fragen in Stufen unterteilt, sodass zu Beginn nur einfache Fragen kommen und später schwerere.

Und hier ist es!
Code: [AUSKLAPPEN]


;******************************************************************************
;*
;*                           ein Q U I Z - Spiel
;*
;* von Thomas Decker in BlitzBasic
;* gestartet am 8.4.2005
;*
;* Das Spiel soll so in der Art von Wer wird Millionär ablaufen. Zunächst
;* möchte ich gänzlich auf externe Dateien verzichten. Ob ich bei der Fülle
;* der Fragen damit auskomme, steht noch in den Sternen. Also auf ans Werk!
;* Ich versuche meinen Quelltext lesbar zu machen und kommentiere so gut es
;* geht. Bei Fragen m@ilto: tdpb@gmx.de
;*
;******************************************************************************


;Wie bei allen meinen Programmen lege ich mit den Konstanten xr und yr die
;Bildschirmauflösung fest.
;SeeRnd verwende ich, da dieses Quiz-Spiel den Zufallsgenerator verwendet und
;nicht immer die selbe Zahlenfolge generiert werden soll.
Const xr = 800   
Const yr = 600
SeedRnd MilliSecs()


;Auch das gehört immer dazu: Ein Fenster erschaffen. Einen Titel für die Titel
;leiste brauchtg man nicht unbedingt, ist aber schöner :-). Falls man mehrere
;Schriften verwendet, so wie ich, sollte man diese auch so früh wie möglich
;laden. Mausposition habe ich auch in globale Variablen gepackt, da ich so
;bestimmen kann, wann diese Variablen aktualisiert werden. Sie sind dann stets
;gleich. MouseX() und MouseY() hingegen kann sich innerhalb einer Abfrage
;verändern, das führt zu Komplikationen
Graphics xr, yr, 16, 2
AppTitle("Quiz-Spiel von Thomas Decker")
Global font_Titel = LoadFont("Blitz", 32)
Global font_Normal = LoadFont("Blitz", 22)
Global font_Box = LoadFont("Blitz", 26, 1)
Global curser_x, curser_y

;Zum Schluss (des Anfangs) kommen noch spielrelevante Variablen dazu. maxFragen
;gibt die Anzahl der zu lösenden Fragen an. Das Array antwort(4) speichert die
;4 Antwortmöglichkeiten. und antpos(4) brauche ich, um die Antwortmöglichkeiten
;auf die Antwortfelder zu verteilen (siehe auch Function mixAntPos).
   Const maxFragen = 4
   Dim antwort$(4)
   Dim antPos(4)
   Restore Fragen
   
SetBuffer BackBuffer()
HidePointer()
   
   For frageNr = 1 To maxFragen
   
      Repeat
      Read fragenStufe$
      Until fragenStufe$ = "#" + frageNr
     
      Read fragenAnz
      frageOffs = Rand(1, fragenAnz)
      For i = 1 To frageOffs
         Read frage$, antwort$(1), antwort$(2), antwort$(3), antwort$(4)
      Next
         richtig$ = antwort$(1)
         mixAntpos()
         
         
         ende = 0
         chose = 0
   
            Repeat
   
   
               curser_x = MouseX()
               curser_y = MouseY()
               FlushMouse()
               FlushKeys()
   
         
               Cls
               drawStaticBackground()
     
               SetFont font_Normal
               Color 255, 255, 255
               center "Frage " + frageNr, 125
               drawPointPad frageNr - 1
               
               drawQuestionBox frage$, 275
               
               If XButton(20, 20) = 1 Or KeyHit(1) Then ende = 1
               
               If chose > 0 Then
                     If chosen$ = richtig$ Then
                           Color 0, 255, 0
                           Center "Ihre Antwort war richtig", 200
                           drawPointPad frageNr
                     Else
                           Color 255, 0, 0
                           Center "Leider falsch", 200
                     End If

                  aw = 350: ah = 54
                  draw6BoxPressed(antwort$(antpos(1)), 25, 375, aw, ah)
                  draw6BoxPressed(antwort$(antpos(2)), 425, 375, aw, ah)
                  draw6BoxPressed(antwort$(antpos(3)), 25, 475, aw, ah)
                  draw6BoxPressed(antwort$(antpos(4)), 425, 475, aw, ah)


               Else
               
                  aw = 350: ah = 54
                  If draw6BoxPressed(antwort$(antpos(1)), 25, 375, aw, ah, True) = True Then chosen$ = antwort$(antpos(1)): chose = MilliSecs()
                  If draw6BoxPressed(antwort$(antpos(2)), 425, 375, aw, ah, True) = True Then chosen$ = antwort$(antpos(2)): chose = MilliSecs()
                  If draw6BoxPressed(antwort$(antpos(3)), 25, 475, aw, ah, True) = True Then chosen$ = antwort$(antpos(3)): chose = MilliSecs()
                  If draw6BoxPressed(antwort$(antpos(4)), 425, 475, aw, ah, True) = True Then chosen$ = antwort$(antpos(4)): chose = MilliSecs()


               End If

               drawRoundBorder 12, 255, 200, 150
               drawMouse()
               Flip(0)   
               
                 
   
            Until ende = 1 Or (chose + 1500 < MilliSecs() And chose > 0) Or (chose > 0 And MouseHit(2))
            If ende = 1 Then Exit;[FOR]
           
           
            If chosen$ <> richtig$ Then Exit
           
           
   
   
   Next
   

   If frageNr = maxFragen + 1 Then ;Komische Eigenschaft: Nach dem Durchlaufen einer FOR..NEXT-Schleife, ist die Variable um eins größer, als der Endwert
   
      SetFont font_Titel
      Repeat
         curser_x = MouseX()
         curser_y = MouseY()
         Cls
         drawStaticBackground()
         Color 255, 255, 0
         center "Sie haben gewonnen", 300
         If XButton(xr / 2 - 10, 350) = 1 Or KeyHit(1) Then ende = 1
         drawRoundBorder 12, 255, 200, 150
         drawMouse()
      Flip()
      Until ende = 1

   End If

   End()
   








Function center(pText$ = "centerText", y = 0)

      x = (xr - StringWidth(pText$)) / 2
      Text x, y, pText$
     
End Function


Function centerTo(zX1 = 0, zX2 = 100, pText$ = "centerText", y = 0)

      x = zX1 + (zX2 - zX1 - StringWidth(pText$)) / 2
      Text x, y, pText$
     
End Function




Function drawStaticBackground()

      SetFont font_Titel
      t$ = "Wer wird Millionär"
     
      Color 100, 255, 100
      Oval xr / 2 - StringWidth(t$), 25, 2 * StringWidth(t$), StringHeight(t$) + 50
      Color 50, 150, 255
      Oval xr / 2 - 0.9 * StringWidth(t$), 40, 1.8 * StringWidth(t$), StringHeight(t$) + 20
      Color 50, 255, 50
      center t$, 50
     
End Function


Function drawRoundBorder(dots = 10, r1 = 255, g1 = 255, b1 = 255, r2 = 0, g2 = 0, b2 = 0)

      Color r1, g1, b1
      Rect 0, 0, xr, dots, 1
      Rect 0, yr - dots, xr, dots, 1
      Rect 0, 0, dots, yr, 1
      Rect xr - dots, 0, dots, yr, 1
     
     
      ;Color r2, g2, b2
      ;Rect dots, dots, xr - 2 * dots, yr - 2 * dots, 1
      Color r1, g1, b1
      Rect dots, dots, dots / 2, dots / 2, 1
      Rect dots, yr - 1.5 * dots, dots / 2, dots / 2, 1
      Rect xr - 1.5 * dots, dots, dots / 2, dots / 2, 1
      Rect xr - 1.5 * dots, yr - 1.5 * dots, dots / 2, dots / 2, 1
      Color r2, g2, b2
      Oval dots, dots, dots, dots, 1
      Oval dots, yr - 2 * dots, dots, dots, 1
      Oval xr - 2 * dots, dots, dots, dots, 1
      Oval xr - 2 * dots, yr - 2 * dots, dots, dots, 1

End Function


Function drawMouse()

      Color 255, 255, 255
      Oval cx - 4, cy - 4, 8, 8
      Color 0, 255, 255
      Oval curser_x - 3, curser_y - 3, 6, 6

End Function

Function XButton(pX = 0, pY = 0)

      gr = 20
      If mouseInRect(pX, pY, pX + gr, pY + gr) Then
         Color 255, 255, 0
         miR = True
      Else
         Color 155, 155, 0
         miR = False
      End If
           
      Line pX, pY, pX + gr, pY + gr
      Line pX, pY + gr, pX + gr, pY
     
     
      Return MouseDown(1) And miR

End Function


Function mouseInRect(pX1, pY1, pX2, pY2)

   If curser_X < pX1 Then Return False
   If curser_X > pX2 Then Return False
   If curser_Y < pY1 Then Return False
   If curser_Y > pY2 Then Return False
   Return True
   
End Function


Function drawQuestionBox(pF$ = "???", pY = 0)

   width = 600
   height = 54
   pX = (xr - width) / 2

   draw6Box pF$, pX, pY, width, height

End Function   


Function draw6Box(t$, pX, pY, w, h, button = False)

   SetFont font_Box
   
   Color 255, 255, 255
   Rect pX, pY, w, h, 0
   
   If mouseInRect(pX, pY, pX + w, pY + h) And button Then
      Color 255, 0, 255
      Rect pX + 2, pY + 2, w - 4, h - 4, 0
      Rect pX + 3, pY + 3, w - 6, h - 6, 0
   End If
     
   Color 150, 250, 255
   If StringWidth(t$) < w Then
      centerTo pX, pX + w,  t$, pY + (h - StringHeight(t$)) / 2
   Else
      For i = Len(t$) To 1 Step -1
         If Mid$(t$, i, 1) = " " And StringWidth(Left$(t$, i)) < w Then
            cut = i: Exit
         End If
      Next
      t1$ = Left$(t$, cut)
      t2$ = Mid$(t$, cut + 1, -1)
      centerTo pX, pX + w, t1$, pY
      centerTo pX, pX + w, t2$, pY + StringHeight(t$)
   
   End If
   

End Function


Function draw6BoxPressed(t$, pX, pY, w, h, button = False)

   draw6Box t$, pX, pY, w, h, button
     
   Return MouseDown(1) And mouseInRect(pX, pY, pX + w, pY + h)
   
End Function


Function mixAntpos()

   Local blocked[4]
   For i = 1 To 4
   blocked[i] = False
   Next
   
   For i = 1 To 4
     
      Repeat
      antpos(i) = Rand(1, 4)
      Until blocked[antpos(i)] = False
      blocked[antpos(i)] = True
           
   Next

End Function


Function drawPointPad(p = 0)
   
   a = xr / (maxFragen + 2)
   g = 20

   For i = 1 To maxFragen
      If i <= p Then
         Color 255, 255, 0
         Oval  (1.5 * a) + (i - 1) * a - 0.5 * g, yr - 50, g, g
      Else
         Color 55, 55, 0
         Oval  (1.5 * a) + (i - 1) * a - 0.5 * g, yr - 50, g, g
      End If
   Next


End Function






;Data "#fragenstufe", fragenAnzahl
;Data "Frage", "Antwort", "Falsche Antwort1", "Falsche Antwort2", "Falsche Antwort3"
.Fragen
Data "#1", 3
Data "Was ist 1 + 1?", "2", "1", "3", "4"
Data "Was ist 1 + 2?", "3", "2", "1", "4"
Data "Was ist 2 + 2?", "4", "2", "3", "1"
Data "#2", 5
Data "Welches Tier ist groß, grau und hat einen Rüssel", "Elefant", "Maus", "Katze", "Regenwurm"
Data "Wo steht der Kölner-Dom?", "Köln", "Berlin", "München", "Hamburg"
Data "Wie heißt <<Krieg der Sterne>> im Original?", "Star Wars", "Tank Wars", "Moon Wars", "Jedi Wars"
Data "Schnappi ist...", "ein Krokodil", "der neue Mercedes-Prototyp", "das Gegenteil von Schnuppi", "das PC-Spiel des Jahres 1989"
Data "Punkt - Punkt - Komma - Strich - ...", "Fertig ist das Mondgesicht", "Fertig ist das Nudelgericht", "Fertig ist das Kurzgedicht", "is mir egal, ich kenn das nicht"
Data "#3", 3
Data "Wieviele Augen hat ein Würfel", "21", "20", "22", "23"
Data "Ringtone-Werbung ist ...", "NERVIG!!!", "Super", "Klasse", "Toll"
Data "Legolas ist...","ein Elb","ein Auto","ein Fussballspieler","ein Ferienort"
Data "#4", 2
Data "Wie heißt ein berühmtes Lied von Cat Stevens?", "Father and son", "Mother and daughter", "Aunt and uncle", "Grandpa and grandma"
Data "Welches Skat-Spiel ist das höchste?", "Grand mit eins", "Karo mit zwei", "Null", "Herz ohne zwei"
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080

tyty

BeitragDi, Apr 11, 2006 8:21
Antworten mit Zitat
Benutzer-Profile anzeigen
Wenn es einmal im Trash war, wird es sicher nocheinmal dort landen...
Rolling Eyes
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!

SpionAtom

BeitragDi, Apr 11, 2006 10:36
Antworten mit Zitat
Benutzer-Profile anzeigen
tyty hat Folgendes geschrieben:
Wenn es einmal im Trash war, wird es sicher nocheinmal dort landen...
Rolling Eyes


Äh, hab ich was verpasst?! Ich denke ein bißchen Selbstironie wird erlaubt sein, wenn du den blöden Spruch am Anfang meinst. Und ansonsten habe ich den Code hier nochmal gepostet, weil der Thread, in den ich ursprünglich angehängt habe, erwartenderweise getrasht wurde.
Und wennn ich meine Programme schon teile, warum nicht mit dem Blitzforum. Der Code ist einigermaßen sauber, er funktioniert, er ist ausbaufähig, vielleichtg hilft er anderen weiter.

Also warum Trash Question
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080

tyty

BeitragDi, Apr 11, 2006 15:07
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich glaub ich hab da was verwechselt... Embarassed
Sieht gut aus. Wink
User posted image

Kaikille suomea puhuville ihmisille: tyty = tyty the technical youngster!!!

Kabelbinder

Sieger des WM-Contest 2006

BeitragDi, Apr 11, 2006 15:52
Antworten mit Zitat
Benutzer-Profile anzeigen
Schöne Oberfläche und vor allem ohne exterrne Datein. Find ich gut.
<Wing Avenger Download> ◊◊◊ <Macrophage Download>

SpionAtom

BeitragDi, Apr 11, 2006 16:56
Antworten mit Zitat
Benutzer-Profile anzeigen
Super, jetzt ist mein Ego wieder aufgeladen Cool
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group