Im wondering how i would go about using a bag in the game im making. The bag is supposed to hold 2 items that can be found in different rooms around the "map" and when both these items are found the game can be completed by finding the boss room. The bag is supposed to be its own java class. And how do i make the player activate these items?
rum4 and rum6 is the item rooms for anyone wondering.
(I dont want anyone to finish this game for me, i just want some help)
//Sorry for the swedish text.
//This is obviously not all of the code but the rest of it is not neccessary.
import java.util.Scanner;
public class Spel
{
public static void main(String[] args) {
Rum start = new Rum("Du är i en mörk och fuktig källare."," En källare. ");
Rum rum1 = new Rum("Du är mitt i en snöstorm!", "En snöstorm. ");
Rum rum2 = new Rum("Du hittade ett svärd!", "Ett hus. ");
Rum rum3 = new Rum("Du gick in i en fälla, slå över 3 för att fly norrut.", "En skog. ");
Rum rum4 = new Rum("Jaha... här fanns det ingenting.", "En äng. ");
start.north = rum1;
start.east = rum2;
start.south = rum3;
rum1.south = start;
rum1.east = rum4;
rum2.west = start;
rum2.north = rum4;
rum3.fälla = new trap();
rum3.north = start;
rum4.west = rum1;
rum4.south = rum2;
Rum current = start;
while(true) {
System.out.println(current);
System.out.println("Vart vill du gå? (n,s,v,o)");
char c = new Scanner(System.in).next().charAt(0);
switch(c) {
case 'n':
current = current.north;
break;
case 's':
current = current.south;
break;
case 'v':
current = current.west;
break;
case 'o':
current = current.east;
break;
}
if (current.fälla != null){
current.fälla.rulla();
}
// if (monster){
// System.out.println("Du kan nu döda monsteret");
if(current == null) {
System.out.println("Du ramlar av världen och dör †††");
System.out.println("Försök igen");
current = start;
}
}
I would create a class Bag with two Items
public class Bag {
Item item1;
Item item2;
}
public class Item {
<any item properties here>
}