XKahn Posted August 27, 2010 Posted August 27, 2010 This is a simple game, an economic simulation. I will keep posting more in here so I don't clutter up the forum. expandcollapse popup#include <GUIListBox.au3> ;Kingdom also known as Hammurabi, Dukedom, King, Santa Paravia en Fiumaccio, Dynasty, Manor, etc.. ;This BASIC game dates way back to the late 1970's or early 1980's and you can find the BASIC code online. ;This game inspired games like Civilization. It might not seem like much, but it should help you learn to ;use some of the simple features of AutoIt3. ;Starting Global variables $Death_Toll = 0 $Percent = 0 $Year = 0 $Population = 100 $Silos = 2800 $Harvest = 3000 $Rats = $Harvest - $Silos $Yield = 3 $Acres = 1000 $Births = 5 $Q = 1 $Deaths = 0 $Food = 0 $Idle = 10 $Crop = 1000 ;Status Screen GUICreate("Kingdom", 600, 300, 10, 10) $hListBox = GUICtrlCreateList("", 5, 5, 590, 290, 0x00200000) GUICtrlSetFont (-1, 12) _GUICtrlListBox_AddString($hListBox, "Sire, it is the year " & $Year & " of your reign.") _GUICtrlListBox_AddString($hListBox, "There was " & $Deaths & " deaths from starvation") _GUICtrlListBox_AddString($hListBox, "and I am glad to report " & $Births & " births in the kingdom.") _GUICtrlListBox_AddString($hListBox, "") _GUICtrlListBox_AddString($hListBox, "The population is now " & $Population & " in the kingdom.") _GUICtrlListBox_AddString($hListBox, "The kingdom owns " & $Acres & " acres of land.") _GUICtrlListBox_AddString($hListBox, "Your people harvested " & $Yield & " bushels per acre,") _GUICtrlListBox_AddString($hListBox, "the vermin ate " & $Rats & " bushels.") _GUICtrlListBox_AddString($hListBox, "The kingdom has " & $Silos & " bushels in the silos.") GUISetState() ;Main Loop $msg = GUIGetMsg() While $Year < 11 and $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Buy_Land () Feed_People () Plant_Crops () Update_Status () WEnd Final_Stats () ;Final Loop $msg = GUIGetMsg() While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() WEnd Func Update_Status () $Yield = Random (2,6,1) $Harvest = $Crop * $Yield $Rats = 0 $N = Random (1,5,1) ;Rats eat 20 to 25% of Food or none at all IF $N > 3 THEN $Rats = INT ($Silos/$N) EndIf $Silos -= $Rats $Silos += $Harvest ;Births are from 2 idle subjects $Births = Int($Idle/2) ;Subject need 20 Food $N=INT($Food/20) IF $Population < $N THEN $Deaths = 0 Else $Deaths = $Population - $N ;Over 45% Starved = Revolution! IF $Deaths > $Population * 0.45 THEN _GUICtrlListBox_AddString($hListBox, "You starved " & $Deaths & " of your people in 1 year!") $Crop = -1 EndIf $Population = $N $Death_Toll += $Deaths $Percent = Int(($Death_Toll / $Year *10))*0.1 EndIf ;Next Year $Year += 1 _GUICtrlListBox_ReplaceString ($hListBox, 0, "Sire, it is the year " & $Year & " of your reign.") _GUICtrlListBox_ReplaceString ($hListBox, 1, "There was " & $Deaths & " deaths from starvation") _GUICtrlListBox_ReplaceString ($hListBox, 2, "and I am glad to report " & $Births & " births in the kingdom.") ;Add the new births and check for plague $Population += $Births Plague () _GUICtrlListBox_ReplaceString ($hListBox, 4, "The population is now " & $Population & " in the kingdom.") _GUICtrlListBox_ReplaceString ($hListBox, 5, "The kingdom owns " & $Acres & " acres of land.") _GUICtrlListBox_ReplaceString ($hListBox, 6, "Your people harvested " & $Yield & " bushels per acre,") _GUICtrlListBox_ReplaceString ($hListBox, 7, "the vermin ate " & $Rats & " bushels.") _GUICtrlListBox_ReplaceString ($hListBox, 8, "The kingdom has " & $Silos & " bushels in the silos.") ;Revoultion Flag to end the game If $Crop = -1 Then $Year = 12 EndIf EndFunc Func Plague () _GUICtrlListBox_ReplaceString ($hListBox, 3, "") ;15% chance of plague between 51 and 75% of total population dies. If Random (1,100,1) < 16 Then $Q = Int($Population * 0.51) $N = Int($Population * 0.75) $Population -= Random ($Q,$N,1) _GUICtrlListBox_ReplaceString ($hListBox, 3, "The horrible plague has kill over half the people in the kingdom.") EndIf EndFunc Func Buy_Land () $N = Random (17,27,1) $I = 0 While $I = 0 $Q = InputBox ("BUY LAND","Land is trading at " & $N & " bushels per acre." & @CRLF & "How many acres do you buy?",0) If $Q <= 0 Then $Q = 0 $I = 1 Sell_Land ($N) Else If $N * $Q <= $Silos Then $Acres += $Q $Silos -= ($Q * $N) $I = 1 EndIf EndIf WEnd EndFunc Func Sell_Land ($N) $I = 0 While $I = 0 $Q = InputBox ("SELL LAND","Land is trading at " & $N & " bushels per acre." & @CRLF & "How many acres do you sell?",0) If $Q < 0 Then $Q = 0 $I = 1 Else If $Q <= $Acres Then $Acres -= $Q $Silos += ($Q * $N) $I = 1 EndIf EndIf WEnd EndFunc Func Feed_People () $I = 0 While $I = 0 $Q = InputBox ("You have " & $Silos & " bushels.", "Each person eats 20 bushels per year." & @CRLF & "How much do you distribute for food?",0) If $Q < 0 Then $Food = 0 $I = 1 Else If $Q <= $Silos Then $Food = $Q $Silos -= $Q $I = 1 EndIf EndIf WEnd EndFunc Func Plant_Crops () $I = 0 $N = $Population*10 If $Acres < $N Then $N = $Acres EndIf If ($Silos*2) < $N Then $N = $Silos*2 EndIf While $I = 0 $Q = InputBox ("You have " & $Silos & " bushels.", "You can plant up to " & $N & " acres." & @CRLF & "How many acres do you plant?",0) If $Q < 0 Then $Crop = 0 $I = 1 Else If $Q <= $N Then $Crop = $Q ;People not working $Idle = $Population - Int($Q/10) If $Idle < 0 Then $Idle = 0 EndIf $Silos -= Int($Q*0.5) $I = 1 EndIf EndIf WEnd EndFunc Func Final_Stats () If $Year < 12 Then _GUICtrlListBox_AddString($hListBox, "In the last 10 years " & $Percent & "% of your people") _GUICtrlListBox_AddString($hListBox, "died per year from starvation. A total of " & $Death_Toll) _GUICtrlListBox_AddString($hListBox, "people died.") $I = Int(($Acres / $Population)*10)*0.1 _GUICtrlListBox_AddString($hListBox, "You started with 10 acres per person and ended with") _GUICtrlListBox_AddString($hListBox, $I & " acres per person.") Else ;Lost Game worst performance rating $Percent = 100.0 EndIf $N = "History recorded your skills above all others." $Q = "Your subjects morned your death and your birth is a national holiday." IF $Percent > 3.0 or $I < 10.0 THEN $N = "Your reign was a footnote in history." $Q = "People said they might write a poem about you... maybe someday." EndIf IF $Percent > 10.0 or $I < 9.0 THEN $N = "Your reign was recorded in history, as the poorest since" $Q = "Nero set fire to Rome." EndIf IF $Percent > 33.0 or $I < 7.0 THEN $N = "Due to your poor performance as leader, the people drag" $Q = "you from the castle and burn you at the stake." EndIf _GUICtrlListBox_AddString($hListBox, "") _GUICtrlListBox_AddString($hListBox, $N) _GUICtrlListBox_AddString($hListBox, $Q) $Year = 11 EndFunc Just copy and paste to your editor. Enjoy!
FuryCell Posted August 27, 2010 Posted August 27, 2010 Very cool and nostalgic. Reminds me of some of the text based games I downloaded for my 386 back when I was just learning computers. BTW,I was burned at the stake the first time. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
XKahn Posted August 28, 2010 Author Posted August 28, 2010 Very cool and nostalgic. Reminds me of some of the text based games I downloaded for my 386 back when I was just learning computers. BTW,I was burned at the stake the first time.Yes, so was I. My son found the trick is keeping those peons busy working not making babies. A plague helps a lot because it is not counted against you (act of God). Like I said something simple that could be expanded if one wants. My son asked if I was going to add graphics. I told him I would make something more "graphic" for my next script and asked him for a suggestion. He said a card trading game, so I will give that one a go. I will have to make up some cards.Here is the link to more of those BASIC game codes.
FuryCell Posted August 28, 2010 Posted August 28, 2010 Yes, so was I. My son found the trick is keeping those peons busy working not making babies. A plague helps a lot because it is not counted against you (act of God). Like I said something simple that could be expanded if one wants. My son asked if I was going to add graphics. I told him I would make something more "graphic" for my next script and asked him for a suggestion. He said a card trading game, so I will give that one a go. I will have to make up some cards.Here is the link to more of those BASIC game codes.Thanks for the link. Looks like some nice practice and fun converting to au3. Now I remeber why I had games like that on the 386. I was downloading quickbasic code. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
XKahn Posted September 2, 2010 Author Posted September 2, 2010 (edited) Binaries and supporting files for this script can be downloaded here.OK my son says this is tough to beat and also suggested I add sounds for the different cards. However I am already burnt making the images for the cards. So here is the full source for GTCARD it is also included with the download above. Enjoy!expandcollapse popup#include <Array.au3> #include <GuiConstantsEx.au3> #include <Sound.au3> #comments-start This script is public domain for you to use and learn from as you see fit. The orginal script was uploaded on 9-1-2010 in the public forum for AutoIt3 scripts: http://www.autoitscript.com/forum/ by user XKahn. This script has been compiled and the original binaries can be found at: www.filefront.com/user/xkahn This is a generic "Trading Card Game" in the same venue as Magic the Gathering or others. If you make changes to this script please redistribute with additional comments so other may learn from you as well. #comments-end ;Global variables needed for program Global $hp[2] Global $str[2] Global $int[2] Global $wis[2] Global $dex[2] Global $dmg[2] Global $hand[8] Global $cava[8] Global $deck1[80] Global $deck2[80] Global $ps1 Global $ps2 Global $phase_stat Global $d1 Global $d2 ;get the screen size $dtx = @DesktopWidth $dty = @DesktopHeight $dth = ($dtx / 2) -1 $dtv = ($dty / 2) -1 $card1 = 8 $card2 = 8 $phase = 0 $hp[0] = 100 $str[0] = 0 $int[0] = 0 $wis[0] = 0 $dex[0] = 0 $dmg[0] = 0 $hp[1] = 100 $str[1] = 0 $int[1] = 0 $wis[1] = 0 $dex[1] = 0 $dmg[1] = 0 GuiCreate("CARD ARENA",800,600,0,0,0x01000000) GUISetBkColor(0x000000) Display_stats () If FileExists ("deck.ini") Then Load_Decks () Else MsgBox (0,"BIG STINKING ERROR","You MUST have a deck.ini file"&@CRLF&"in the working folder"&@CRLF&"for this to function!") Exit EndIf Display_Helps () ;Set up Card Areas $hand[0] = GUICtrlCreatePic("cards\backcard.jpg", 10, $dty - 500, 150, 200) $hand[1] = GUICtrlCreatePic("cards\backcard.jpg", 210, $dty - 500, 150, 200) $hand[2] = GUICtrlCreatePic("cards\backcard.jpg", 410, $dty- 500, 150, 200) $hand[3] = GUICtrlCreatePic("cards\backcard.jpg", 610, $dty - 500, 150, 200) $hand[4] = GUICtrlCreatePic("cards\backcard.jpg", 10, $dty - 250, 150, 200) $hand[5] = GUICtrlCreatePic("cards\backcard.jpg", 210, $dty - 250, 150, 200) $hand[6] = GUICtrlCreatePic("cards\backcard.jpg", 410, $dty - 250, 150, 200) $hand[7] = GUICtrlCreatePic("cards\backcard.jpg", 610, $dty - 250, 150, 200) $drawn = GUICtrlCreatePic("cards\backcard.jpg", 810, $dty - 350, 150, 200) $discard = GUICtrlCreatePic("cards\backcard.jpg", 810, $dty - 600, 150, 200) $played = "" Deal_Cards () Update_Phase ("DRAW PHASE") Refresh_Stats () ;Optional background music, some sound effects would be nice too. $sound = "off" If FileExists ("Music.mp3") Then $sound = _SoundOpen ("Music.mp3") EndIf GuiSetState() $msg = GUIGetMsg() While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select ;Play/Discard Phase = 1 Case $msg = $drawn and $phase = 1 $played = $deck1[$card1] GUICtrlSetImage ($drawn,"cards/backcard.jpg") $card1 += 1 If $card1 = 80 Then $card1 = 8 EndIf Sleep (250) $phase = 2 Update_Phase ("PLAY PHASE") ;Draw Phase = 0 Case $msg = $drawn and $phase = 0 $i = StringSplit ($deck1[$card1],",") GUICtrlSetImage ($drawn,"cards/"&$i[8]) $phase = 1 Update_Phase ("PLAY PHASE") Sleep (250) Case $msg = $hand[0] and $phase = 1 Play_Card (0) Case $msg = $hand[1] and $phase = 1 Play_Card (1) Case $msg = $hand[2] and $phase = 1 Play_Card (2) Case $msg = $hand[3] and $phase = 1 Play_Card (3) Case $msg = $hand[4] and $phase = 1 Play_Card (4) Case $msg = $hand[5] and $phase = 1 Play_Card (5) Case $msg = $hand[6] and $phase = 1 Play_Card (6) Case $msg = $hand[7] and $phase = 1 Play_Card (7) ;What Effects if any Case $phase = 2 Card_Effect () EndSelect ;This routine will loop an MP3 as background music if the file is present. If $sound <> "off" Then If _SoundStatus($sound) = "stopped" Then _SoundPlay($sound) Sleep (1500) EndIf EndIf WEnd ;Read setup.ini file Func Load_Decks () $db = GUICtrlCreateButton ("OK",$dth - 150, $dtv + 155,300,30) $dc = GUICtrlCreateList("", $dth - 150, $dtv - 150, 300, 300) $d1 = "" $d2 = "" $setup = FileOpen ("deck.ini",0) $line = FileReadLine($setup) While Not @error = -1 if StringInStr($line, ":") <> 0 Then $n = StringInStr($line, ":") $d1 &= StringTrimLeft($line,$n) & "|" EndIf $line = FileReadLine($setup) WEnd FileClose($setup) $d1 = StringTrimRight ($d1,1) ;Choose a Random deck for opponent $m = StringSplit ($d1,"|") $d2 = $m[Random(1,$m[0],1)] If $m[0] = 0 Then MsgBox (0,"STINKY ERROR #2", "There are no decks found in your deck.ini file.") Exit EndIf ;Get Player deck name GuiCtrlSetData($dc, $d1 ,$m[1]) GuiSetState() $d1 = $m[1] $mesg = 0 While $mesg <> $GUI_EVENT_CLOSE $mesg = GUIGetMsg() Select Case $mesg = $dc $d1 = GUICtrlRead($dc) Case $mesg = $db ExitLoop EndSelect WEnd Sleep (250) GUICtrlDelete ($db) GUICtrlDelete ($dc) ;Load the 2 decks into 2 arrays. Reopens the deck.ini seeking deck information. ;If the deck is not 80 cards it will grab from the next deck or get stuck in a loop. ;If the deck is over 80 cards it will ignore extras at the end. $setup = FileOpen ("deck.ini",0) $line = FileReadLine($setup) While Not @error = -1 if StringInStr($line, ":" & $d1) <> 0 Then $i = 0 Do $line = FileReadLine($setup) $n = StringInStr($line, ",") $v = StringLeft($line, $n-1) For $j = 1 to $v $deck1[$i] = $line $i += 1 Next Until $i = 80 EndIf $line = FileReadLine($setup) WEnd FileClose($setup) $setup = FileOpen ("deck.ini",0) $line = FileReadLine($setup) While Not @error = -1 if StringInStr($line, ":" & $d2) <> 0 Then $i = 0 Do $line = FileReadLine($setup) $n = StringInStr($line, ",") $v = StringLeft($line, $n-1) For $j = 1 to $v $deck2[$i] = $line $i += 1 Next Until $i = 80 EndIf $line = FileReadLine($setup) WEnd FileClose($setup) EndFunc Func Play_Card ($q) $played = $deck1[$q] $deck1[$q] = $deck1[$card1] $i = StringSplit ($deck1[$card1],",") GUICtrlSetImage ($hand[$q],"cards/"&$i[8]) GUICtrlSetImage ($drawn,"cards/backcard.jpg") $deck1[$card1] = $played $card1 += 1 If $card1 = 80 Then Reshuffle () $card1 = 8 EndIf Sleep (250) $phase = 2 EndFunc Func Card_Effect () $i = StringSplit ($played,",") $ts = 0 Select Case $i[3] = "E" If $i[2] <= $str[0] Then $ts = 1 EndIf Case $i[3] = "W" If $i[2] <= $int[0] Then $ts = 1 EndIf Case $i[3] = "A" If $i[2] <= $dex[0] Then $ts = 1 EndIf Case $i[3] = "F" If $i[2] <= $wis[0] Then $ts = 1 EndIf EndSelect If $ts > 0 Then If $i[5] = "STR" Then $str[0] = Add_Check ($str[0],$i[4]) EndIf If $i[5] = "INT" Then $int[0] = Add_Check ($int[0],$i[4]) EndIf If $i[5] = "WIS" Then $wis[0] = Add_Check ($wis[0],$i[4]) EndIf If $i[5] = "DEX" Then $dex[0] = Add_Check ($dex[0],$i[4]) EndIf If $i[5] = "HP" Then $hp[0] = Add_Check ($hp[0],$i[4]) If $hp[0] > 100 Then $hp[0] = 100 EndIf EndIf If $i[5] = "DM" Then $dmg[0] += $i[4] EndIf If $i[7] = "STR" Then $str[1] = Add_Check ($str[1],$i[6]) EndIf If $i[7] = "INT" Then $int[1] = Add_Check ($int[1],$i[6]) EndIf If $i[7] = "WIS" Then $wis[1] = Add_Check ($wis[1],$i[6]) EndIf If $i[7] = "DEX" Then $dex[1] = Add_Check ($dex[1],$i[6]) EndIf If $i[7] = "HP" Then $i[6] -= $dmg[0] If $i[6] > 0 Then $i[6] = 0 EndIf $dmg[0] = 0 $hp[1] += $i[6] If $hp[1] < 0 Then $hp[1] = 0 Win_Game () EndIf EndIf If $i[7] = "DM" Then $dmg[1] += $i[6] EndIf EndIf Refresh_Stats () $phase = 3 Update_Phase ("PLAYER 2") Player_2 () EndFunc ;Certain values never get reduce less than zero Func Add_Check ($i,$j) $i += $j If $i < 0 Then $i = 0 EndIf Return $i EndFunc ;Reshuffle the deck Func Reshuffle () For $i = 8 to 79 $j = Random (8,79,1) $a = $deck1[$i] $deck1[$i] = $deck1[$j] $deck1[$j] = $a Next EndFunc ;Shuffle and deal hands Func Deal_Cards () For $i = 0 to 79 $j = Random (0,79,1) $a = $deck1[$i] $deck1[$i] = $deck1[$j] $deck1[$j] = $a $k = Random (0,79,1) $a = $deck2[$i] $deck2[$i] = $deck2[$k] $deck2[$k] = $a Next $a = StringSplit ($deck1[0],",") GUICtrlSetImage ($hand[0],"cards/"&$a[8]) $a = StringSplit ($deck1[1],",") GUICtrlSetImage ($hand[1],"cards/"&$a[8]) $a = StringSplit ($deck1[2],",") GUICtrlSetImage ($hand[2],"cards/"&$a[8]) $a = StringSplit ($deck1[3],",") GUICtrlSetImage ($hand[3],"cards/"&$a[8]) $a = StringSplit ($deck1[4],",") GUICtrlSetImage ($hand[4],"cards/"&$a[8]) $a = StringSplit ($deck1[5],",") GUICtrlSetImage ($hand[5],"cards/"&$a[8]) $a = StringSplit ($deck1[6],",") GUICtrlSetImage ($hand[6],"cards/"&$a[8]) $a = StringSplit ($deck1[7],",") GUICtrlSetImage ($hand[7],"cards/"&$a[8]) EndFunc ;Creates Labels Func Display_stats () $ts = " PLAYER 1: " & @CRLF & " HP: " & $hp[0] & @CRLF & " STR: " & $str[0] & @CRLF & " INT: " & $int[0] & @CRLF & " WIS: " & $wis[0] & @CRLF & " DEX: " & $dex[0] $ps1 = GUICtrlCreateLabel ($ts,10,10,$dth-20,140) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffffff) GUICtrlSetFont (-1, 15,400,0,"Arial") $ts = " PLAYER 2: " & @CRLF & " HP: " & $hp[1] & @CRLF & " STR: " & $str[1] & @CRLF & " INT: " & $int[1] & @CRLF & " WIS: " & $wis[1] & @CRLF & " DEX: " & $dex[1] $ps2 = GUICtrlCreateLabel ($ts ,$dth+1,10,$dth-20,140) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffffff) GUICtrlSetFont (-1, 15,400,0,"Arial") $phase_stat = GUICtrlCreateLabel ("CHOOSE A DECK",810, $dty - 125,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 15,400,0,"Arial Black") EndFunc ;Display Card Helps Func Display_Helps () $cava[0] = GUICtrlCreateLabel ("",10, $dty - 525,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[1] = GUICtrlCreateLabel ("",210, $dty - 525,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[2] = GUICtrlCreateLabel ("",410, $dty - 525,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[3] = GUICtrlCreateLabel ("",610, $dty - 525,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[4] = GUICtrlCreateLabel ("",10, $dty - 275,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[5] = GUICtrlCreateLabel ("",210, $dty - 275,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[6] = GUICtrlCreateLabel ("",410, $dty - 275,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") $cava[7] = GUICtrlCreateLabel ("",610, $dty - 275,200,50) GUICtrlSetBkColor(-1, -2) GUICtrlSetColor(-1, 0xffff00) GUICtrlSetFont (-1, 12,400,0,"Arial Narrow") EndFunc ;Set phase to string Func Update_Phase ($ts) GUICtrlSetData ($phase_stat, $ts) EndFunc Func Refresh_Stats () $ts = " PLAYER 1: "& $d1 & @CRLF & " HP: " & $hp[0] & @CRLF & " STR: " & $str[0] & @CRLF & " INT: " & $int[0] & @CRLF & " WIS: " & $wis[0] & @CRLF & " DEX: " & $dex[0] GUICtrlSetData ($ps1, $ts) $ts = " PLAYER 2: "& $d2 & @CRLF & " HP: " & $hp[1] & @CRLF & " STR: " & $str[1] & @CRLF & " INT: " & $int[1] & @CRLF & " WIS: " & $wis[1] & @CRLF & " DEX: " & $dex[1] GUICtrlSetData ($ps2, $ts) For $n = 0 to 7 $i = StringSplit ($deck1[$n],",") $ts = "Cost:"&$i[2] Select Case $i[3] = "E" $ts &= " STR ("&$i[4]&$i[5]&"/"&$i[6]&$i[7]&")" Case $i[3] = "W" $ts &= " INT ("&$i[4]&$i[5]&"/"&$i[6]&$i[7]&")" Case $i[3] = "A" $ts &= " DEX ("&$i[4]&$i[5]&"/"&$i[6]&$i[7]&")" Case $i[3] = "F" $ts &= " WIS ("&$i[4]&$i[5]&"/"&$i[6]&$i[7]&")" EndSelect GUICtrlSetData ($cava[$n], $ts) Next EndFunc ;Player 2 Turn Func Player_2 () $ts = 0 If $hp < 81 Then For $j = 0 to 8 $i = StringSplit ($deck2[$j],",") Select Case $i[3] = "E" and $i[2] <= $str[1] and $i[5] = "HP" $ts = 1 $k = $j Case $i[3] = "W" and $i[2] <= $int[1] and $i[5] = "HP" $ts = 1 $k = $j Case $i[3] = "A" and $i[2] <= $dex[1] and $i[5] = "HP" $ts = 1 $k = $j Case $i[3] = "F" and $i[2] <= $wis[1] and $i[5] = "HP" $ts = 1 $k = $j EndSelect Next EndIf ;Seek a weapon if cure not found or needed If $ts = 0 Then For $j = 0 to 8 $i = StringSplit ($deck2[$j],",") Select Case $i[3] = "E" and $i[2] <= $str[1] and Abs($i[6]) > 0 $ts = 1 $k = $j Case $i[3] = "W" and $i[2] <= $int[1] and Abs($i[6]) > 0 $ts = 1 $k = $j Case $i[3] = "A" and $i[2] <= $dex[1] and Abs($i[6]) > 0 $ts = 1 $k = $j Case $i[3] = "F" and $i[2] <= $wis[1] and Abs($i[6]) > 0 $ts = 1 $k = $j EndSelect Next EndIf ;Seek defense if no card yet If $ts = 0 Then For $j = 0 to 8 $i = StringSplit ($deck2[$j],",") Select Case $i[3] = "E" and $i[2] <= $str[1] and Abs($i[4]) > 0 $ts = 1 $k = $j Case $i[3] = "W" and $i[2] <= $int[1] and Abs($i[4]) > 0 $ts = 1 $k = $j Case $i[3] = "A" and $i[2] <= $dex[1] and Abs($i[4]) > 0 $ts = 1 $k = $j Case $i[3] = "F" and $i[2] <= $wis[1] and Abs($i[4]) > 0 $ts = 1 $k = $j EndSelect Next EndIf ;Discard or Play If $ts = 0 Then $k = Random (0,8,1) Else $i = StringSplit ($deck2[$k],",") If $i[5] = "STR" Then $str[1] = Add_Check ($str[1],$i[4]) EndIf If $i[5] = "INT" Then $int[1] = Add_Check ($int[1],$i[4]) EndIf If $i[5] = "WIS" Then $wis[1] = Add_Check ($wis[1],$i[4]) EndIf If $i[5] = "DEX" Then $dex[1] = Add_Check ($dex[1],$i[4]) EndIf If $i[5] = "HP" Then $hp[1] = Add_Check ($hp[1],$i[4]) If $hp[1] > 100 Then $hp[1] = 100 EndIf EndIf If $i[5] = "DM" Then $dmg[1] += $i[4] EndIf If $i[7] = "STR" Then $str[0] = Add_Check ($str[0],$i[6]) EndIf If $i[7] = "INT" Then $int[0] = Add_Check ($int[0],$i[6]) EndIf If $i[7] = "WIS" Then $wis[0] = Add_Check ($wis[0],$i[6]) EndIf If $i[7] = "DEX" Then $dex[0] = Add_Check ($dex[0],$i[6]) EndIf If $i[7] = "HP" Then $i[6] -= $dmg[1] If $i[6] > 0 Then $i[6] = 0 EndIf $dmg[1] = 0 $hp[0] += $i[6] If $hp[0] < 0 Then $hp[0] = 0 Lose_Game () EndIf EndIf If $i[7] = "DM" Then $dmg[0] += $i[6] EndIf EndIf $i = StringSplit ($deck2[$k],",") GUICtrlSetImage ($discard,"cards/"&$i[8]) $n = $deck2[$k] $deck2[$k] = $deck2[$card2] $deck2[$card2] = $n $card2 += 1 If $card2 = 79 Then $card2 = 8 EndIf $n = $deck2[8] $deck2[8] = $deck2[$card2] $deck2[$card2] = $n Refresh_Stats () $phase = 0 Update_Phase ("DRAW PHASE") EndFunc Func Win_Game () $ts = " PLAYER 1: "& $d1 & @CRLF & " WON THE MATCH" & @CRLF & " STR: " & $str[0] & @CRLF & " INT: " & $int[0] & @CRLF & " WIS: " & $wis[0] & @CRLF & " DEX: " & $dex[0] GUICtrlSetData ($ps1, $ts) $ts = " PLAYER 2: "& $d2 & @CRLF & " LOST THE MATCH" & @CRLF & " STR: " & $str[1] & @CRLF & " INT: " & $int[1] & @CRLF & " WIS: " & $wis[1] & @CRLF & " DEX: " & $dex[1] GUICtrlSetData ($ps2, $ts) Restart () EndFunc Func Lose_Game () $ts = " PLAYER 1: "& $d1 & @CRLF & " LOST THE MATCH" & @CRLF & " STR: " & $str[0] & @CRLF & " INT: " & $int[0] & @CRLF & " WIS: " & $wis[0] & @CRLF & " DEX: " & $dex[0] GUICtrlSetData ($ps1, $ts) $ts = " PLAYER 2: "& $d2 & @CRLF & " WON THE MATCH" & @CRLF & " STR: " & $str[1] & @CRLF & " INT: " & $int[1] & @CRLF & " WIS: " & $wis[1] & @CRLF & " DEX: " & $dex[1] GUICtrlSetData ($ps2, $ts) Restart () EndFunc Func Restart () $ts = MsgBox (0x24,"","Play again?") If $ts = 6 Then Run ("gtcard.exe") EndIf Sleep (250) Exit EndFuncEDIT:Here is little bit of help how game play works, I assume you can figure this part out by looking at the script.There are 3 decks in the deck.ini file. The program scans the file 3 times. The first scan looks for the colons ":" and pulls any text after that listing those as names.Example; anything typed before is trimmed:THIS is the name of my deck On the second pass it looks for the title you chose and counts in the next 80 cards5,0,E,1,STR,0,0,EARTH.JPGThe program takes the first number as quantity and converts it into 5 cards;$deck1[0] = "5,0,E,1,STR,0,0,EARTH.JPG"$deck1[1] = "5,0,E,1,STR,0,0,EARTH.JPG"$deck1[2] = "5,0,E,1,STR,0,0,EARTH.JPG"$deck1[3] = "5,0,E,1,STR,0,0,EARTH.JPG"$deck1[4] = "5,0,E,1,STR,0,0,EARTH.JPG"I am storing an array of 8 items inside an array. On the second pass the AI deck is read in the same as above.As for game play I kept the rules simple. Elements 4 and 5 of each card array tell what variable is effected by the person playing the card. Elements 6 and 7 of each card array tells how the variable effected on the opponent.Finally the AI wasn't hard to figure out. It checks for any playable health modifying cards if the HP is less than 81 points because health is everything. Then if a playable card has not been found it seeks a playable weapon. If no weapon has been found then it seeks a defensive card. If it has no playable cards one is chosen at random to discard.The HARD part or time consuming issue when making a game like this, is the graphics. I grabbed some images off the internet and ran them through the Gimp. That took me a few days. Another issue to consider is the balance of the decks. For example, you could easily make a deck impossible to beat by adding this card;1,1,F,0,0,-100,HP,NUKEHIM.JPGOr you could make your deck too weak and get your butt kicked. Edited September 2, 2010 by XKahn
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now