! Adventures in Fruit Gardens ! by Muki Soomar ! Version 1 Constant Story "^ADVENTURES IN FRUIT GARDEN^"; Constant Headline "^Interactive Game for CIS 587 Project^^by Muki Soomar^^"; Release 1; Constant DEBUG; Include "Parser"; Include "VerbLib"; Include "Grammar"; ! Attributes for tree and fruits Attribute rotten; Attribute shakeable; Attribute pluckable; Attribute peelable; Attribute discovered; Attribute ripe; ! State the player is in Attribute APPLE_STATE; Attribute BANNANA_STATE; Attribute ORANGE_STATE; Attribute STRAWBERRY_STATE; ! Type of fruits Constant CAPPLE 1; Constant CBANNANA 2; Constant CORANGE 3; Constant CSTRAWBERRY 4; ! Fruit location Constant ON_GROUND 0; Constant ON_TREE 1; Constant MAX_FRUITS = 30; Global currentState = 0; Global gameScore; ! Class definitions Class Fruit (MAX_FRUITS) with type, points, rottenOrNot, description "A fruit you can pick, but examine closely before you bag it", before [x i state; if (self ofclass Apple) {i=CAPPLE; state=APPLE_STATE; } else if (self ofclass Bannana) {i=CBANNANA; state=BANNANA_STATE;} else if (self ofclass Orange) {i=CORANGE; state=ORANGE_STATE; } else if (self ofclass Strawberry) {i=CSTRAWBERRY; state=STRAWBERRY_STATE;} Smell, Look, Touch, Taste: if (currentState == state && self in player) { give self discovered; if (self has rotten) "You find the fruit to be rotten"; "The fruit looks great and delicious"; } if (self notin player) "You cannot do this unless you have the fruit"; Drop, Insert: if (self has rotten && currentState == state && self in player) { if (second == Bag ) { if (Bag has discovered) { move self to Bag; "You put the ", (string)self.type, " into the bag"; } "You dont have a bag to do this"; } if (second == Dumpster) { move self to Dumpster; "You chcuk the ", (string)self.type, " into the Dumpster"; } "You got rid of the ", (string)self.type, ". Should you have not thrown it into the dump ?"; } else if (currentState == state && self in player) { if (second == Bag) { if (Bag has discovered) { move self to Bag; "You put the apple into the bag"; } "You dont have a bag to do this"; } move self to parent(player); "You wasted a good ", (string)self.type, " by throwing it away"; } if (self notin player) "You cannot do any such thing"; Eat: if (currentState == state && self in player && self notin GardenSquare) { if (self has rotten) { move self to parent(player); !make it dumpster "Your mouth starts to taste awful. You start checking the ", (string)self.type, " again and notice it has worms inside. Shoooo.. you spit out the rest of it. You walk down to the dumpster and chuck it in. You start to wonder how many of those small nasty creatures you swallowed with those bites. Ahh... next time you better check before starting to munch them!!"; } if (self has peelable) { print "You peel the ", (string)self.type, " and gobble the whole darned thing. "; } else { print "You taste the ", (string)self.type, ". Hmmm.. tastes great. You munch it away as you find new energy coming into you. "; } switch(random (5)) { 1: "How hungry yu must be to much it away like that!!"; 2: "How hungry you must be !!"; 3: "You really must be hungry !!"; 4: "You really must be famished !!! "; 5: "You must not have eaten in days !!"; } } else { "you don't see any ", (string)self.type, " yet !!"; } Take: if (currentState == state && self in GardenSquare) { move self to player; "You pick up the ", (string)self.type, " in your hand"; } else "You can't see a ", (string)self.type, " to pick it up"; ], create [; self.rottenOrNot = random (0,1); if (self.rottenOrNot == 0) give self ~rotten; else give self rotten; ], destroy [; ], has edible concealed; Class Apple (MAX_FRUITS) class Fruit with name "apple" "apples//p", plural "apples", points 50, description "Red delicious apple", before [x; Pluck: if (currentState == APPLE_STATE && player in AppleTree) { objectloop(x ofclass Apple) { if (x in AppleTree) { move x to player; break; } } "You pluck an apple"; } ], create [; self.type = "apple"; ]; Class Orange (MAX_FRUITS) class Fruit with name "orange" "oranges//p", plural "oranges", points 75, description "ORANGE orange", create [; self.type = "orange"; give self peelable; ]; Class Bannana (MAX_FRUITS) class Fruit with name "bannana" "bannanas//p", plural "bannanas", points 35, description "bannana", before [x; Cut: ! Can only cut bannanas !! if (Sickle in player && currentState == BANNANA_STATE ) { !&& player in BannanaTree ) { objectloop(x ofclass Bannana) { if (x in BannanaTree) { move x to GardenSquare; } } "You cut the bannanas from the tree and they all fall to the ground"; } "You need to go to the bannana tree to cut them and should have something sharp to cut them"; ], create [; self.type = "bannana"; give self peelable; ]; Class Strawberry (MAX_FRUITS) class Fruit with name "berry" "strawberry" "strawberries//p", plural "strawberries", points 20, description "strawberry", create [; self.type = "strawberry"; ]; !------------------------------------------- Object GardenSquare "Garden Square" with name "garden" "square", initial "You enter into the garden square.", description "In the garden of your dreams you see your favorite trees.", before [x onG onT; ThrowAt,ThrownAt: ; Take: if (noun == bag && bag hasnt discovered) "You havent found any bag yet"; Examine: if (noun == AppleTree && currentState == APPLE_STATE ) { objectloop (x ofclass Apple) { if (x in self) onG=1; if (x in AppleTree) onT=1; } if (onG) print "You see some apples on the ground^"; if (onT) print "You see some apples on the apple tree^"; rtrue; } else if (noun == BannanaTree && currentState == BANNANA_STATE) { objectloop (x ofclass Bannana) { if (x in self) onG=1; if (x in bannanaTree) onT=1; } if (onG) print "There are some bannanas on the ground^"; if (onT) print "There are some bannanas on the bannana tree^"; give player BANNANA_STATE; currentState = BANNANA_STATE; rtrue; } else if (noun == OrangeTree && currentState == ORANGE_STATE) { objectloop (x ofclass Orange) { if (x in self) onG=1; if (x in OrangeTree) onT=1; } if (onG) print "There are some orange(s) on the ground^"; if (onT) print "There are some orange(s) on the orange tree^"; give player ORANGE_STATE; currentState = ORANGE_STATE; rtrue; } else if (noun == BerriesTree && currentState == STRAWBERRY_STATE) { objectloop (x ofclass Strawberry) { if (x in self) onG=1; if (x in BerriesTree) onT=1; } if (onG) print "There are some Strawberry(ies) on the ground^"; if (onT) print "There are some Strawberry(ies) on the strawberry tree^"; give player STRAWBERRY_STATE; currentState = STRAWBERRY_STATE; rtrue; } if (noun == Bag && Bag hasnt discovered) "You cannot see any bag"; Go: if (noun == AppleTree) { give player APPLE_STATE; currentState = APPLE_STATE; "You walk to the apple tree to examine it and take a closer look"; } if (noun == BannanaTree) { give player BANNANA_STATE; currentState = BANNANA_STATE; "You walk to the bannana tree to examine it and take a closer look"; } if (noun == OrangeTree) { give player ORANGE_STATE; currentState = ORANGE_STATE; "You walk to the Orange tree to examine it and take a closer look"; } if (noun == BerriesTree) { give player STRAWBERRY_STATE; currentState = STRAWBERRY_STATE; "You walk close to the Strawberries tree to examine it and take a closer look"; } else rtrue; ], has light supporter; Object Grass "grass" GardenSquare with name "grass" "lawn", intitial "Green grass grew all around in the garden", description "The tall and long grass was spread all over in the garden", before [; Examine: "Wild and green grass covered the garden square all over. You find a little dumpster in the center of the garden partially hidden by the long grass."; Search: if (currentState == Bag.bag_state && Bag hasnt discovered) { give Bag discovered; "Hidden in the long grass by the ", (string)Bag.bag_location, " you discover a medium sized empty fruit bag. Ahh.. just the thing you need to bag the fruits you collect"; } if (currentState == Sickle.s_state && Sickle hasnt discovered) { give Sickle discovered; "You discover a sharp sickle here"; } ], has scenery; ! Create an Apple tree for the apple garden Object AppleTree "Apple tree" GardenSquare with parse_name [ w fruitName n; w = NextWord(); if (w == 'apple') { n ++; fruitName = w; w = NextWord(); } if (w == 'tree' && fruitName == 'apple') return n + 1; return 0; ], initial "The apple tree is on your left as you enter the garden", description "You see the apple tree on your left from the entrance", before [x; Shake: if (player has APPLE_STATE) { ! Only one apple breaks at a time print "You shake the apple tree hard. "; objectloop (x ofclass Apple) { if (x in AppleTree && x has ripe) { move x to GardenSquare; print "A ripe apple drops to the ground^"; rtrue; } } } Climb: if (currentState == APPLE_STATE) { move player to self; "You climb the apple tree"; } "You have to go to the apple tree to climb it !"; ], has static enterable shakeable supporter light; ! Create an Bannana tree for the garden Object BannanaTree "bannana tree" GardenSquare with parse_name [ w fruitName n; w = NextWord(); if (w == 'bannana') { n ++; fruitName = w; w = NextWord(); } if (w == 'tree' && fruitName == 'bannana') return n + 1; return 0; ], initial "The bannana tree is on your far right", description "You see the bannana tree on your far right side in the garden from the entrance", before [x; Shake: if (currentState == BANNANA_STATE) { ! Only one apple breaks at a time print "You shake the bannana tree hard. But it accomplishes nothing. You will need to climb the tree and cut it using a sharp instrument"; } Climb: if (currentState == BANNANA_STATE) { move player to self; "You climb the bannana tree"; } "You have to go to the bannana tree to climb it !"; ], has static enterable shakeable supporter; ! Create an Orange tree for the garden Object OrangeTree "Orange tree" GardenSquare with parse_name [ w fruitName n; w = NextWord(); if (w == 'orange') { n ++; fruitName = w; w = NextWord(); } if (w == 'tree' && fruitName == 'orange') return n + 1; return 0; ], initial "Straight ahead you see the orange tree", description "Oranges - and lots of them hung from this tree", before [x; Shake: ! Only one apple breaks at a time if (player has ORANGE_STATE) { print "You shake the orange tree hard. "; objectloop (x ofclass Orange) { if (x in OrangeTree && x has ripe) { move x to GardenSquare; print "A ripe orange drops to the ground^"; rtrue; } } } Climb: if (currentState == ORANGE_STATE) { move player to self; "You climb the orange tree"; } "You have to go to the orange tree to climb it !"; ], has static enterable shakeable supporter; ! Create an Strawberries tree for the garden Object BerriesTree "Strawberry tree" GardenSquare with parse_name [ w fruitName n; w = NextWord(); if (w == 'berries' || w == 'strawberry') { n ++; fruitName = w; w = NextWord(); } if (w == 'tree' && (fruitName == 'strawberry' || fruitName == 'berry') ) return n + 1; return 0; ], initial "Close to the orange tree you see the small strawberry tree", description "Strawberries - and lots of them hung from this tree", before before [x; Shake: if (player has STRAWBERRY_STATE) { ! Only one fruit breaks at a time print "You shake the orange tree hard. "; objectloop (x ofclass Strawberry) { if (x in BerriesTree && x has ripe) { move x to GardenSquare; print "A ripe strawberry drops to the ground^"; rtrue; } } } Climb: if (currentState == STRAWBERRY_STATE) { move player to self; "You climb the strawberry tree"; } "You have to go to the srawberry tree to climb it"; ], has static enterable shakeable supporter; ! Bag object to bag the fruits Object Bag "Bag" GardenSquare with name "bag" "sack", bag_state, bag_location before [; Drop: move self to GardenSquare; self.bag_state = currentState; "You put the bag down near the ", self.bag_location; Take: if (currentState ~= self.bag_state) "You dont see the bag here"; if (self hasnt discovered) "You havent found any bag yet"; if (self has discovered) { move self to player; "You pick up the bag and sling it over your shoulders"; } rtrue; ], has concealed container open openable; Object Sickle "sickle" GardenSquare with name "knife" "sickle", s_state, s_location before [; Drop: move self to GardenSquare; self.s_state = currentState; "You put down the sickle near the ", self.s_location; Take: if (currentState ~= self.s_state) "You dont see any sickle here"; if (self hasnt discovered) "You havent found one yet"; if (self has discovered) { move self to player; "You pick up the sickle in your hand"; } ], has concealed; !Dumpster for !throwing rotten fruits Object Dumpster "Dumpster" GardenSquare with name "dumpster" "dump", before [; ], has concealed static container open; !------------------------------------------------------------------------------ ! New Functions !------------------------------------------------------------------------------ ! Scoring Sub [DoScore x rottenFlag; gameScore = 0; objectloop (x ofclass Fruit) { if (x in Bag && x hasnt rotten) { gameScore = x.points + gameScore; } if (x in Bag && x has rotten) { rottenFlag = 1; } } if (rottenFlag) { gameScore = 0; objectloop (x ofclass Fruit) { if (x in Bag) give x rotten; } print "^You had put a rotten fruit in the bag that spoilt all your other fruits. Your score is zero.^"; } else print "^Your score is : ", gameScore, "^ and number of moves you took : ", turns; ]; !------------------------------------------------------------------------------ ! New Verbs Subroutines !------------------------------------------------------------------------------ [ KickSub; <>;]; [ KickUnderSub; "What would that accomplish?";]; [ ShakeSub; "It will not accomplish anything !";]; [ PointsSub; DoScore();]; [ PluckSub; "You have to reach the fruit to pluck it";]; !------------------------------------------------------------------------------ ! New Verbs !------------------------------------------------------------------------------ Verb "kick" "beat" * noun -> Kick * noun "under" noun -> KickUnder; Verb "pluck" * noun -> Pluck; Verb "shake" * noun -> Shake; Verb "points" * -> Points; Extend 'go' *'to' noun -> Go; Extend 'walk' *'in' noun -> Go; Extend 'run' *'to' noun -> Go; !--------------------------------------- ! Initialise the game with the initial location of the player [ Initialise index fruitObj spoilt ripeOrNot bagState sickleState; ! Create all the objects here ! Create different kinds of fruits and put them in the garden for (index=1: index<= MAX_FRUITS: index++) { switch ( random(CAPPLE, CBANNANA, CORANGE, CSTRAWBERRY) ) { CAPPLE: fruitObj = Apple.create(); CBANNANA: fruitObj = Bannana.create(); CORANGE: fruitObj = Orange.create(); CSTRAWBERRY: fruitObj = Strawberry.create(); } spoilt = random(0,1); if (spoilt) give fruitObj rotten; ripeOrNot = random(0,1); if (ripeOrNot) give fruitObj ripe; if (random(ON_TREE, ON_GROUND) == ON_GROUND ) { give fruitObj ~pluckable; move fruitObj to GardenSquare; } else { give fruitObj pluckable; if (fruitObj ofclass Apple) move fruitObj to AppleTree; else if (fruitObj ofclass Bannana) move fruitObj to BannanaTree; else if (fruitObj ofclass Orange) move fruitObj to OrangeTree; else if (fruitObj ofclass StrawBerry) move fruitObj to BerriesTree; } } ! Randomise the Bag and the sickle location so everytime it will be different bagState = random(CAPPLE, CBANNANA, CORANGE, CSTRAWBERRY); sickleState = random(CAPPLE, CBANNANA, CORANGE, CSTRAWBERRY); switch(bagState) { CAPPLE: Bag.bag_state = APPLE_STATE; Bag.bag_location = "apple tree"; CBANNANA: Bag.bag_state = BANNANA_STATE; Bag.bag_location = "bannana tree"; CORANGE: Bag.bag_state = ORANGE_STATE; Bag.bag_location = "orange tree"; CSTRAWBERRY: Bag.bag_state = STRAWBERRY_STATE; Bag.bag_location = "strawberry tree"; } Sickle.s_state = BANNANA_STATE; Sickle.s_location = "bannana tree"; !switch(sickleState) { ! CAPPLE: Sickle.s_state = APPLE_STATE; Sickle.s_location = "apple tree"; ! CBANNANA: Sickle.s_state = BANNANA_STATE; Sickle.s_location = "bannana tree"; ! CORANGE: Sickle.s_state = ORANGE_STATE; Sickle.s_location = "orange tree"; ! CSTRAWBERRY: Sickle.s_state = STRAWBERRY_STATE; Sickle.s_location = "strawberry tree"; !} ! Start all the daemons here StartDaemon(Fruit); ! set up the initial location location = GardenSquare; print "^^You arrive at your favorite adventure place - the fruit garden. As you stand in front of the entrance you look around the Garden Square that you had visited so many times with your friends and played in it when you were a kid. The garden still has the same appearance - green grass with long grass in some areas making you wonder what will spring out of them and what treasures you might find in them.^^ You can hear wild life sounds around you making you feel you have come back to your wild adventure land!!.^^ This garden has been one of your favorite adventure place since your childhood and you remember how you loved to climb the trees and pluck the fruits. You start thinking - lets have fun and see how many fruits I can collect today and how fast."; print "^^At any time type "; style bold; print "points"; style roman; print " to display the score.^^"; ];