Text based Game

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 2023 Views - Last Post: 11 October 2012 - 08:17 AM Rate Topic: -----

#16 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Text based Game

Posted 10 October 2012 - 05:10 PM

import java.util.Scanner;

public class Test
{
  public static void main(String args[])
  {
	  new Test();
  }
private int numofCaves= 0;

public Test() {
	 System.out.println(getNumofCaves()); // prints 0
	  setNumofCaves(10);
	  System.out.println(getNumofCaves()); //prints 10
}
  
  public int getNumofCaves() {
		return numofCaves;  // The return value is 0
	}
	public void setNumofCaves(int numofCaves) {
		this.numofCaves = numofCaves;// The return value is 10
	}
}



Worked perfectly fine for me. You are probably referring to these methods with 2 different objects that have different values for numOfCaves.
Was This Post Helpful? 0
  • +
  • -

#17 kendel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 04-October 08

Re: Text based Game

Posted 10 October 2012 - 10:45 PM

Got it thank you....
Was This Post Helpful? 0
  • +
  • -

#18 kendel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 04-October 08

Re: Text based Game

Posted 11 October 2012 - 08:17 AM

How you you use a comparison in MapHash. I am trying to write an if statement that says if the user enters a number, that has a value located in the current Selected key then output is true.

I am currently using -- protected static MultiMap caves = new MultiHashMap(); Which contains a <Key, Value> but every key has multiple values.

if(action.toLowerCase().charAt(0) == 'm' && gameMap.caves.get(Integer.toString(player.getCurrentCave()).contentEquals(target)){
				player.setCurrentCave(target);
				System.out.println("You are in room "+player.viewMap());	



That current if statement is wrong.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2