Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. /**
  5. * Write a description of class Swords here.
  6. *
  7. * @author (your name)
  8. * @version (a version number or a date)
  9. */
  10. public class Swords extends Item
  11. {
  12. // instance variables - replace the example below with your own
  13. private int dmg;
  14. ArrayList<String> swordNames = new ArrayList();
  15. HashMap<String,String> swordDesc = new HashMap<String,String>();
  16.  
  17. /**
  18. * Constructor for objects of class Swords
  19. */
  20. public Swords()
  21. {
  22. generateSwordName();
  23. super(getRandomSword(), "asd", 40, 40, "Item");
  24. dmg = generateRandom(2, 50);
  25. }
  26.  
  27. public int generateRandom(int Start, int End)
  28. {
  29. int START = Start;
  30. int END = End;
  31. Random random = new Random();
  32. long range = (long)END - (long)START +1;
  33. long fraction = (long)(range * random.nextDouble());
  34. int randomNumber = (int)(fraction + START);
  35. return randomNumber;
  36. }
  37.  
  38. public void generateSwordName()
  39. {
  40. swordNames.add("Blade of Slimer");
  41. swordDesc.put("Blade of Slimer", new String("Blade of Slimer is a sword forged from the waste of Slimer, surprisingly durable."));
  42. swordNames.add("Thorny Farris");
  43. swordDesc.put("Thorny Farris", new String("A rose thorn was accidently dropped into a bottle of Farris, and a majestic sword emerged from the bottle"));
  44. swordNames.add("The Sword of Leah");
  45. swordDesc.put("The Sword of Leah", new String(" A sword carried by the Leah family for generations, later given the ability to cut through magic."));
  46. swordNames.add("Grayswandir");
  47. swordDesc.put("Grayswandir", new String("A sword used by Corwin of Amber. Grayswandir is associated with the moon and the night."));
  48. swordNames.add("Werewindle");
  49. swordDesc.put("Werewindle", new String("A sword used by Brand of Amber. Werewindle is associated with the sun and day."));
  50. swordNames.add("Dull Sword");
  51. swordDesc.put("Dull Sword", new String("A dull sword"));
  52.  
  53. }
  54.  
  55. public String getRandomSword()
  56. {
  57. int swordSize = swordNames.size()-1;
  58. String randomSwords = swordNames.get(generateRandom(0,swordSize));
  59. return randomSwords;
  60. }
  61.  
  62.  
  63. /**
  64. * Skriver ut informasjon om itemet.
  65. */
  66. public void print()
  67. {
  68. int minDmg = dmg - 2;
  69. int maxDmg = dmg + 2;
  70. System.out.println("########################");
  71. System.out.println("# Name of item: " + super.getName());
  72. System.out.println("# Item description: " + super.getDesc());
  73. System.out.println("# Sword damage: " + minDmg + "-" + maxDmg);
  74. System.out.println("# Item value: " + super.getValue() + " coins");
  75. System.out.println("# Item weight: " + super.getWeight() + "kg");
  76. System.out.println("########################");
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement