Programming Fundamentals | My Assignment Tutor

Major Assignment: Clara Digger Game 1 Major Assignment:Clara Digger Game300580Programming FundamentalsWeek 10 AssignmentThe major assignment involves producing a Digger style game with Clara using the project files that are given to you.The essence of the game – is to make Clara eat all available leaves and collect all the gold, while avoiding collisions with ghostschasing her. Clara can move around in her world by walking inside tunnels. She can also dig tunnels as she walks through earthpatches. Ghosts can only move inside tunnels. You will find the gameplay video of the original Digger game on YouTube at thefollowing URL: https://youtu.be/oCPKlyj3i_k. Our version of the game is simpler. It does not have shooting or collecting bonusitems. In our game the player is also required to collect all gold and all leaves before progressing to the next level. Finally, in ourgame ghosts must return to the ghost healer for regeneration and can walk through walls and gold sacks when dead.The gameplay video of our Clara Digger game is available at: https://youtu.be/6QoP9FRRkzI.Clara in the game is to be controlled by the player through keyboard. Apart from leaves, there are also gold sacks available inClara’s world. Clara must break these by digging a hole underneath (which makes gold sacks fall down). She must be careful asthese gold sacks are heavy and can kill Clara. She can use these gold sacks as a weapon against ghosts. Dropping a gold sack ona ghost makes them die. Dead ghosts can regenerate once they return to their home base (also known as the ghost healer) that ismarked by a red heart. Major Assignment: Clara Digger Game 2 Ghosts start at different positions and chase Clara. If during this chase Clara happens to drop a gold sack on a ghost, the ghostdies by changing into an almost invisible creature that moves from the collision location to the base and then regenerates oncethe base is reached. If a collision happens between Clara and a ghost, then Clara loses, and the game is over.In solving the major assignment, you will not be entirely on your own, as the steps involved are broken up in this assignmentbrief. During practical classes your tutors will explain you the basics of completing these steps. Before we start, there will be anexplanation of all commands available in both Clara and the Ghosts vocabularies.Important RequirementsFor your convenience, all important requirements specified in this brief are re-listed here:– Clara must be capable of being controlled with at least the arrow keys on the keyboard.– Clara must stop before hitting gold sacks that have a soil or another gold sack behind (in the direction of Clara’smovement)– Clara is able to push gold sacks forward if there is no earth patch or another gold sack in front.– Clara must be able to eat leaves and play the appropriate sound when doing so.– When all the leaves are eaten and all gold is collected, the game must progress to the next level.– When each level starts the intro sound must be played and must continue playing until the end of the game.– Ghosts must move faster than Clara.– Ghosts must randomly decide on a direction to go in when they find themselves in an intersection. They mustprioritise the direction towards Clara.– When Clara and a Ghost collide, Clara must die.– When Clara is dead the player must not be able to continue controlling her.– Clara must be able to collect gold and must play the corresponding sounds.– Clara must be able to dig tunnels when she moves through earth patches.– Gold sacks must start shaking once there is no earth underneath. After shaking for a few seconds gold sacks must falldown and break at the bottom of the corresponding vertical tunnel.– Appropriate sounds for shaking, falling and breaking gold sacks must be played.– When a gold sack falls on a ghost, the ghost must die.– When Ghosts are dead they must attempt to return to the Ghost Healer.– When Ghosts collide with the Ghost Healer they must no longer be dead.– You must make, at a minimum, one extra level.– All files must compile and the game must run. Major Assignment: Clara Digger Game 3 Important note 1While in the past you only had to only work with the MyClara class, this time you will also have to edit the Ghost class and theGold class. The logic you put in these classes will control the corresponding characters in the game.Important note 2Do not let the following list of commands scare you, as they are further explained in the assignment brief and your tutors willhelp you to select those commands that you need for each task.Important note 3For this assignment you should no longer have a main loop (for or while) inside act(). Instead you should rely on executing act()repetitively (similar to how you did in Practical 2). The stop(); command MUST NOT be used in this assignment.Clara’s vocabularyFor this assignment, the following commands are available for Clara:Command Name Command Description Command Input Command OutputonEarth() Checks where Clara is ontop of an earth patchNothing. true if Clara is on top of anearth patch.false if Clara is not on top ofan earth patch.removeEarth() Removes the earth patchif Clara happens to standon top of one.Nothing. Nothing.getDirection() Gets which directionClara is facing.Nothing. A string which represents thedirection Clara is facing.“up” if Clara is facing uptoward the top of the screen.“down” if Clara is facingtoward the bottom of thescreen.“right” if Clara is facing to theright side of the screen.“left” if Clara is facing to theleft side of the screen.setDirection(string) Makes Clara face aspecific direction.It will not change herdirection if there is a treein the way.A String, which specifieswhich direction you wantClara to face.“up” – face toward the top ofthe screen.Nothing. Major Assignment: Clara Digger Game 4 “down” – face toward thebottom of the screen.“right” – face toward the rightside of the screen.“left” – face toward the leftside of the screen.Clara’s vocabulary – continuedCommand Name Command Description Command Input Command Outputmove() Makes Clara move onestep in the direction thatshe is facingNothing. Nothing.onGold() Checks whether Clara ispositioned on top of abroken gold sack.Nothing. true if Clara is on top of abroken gold sack patch.false if Clara is not on topof a broken gold sackpatch.removeGold() Collects gold if ClaraClara happens to stand ontop of a broken gold sack.Nothing. Nothing.animate() Clara continues heranimation by one frame.For more information, seethe section “Part 2 –Animating Clara’sMovement”.Nothing. Nothing.animateDead() Clara visually shows thatshe is dead.For more information, seethe section “Part 9 –Ghosts Colliding WithClara and Losing”Nothing. Nothing.onLeaf() Checks if Clara is on topof a leaf.Nothing. true if Clara is on top of aleaf.false if Clara is not on topof a leaf.removeLeaf() Clara removes a leaf thatshe is standing on.Nothing. Nothing.Will show an error if shetries to remove a leaf thatisn’t there.isClaraDead() Checks if Clara should bedead.Nothing. true if Clara should bedead. Major Assignment: Clara Digger Game 5 For more information, seethe function“makeClaraDead()” in theGhost’s vocabulary andthe section “Part 9 –Ghosts Colliding withClara and Losing”false if Clara should notbe dead.Clara’s vocabulary – continuedCommand Name Command Description Command Input Command OutputallLeavesEaten() Checks if Clara has eaten allof the leaves in the level.Nothing. true if there are no more leavesfor Clara to eat.false if there are still leaves forClara to eat.playCollectGold() Plays gold collecting sound. Nothing NothingplayLeafEatenSound() Plays the sound of Claraeating a single leaf.Nothing. Nothing.playIntro() Plays the digger introsound.Nothing. Nothing.isIntroStillPlaying() Checks if the digger introsound is still playing.For more information seethe section “Part 4 – EatingLeaves and Winning”Nothing. true if the sound is playing.false if the sound is notplaying.wrapAroundWorld() Enables Clara toautomatically move off oneside of the game, and endup on the other.Nothing. Nothing.getCurrentLevelNumber() Gets the number of thecurrent level.Nothing. An integer representing thecurrent level number.E.g. If the current level is 1,then it will return 1.advanceToLevel(char[][]) Changes the current gamelevel to the one specified. Ifit is sent null, then it willautomatically load the firstlevel.To see more information onhow to use it, see “Part 4 –Eating Leaves andWinning”For more information onmaking levels to send themethod, see “Part 12 –A level as per“Part 12 –Making andAdding Levels”,or null.Nothing. Major Assignment: Clara Digger Game 6 Making and AddingLevels”allGoldEaten() Checks if Clara hascollected all of the gold inthe level.Nothing. true if there is no more gold leftto be collected (unbroken goldsacks also count).false if there are still gold left tobe collected.Ghosts’ vocabularyFor this assignment, you will also be required to code new characters, ghosts. The ghosts pose a threat to Clara as she tries to eatall of her leaves and collect the gold. The ghosts try to prevent her from accomplishing this mission.The behaviour of each ghost is controlled by the act() method inside the Ghost class. Each of the ghosts in the game is essentiallyan instance of the Ghost class (we will learn about classes in Lecture 10 of the course).In order to assist you in programming ghosts there are Ghost commands already made for you. Some of these commands areexactly the same as Clara’s, some are slightly different, and some are completely unique to the Ghosts. Be sure to read thefollowing list of commands carefully:Command Name Command Description Command Input Command OutputearthFront() Checks if there is an earthpatch in front of theGhost.Nothing. true if there is an earthpatch in front of theGhost.false if there is no earthpatch in front of theGhost.earthAbove() Checks if there is an earthpatch above the Ghost.Note that this method isrelative to the screen, notthe Ghost. That is,regardless of the directionof the Ghost, an earthpatch that is above it, willalways be above it.Nothing. true if there is an earthpatch above the Ghost.false if there is no earthpatch above the Ghost.earthBelow() Checks if there is an earthpatch below the Ghost.Note that this method isrelative to the screen, notthe Ghost. That is,regardless of the directionof the Ghost, an earthpatch that is below it, willalways be below it.Nothing. true if there is an earthpatch below the Ghost.false if there is no earthpatch below the Ghost. Major Assignment: Clara Digger Game 7 earthToLeft() Checks if there is an earthpatch to the left of theGhost.Note that this method isrelative to the screen, notthe Ghost. That is,regardless of the directionof the Ghost, an earthpatch that is to the left ofit, will always be to the leftit.Nothing. true if there is an earthpatch to the left of theGhost.false if there is no earthpatch to the left of theGhost.Ghosts’ vocabulary – continuedCommand Name Command Description Command Input Command OutputearthToRight() Checks if there is an earth patchto the right of the Ghost.Note that this method is relativeto the screen, not the Ghost.That is, regardless of thedirection of the Ghost, an earthpatch that is to the right of it,will always be to the right it.Nothing. true if there is anearth patch to theright of the Ghost.false if there is noearth patch to theright of the Ghost.getDirection() Gets which direction the Ghostis facing.Nothing. A string whichrepresents thedirection the Ghost isfacing.“up” if the Ghost isfacing up toward thetop of the screen.“down” if the Ghostis facing toward thebottom of the screen.“right” if the Ghost isfacing to the rightside of the screen.“left” if the Ghost isfacing to the left sideof the screen.setDirection(string) Makes the Ghost face a specificdirection.The Ghost will not change to adirection that has a tree in theway.A string, which specifies whichdirection you want the Ghost toface.“up” if you want it to facetoward the top of the screen.Nothing. Major Assignment: Clara Digger Game 8 “down” if you want it to facetoward the bottom of thescreen.“right” if you want it to facetoward the right side of thescreen.“left” if you want it to facetoward the left side of thescreen.Ghosts’ vocabulary – continuedCommand Name Command Description Command Input Command Outputmove(int) Moves the Ghost at thespecified speed. Theghost will move in thedirection it is currentlyfacing until it hits anobstacle or until thedirection is changedAn integer, whichspecifies how fast youwant the Ghost to move.Nothing.goldFront() Checks whether there isa gold sack in front ofthe ghost.Nothing. true if there is a gold sack infront of the ghost.false if there is no gold sack infront of the ghost.animate() The Ghost continues itsanimation by one frame.For more information,see the section “Part 6 –Animating Ghost’sMovement”.Nothing. Nothing.animateDead() The Ghosts continuesits death animation byone frame.For more information,see the section “Part 10– Eating Mushroomsand Making GhostsEatable”Nothing. Nothing.intersectsWithName(String) Checks whether theghost intersects acharacter with a givenname. This is useful forchecking for intersectingwith gold.The name of theCharacter type (e.g.“Gold”).true if there the ghostintersects a character withthis namefalse if there is nointersection.getClara() Gets Clara. Nothing. Clara. Major Assignment: Clara Digger Game 9 Is to be used with the“isAboveMe”,“isBelowMe”,“isToMyLeft” and“isToMyRight”commands, explainedbelow.Ghosts’ vocabulary – continuedCommand Name Command Description Command Input Command OutputgetGhostHealer() Gets the Ghost Healer.Is to be used with the“isAboveMe”, “isBelowMe”,“isToMyLeft” and“isToMyRight” commands,explained below.Nothing. Ghost Healer.isAboveMe(Character) Checks whether the specifiedCharacter is above the Ghost.Clara or Ghost Healer. true if specified Characteris above the Ghost.false if the specifiedCharacter is not above theGhost.isBelowMe(Character) Checks whether the specifiedCharacter is below theGhost.Clara or Ghost Healer. true if specified Characteris below the Ghost.false if the specifiedCharacter is not below theGhost.isToMyLeft(Character) Checks whether the specifiedCharacter is to the left of theGhost.Clara or Ghost Healer. true if specified Characteris to the left of the Ghost.false if the specifiedCharacter is not to the leftof the Ghost.isToMyRight(Character) Checks whether the specifiedCharacter is to the right ofthe Ghost.Clara or Ghost Healer. true if specified Characteris to the right of the Ghost.false if the specifiedCharacter is not to theright of the Ghost.intersects(Character) Checks whether the specifiedCharacter is currentlyintersecting the Ghost.Clara or Ghost Healer. true if the specifiedCharacter is currentlyintersecting the Ghost.false if the specifiedCharacter is not currentlyintersecting the Ghost.makeClaraDead() Makes Clara’s“isClaraDead()” methodreturn true.Nothing. Nothing. Major Assignment: Clara Digger Game 10 For more information, seethe section “Part 9 – GhostsColliding with Clara andLosing”wrapAroundWorld() Enables the Ghost toautomatically move off oneside of the game, and end upon the other side.Nothing. Nothing.Gold’s vocabularyAnother class that you need to edit is the Gold class. This class helps you to control the behaviour of the gold sacks. Gold sacksmust start shaking once there is no earth underneath. Apart from shaking the corresponding sound must be played. After a fewseconds of playing the shaking animation, the gold sack must start falling. After falling to the ground, the gold sack must breakand reveal gold coins. Below are the commands available inside the Gold class:Command Name Command Description Command Input Command OutputplayBombTicking() Plays the bomb tickingsounds to correspond withgold sack shakingNothing. Nothing.getDirection() Gets which direction theGhost is facing.Nothing. A string which representsthe direction the Ghost isfacing.“up” if the Ghost is facingup toward the top of thescreen.“down” if the Ghost isfacing toward the bottomof the screen.“right” if the Ghost isfacing to the right side ofthe screen.“left” if the Ghost is facingto the left side of thescreen.setDirection(string) Makes the Ghost face aspecific direction.The Ghost will not changeto a direction that has atree in the way.A string, which specifieswhich direction you wantthe Ghost to face.“up” if you want it to facetoward the top of thescreen.“down” if you want it toface toward the bottom ofthe screen.Nothing. Major Assignment: Clara Digger Game 11 “right” if you want it toface toward the right sideof the screen.“left” if you want it to facetoward the left side of thescreen.Gold’s vocabulary – continuedCommand Name Command Description Command Input Command Outputmove(int) Moves the Ghost at thespecified speed. Theghost will move in thedirection it is currentlyfacing until it hits anobstacle or until thedirection is changedAn integer, whichspecifies how fast youwant the Ghost to move.Nothing.animateShake() Animate the shakinggold sack.Nothing. Nothing.animate() Animate with normalappearanceNothing. Nothing.animateFlip() Animate upside-down Nothing. Nothing.intersects(Character) Checks whether theghost intersects acharacter (e.g. Clara)The reference to thecharacter (e.g.getClara())true if there the ghostintersects a characterfalse if there is nointersection.playGoldFall() Plays the sound of agold sack falling.Nothing. Nothing.playGoldDrop () Plays the sound thatcorresponds to the goldsack touching theground after falling.Nothing. Nothing.removeSelf() Makes the gold sackdisappearNothing. Nothing.putBrokenGold() Makes the broken goldsprite appear.Nothing. Nothing.isAtBottom() Checks whether a goldsack moves past thebottom edge of theworld.Nothing. true if moved past the edge andfalse otherwisestopAtBottomEdge()Makes sure that the goldsack returns back to thebottom edge of theworld after moving pastit.Nothing. Nothing. Major Assignment: Clara Digger Game 12 Making the GamePart 1 – Moving Clara and keyboard inputTo start programming Clara, you must switch to the corresponding “MyClara” tab in your browser.One of your first tasks – is to learn how to process keyboard input of the player by using “Keyboard.isKeyDown(String)” method.Try passing the movement constants defined inside MyClara.java as input for “Keyboard.isKeyDown(String)” and see whathappens when you press the arrow keys. Try starting by using “System.out.println()” to print which of the keys was pressed tomake yourself familiar with keyboard input.Next thing for you to do – is to make sure that Clara can be controlled with the arrow keys. You may add extra functionality,such as controls for left-handed players, but that is not compulsory. You will need to use Clara’s “setDirection(String)” method,which can be sent one of the following commands; “up”, “down”, left” or “right” (a good idea is to use the same movementconstants defined inside MyClara rather than using those String literals inside your code). Passing the aforementioned Stringvalues to “setDirection(String)” method will set Clara’s direction to the command you specify.Once you’re able to process keyboard input and make Clara respond to it by turning in the right direction – now it’s time to makeClara move. In order to make Clara move, you will need to use the “move()” method like you did in your practicals. Clara mustmove every time the player presses an arrow key.Once you have made Clara move around, you might notice that Clara may occasionally disappear off the edge of the world. Itis important that Clara, and the Ghosts, at some point call the method “wrapAroundWorld()” to deal with this issue. This willenable them to reappear on the opposite side of the world that they disappear off.Gold sacks are Clara’s secret weapons against ghosts. Clara is able to push gold sacks around if there is an empty space next tothe gold sack in the direction of Clara’s movement. Clara can strategically dig tunnels and drop these on ghosts. Moving goldsacks will happen by itself when Clara moves towards them and the conditions are right (nothing is blocking the gold sack).Part 2 – Animating Clara’s movementIn order to animate Clara, you will need to call the “animate()” method. You may notice, that if you just call the “animate()”method, that it cycles through Clara’s animation very quickly. This is because every time the method is called, it advances Clara’sanimation to the next frame.You will need to figure out a way of not calling it every time the “act()” method runs, but every so many times that the “act()”method runs.HINT: If you are having trouble, try only calling “animate()” every second time the act method is called. Then try editing thatattempt to work only every third time the act method is called. It will ultimately be up to you to determine what looks best.Part 3 – Digging through earth patchesThe key game mechanic of the Digger game is digging through earth. You must program Clara to remove earth patches if shehappens to step on one.HINT: You will need to use the “onEarth()” and “removeEarth()” methods. Major Assignment: Clara Digger Game 13 Part 4 – Eating leaves, collecting gold and winning the gameClara will need to eat all leaves and all gold in her world in order to win. First, she must be programmed to eat leaves. If you areunsure of how to do this, please review practicals 1 and 2.Once you’ve got Clara eating leaves, you’ll need to play the right sound every time a leaf is eaten. To do so, you’ll need to callthe method “playLeafEatenSound()” at an appropriate point in your code.The next step is collecting gold. Gold can only be collected after the corresponding gold sack is broken. Breaking a gold sackinvolves digging under the gold sack and waiting for it to fall and break. You will be programming the gold sacks in part 5.Collecting gold is very similar to eating leaves. You will require the following methods: “onGold()”, “removeGold()” and“playCollectGold()”.When you have Clara happily eating leaves and collecting gold, you’ll need to check that all leaves have been eaten and all goldhas been collected. After this you must progress to the next level. You will need to use the “allLeavesEaten()”, “allGoldEaten()”,“advanceToLevel(char[][])” and “getCurrentLevelNumber()” methods. You will need to somehow check what the current levelis, and either advance to the next available level, or, if there are no more available levels, advance back to the first level again.Note that if you wish to return back to the first level, all you need to do is send LEVEL_1 or null to the“advanceToLevel(char[][])” method.Please note that actually adding levels to the “advanceToNextLevel()” method is covered in “Part 13 – Making and addinglevels”.Once you can advance to new levels or return to the first level after player completes it, it’s time to play the famous Digger intromusic at the start of each level. This music must continue playing until the end of the game, so you will have to keep restartingit.You will need to use the methods “playIntro()” and “isIntroStillPlaying()” for starting the music and testing whether it hasfinished playing or not.Note that after doing the above, you may wish to comment out the code that plays the intro music while testing the game(especially while working in the university computer lab) but remember to uncomment it and add it back in when you’re readyto submit.Part 5 – Programming gold sacksIn order to program the movement and breaking of the gold sacks you must work with the “Gold” class. This class is shown inthe corresponding tab in Clara’s World. Your gold sacks must operate in 4 different modes: normal, shaking, falling and broken.You will have to use variables for memorising the current mode and to decide how the gold sack must behave.Depending on its state, a gold sack must call one of the following methods to animate it:• animate() for normal animation of a stationary gold sack• animateShake() for animating the shaking of the gold sack before it starts to fall• animateFlip() for animating the falling gold sack.In the normal mode the gold sack must remain stationary. This mode is active when there is earth patch underneath the sack.Once the earth patch underneath disappears, the gold sack must switch into the shaking mode and must remain in this mode forabout three seconds. When shaking mode is activated, you must play the shaking sound using the “playBombTicking()” method.After spending three seconds in the shaking mode the gold sack must start falling. The process of falling is achieved by callingthe “move(int)” method. This method has the input parameter that specifies how fast the sack is falling. Before calling the Major Assignment: Clara Digger Game 14 “move(int)” method you should call “setDirection(String)” to specify the direction of movement. Once the falling mode isactivated, you must also play the falling sound with the help of the “playGoldFall()” method. The fall will stop as soon as thegold sack lands on an earth patch. You should consider adding the “wrapAroundWorld()” method inside “act()” to avoid fallingof the edges of the screen.Finishing the fall would result in activating the broken mode. In this mode the gold sack must disappear (you can make itdisappear by calling the “removeSelf()” method) and will be replaced by the broken gold object (coins) that can be collected byClara. The “putBrokenGold()” method should be used for creating the broken gold object. Activating the broken mode mustalso result in playing the corresponding sound using the “playGoldDrop()” method.Note that the Gold class is a subclass of Character. This means that it can use some of the basic functionality that Clara andGhost classes use. The two methods that you will find particularly useful are “setDirection()” and “getDirection()”. Using thesewill allow you to rotate a gold sack around and to sense its surroundings. The result of using the “setDirection()” method is notimmediately visualised. A good strategy for testing surroundings is to memorise the original direction of the gold sack, changeits direction to something else with “setDirection()”, check the surroundings with “earthFront()” and then change the directionback to what it originally was. This will make it possible for you to scan surroundings and, for example, decide whether it is timefor the gold sack to initiate the fall.Dropping the gold sack on Clara should result in Clara’s death and finishing the game. You should use the “intersect(Character)”method for testing whether a gold sack intersects with Clara. You would have to pass the instance of Clara to it, which can beobtained via the “getClara()” method. To signal to Clara that it’s time for her to die, you must use the “makeClaraDead()”method. This method will result in “isClaraDead()” method of Clara to return true. You should return to the MyClara class andmake sure that Clara is animated as dead (with “animateDead()”) when this method returns true.Dropping a gold sack on a ghost should also result in the corresponding ghost dying. It is, however, better to track intersectionsbetween gold sacks and ghost inside the Ghost class.On rare occasions there will be situations when the entire column, where the gold sack is located, is cleared of earth. Toprevent the gold sack from infinitely flying down this column and reappearing at the top, you should use isAtBottom() andstopAtBottomEdge() methods to make sure that in such situations the gold sack breaks when at the bottom edge of Clara’sWorld.Part 6 – Moving ghostsTo program the ghosts, you must edit the Ghost class. Switch to the “Ghost” tab in Clara’s World and start editing the code.Making ghosts move is very similar to making gold sacks move, but all your corresponding code must now be placed inside theGhost class. You will need to call the “move(int)” method and determine a suitable speed for ghosts. Note that they should movefaster than Clara.Don’t forget to call the “wrapAroundWorld()” method, so that ghosts correctly move after reaching the edge of the world.When moving around Clara’s World, ghosts must not walk through earth patches or gold sacks.Part 7 – Animating ghosts’ movementMaking the ghosts animated works in the similar way as animating Clara. The methods you call are exactly the same. Similarto Clara, you will need to figure out a way of calling the “animate()” method every so often that the act method is called, andthat it is up to you to determine how often they should animate. After a collision with a falling gold sack ghosts mush switchinto the dead state. While in the dead state ghosts must call the “animateDead()” method for showing the correspondinganimation. Major Assignment: Clara Digger Game 15 Part 8 – Ghosts and collisions with earth patches and gold sacksMaking ghosts detect that a stationary gold sack is in the way and stop, is achieved with the help of the “goldFront()” method.Detecting an earth patch in front is achieved with the help of “earthFront()”. Although, unlike Clara, there is no human playerto tell the ghosts where to go after they encounter an earth patch or a gold sack blocking their way. It is up to you to decide whatthey should generally do when they hit one.Note that telling the Ghosts where to face will involve using the “setDirection(string)” method, just like with Clara or Gold.It may assist your general ghost logic if you use the “getDirection()” method, which returns a string just like you would send the“setDirection(string)” method, and that the string will be either “up”, “down”, “left” or “right”. It is not necessary to use the“getDirection()” method, but you may find it helpful while testing and debugging your code.Whenever a ghost encounters an earth patch or a gold sack it is generally a good idea to turn around and start going in theopposite direction.Part 9 – AI and IntersectionsAn important part of making your Ghosts intelligent – is detecting an intersection and deciding which way to go. At anintersection ghosts must use a combination of random numbers (covered in the lectures) and chasing Clara. It is recommendedthat at every intersection the ghost walks towards Clara with a probability of 90% and picks a random direction with a probabilityof 10%. Combining random numbers with probabilities was covered in the lecture on random numbers.You will need to use the methods “earthAbove()”, “earthBelow()”, “earthToLeft()” and “earthToRight()” to detect anintersection.It should be noted that, unlike most sensor commands that you’ve used before, like “treeFront()” and “treeLeft()”, thesecommands are not relative to the direction that the ghost is facing, they are relative to the screen itself. This means that an earthpatch that is above the ghost, will always be above the ghost, regardless of which direction it is facing. This basic logic is true forall four aforementioned commands.Test them out in order to understand them. Drag one of the ghosts around and see what the result of calling those methods is.It should be noted that, for the most part, an intersection can be defined as a location where there are three or more directions togo to.HINT: You might want to check to make sure the ghost has passed the intersection it is currently at before running the code tochoose a direction at an intersection. (Otherwise, it might just hang around the same intersection and not go anywhere).For chasing Clara you should use the “isAboveMe()”, “isBelowMe()”, “isToMyLeft()”, “isToMyRight()” and “getClara()”methods to give them a 90% chance of moving in the Clara’s direction at every intersection. Note that the “isAboveMe()”,“isBelowMe()”, “isToMyLeft()”, “isToMyRight()” methods are further explained in the “Part 11 – Ghosts and regeneration”.Part 10 – Ghosts colliding with Clara and losingGhosts must pose a threat to Clara, and as such, they must kill her if they catch her. In order to do so, you will need to checkwhether they have collided with Clara. Checking for collisions can be achieved with the help of methods such as“intersects(Character)”, “getClara()” and “makeClaraDead()” inside the Ghost class. Clara will need to use the method“isClaraDead()” to signal that the game is over.It is important for the ghosts to be continually checking whether they have caught Clara, and it is important for Clara to checkwhether she is dead to prevent further movement and animation. Major Assignment: Clara Digger Game 16 Once you have Clara capable of checking whether she is dead, you will need to show the appropriate death image, with Clara’smethod “animateDead()”.It is also important that you stop processing keyboard input from the player at the point of Clara’s death.Note that Clara’s “animateDead()” method only contains one frame, and so it is acceptable to run it every time the act methodis called after Clara is dead.Part 11 – Ghosts colliding with falling gold sacks and dyingClara is able to kill ghosts by dropping gold sacks on them. From within the Ghost class it is possible to detect a collision with amoving gold sack via the intersectsWithName(“Gold”) method. It is recommended that ghosts operate in one of the two modes:dead or alive. Intersections with moving gold sacks should result in the corresponding ghost switching in the dead mode. In thedead mode ghosts must play the dead animation via “animateDead()” method.It is important to note that the Ghosts do not stop moving when they are dead, and that the Ghost’s “animateDead()” methodwill need to be run every so many times that the act method is called, just like the “animate()” method.It is also important that ghosts should not harm Clara when they are dead.When in the dead mode ghosts must return to the ghost healer for regeneration. It is acceptable for the ghosts to walk throughall objects such as earth patches, gold sacks, etc. when returning to the healer in the dead mode.Part 11 – Ghosts and RegenerationWhen a Ghost is dead, it will need to return to the ghost healer, which is shown as the red heart near where the ghosts start. Itwill be up to you to decide how they should logically make their way back to the ghost healer.You will need to use the “isAboveMe(Character)”, “isBelowMe(Character)”, “isToMyLeft(Character)”,“isToMyRight(Character)” and “getGhostHealer()” methods to make this happen.Note that the “isAboveMe(Character)”, “isBelowMe(Character)”, “isToMyLeft(Character)”, “isToMyRight(Character)”methods need to be sent a Character instance, and that only two are available to you, through the “getGhostHealer()” and“getClara()” methods. You will need to send those ‘get’ methods to the corresponding ‘is’ method in order to get an appropriateanswer.An example of how to use the above methods is below:“isAboveMe( getGhostHealer() );”If the above example returns true, then the ghost healer is above the corresponding Ghost class instance.Once a ghost returns to the ghost healer object, it will need to make itself no longer dead. You will need the“intersects(Character)” and “getGhostHealer()” methods to make this work.Hint: To avoid ghosts being stuck between 2 intersections – you may want to remember the direction the ghost came form (use“getDirection()” for this) before setting a new direction and don’t send the ghost to this direction again.Part 13 – Making and Adding LevelsIt’s time to understand how Clara’s world is designed in this game, and how to design and add your own levels. Major Assignment: Clara Digger Game 17 When you first opened up “MyClara”, you may have noticed the first level at the top of the code. This is the format you willneed to use in order to create your own levels. See the image below for what you should roughly see when first opening up“MyClara”.Figure 12.1 The first level is done for youYou will need to rename the level from “LEVEL_1” to “LEVEL_2”.You’ll notice that a level is simply an array of characters that visually represent the level that they make. The characters used areas follows:‘~’ represents an earth patch.‘.’ represents a leaf, which Clara needs to eat in order to progress to the next level.‘ ’ represents nothing, which is essentially an empty tile.‘%’ represents a Ghost. At least one must be present in every level you make.‘?’ represents a Ghost Healer, which the Ghosts return to when eaten in order to come back to life. At least one must be presentin every level you make.‘G’ represents a gold sack.‘@’ represents Clara, it is where she will start at the beginning of the level. Only one must be present in every level you make.The characters that make up the array of a level in Clara’s world each surrounded by single quotes (‘’) and the characters in asingle row are separated by commas (,).A single row in a level is surrounded by curly braces({}), and the end of a row of a level, that is not the end of the whole level, isindicated by a comma after the closing curly brace (},).This is all indicated in the image below. Major Assignment: Clara Digger Game 18 Figure 12.2 How a level of Clara’s world is constructed in an arrayNow you should have a rough understanding of how Clara’s World is constructed.In order to build your own level, all you have to do is delete all of the streets of the level and write your own level in there,following the above rules in order to present it and write it properly.Just in case you’re still unsure of what to delete before you write your own level, only delete the section as highlighted in thefollowing image.Figure 12.3 The part to delete to write your own level Major Assignment: Clara Digger Game 19 Then create your own level, in between the curly braces that are left after you delete what was highlighted.After you’re done, you’ll need to go to where you call the “advanceToLevel(char[][])” method and figure out a way of sendingit “LEVEL_2” when the player has finished “LEVEL_1”.Now add a new level and test it.To add another level, simply copy and paste “LEVEL_2” inside MyClara and change it to “LEVEL_3” and modify it just likeyou did for level 2.Add as many levels as you want, although technically you are only required to add one more level.Part 14 – Life is GoodNow tidy up your code, add more levels if you want, but be sure to properly comment what you’ve coded.You’re ready to hand in your assignment. Life is good! Submit all files to your tutor by 23:59 on Friday 4 June.Late penalties apply for submissions after the due date above (see learning guide).

QUALITY: 100% ORIGINAL PAPER – NO PLAGIARISM – CUSTOM PAPER

Leave a Reply

Your email address will not be published. Required fields are marked *