Hello to everyone!
I'll post here the code I am currently developing for making easier the creation of new rules (and therefore, solitaires) for XM Solitaire, a freeware solitaire suite collection which allow the users to add their own solitaire games, via XML scripts.
My program/code generates automatically the scripts, based on the rules and card positions selected by the user.
At this moment, it can fully generate the code for the <game> tag, but there are still another 6 tags to completely define a solitaire game with this piece of software.
Code optimizations and suggestions are welcome!
XM Solitaire Official Web: http://petr.lastovicka.sweb.cz/games.html
XM Solitaire Game Rule Editor - v0.0
Spoiler
Code: Select all
Gui, Principal:New, , XM Solitaire Game Rule Editor
Gui, Add, Text, , Name of the game
Gui, Add, Edit, yp-3 xp+95 vNameOfGame
Gui, Add, Text, yp+3 xp+130, Number of decks
Gui, Add, Edit, ReadOnly w40 yp-3 xp+90 vNumberOfDecks
Gui, Add, UpDown, vRange Range1-4, 1
Gui, Add, Text, yp+3 xp+50, Autoplay
Gui, Add, DropDownList, w45 yp-3 xp+50 vAutoplay, Yes||No|
Gui, Add, Text, yp+40 x10, Conditional pairing
;Theses two controls are invisible, unless a rule to pair cards up to a concrete sum is selected
Gui, Add, Edit, Hidden ReadOnly w40 x10 y40 x520 vIntegerSum
Gui, Add, UpDown, Hidden y40 vIntegerSumRange Range2-26, 13
Gui, Add, DropDownList, w105 y40 x100 gChangeExplanation vPair, No condition||[integer]|Same suit|Same rank|Same suit & rank
Gui, Add, Text, w350 yp+3 xp+110 vExplanation, ---> (This game won't require to pair the cards)
Gui, Add, Text, yp+40 x10, Suits required to play
Gui, Add, CheckBox, yp xp+120 vSpadesSuit Checked, Spades
Gui, Add, CheckBox, yp xp+60 vClubsSuit Checked, Clubs
Gui, Add, CheckBox, yp xp+50 vHeartsSuit Checked, Hearts
Gui, Add, CheckBox, yp xp+55 vDiamondsSuit Checked, Diamonds
Gui, Add, Text, yp+40 x10, Card values required for this game
Gui, Add, ListBox, r4 w32 yp-3 xp+170 vRankChoice1 Multi, Aces||2||3||4||
Gui, Add, ListBox, r4 w30 yp xp+33 vRankChoice2 Multi, 5||6||7||8||
Gui, Add, ListBox, r5 w50 yp xp+31 vRankChoice3 Multi, 9||10||Jacks||Queens||Kings||
Gui, Add, Button, yp xp+53 w80 gSelectAll, Select All
Gui, Add, Button, yp+25 xp w80 gSelectNone, Select None
Gui, Add, Button, y440 x10 gGenerateRulesWindow, Generate
Gui, Add, Tab3, y200 x10 w550 h230, Stock|Reserve|Tableau|Waste|Foundation|Cell
; Gui, Tab
Gui, Show, w570 h500
return
ChangeExplanation:
GuiControlGet, PairOptionRead, , Pair
if(PairOptionRead<>"[integer]")
{
; Adapt the size of the text string explanation, and hide integer sum controls
GuiControl, Move, Explanation, w350
GuiControl, Hide, IntegerSum
GuiControl, Hide, IntegerSumRange
if(PairOptionRead="No condition")
{
ExplanationMessage=---> (This game won't require to pair the cards)
}
else if (PairOptionRead="Same suit")
{
ExplanationMessage=---> (This game will require to pair the cards with the same suit/color)
}
else if (PairOptionRead="Same rank")
{
ExplanationMessage=---> (This game will require to pair the cards with the same rank/value)
}
else if (PairOptionRead="Same suit & rank")
{
ExplanationMessage=---> (This game will require to pair the cards with the same color and value)
}
}
else
{
ExplanationMessage=---> This game will require to pair the cards whose sum is equal to
; Adapt the size of the text string explanation, and show integer sum controls
GuiControl, Move, Explanation, w310
GuiControl, Show, IntegerSum
GuiControl, Show, IntegerSumRange
}
GuiControl, Text, Explanation, %ExplanationMessage%
return
SelectAll:
Loop, 4
{
GuiControl, Choose, RankChoice1, %A_Index%
GuiControl, Choose, RankChoice2, %A_Index%
}
Loop, 5
{
GuiControl, Choose, RankChoice3, %A_Index%
}
return
SelectNone:
Gui +LastFound ; Avoids the need to specify WinTitle below.
GuiControl, Choose, RankChoice1, 0 ; Deselect all items
GuiControl, Choose, RankChoice2, 0
GuiControl, Choose, RankChoice3, 0
return
GenerateRulesWindow:
XMLRules:=GenerateRules()
Gui, Generated:New, , Generated Rules
Gui, Generated:Add, Edit, ReadOnly w380 r13 vGeneratedRules, %XMLRules%
Gui, Generated:Show, w400 h200
WinSet, AlwaysOnTop, On, Generated Rules
return
GenerateRules()
{
; <game> tag:
GuiControlGet, NameOfGameRead, , NameOfGame
GuiControlGet, NumberOfDecksRead, , NumberOfDecks
GuiControlGet, AutoplayRead, , Autoplay
if (AutoplayRead="Yes")
AutoplayRead=1
else
AutoplayRead=0
GuiControlGet, PairRead, , Pair
if (PairRead="[integer]")
{
GuiControlGet, IntegerSumRead, , IntegerSum
PairRead:=IntegerSumRead
}
else if (PairRead="No condition")
{
PairRead:=0
}
else if (PairRead="Same suit")
{
PairRead=suit
}
else if (PairRead="Same rank")
{
PairRead=rank
}
else if (PairRead="Same suit & rank")
{
PairRead=rankcolor
}
GuiControlGet, SpadesSuitRead, , SpadesSuit
GuiControlGet, ClubsSuitRead, , ClubsSuit
GuiControlGet, HeartsSuitRead, , HeartsSuit
GuiControlGet, DiamondsSuitRead, , DiamondsSuit
if(SpadesSuitRead=1)
SuitRead.="s"
if(ClubsSuitRead=1)
SuitRead.="c"
if(HeartsSuitRead=1)
SuitRead.="h"
if(DiamondsSuitRead=1)
SuitRead.="d"
GuiControlGet, Rank1Read, , RankChoice1
GuiControlGet, Rank2Read, , RankChoice2
GuiControlGet, Rank3Read, , RankChoice3
RankRead := Rank1Read . "|" . Rank2Read . "|" . Rank3Read
StringReplace, RankRead, RankRead, Aces, a, 1
StringReplace, RankRead, RankRead, Jacks, j, 1
StringReplace, RankRead, RankRead, Queens, q, 1
StringReplace, RankRead, RankRead, Kings, k, 1
StringReplace, RankRead, RankRead, |, , 1
rulesString=<game name="%NameOfGameRead%" decks="%NumberOfDecksRead%" autoplay="%AutoplayRead%" pair="%PairRead%" suit="%SuitRead%" rank="%RankRead%">
rulesString.="`n</game>" ; Same as rulesString = rulesString . "`n</game>"
return, rulesString
}
#IfWinActive Generated Rules
Esc::
GeneratedGuiClose:
Gui, Generated:Destroy
return
#IfWinActive XM Solitaire Game Rule Editor
Esc::
PrincipalGuiClose:
ExitApp