/* ItemGenerator.java * this class contains a static method for creating items randomly */ import java.util.Random; class ItemGenerator { public static Item generate() { Random rng = new Random(); /* used to build the random items */ String[] weaponMats = {"Rusty Iron", "Iron", "Fine Iron", "Steel", "Fine Steel"}; String[] armorMats = {"Leather", "Rusty Iron", "Iron", "Steel", "Fine Steel"}; int[] armorWeights = {7, 19, 18, 15, 12}; String[] weapons = {"Dagger", "Short Sword", "Sword", "Long Sword", "Claymore"}; /* randomly choose a number 0 through 4 */ int choice = rng.nextInt(5); if (choice == 0) { /* weapon */ int material = rng.nextInt(5); int weapon = rng.nextInt(5); return new Item(ItemType.Weapon, weaponMats[material] + " " + weapons[weapon], weapon * 5 + 2, material * 7 + weapon * 3 + 3, material * 3 + weapon * 5 + 4); } else if (choice == 1) { /* armor */ int material = rng.nextInt(5); return new Item(ItemType.Armor, armorMats[material] + " Armor", armorWeights[material], material * 4 + 3, material * 5 + 6); } else { /* random thing */ String[] randos = {"Torch", "Lockpick", "Old Boot", "Broom", "Shovel", "Fork", "Quill", "Spoon", "Rake", "Brick", "Yarn", "Bowl", "Basket", "Vase"}; int weight = rng.nextInt(8) + 1; int value = rng.nextInt(7) + 1; choice = rng.nextInt(randos.length); return new Item(ItemType.Other, randos[choice], weight, value, 0); } } }