Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I might be wrong here (early in the morning...) but I'm guessing you always get the same <em>moves</em> and <em>points</em> value? This is because you are not increasing the values of the actual <em>moves</em> and <em>points</em>. When you send an Int as a parameter to a method you are not sending a pointer to the Int but a copy of it which will be used by the method and then removed when leaving it. You need to either return <em>moves</em> and <em>points</em> after increasing the values or put them as static attributes. Try doing it this way instead: </p> <pre><code>... moves = countMoves(String in, int moves); ... public static int countMoves(String in, int moves) { if(in.equals("left") || in.equals("right") || in.equals("up") || in.equals("down")) { moves++; } System.out.println("You have used " + moves + " moves."); return moves; } </code></pre> <p>Or you could increase them when identifying the moving direction (which is more efficient since you don't have to redo the check if the move was valid): </p> <pre><code>if (in.equalsIgnoreCase("up")) { rowNumber = rowNumber - 1; moves++; } ... </code></pre> <p><strong>EDIT</strong><br> Points Problem:<br> Since you didn't post how Room is implemented I just improvise, but I figure it should look something like this: </p> <pre><code>... points = countPoints(game[rowNumber][columnNumber].getObstacleNumber(), points); ... </code></pre> <p>and change countPoints() to:</p> <pre><code>public static int countPoints(int obstacleNumber, int points) { if(obstacleNumber == 0) points = points; if(obstacleNumber == 1) points++; if(obstacleNumber == 2) points += 2; System.out.println("You have obtained " + points + " points so far. Keep hunting!"); return points; } </code></pre> <p>or just (provided you know that the input is correct):</p> <pre><code>public static int countPoints(int obstacleNumber, int points) { points += obstableNumber; System.out.println("You have obtained " + points + " points so far. Keep hunting!"); return points; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload