logo

Assignment on Crafting

   

Added on  2019-09-30

6 Pages2073 Words332 Views
This program simulates the crafting of various items in games. That is given a number of different resources youcan consume them and create a new item. For example if you have wood and steel you can craft a sword. For the sakeof the assignment we consider all these things types of resources.We are going to simulate this by having a different type of object to represent each type of item along with thenumber of items. Each object will represent zero to many items of that type. We also have categories of resourcessuch as Weapons, Metals, Trees. For example Sword is a type of Weapon which in turn is a type of Resource. Crafting may require something specific such as Wood and Steel or it might require something of the same time. Eg Wood andMetal (eg can be Iron or Steel). Consequently, you must take this into account when you build your crafting table. Your basic approach is to have an Crafting Table Object which has a seperate method to represent each type of conversion. For example if you were to Craft a Sword you would call Craft with your Sword object followed by the ingredients in this case Iron and Wood. As long as you have more thanzero of both the ingredients Iron would be consumed and wood would be consumed and the number of swords increase by one.OutlineObviously there is a inheritance involved in this. Your assignment must follow the following rulesEverything that can be crafted or used in crafting must be a resourceThere are Weapon resources which are Anduril, Javelin's, Dagger's, EnchantedPoleArm's and SwordsThere are Metal resources which are Steel and IronThere are Tree resources such as Oak.All other resources are types of Resources and they are Dirt, Sand, Seed, Water and Wood. Metal, Tree and Weapon are also types of resourcesTable (crafting Table) is also a type of Resource.All resources have a nameAll resources should have a number on hand.There should be 21 classes in your implementation they will have at least (in addition to thosebelow) anduril (a legendary weapon), dirt, dagger, enchantedpolearm, iron, javelin, metal, oak, resource, sand, seed, steel, sword,tree, water, weapon and wood.Each resource should be able to return its name and number of resources of that typeEach resource should have a method to increase the number of resources and another to decrease the numberof resources. If you are out and try to use one it should throw an resource exhausted exceptionThere are three types of exceptions that can be thrown in this programoResourceExhausted. You attempted to consume a resource that had none available.oResourceNotEnchanted. You attempted to use a metal that wasn't enchanted where it was necessary.Every resource should be able to return true or false if the number of resources are zero.Weapons resources should have a min damage and max damage variableEvery resource should have constructors for number of resourcesMetals can be enchanted or not enchanted.

All variables and methods should have the appropriate visibilityAll resources should be able to be written to disk via a method call [ boolean saveToDisk(filename)] return true if successful.All resources should have a static method called [Resource readFromDisk(filename)] which will read a resource from the diskand return it to the callerAnduril (a legendary weapon) can only exist once so the increaseResource method can only increase to once. Further calls will not consume anymore resourcesand won't increase the weapon to more than one. The Anduril class should handle this internally.There should be a class Table (itself a Resource) and ResourceExhausted and ResourceNotEnchanted Exception class therest of the classes should be various resources.If you attempt to craft an item and any of your ingredients are out (eg number is zero) the method shouldthrow a ResourceExhausted Exception.Crafting should be done via a crafting table. The crafting table should have methods that acceptparameters to represent the different crafting recipes. The first parameter being the item beingcrafted the rest of the parameters being the ingredients.The following crafting recipes should be supported1.sword from iron and wood2.table from iron, wood, steel and sand3.dagger from steel4.wood from tree5.oak from dirt, seed and water6.enchantedPoleArm from any metal and sword (but only if the metal is enchanted)7.Andurilfrom an EnchantedPoleArm, sand, Seed and Steel8.Javelinfrom woodRequirementsHere are a list of requirements for your assignment.TestDriver class must work. This is designed to use your code.You must use inheritance where appropriatePush as much code up the inheritance structure as possible.You must use abstract where appropriateYou should write some testing to make sure your assignment works. You don't need to usejunithowever, whatever you write should do reasonable job of making sure your assignment works.Only import the needed classes in each classCreate aJpgimage of your inheritance diagram called inheritance.jpg make sure its included in the project atxt file with your testing outline called testing.txtClassjavadoc, Methodjavadoc, Instancejavadocand method body commenting

21 classes should be included in your workspace. Don't panic quite a few of themare only a few lines of code.Whatever you submit it should be compilable and runnable even if it doesn't do everything that is required.Suggested OrderThis is a suggested approach to doing your assignment.Create the packages (base package of unisa.pf.assign02. for the non resource classes, then a resourcesunisa.pf.assign02.resources package for all resources).Draw up the inheritance structure using this document and supplied code to give you clues.Create the missing files and get it to compile (even with empty classes).At each step think about testing and note down cases which could break your program/methodsGet the code commented and testedWrite missing methods so that the TestDriver class will compile.Get the code commented and testedTestingYou are to write a test outline of what you would test and how you would test it in your program. It is not necessary to code this just include a textfile (testing.txt). You should put in sections oneach classand under each class each method and the test cases you would test. You do not need todo junit testing for this assignment (I think you have enough to do without writing all that).Supplied CodeI have supplied you with a testDriver. You must use this code and you should also fully comment the code. I have also added the start of the Crafting Table. You will need to add code to this and createthe remaining classes.Final PartA perfect solution up to here will get you a Distinction. To get a HD you need to attempt the following section.My suggestion is get everthing else perfect and then do this bit last don't try it until everything else is done. Using varargs implement a method (findBestCraftableWeapon with varargs that will allow the callerto call with any combination of Objects find out what is the best weapon that could be crafted. The best weapon is defined as the most possible damage it can make.This is correct, we haven't spoken about varargs.this is a test of your ability to research a new language feature and useit.Hints. Implement a private method to help you search through thearglist for a resource The simplest (not the quickest) way to look for a resource type is by saying if (args[0].getName().equals("Wood")) {

End of preview

Want to access all the pages? Upload your documents or become a member.