Wir haben auch einen Zähler eingebaut welcher mitzählt wieviel richtige man hatte.
Doch zum einem bleibt der Zähler bei der zahl 2 einmal hängen so das zweimal 2 Richtige angezeigt werden.
Zum anderen ist es so das nach einer Falschen Rechnung die nächste auch noch als Falsch bezeichnet wird, auch wenn diese richtig war.
Code: Alles auswählen
#ButtonPlus = 0
#ButtonMinus = 1
#ButtonMal = 2
#ButtonDurch = 3
#StringZahl1 = 4
#StringZahl2 = 5
#StringZahl3 = 6
#StringErgebnis = 7
#MainWindow = 0
#neu = 0
Anzahl_Richtig = 0
falsche = 0
Procedure FillGadget()
SetGadgetText(#StringZahl1,Str(Random(12)))
SetGadgetText(#StringZahl2,Str(Random(12)))
SetGadgetText(#StringZahl3,"")
EndProcedure
Procedure rechne()
val1.s = GetGadgetText(#StringZahl1)
val2.s = GetGadgetText(#StringZahl2)
result = Val(val1)*Val(val2)
SetGadgetText(#StringErgebnis,Str(result))
If result = Val(GetGadgetText(#StringZahl3))
ProcedureReturn #True
EndIf
EndProcedure
If OpenWindow(#MainWindow,0,0,200,400,"Taschenrechner",#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
If CreateGadgetList(WindowID(0))
TextGadget(#PB_Any, 0, 10, 100, 20, "Erste Zahl")
StringGadget(#StringZahl1,0,30,100,20,Str(Random(12)),#PB_String_Numeric)
TextGadget(#PB_Any, 0, 60, 100, 20, "Zweite Zahl")
StringGadget(#StringZahl2,0,80,100,20,Str(Random(12)),#PB_String_Numeric)
TextGadget(#PB_Any, 0, 135, 150, 20, "Resultat eingeben")
StringGadget(#StringZahl3,0,150,100,20,"",#PB_String_Numeric)
; TextGadget(#PB_Any, 0, 175, 300 20, "Resultat Richtig")
TextGadget(#PB_Any, 0, 230, 150, 20, "Neue Rechnung mit Enter")
StringGadget(#StringErgebnis,0,320,100,20,"",#PB_String_Numeric | #PB_String_ReadOnly)
AddKeyboardShortcut(#MainWindow,#PB_Shortcut_Return,#neu)
SetActiveGadget(#StringZahl3)
EndIf
EndIf
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Menu
If EventMenu() = #neu
rechne()
Anzahl_Richtig = Anzahl_Richtig +1
If rechne()
TextGadget(#PB_Any, 0, 260, 150, 60, "Richtig")
TextGadget(#PB_Any, 160, 260, 30, 20, Str(Anzahl_Richtig))
Else
TextGadget(#PB_Any, 0, 260, 150, 60, "Aber aber so was auch, das richtige Resultat lautet")
EndIf
FillGadget()
SetActiveGadget(#StringZahl3)
EndIf
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
EndSelect
Until EventID = #PB_Event_CloseWindow
End