#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\Icons\Island.ico #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include #include ;Some global variables Global $turns = 0, $score = 0, $nItems = 0, $maxturns = 100 Global $temp = "", $vTest = False, $iTest = False Global $torch = False, $qs = True Global $nr = 30 ;initial array size for rooms, directions, objects, locations, etc. Global $n, $v, $v1, $n1, $swim Global $rnum = 1, $lastnum = 1, $iCount = 0 Global $r[$nr], $d[$nr], $id[$nr], $o[$nr], $ol[$nr] ;[Rooms] $r[1] = "You woke up in a daze with a horrible headache, wet and confused. It seems your small fishing boat has" $r[1] = $r[1] & " capsized and you were knocked unconscious. You've washed ashore on a tiny deserted island. You need to" $r[1] = $r[1] & " find a way to enable your rescue by using one and two word commands, verb/noun combinations, such" $r[1] = $r[1] & " as 'get knife', 'examine map', 'inventory', 'score', 'quit', and many other commands. Your movements and" $r[1] = $r[1] & " and actions will tire you quickly, so you must be efficient." & @CRLF & @CRLF & "Your adventure begins now..." & @CRLF & "^02020203" $r[2] = 'You are on the western shore. There is a jungle to the east.^05060403' $r[3] = 'You are treading water just offshore. The current is very strong and pushing you toward the north.^99990299' $r[4] = 'You have entered a dark, misty jungle. You see a dim light to the west.^07089902' $r[5] = 'You see the wreckage of your fishing boat strewn about the beach.^99020703' $r[6] = 'You are at a rocky reef. The sand is very hot beneath your feet.^02990803' $r[7] = 'You are in a small clearing. You hear the call of tropical birds and primates.^99041405' $r[8] = 'You are at the edge of a crystal clear fresh-water lagoon. You can see the shimmering of fish swimming about.^04099906' $r[9] = 'You are on a winding path. It is pretty dark here.^08161110' $r[10] = 'You are on a narrow winding path. It is very dark here.^99150999' $r[11] = 'You are outside the remains of a burned out hut. ^12992109' $r[12] = 'You are outside of a small cave-like tunnel.^13112299' $r[13] = 'You are in a small dark tunnel.^14129999' $r[14] = 'You are outside of a small cave-like tunnel.^99139907' $r[15] = 'You are in a very narrow path.^10991699' $r[16] = 'You are on a winding path.^09179915' $r[17] = 'You are on among a dense garden of giant bamboos.^16991899' $r[18] = 'You are on a rocky eastern shore of the island.^19999917' $r[19] = 'You are at a wide pit at the rock quarry.^99182099' $r[20] = 'You are at the edge of a muddy pit.^21999919' $r[21] = 'You are in ....< QUICK SAND >... and sinking...^99999999' $r[22] = 'You are in a very dark jungle under a thick canopy.^99219999' $r[23] = 'You are near the north end of the island, just south of a small shack.^99229913' $r[24] = 'You are inside a shack at the northern shore. "^99999999' ;re-work the data (rooms, directions you can go) For $i = 1 To UBound($r) - 1 $split = StringInStr($r[$i], "^") $d[$i] = StringMid($r[$i], $split + 1) $r[$i] = StringLeft($r[$i], $split - 1) Next ;[Item Descriptions] initial room #/ description $id[1] = 'a large coconut^coc^07' $id[2] = 'a small sand crab^cra^02' $id[3] = 'sharks circling you^sha^00' $id[4] = 'a small rusty box^box^05' $id[5] = 'a brass key^key^00' $id[6] = 'a parchment scroll^scr^06' $id[7] = 'an bottle of rum^rum^06' $id[8] = 'several gold coins^coi^08' $id[9] = 'a rusty knife^kni^10' $id[10] = 'a map with numbers on it^map^04' $id[11] = 'a grappling hook with a rope attached^hoo^18' $id[12] = 'some scraps of torn clothing^clo^19' $id[13] = 'a book of matches^mat^13' $id[14] = 'an oil-soaked torch^tor^20' $id[15] = 'a satellite phone^pho^00' ;re-work the data (item descriptions, object short name, initial location) For $i = 1 To UBound($id) - 1 $split1 = StringInStr($id[$i], "^", 0, 2) $ol[$i] = StringMid($id[$i], $split1 + 1) $split2 = StringInStr($id[$i], "^", 0, 1) $splen = $split1 - $split2 $o[$i] = StringMid($id[$i], $split2 + 1, $splen - 1) $id[$i] = StringLeft($id[$i], $split2 - 1) Next ;the main screen $Form1 = GUICreate("Stranded", 632, 465, -1, -1) $ChatText = GUICtrlCreateEdit("", 16, 32, 595, 365, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) $ChatInput = GUICtrlCreateInput("", 122, 416, 450, 30) $Label1 = GUICtrlCreateLabel("What now?", 32, 420, 88, 18) GUICtrlSetFont($Label1, 12, 400, 0, "Segoe UI") GUICtrlSetBkColor($Label1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont($ChatInput, 12, 400, 0, "Segoe UI") $Label3 = GUICtrlCreateLabel("Stranded: A Caribbean Odyssey", 190, 6, 430, 24) GUICtrlSetFont(-1, 16, 400, 0, "Tahoma") GUICtrlSetState($ChatInput, $GUI_FOCUS) ; AUTOMATICALLY FOCUSSES ON THE INPUT GUICtrlSetFont(-1, 12, 400, 0, "Segoe UI") GUISetState(@SW_SHOW) ShowLoc() GUICtrlSetFont($ChatText, 12, 400, 0, "Segoe UI") ;Dynamically redimension the arrays For $i = 1 To UBound($r) - 1 If $r[$i] = "" Then $rdim = $i ExitLoop EndIf Next ReDim $r[$rdim] ReDim $d[$rdim] For $i = 1 To UBound($id) - 1 If $id[$i] = "" Then $rdim = $i ExitLoop EndIf Next ReDim $id[$rdim] ReDim $o[$rdim] ReDim $ol[$rdim] Main() Func ProcessVerbs() Select Case $v = "n" $turns = $turns + 1 $rnum = Int(StringLeft($d[$rnum], 2)) ShowLoc() Case $v = "s" $turns = $turns + 1 $rnum = Int(StringMid($d[$rnum], 3, 2)) ShowLoc() Case $v = "e" $turns = $turns + 1 $rnum = Int(StringMid($d[$rnum], 5, 2)) ShowLoc() Case $v = "w" $turns = $turns + 1 $rnum = Int(StringRight($d[$rnum], 2)) ShowLoc() Case $v = "swi" If $rnum = 3 And $n = "sou" Then $rnum = 2 GUICtrlSetData($ChatText, "") _WriteBack("You managed to reach shore. You are exhausted.") $turns = $turns + 10 ShowLoc() EndIf If $rnum = 3 And $n = "" Then _WriteBack("You need to specify the direction you want to swim toward..") GUICtrlSetData($ChatInput, "") EndIf Case StringLeft($v, 2) = "go" Or $v = "ent" ;go _WriteBack("Enter a compass direction (n,s,e,w) to move around...") GUICtrlSetData($ChatInput, "") Case $v = "qui" Or $v = "bye" ;quit _WriteBack("Sorry to see you go..." & @CRLF & "Hit to exit...") Wait() Exit Case $v = "inv" ;inv $iCount = 0 $show = "" For $i = 1 To UBound($ol) - 1 If $ol[$i] = -1 Then $iCount = $iCount + 1 If $iCount = 1 Then $show = $show & "You're carrying: " EndIf $show = $show & $id[$i] & ", " EndIf Next If $iCount > 0 Then $show = StringTrimRight($show, 2) & "." EndIf If $show = "" Then $show = "You're empty-handed." EndIf _WriteBack($show) GUICtrlSetData($ChatInput, "") Case $v = "get" Or $v = "tak" ;get $iCount = 0 For $i = 1 To UBound($o) - 1 ;can you get it? If $n = $o[$i] And $ol[$i] <> "-1" And $ol[$i] = $rnum Then $iCount = $iCount + 1 If $nItems > 4 Then _WriteBack("Your arms are full. You can't carry any more.") Else $ol[$i] = "-1" $nItems = $nItems + 1 _WriteBack("Okay...") $score = $score + 10 If $ol[2] = -1 Then ;you got the crab _ShakeWindow() _WriteBack("Owwww! Owwww! The crab pinched your finger...you dropped it!") Sleep(1000) $ol[$rnum] = $rnum $nItems = $nItems - 1 $score = $score - 10 ShowLoc() EndIf EndIf EndIf Next If $ol[15] = -1 Then $d[22] = "23219912" $d[23] = "24229999" EndIf If $iCount = 0 Then ;don't see it here _WriteBack("I don't see it.") EndIf GUICtrlSetData($ChatInput, "") Case $v = "dro" ;drop $iCount = 0 For $i = 1 To UBound($o) - 1 ;drop it if you have it If $n = $o[$i] And $ol[$i] = "-1" Then $ol[$i] = $rnum $iCount = $iCount + 1 _WriteBack("Ok. Dropped.") $nItems = $nItems - 1 $score = $score - 10 EndIf Next If $iCount = 0 Then ;don't have it _WriteBack("It's not something you're carrying.") EndIf GUICtrlSetData($ChatInput, "") Case $v = "loo" ; look GUICtrlSetData($ChatText, "") _WriteBack("You might want to say 'examine'...") ShowLoc() GUICtrlSetData($ChatInput, "") Case $v = "exa" ; examine Select Case $n = "box" _WriteBack("It is very rusty and has a lock on it.") GUICtrlSetData($ChatInput, "") Case $n = "coi" _WriteBack("It pays to examine your surroundings and objects you see. These coins could be very valuable.") GUICtrlSetData($ChatInput, "") Case $n = "map" _WriteBack("Looks like notes for a computer program and has lots of what looks like random number on it.") GUICtrlSetData($ChatInput, "") Case $n = "scr" _WriteBack("It has a message scrawled on it saying 'Beware of creatures that swim'.") GUICtrlSetData($ChatInput, "") Case Else _WriteBack("Close examination reveals no remarkable characteristics.") GUICtrlSetData($ChatInput, "") EndSelect Case $v = "ope" Or $v = "unl" ; open/unlock Select Case $n = "box" TestInInv() Select Case $iTest = False _WriteBack("You cannot open/unlock something you don't have.") GUICtrlSetData($ChatInput, "") Case $iTest = True And $ol[5] <> -1 _WriteBack("You will need a key to unlock it.") GUICtrlSetData($ChatInput, "") Case $iTest = True And $ol[5] = -1 GUICtrlSetData($ChatText, "") _WriteBack("You opened the box!") $ol[15] = $rnum ShowLoc() EndSelect Case Else _WriteBack("That's not something you can do.") EndSelect GUICtrlSetData($ChatInput, "") Case $v = "thr" ; ; throw Select Case $n = "hoo" Or $n = "rop" If $rnum = 21 And $ol[11] = -1 Then GUICtrlSetData($ChatText, "") _WriteBack("After making a nice throw and pulling yourself out, you managed to tie the rope to trees on each side of the pit.") $r[21] = "You are clinging to a rope strung across and dangerous looking pit." $d[21] = "22209999" $ol[11] = 0 $qs = False ShowLoc() EndIf Case Else $iCount = 0 For $i = 1 To UBound($o) - 1 If $n = $o[$i] And $ol[$i] = -1 Then _WriteBack("Ok. You threw it.") $ol[$i] = $rnum $iCount = $iCount + 1 EndIf Next If $iCount = 0 Then _WriteBack("No can do, my friend.") EndIf EndSelect GUICtrlSetData($ChatInput, "") Case $v = "lig" Or $v = "bur" Or $v = "ign" ; light/burn Select Case $n = "tor" And $ol[14] = -1 And $ol[13] = -1 GUICtrlSetData($ChatText, "") _WriteBack("The torch will now illuminate dark passageways.") GUICtrlSetData($ChatInput, "") $torch = True $ol[5] = 22 $d[22] = "99219912" $d[12] = "13992299" $d[23] = "24229999" ShowLoc() Case $n = "tor" And $ol[13] <> -1 _WriteBack("No matches.") GUICtrlSetData($ChatInput, "") Case $n <> "tor" And $ol[14] <> -1 TestInInv() If $iTest = False Then _WriteBack("You don't have it.") GUICtrlSetData($ChatInput, "") EndIf Case Else _WriteBack("That would be irresponsibly dangerous.") GUICtrlSetData($ChatInput, "") EndSelect Case $v = "sav" Local $hFileOpen = FileOpen("Game.sav", $FO_OVERWRITE) FileWrite($hFileOpen, $rnum & @CRLF) For $i = 1 To UBound($d) - 1 FileWrite($hFileOpen, $d[$i] & @CRLF) Next For $i = 1 To UBound($ol) - 1 FileWrite($hFileOpen, $ol[$i] & @CRLF) Next FileWrite($hFileOpen, $turns & @CRLF) FileWrite($hFileOpen, $nItems & @CRLF) FileWrite($hFileOpen, $torch & @CRLF) FileWrite($hFileOpen, $score & @CRLF) If $qs = False Then $r[21] = "You are clinging to a rope strung across and dangerous looking pit." EndIf FileWrite($hFileOpen, $r[21] & @CRLF) FileClose($hFileOpen) _WriteBack("Data saved.") GUICtrlSetData($ChatInput, "") Case $v = "loa" Or $v = "res" $iCount = 1 Local $hFileOpen = FileOpen("Game.sav", $FO_READ) $rnum = FileReadLine($hFileOpen, $iCount) For $i = 1 To UBound($r) - 1 $iCount = $iCount + 1 $d[$i] = FileReadLine($hFileOpen, $iCount) Next For $i = 1 To UBound($ol) - 1 $iCount = $iCount + 1 $ol[$i] = FileReadLine($hFileOpen, $iCount) Next $iCount = $iCount + 1 $turns = FileReadLine($hFileOpen, $iCount) $iCount = $iCount + 1 $nItems = FileReadLine($hFileOpen, $iCount) $iCount = $iCount + 1 $torch = FileReadLine($hFileOpen, $iCount) $iCount = $iCount + 1 $score = FileReadLine($hFileOpen, $iCount) $iCount = $iCount + 1 $r[21] = FileReadLine($hFileOpen, $iCount) FileClose($hFileOpen) _WriteBack("Data restored.") Sleep(2000) GUICtrlSetData($ChatInput, "") ShowLoc() Case $v = "rea" If $n = "scr" Then _WriteBack("It says: 'Beware of shiny distractions. Protect your health.'") GUICtrlSetData($ChatInput, "") EndIf If $n = "map" Then _WriteBack("All it shows is a series of numbers, perhaps some kind of code...") GUICtrlSetData($ChatInput, "") EndIf Case $v = "fuc" Or $v = "shi" ;curse words _WriteBack("Whoa, Nellie! You should really watch your language!!") GUICtrlSetData($ChatInput, "") Case $v = "say" Or $v = "yel" ; say or yell _WriteBack("Okay..." & "'" & StringUpper($n1) & "'.") GUICtrlSetData($ChatInput, "") Case $v = "sco" _WriteBack("You have used " & $turns & " turns thus far and scored " & $score & " points." & @CRLF & "You need to hurry...you won't last long in this heat!") GUICtrlSetData($ChatInput, "") Case $v = "hel" Helpme() GUICtrlSetData($ChatInput, "") Case $v = "eat" ;suggested improvement: kill the crab and eat it for extra health, more turns _WriteBack("Now is not the time to take a lunch break...") GUICtrlSetData($ChatInput, "") Case $v = "dri" ;suggested improvement: fill the bottle and drink from the lagoon for extra health, more turns _WriteBack("Really? No, I don't think so.") GUICtrlSetData($ChatInput, "") Case $v = "kil" _WriteBack("Violence is never the answer!") GUICtrlSetData($ChatInput, "") Case Else _WriteBack("I don't understand your command.") GUICtrlSetData($ChatInput, "") EndSelect EndFunc ;==>ProcessVerbs Func TestIsHere() $vTest = False For $i = 1 To UBound($o) - 1 ;test to see if it's here If $n = $o[$i] And $ol[$i] = $rnum Then $vTest = True EndIf Next EndFunc ;==>TestIsHere Func TestInInv() $iTest = False For $i = 1 To UBound($o) - 1 ;test to see if you have it If $n = $o[$i] And $ol[$i] = -1 Then $iTest = True EndIf Next EndFunc ;==>TestInInv Func _WriteBack($text) GUICtrlSetData($ChatText, $text & @CRLF, GUICtrlRead($ChatInput)) EndFunc ;==>_WriteBack Func TestWin() If $rnum = 24 And $ol[15] = -1 And $ol[10] = -1 Then $show = "Your ordeal has come to an end. Those cryptic numbers on the map turned out to be " $show = $show & "the phone numbers of the nearest U.S. Coast Guard Station. You called " $show = $show & "and the rescue vessel is enroute to your location. You solved this puzzle " $show = $show & "using only " & $turns & " turns. Good job!" $show = $show & @CRLF & @CRLF & "Congratulations!" & @CRLF & "Tap to exit..." _WriteBack($show) Wait() Exit EndIf EndFunc ;==>TestWin Func Main() While 1 ;process button input TestWin() $nMsg = GUIGetMsg() Switch $nMsg Case $ChatInput ; PRESS ENTER WHILE IN THE INPUT BOX $turns = $turns + 1 ParseInp() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ;==>Main Func ShowLoc() ;show where you are If $rnum > UBound($r) - 1 Then _ShakeWindow() $rnum = $lastnum EndIf If $rnum = 3 Then $d[3] = "99999999" $swim = $swim + 1 If $swim = 6 Then GUICtrlSetData($ChatText, "") _WriteBack("Your demise was swift. You were not able to outswim the sharks." & @CRLF & "Press to exit.") Wait() Exit EndIf If $swim > 3 Then $ol[3] = 3 _WriteBack("!!!!!!!!! S H A R K S !!!!!!!!!") _ShakeWindow() Else _WriteBack("The current is very strong...") EndIf EndIf GUICtrlSetFont($ChatText, 12, 400, 0, "Segoe UI") If $turns > 1 Then _WriteBack(" -----------------------------------------------------------------------------------------") $show = $r[$rnum] Sleep(250) $iCount = 0 For $i = 1 To UBound($ol) - 1 If $ol[$i] = $rnum Then $iCount = $iCount + 1 If $iCount = 1 Then $show = $show & @CRLF & "You can see: " EndIf $show = $show & $id[$i] & ", " EndIf Next If $iCount > 0 Then $show = StringTrimRight($show, 2) & "." EndIf If $d[$rnum] <> "99999999" Then $show = $show & @CRLF & "It appears you can go: " If StringLeft($d[$rnum], 2) < 99 And StringLeft($d[$rnum], 2) > 0 Then $show = $show & " North " EndIf If StringMid($d[$rnum], 3, 2) < 99 And StringMid($d[$rnum], 3, 2) > 0 Then $show = $show & " South " EndIf If StringMid($d[$rnum], 5, 2) < 99 And StringMid($d[$rnum], 5, 2) > 0 Then $show = $show & " East " EndIf If StringRight($d[$rnum], 2) < 99 And StringRight($d[$rnum], 2) > 0 Then $show = $show & " West " EndIf EndIf If $turns = 60 Then $show = $show & @CRLF & " DANGER!! The heat, humidity and exhaustion" & @CRLF & " is taking it's toll." & @CRLF & " You are getting weak..." EndIf If $turns = 80 Then $show = $show & @CRLF & " EXTREME DANGER !! You are becoming semi-conscious and disoriented. Breathing is difficult..." EndIf If $turns = $maxturns Then $show = $show & @CRLF & " R.I.P." & @CRLF & "Sadly...it all ends for you, right here, right now." & @CRLF $show = $show & "Your adventure is over. Tap to exit..." Wait() Exit EndIf _WriteBack($show) GUICtrlSetData($ChatInput, "") $lastnum = $rnum GUICtrlSetState($ChatInput, $GUI_FOCUS) GUICtrlSetState($Label1, $GUI_SHOW) EndFunc ;==>ShowLoc Func ParseInp() ;process typed input $strSentence = GUICtrlRead($ChatInput) ;_WriteBack("> " & $strSentence) $strSentence = StringLower($strSentence) $split = StringInStr($strSentence, " ") If $split = 0 Then ;one word command $v1 = $strSentence $n1 = "" Else $v1 = StringLeft($strSentence, $split - 1) $n1 = StringMid($strSentence, $split + 1) EndIf If StringLen($v1) > 3 Then $v = StringLeft($v1, 3) Else $v = $v1 EndIf If StringLen($n1) > 3 Then $n = StringLeft($n1, 3) Else $n = $n1 EndIf ProcessVerbs() EndFunc ;==>ParseInp Func Helpme() $turns = $turns - 1 $show = "You are stranded on an island in the Caribbean. You will have to " $show = $show & "make the best of your situation until you can be rescued. Use the " $show = $show & "buttons to move about the island and explore. Be aware of your " $show = $show & "surroundings. Enter one and two-word commands to direct the action. For example: " $show = $show & "you could type 'get key', 'drop book', 'examine paper', 'open box', or use " $show = $show & "other verb/noun combinations to manipulate your situation. Typing 'inv' will " $show = $show & "show you a list of what you are carrying, 'score' will tell you how you " $show = $show & "how you are doing, and 'quit' to end the game. Good luck!" MsgBox($MB_OK, "Game Instructions", $show) EndFunc ;==>Helpme Func _ShakeWindow() ;self-explanatory Local $Window = WinGetTitle("", ""), $ShakeAmount = 5, $Win_pos = WinGetPos($Window) For $i = 0 To 20 WinMove($Window, "", $Win_pos[0], $Win_pos[1] + $ShakeAmount * Mod($i, 2)) Sleep(10) Next EndFunc ;==>_ShakeWindow Func Wait() Do Sleep(10) Until _IsPressed("20") ;spacebar EndFunc ;==>Wait