#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\Icons\Pirate.ico #AutoIt3Wrapper_UseUpx=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include ;This script is a novice attempt to re-create an old 1980's style text adventure game. The buttons ;will move you from location to location, and you can enter simple one and two-word commands to interact ;with the game. Example: "get key", "drop book", "open box", "inventory", "score", "quit". This is ;far from finished. The items bear little connection to the locations where they are located, and ;there is really no solutions or hazards yet implemented. It's just a start...and was mainly to ;see if I could make AutoIt duplicate some of functions that I (vaguely) remember implementing ;in BASIC. ;My only request....if you modify this, please share it or upload it under a different filename. ;---- Bill Cook Global $turns = 0, $score = 0, $nItems = 0 Global $temp = "", $vTest = False, $iTest = False Global $torch = False Global $no[30] ;max number of nouns/objects Global $nr = 30 ;max number of rooms, directions Global $ni = 30 ;item locations, item descriptions Global $s = 30 ;some responses Global $n, $v, $v1, $n1 Global $rnum = 1, $lastnum = 1, $iCount = 0 Global $r[$nr], $d[$nr], $iLoc[$ni], $item[$ni], $iMsg ;[Rooms] $r[1] = 'You woke up in a daze with a horrible headache. You are wet and confused. ' $r[1] = $r[1] & ' It seems your small fishing boat has capsized and you were rendered unconscious. ' $r[1] = $r[1] & ' You washed ashore on a tiny island.' $r[2] = 'You are on the beach on the west side of the island. There is a jungle to the east, the wind is picking up.' $r[3] = 'You are treading water just offshore. The current is very strong and pushing you toward the north.' $r[4] = 'You have entered a dark, misty jungle. You see a dim light to the west.' $r[5] = 'You see the wreckage of your fishing boat strewn about the beach.' $r[6] = 'You are at a rocky reef. The sand is very hot beneath your feet.' $r[7] = 'You are in a clearing among large mangrove trees. You hear the call of tropical birds and primates.' $r[8] = 'You are at the edge of a crystal clear fresh-water lagoon. You can see the shimmering of fish swimming about.' $r[9] = 'You are on a winding path. It is pretty dark here.' $r[10] = 'You are on a narrow winding path. It is very dark here.' $r[11] = 'You outside a large hut. There is a ladder leading up to the entrance.' $r[12] = 'You are outside of a small cave-like tunnel.' $r[13] = 'You are in a small tunnel.' $r[14] = 'You are outside a small cave-like tunnel.' $r[15] = 'You are in a very narrow path.' $r[16] = 'You are on a winding path.' $r[17] = 'You are on among a dense garden of giant bamboos.' $r[18] = 'You are on a rocky eastern shore of the island.' $r[19] = 'You are at a wide pit at the rock quarry.' $r[20] = 'You are at the edge of a muddy pit.' $r[21] = 'You are in ....< QUICK SAND >... and sinking...' $r[22] = 'It is too dark to see anything here...' $r[23] = 'You are on the north shore.' $r[24] = 'You are in a small shack. A sign on the wall says "U.S. Coast Guard, 1-800-RescueMe"' ;[Directions] 99=Dead End 'NNSSEEWW' $d[1] = '02020203' $d[2] = '05060403' $d[3] = '99990299' $d[4] = '07089902' $d[5] = '99020703' $d[6] = '02990803' $d[7] = '99041405' $d[8] = '04099906' $d[9] = '08161110' $d[10] = '99150999' $d[11] = '12992109' $d[12] = '13112299' $d[13] = '14129999' $d[14] = '99139907' $d[15] = '10991699' $d[16] = '09179915' $d[17] = '16991899' $d[18] = '19999917' $d[19] = '99182099' $d[20] = '21999919' $d[21] = '22999999' $d[22] = '99219999' $d[23] = '99229913' $d[24] = '99999999' ;[Item Descriptions] initial room #/ description $item[1] = '07/a large coconut' $item[2] = '02/a small sand crab' $item[3] = '00/OMG! SHARKS!' $item[4] = '05/a small rusty box' $item[5] = '23/a brass key' $item[6] = '06/a parchment scroll' $item[7] = '06/a small sea lion' $item[8] = '08/several gold coins' $item[9] = '10/a rusty knife' $item[10] = '04/a small bottle' $item[11] = '18/a grappling hook with a rope attached' $item[12] = '22/bones' $item[13] = '00/a book of matches' $item[14] = '20/an oil-soaked torch' $item[15] = '24/a satellite phone' ;Short Descriptions/nouns $no[1] = "coc" $no[2] = "cra" $no[3] = "sha" $no[4] = "box" $no[5] = "key" $no[6] = "scr" $no[7] = "sea" $no[8] = "coi" $no[9] = "kni" $no[10] = "bot" $no[11] = "hoo" $no[12] = "bon" $no[13] = "mat" $no[14] = "tor" $no[15] = "pho" For $i = 1 To $ni - 1 $iLoc[$i] = StringLeft($item[$i], 2) ;initial item locations array Next For $i = 1 To $ni - 1 $item[$i] = StringTrimLeft($item[$i], 3) ;item descriptions array Next $Form1 = GUICreate("Caribbean Odyssey", 432, 265, -1, -1) $ChatText = GUICtrlCreateEdit("", 16, 32, 395, 165, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) $ChatInput = GUICtrlCreateInput("", 68, 211, 75, 23) $Label1 = GUICtrlCreateLabel("What now?", 16, 204, 48, 35) GUICtrlSetFont(-1, 10, 400, 0, "Segoe UI") $Button1 = GUICtrlCreateButton("North", 150, 210, 41, 25) $Button2 = GUICtrlCreateButton("South", 195, 210, 41, 25) $Button3 = GUICtrlCreateButton("East", 240, 210, 41, 25) $Button4 = GUICtrlCreateButton("West", 285, 210, 41, 25) $Button5 = GUICtrlCreateButton("Up", 330, 210, 41, 25) $Button6 = GUICtrlCreateButton("Down", 375, 210, 41, 25) $Label3 = GUICtrlCreateLabel("Caribbean Island Adventure", 100, 6, 330, 24) GUICtrlSetFont(-1, 14, 400, 0, "Tahoma") GUICtrlSetState($ChatInput, $GUI_FOCUS) ; AUTOMATICALLY FOCUSSES ON THE INPUT GUISetState(@SW_SHOW) ShowLoc() GUICtrlSetFont($ChatText, 10, 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($item) - 1 If $item[$i] = '' Then $rdim = $i ExitLoop EndIf Next ReDim $item[$rdim] ReDim $no[$rdim] Main() ;tentatively, the solution: ;get grappling hook ;cross quicksand ;get key ;unlock box ;get matches ;light torch ;find secret passage ;get phone ;call for help -> you are rescued...bonus points 50. ;show score ;hazards ;in the ocean...drifting north...3 times clicking South back on the beach if empty handed. ;in the ocean...drifting north...3 times clicking south with inventory on hand...end of game due to drowning ;in the quicksand...sinking...only way out is to throw hook ;turns reach 60 ... you need to eat and drink something or you will starve ;turns reach 80 ... if you did not kill and eat the crab and fill bottle from lagoon and drink...game over ;Verbs left: save ;restore, load ;close ;kill, hit, stab, cut, shoot, fight ;read ;call Func ProcessVerbs() Select Case StringLeft($v, 2) = "go" Or $v = "ent" ;go _WriteBack("Please use buttons to move around...") GUICtrlSetData($ChatInput, "") Case $v = "qui" Or $v = "bye" ;quit MsgBox($MB_OK, "Quitting?", "Sorry to see you go!", 3) Exit Case $v = "inv" ;inv $iCount = 0 $show = "" For $i = 1 To UBound($iLoc) - 1 If $iLoc[$i] = -1 Then $iCount = $iCount + 1 If $iCount = 1 Then $show = $show & "You're carrying: " EndIf $show = $show & $item[$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($no) - 1 ;can you get it? If $n = $no[$i] And $iLoc[$i] <> "-1" And $iLoc[$i] = $rnum Then $iCount = $iCount + 1 $nItems = $nItems + 1 If $nItems > 5 Then _WriteBack("Your arms are full. You can't carry any more.") Else $iLoc[$i] = "-1" _WriteBack("Okay...") ConsoleWrite($nItems & @CRLF) $score = $score + 10 EndIf EndIf Next If $iLoc[2] = -1 Then ;you got the crab _ShakeWindow() _WriteBack("Owwww! Owwww! The crab pinched your finger...you dropped it!") Sleep(2000) $iLoc[$rnum] = $rnum $score = $score - 10 EndIf If $iCount = 0 Then ;don't see it here _WriteBack("I don't see it.") EndIf ShowLoc() GUICtrlSetData($ChatInput, "") Case $v = "dro" Or $v = "thr" ;drop $iCount = 0 For $i = 1 To UBound($no) - 1 ;drop it if you have it If $n = $no[$i] And $iLoc[$i] = "-1" Then $iLoc[$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 ShowLoc() GUICtrlSetData($ChatInput, "") Case $v = "loo" ; look If $n = "" Then _WriteBack("What do you want me to look at?") Else _WriteBack("You might want to say 'examine'...") EndIf GUICtrlSetData($ChatInput, "") Case $v = "exa" ; examine TestIsHere() TestInInv() If $vTest = False And $iTest = False Then ConsoleWrite($n & $iLoc[$rnum] & $rnum) _WriteBack("It's not here.") GUICtrlSetData($ChatInput, "") Else Select Case $n = "box" _WriteBack("It has a lock on it.") GUICtrlSetData($ChatInput, "") Case $n = "coi" _WriteBack("Looks like solid gold!") GUICtrlSetData($ChatInput, "") Case $n = "scr" _WriteBack("There's writing on it.") GUICtrlSetData($ChatInput, "") Case Else _WriteBack("It's not very remarkable.") GUICtrlSetData($ChatInput, "") EndSelect EndIf Case $v = "ope" Or $v = "unl" ; open/unlock TestInInv() TestIsHere() Select Case $vTest = False And $iTest = False _WriteBack("It's not here.") Case $iTest = False _WriteBack("You don't have it.") Case $iTest = True And $iLoc[5] <> -1 _WriteBack("It's locked. You will need a key.") Case $iTest = True And $iLoc[5] = -1 _WriteBack("Okay. You found some matches!") $iLoc[13] = $rnum GUICtrlSetData($ChatInput, "") ShowLoc() Case Else _WriteBack("I don't think you can do that.") EndSelect GUICtrlSetData($ChatInput, "") Case $v = "thr" ; ; throw If $n = "hoo" or $n = "rop" and $rnum =21 Then _WriteBack("You pulled yourself out!") GUICtrlSetData($ChatInput, "") $rnum = 22 $d[22] = '23219999' ShowLoc() EndIf Case $v = "lig" or $v = "bur" or $v = "ign"; light/burn Select Case $n = "tor" and $iLoc[14] = -1 and $iLoc[13] = -1 _WriteBack("You will now see better in dark passages.") GuiCtrlSetData($ChatInput, "") if $rnum = 22 or $rnum = 12 Then $d[22] = "23219912" $d[12] = "12112208" $d[23] = "24229913" EndIf Case $n = $iLoc[13] <> -1 _WriteBack("No matches.") GuiCtrlSetData($ChatInput, "") Case $n <> "tor" TestInInv() if $iTest = False Then _WriteBack("You don't have it.") GuiCtrlSetData($ChatInput,"") EndIf _WriteBack("That would be irresponsibly dangerous.") GuiCtrlSetData($ChatInput, "") EndSelect Case $v = "fuc" Or $v = "shi" ;curse words _WriteBack("Whoa! You should really watch your language!!") GUICtrlSetData($ChatInput, "") Case $v = "say" Or $v = "yel" _WriteBack("Okay..." & "'" & $n1 & "'.") GUICtrlSetData($ChatInput, "") Case $v = "sco" _WriteBack("You have scored " & $score & " points out of a possible 200.") GUICtrlSetData($ChatInput, "") Case $v = "hel" _WriteBack("Don't expect me to help you. You're on your own!") GUICtrlSetData($ChatInput, "") Case $v = "eat" _WriteBack("Now is not the time to take a lunch break...") GUICtrlSetData($ChatInput, "") Case $v = "dri" _WriteBack("Really? No, I don't think so.") Case Else _WriteBack("I don't understand your command.") GUICtrlSetData($ChatInput, "") EndSelect EndFunc ;==>ProcessVerbs Func TestIsHere() $vTest = False For $i = 1 To UBound($no) - 1 ;test to see if it's here If $n = $no[$i] And $iLoc[$i] = $rnum Then $vTest = True EndIf Next EndFunc ;==>TestIsHere Func TestInInv() $iTest = False For $i = 1 To UBound($no) - 1 ;test to see if you have it If $n = $no[$i] And $iLoc[$i] = -1 Then $iTest = True EndIf Next EndFunc ;==>TestInInv Func _WriteBack($text) GUICtrlSetData($ChatText, $text & @CRLF, GUICtrlRead($ChatInput)) EndFunc ;==>_WriteBack Func Main() While 1 ;process button input $nMsg = GUIGetMsg() Switch $nMsg Case $ChatInput ; PRESS ENTER WHILE IN THE INPUT BOX ParseInp() Case $GUI_EVENT_CLOSE Exit Case $Button1 ;north $rnum = Int(StringLeft($d[$rnum], 2)) ShowLoc() Case $Button2 ;south $rnum = Int(StringMid($d[$rnum], 3, 2)) ShowLoc() Case $Button3 ;east $rnum = Int(StringMid($d[$rnum], 5, 2)) ShowLoc() Case $Button4 ;west $rnum = Int(StringRight($d[$rnum], 2)) ShowLoc() Case $Button5 ; _ShakeWindow() Case $Button6 ; _ShakeWindow() EndSwitch WEnd EndFunc ;==>Main Func ShowLoc() ;show where you are If $rnum > UBound($r) - 1 Then _ShakeWindow() $rnum = $lastnum EndIf GUICtrlSetFont($ChatText, 10, 400, 0, "Segoe UI") $show = " . . . " & $r[$rnum] & " " $iCount = 0 For $i = 1 To UBound($iLoc) - 1 If $iLoc[$i] = $rnum Then $iCount = $iCount + 1 If $iCount = 1 Then $show = $show & "You can see: " EndIf $show = $show & $item[$i] & ", " EndIf Next If $iCount > 0 Then $show = StringTrimRight($show, 2) & "." EndIf _WriteBack($show) GUICtrlSetData($ChatInput, "") $turns = $turns + 1 $lastnum = $rnum GUICtrlSetState($ChatInput, $GUI_FOCUS) 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 _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() _WriteBack("Paused...Hit " & @CRLF) Do Sleep(10) Until _IsPressed("20") ;spacebar EndFunc ;==>Wait