I've written another little game, this one should not have such performance problems like my tetris ;-)
; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: Nils Winkler <[email protected]> ; ; Script Function: ; Just a simple Yatzee game :-) ; ; Version: 1.00 ; ; ToDo: ; High Score Start: SetFormat, integer, d ; Menüleiste erstellen / create the little menu bar Menu, FileMenu, Add, &Switch language, Sub_SwitchLanguage Menu, FileMenu, Add, &Restart game, Sub_Initialize Menu, FileMenu, Add, E&xit, GuiClose Menu, MyMenuBar, Add, &File, :FileMenu Gui, Menu, MyMenuBar ; Texte für die Würfel erstellen / create the die texts Gui, Add, Text, x6 y17 w30 h20 vt_One1, Gui, Add, Text, x126 y17 w60 h30 vt_One2, Gui, Add, Text, x6 y57 w30 h20 vt_Two1, Gui, Add, Text, x126 y57 w60 h30 vt_Two2, Gui, Add, Text, x6 y97 w30 h20 vt_Three1, Gui, Add, Text, x126 y97 w60 h30 vt_Three2, Gui, Add, Text, x6 y137 w30 h20 vt_Four1, Gui, Add, Text, x126 y137 w60 h30 vt_Four2, Gui, Add, Text, x6 y177 w30 h20 vt_Five1, Gui, Add, Text, x126 y177 w60 h30 vt_Five2, Gui, Add, Text, x6 y217 w30 h20 vt_Six1, Gui, Add, Text, x126 y217 w60 h30 vt_Six2, ; Summe und Bonus / sum and bonus Gui, Add, Text, x6 y297 w180 h20 vt_Sum1, Gui, Add, Text, x6 y337 w180 h20 vt_SumLeft, Gui, Add, Text, x196 y297 w40 h20 Right vv_Sum1, Gui, Add, Text, x196 y317 w40 h20 Right vv_Bonus, Gui, Add, Text, x196 y337 w40 h20 Right vv_SumLeftPart, ; Schalter rechts von den Würfeln erstellen / create the buttons right of the dice Gui, Add, Button, x196 y17 w40 h30 vv_ones gSub_Ones, Gui, Add, Button, x196 y57 w40 h30 vv_twos gSub_Twos, Gui, Add, Button, x196 y97 w40 h30 vv_threes gSub_Threes, Gui, Add, Button, x196 y137 w40 h30 vv_fours gSub_Fours, Gui, Add, Button, x196 y177 w40 h30 vv_fives gSub_Fives, Gui, Add, Button, x196 y217 w40 h30 vv_sixs gSub_Sixs, ; Texte rechter Teil / right part texts Gui, Add, Text, x276 y17 w100 h30 vt_ThreeOK, Gui, Add, Text, x276 y57 w100 h30 vt_FourOK, Gui, Add, Text, x276 y97 w100 h30 vt_FullHouse, Gui, Add, Text, x276 y137 w100 h30 vt_LittleStreet, Gui, Add, Text, x276 y177 w100 h30 vt_BigStreet, Gui, Add, Text, x276 y217 w100 h30 vt_Yatzee, Gui, Add, Text, x276 y257 w100 h30 vt_Chance, Gui, Add, Text, x276 y337 w100 h30 vt_SumRightPart, Gui, Add, Text, x6 y367 w140 h30 vt_FinalSum, ; Variable rechter Teil / right part variables Gui, Add, Button, x386 y17 w40 h30 vv_ThreeOK gSub_ThreeOK, Gui, Add, Button, x386 y57 w40 h30 vv_FourOK gSub_FourOK, Gui, Add, Button, x386 y97 w40 h30 vv_FullHouse gSub_FullHouse, Gui, Add, Button, x386 y137 w40 h30 vv_LittleStreet gSub_LittleStreet, Gui, Add, Button, x386 y177 w40 h30 vv_BigStreet gSub_BigStreet, Gui, Add, Button, x386 y217 w40 h30 vv_Yatzee gSub_Yatzee, Gui, Add, Button, x386 y257 w40 h30 vv_Chance gSub_Chance, Gui, Add, Text, x386 y337 w40 h30 Right vv_SumRightPart, Gui, Add, Text, x196 y367 w40 h30 Right vv_FinalSum, Gui, Add, Text, x6 y390 w40 h12 vt_Dice, Gui, Add, Button, x326 y397 w100 h30 vt_RollDice gSub_RollDice, Gui, Add, Checkbox, x6 y402 w50 h30 vv_die[1], Gui, Add, Checkbox, x66 y402 w50 h30 vv_die[2], Gui, Add, Checkbox, x126 y402 w50 h30 vv_die[3], Gui, Add, Checkbox, x186 y402 w50 h30 vv_die[4], Gui, Add, Checkbox, x246 y402 w50 h30 vv_die[5], Gui, Font, S8, Gui, Add, Text, x6 y317 w190 h20 vt_bonus, Gui, Font, s1, Courier ; Einser Wuerfel Gui, Add, Button, disabled x46 y17 w30 h30, Gui, Add, Text, x56 y25 w8 h9,* Gui, Add, Button, disabled x86 y17 w30 h30, Gui, Add, Text, x96 y25 w8 h9,* ; Zweier Wuerfel Gui, Add, Button, disabled x46 y57 w30 h30, Gui, Add, Text, x48 y58 w8 h9,* Gui, Add, Text, x64 y73 w8 h9,* Gui, Add, Button, disabled x86 y57 w30 h30, Gui, Add, Text, x88 y58 w8 h9,* Gui, Add, Text, x104 y73 w8 h9,* ; Dreier Wuerfel Gui, Add, Button, disabled x46 y97 w30 h30, Gui, Add, Text, x48 y98 w8 h9,* Gui, Add, Text, x56 y105 w8 h9,* Gui, Add, Text, x64 y113 w8 h9,* Gui, Add, Button, disabled x86 y97 w30 h30, Gui, Add, Text, x88 y98 w8 h9,* Gui, Add, Text, x96 y105 w8 h9,* Gui, Add, Text, x104 y113 w8 h9,* ; Vierer Wuerfel Gui, Add, Button, disabled x46 y137 w30 h30, Gui, Add, Text, x48 y138 w8 h9,* Gui, Add, Text, x64 y138 w8 h9,* Gui, Add, Text, x48 y153 w8 h9,* Gui, Add, Text, x64 y153 w8 h9,* Gui, Add, Button, disabled x86 y137 w30 h30, Gui, Add, Text, x88 y138 w8 h9,* Gui, Add, Text, x104 y138 w8 h9,* Gui, Add, Text, x88 y153 w8 h9,* Gui, Add, Text, x104 y153 w8 h9,* ; Fuenfer Wuerfel Gui, Add, Button, disabled x46 y177 w30 h30, Gui, Add, Text, x48 y178 w8 h9,* Gui, Add, Text, x64 y178 w8 h9,* Gui, Add, Text, x56 y185 w8 h9,* Gui, Add, Text, x48 y193 w8 h9,* Gui, Add, Text, x64 y193 w8 h9,* Gui, Add, Button, disabled x86 y177 w30 h30, Gui, Add, Text, x88 y178 w8 h9,* Gui, Add, Text, x104 y178 w8 h9,* Gui, Add, Text, x96 y185 w8 h9,* Gui, Add, Text, x88 y193 w8 h9,* Gui, Add, Text, x104 y193 w8 h9,* ; Sechser Wuerfel Gui, Add, Button, disabled x46 y217 w30 h30, Gui, Add, Text, x48 y218 w8 h9,* Gui, Add, Text, x56 y218 w8 h9,* Gui, Add, Text, x64 y218 w8 h9,* Gui, Add, Text, x48 y233 w8 h9,* Gui, Add, Text, x56 y233 w8 h9,* Gui, Add, Text, x64 y233 w8 h9,* Gui, Add, Button, disabled x86 y217 w30 h30, Gui, Add, Text, x88 y218 w8 h9,* Gui, Add, Text, x96 y218 w8 h9,* Gui, Add, Text, x104 y218 w8 h9,* Gui, Add, Text, x88 y233 w8 h9,* Gui, Add, Text, x96 y233 w8 h9,* Gui, Add, Text, x104 y233 w8 h9,* ; Font zurücksetzen / reset font Gui, Font ; Sprache initialisieren / Initialize language v_Language := 0 ; 0 = German, 1 = English Gosub, Sub_SwitchLanguage Gui, Show, Center h437 w438, Yatzee ; Varaible initialisieren / initalize variables Gosub, Sub_Initialize Return ; Programm beenden / exit program GuiClose: ExitApp Sub_Initialize: v_Round := 0 v_Sum1 := 0 v_Bonus := 0 v_SumLeftPart := 0 v_SumRightPart := 0 v_FinalSum := 0 v_ones = 0 v_twos = 0 v_threes = 0 v_fours = 0 v_fives = 0 v_sixs = 0 v_ThreeOK = 0 v_FourOK = 0 v_FullHouse = 0 v_LittleStreet = 0 v_BigStreet = 0 v_Yatzee = 0 v_Chance = 0 ; Schalter aktivieren / enable buttons GuiControl, Enable, v_Ones GuiControl, Enable, v_Twos GuiControl, Enable, v_Threes GuiControl, Enable, v_Fours GuiControl, Enable, v_Fives GuiControl, Enable, v_Sixs GuiControl, Enable, v_ThreeOK GuiControl, Enable, v_FourOK GuiControl, Enable, v_FullHouse GuiControl, Enable, v_LittleStreet GuiControl, Enable, v_BigStreet GuiControl, Enable, v_Yatzee GuiControl, Enable, v_Chance Gosub, Sub_ResetDice Gosub, Sub_Refresh Return Sub_Refresh: ; Summe der Würfelwerte berechnen / calculate dice sum v_Sum1 := v_Ones + v_Twos + v_Threes + v_Fours + v_Fives + v_Sixs ; Bouns prüfen / check bonus If v_Sum1 >= 63 v_Bonus := 35 v_SumLeftPart := v_Sum1 + v_Bonus v_SumRightPart := v_ThreeOK + v_FourOK + v_FullHouse + v_LittleStreet + v_BigStreet + v_Yatzee + v_Chance v_FinalSum := v_SumLeftPart + v_SumRightPart ; Summe und Bonus aktualisieren / refresh sum and bonus GuiControl,, v_Sum1, %v_Sum1% GuiControl,, v_Bonus, %v_Bonus% GuiControl,, v_SumLeftPart, %v_SumLeftPart% GuiControl,, v_SumRightPart, %v_SumRightPart% GuiControl,, v_FinalSum, %v_FinalSum% ; Würfelwerte aktualiseren / refresh dice values GuiControl,, v_ones, %v_ones% GuiControl,, v_twos, %v_twos% GuiControl,, v_threes, %v_threes% GuiControl,, v_fours, %v_fours% GuiControl,, v_fives, %v_fives% GuiControl,, v_sixs, %v_sixs% ; rechten Teil aktualisieren / refresh right part GuiControl,, v_ThreeOK, %v_ThreeOK% GuiControl,, v_FourOK, %v_FourOK% GuiControl,, v_FullHouse, %v_FullHouse% GuiControl,, v_LittleStreet, %v_LittleStreet% GuiControl,, v_BigStreet, %v_BigStreet% GuiControl,, v_Yatzee, %v_Yatzee% GuiControl,, v_Chance, %v_Chance% ; Würfelwerte aktualiseren / refresh dice rolls Loop, 5 { __die := v_die[%A_Index%] GuiControl,, v_die[%A_Index%], %__die%`n } Return Sub_SwitchLanguage: v_Language := 1 - v_Language if v_Language = 0 { ; German GuiControl,, t_One1, 1er GuiControl,, t_One2, nur Einser zählen GuiControl,, t_Two1, 2er GuiControl,, t_Two2, nur Zweier zählen GuiControl,, t_Three1, 3er GuiControl,, t_Three2, nur Dreier zählen GuiControl,, t_Four1, 4er GuiControl,, t_Four2, nur Vierer zählen GuiControl,, t_Five1, 5er GuiControl,, t_Five2, nur Fünfer zählen GuiControl,, t_Six1, 6er GuiControl,, t_Six2, nur Sechser zählen GuiControl,, t_Sum1, Zwischensumme GuiControl,, t_SumLeft, Summe linker Teil GuiControl,, t_ThreeOK, Dreierpasch GuiControl,, t_FourOK, Viererpasch GuiControl,, t_FullHouse, Full House GuiControl,, t_LittleStreet, Kleine Strasse GuiControl,, t_BigStreet, Grosse Strasse GuiControl,, t_Yatzee, Yatzee GuiControl,, t_Chance, Chance GuiControl,, t_SumRightPart, Summe rechter Teil GuiControl,, t_FinalSum, Gesamtsumme GuiControl,, t_Dice, Würfel: GuiControl,, t_RollDice, Würfeln GuiControl,, t_bonus, Bonus (35)`, falls Zwischensumme >= 63 } else { ; English GuiControl,, t_One1, 1's GuiControl,, t_One2, only One's count GuiControl,, t_Two1, 2's GuiControl,, t_Two2, only Two's count GuiControl,, t_Three1, 3's GuiControl,, t_Three2, only Three's count GuiControl,, t_Four1, 4's GuiControl,, t_Four2, only Four's count GuiControl,, t_Five1, 5's GuiControl,, t_Five2, only Five's count GuiControl,, t_Six1, 6's GuiControl,, t_Six2, only Six's count GuiControl,, t_Sum1, partial sum GuiControl,, t_SumLeft, Sum of left part GuiControl,, t_ThreeOK, Three of a kind GuiControl,, t_FourOK, Four of a kind GuiControl,, t_FullHouse, Full House GuiControl,, t_LittleStreet, Litte street GuiControl,, t_BigStreet, Big street GuiControl,, t_Yatzee, Yatzee GuiControl,, t_Chance, Chance GuiControl,, t_SumRightPart, Sum of right part GuiControl,, t_FinalSum, Final sum GuiControl,, t_Dice, Dice: GuiControl,, t_RollDice, Roll dice GuiControl,, t_bonus, Bonus (35) if partitial sum >= 63 } Return Sub_RollDice: v_RollCount += 1 Loop, 5 { __index := A_Index GuiControlGet, __state,, v_die[%__index%] If __state = 0 Random, v_die[%__index%], 1 ,6 } Gosub, Sub_Refresh ; nur drei mal würfeln / just roll three times If v_RollCount = 3 GuiControl, Disable, t_RollDice Return Sub_ResetDice: ; Haken bei den Würfelwerten entfernen / uncheck dice Loop, 5 { __index := %A_Index% GuiControl,, v_die[%A_Index%], 0 GuiControl,, v_die[%A_Index%], `n } v_RollCount := 0 ; Würfelschalter aktivieren / activate roll dice button GuiControl, Enable, t_RollDice Gosub, Sub_RollDice Gosub, Sub_Round Return ; Ein Spiel geht über 12 Runden. ; A game has 13 turns. Sub_Round: v_Round += 1 If v_Round = 14 { ; Spiel beendet / game over GuiControl, Disable, t_RollDice If v_Language = 0 { MsgBox, Spiel beendet. Du hast %v_FinalSum% Punkte erreicht. } Else { MsgBox, Game over. You got %v_FinalSum% points. } } Return Sub_Ones: v_ones := 0 Loop, 5 { If v_die[%A_Index%] = 1 v_ones += 1 } GuiControl, Disable, v_ones GuiControl,, v_die[1], %v_ones%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Twos: v_twos := 0 Loop, 5 { If v_die[%A_Index%] = 2 v_twos += 2 } GuiControl, Disable, v_twos GuiControl,, v_die[2], %v_twos%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Threes: v_threes := 0 Loop, 5 { If v_die[%A_Index%] = 3 v_threes += 3 } GuiControl, Disable, v_threes GuiControl,, v_die[3], %v_threes%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Fours: v_fours := 0 Loop, 5 { If v_die[%A_Index%] = 4 v_fours += 4 } GuiControl, Disable, v_fours GuiControl,, v_die[4], %v_fours%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Fives: v_fives := 0 Loop, 5 { If v_die[%A_Index%] = 5 v_fives += 5 } GuiControl, Disable, v_fives GuiControl,, v_die[5], %v_fives%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Sixs: v_sixs := 0 Loop, 5 { If v_die[%A_Index%] = 6 v_sixs += 6 } GuiControl, Disable, v_sixs GuiControl,, v_die[6], %v_sixs%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_ThreeOK: v_ThreeOK := 0 __Sum := 0 Loop, 6 __count[%A_Index%] := 0 Loop, 5 { __die := v_die[%A_Index%] __sum += __die __count[%__die%] += 1 } Loop, 6 If __count[%A_Index%] >= 3 { v_ThreeOK := __sum Break } GuiControl, Disable, v_ThreeOK GuiControl,, v_ThreeOK, %v_ThreeOK%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_FourOK: v_FourOK := 0 __Sum := 0 Loop, 6 __count[%A_Index%] := 0 Loop, 5 { __die := v_die[%A_Index%] __sum += __die __count[%__die%] += 1 } Loop, 6 If __count[%A_Index%] >= 4 { v_FourOK := __sum Break } GuiControl, Disable, v_FourOK GuiControl,, v_ThreeOK, %v_FourOK%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return ; Full House: ; zwei gleiche und drei andere gleiche, aber keine fünf gleiche! ; two of a kind and three of an other kind, but not five of a kind! Sub_FullHouse: v_FullHouse := 0 __foundTwo := 0 __foundThree := 0 Loop, 6 __count[%A_Index%] := 0 Loop, 5 { __die := v_die[%A_Index%] __count[%__die%] += 1 } Loop, 6 If __count[%A_Index%] = 2 __foundTwo := 1 Else If __count[%A_Index%] = 3 __foundThree := 1 If (__foundTwo = 1 && __foundThree = 1) v_FullHouse := 25 GuiControl, Disable, v_FullHouse GuiControl,, v_FullHouse, %v_FullHouse%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return ; Kleine Strasse / Litte Street: ; 1 2 3 4 oder / or 2 3 4 5 oder / or 3 4 5 6 Sub_LittleStreet: v_LittleStreet := 0 Loop, 6 __count[%A_Index%] := 0 Loop, 5 { __die := v_die[%A_Index%] __count[%__die%] += 1 } If __count[3] >= 1 If __count[4] >= 1 { If __count[2] >= 1 { If __count[1] >= 1 v_LittleStreet := 30 If __count[5] >= 1 v_LittleStreet := 30 } If __count[5] >= 1 If __count[6] >= 1 v_LittleStreet := 30 } GuiControl, Disable, v_LittleStreet GuiControl,, v_LittleStreet, %v_LittleStreet%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return ; Grosse Strasse / Big Street: ; 1 2 3 4 5 oder / or 2 3 4 5 6 Sub_BigStreet: v_BigStreet := 0 Loop, 6 __count[%A_Index%] := 0 Loop, 5 { __die := v_die[%A_Index%] __count[%__die%] += 1 } If __count[2] = 1 If __count[3] = 1 If __count[4] = 1 If __count[5] = 1 If (__count[1] = 1 OR __count[6] = 1) v_BigStreet := 40 GuiControl, Disable, v_BigStreet GuiControl,, v_BigStreet, %v_BigStreet%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Yatzee: v_Yatzee := 0 Loop, 6 __count[%A_Index%] := 0 Loop, 5 { __die := v_die[%A_Index%] __count[%__die%] += 1 } Loop, 6 If __count[%A_Index%] = 5 { v_Yatzee := 50 Break } GuiControl, Disable, v_Yatzee GuiControl,, v_Yatzee, %v_Yatzee%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return Sub_Chance: v_Chance := 0 Loop, 5 v_Chance += v_die[%A_Index%] GuiControl, Disable, v_Chance GuiControl,, v_Chance, %v_Chance%`n Gosub, Sub_Refresh Gosub, Sub_ResetDice Return
Have fun...
NiWi.