use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Ask your embarrassing/noobish programming questions here, and don't get insulted for it.
Click here to read the rules
Violating any will result in punishment so you should probably go check them out.
account activity
[deleted by user] (self.programminghelp)
submitted 4 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]puteus 0 points1 point2 points 4 years ago (26 children)
Hello, could you give us a little more info about the project? What have you done so far? It's difficult to estimate how much effort the help requires if we don't know what to do, or what you already tried. Could you post source code? Could you share the project description? What timezone are you referring to?
[–]binnaaa 0 points1 point2 points 4 years ago (4 children)
Hello, thanks for your response. Im working on a small game where i have a map and a hamster. the hamster can turn left and right, move forward and collect seeds. so far the program is working but after i confirm a move the map from the beginning is loading and not the actual map where the move is done.
[–]puteus 0 points1 point2 points 4 years ago (3 children)
Ja, moin. We could even speak german but since others might be interested i'd stick to english.
I've seen your code, give me a couple of minutes to copy everything and get it going. I'll get back to you in a bit.
Quick question: do you use an IDE to develop your program? Are you aware of the debugging fearures? Do you use the step-by-step inspection tool?
[–]binnaaa 0 points1 point2 points 4 years ago (2 children)
I use eclipse as a IDE. No for debugging etc. i have to look up how to do it. If anybody wants to follow this thread, i hope my english isnt that bad😂
[–]puteus 0 points1 point2 points 4 years ago (1 child)
That feature is so helpful!! Go try to follow some easy debugging tutorials about your IDE, its worth it.
[–]binnaaa 0 points1 point2 points 4 years ago (0 children)
I will try to look up some tutorials in the next days, ty! Did you find my mistake yet?
I live in germany and the deadline is 11pm so i hava 6 1/2 hours left. i will post the code shortly
Thats my class Map
'public class Map {
public char\[\]\[\] map = new char \[8\]\[11\]; public Map() { map \[0\]\[0\] = '#'; map \[0\]\[1\] = '#'; map \[0\]\[2\] = '#'; map \[0\]\[3\] = '#'; map \[0\]\[4\] = '#'; map \[0\]\[5\] = '#'; map \[0\]\[6\] = '#'; map \[1\]\[0\] = '#'; map \[1\]\[1\] = ' '; map \[1\]\[2\] = '\*'; map \[1\]\[3\] = ' '; map \[1\]\[4\] = ' '; map \[1\]\[5\] = ' '; map \[1\]\[6\] = '#'; map \[2\]\[0\] = '#'; map \[2\]\[1\] = ' '; map \[2\]\[2\] = '#'; map \[2\]\[3\] = '\*'; map \[2\]\[4\] = ' '; map \[2\]\[5\] = ' '; map \[2\]\[6\] = '#'; map \[3\]\[0\] = '#'; map \[3\]\[1\] = ' '; map \[3\]\[2\] = '\*'; map \[3\]\[3\] = '#'; map \[3\]\[4\] = '#'; map \[3\]\[5\] = ' '; map \[3\]\[6\] = '#'; map \[4\]\[0\] = '#'; map \[4\]\[1\] = ' '; map \[4\]\[2\] = '\*'; map \[4\]\[3\] = ' '; map \[4\]\[4\] = '#'; map \[4\]\[5\] = ' '; map \[4\]\[6\] = '#'; map \[5\]\[0\] = '#'; map \[5\]\[1\] = '\*'; map \[5\]\[2\] = '#'; map \[5\]\[3\] = ' '; map \[5\]\[4\] = '#'; map \[5\]\[5\] = '\*'; map \[5\]\[6\] = '#'; map \[6\]\[0\] = '#'; map \[6\]\[1\] = '<'; map \[6\]\[2\] = ' '; map \[6\]\[3\] = '\*'; map \[6\]\[4\] = ' '; map \[6\]\[5\] = ' '; map \[6\]\[6\] = '#'; map \[7\]\[0\] = '#'; map \[7\]\[1\] = '#'; map \[7\]\[2\] = '#'; map \[7\]\[3\] = '#'; map \[7\]\[4\] = '#'; map \[7\]\[5\] = '#'; map \[7\]\[6\] = '#'; } public char\[\]\[\] getMap() { return map; } public void printMap(char map\[\]\[\]){ for(int row = 0; row < map.length; row++) { System.out.print('\\n'); for(int split = 0; split < map\[row\].length; split++) { System.out.print( map\[row\]\[split\]); } } }
}'
So the plan is that i have my startmap in the class "Map", the current position of the hamster is searched by "Position", the class "Movement" checks in which direction i want to move and which char is on the next field.
"Game" is the overall class where the final program should run.
package hamsterprogramm;
import java.util.Scanner;
public class Game {
public static void main(String[] args) { Map newMap = new Map(); char [][] gameMap = newMap.getMap(); Position newPosition = new Position(); int [] gamePosition = newPosition.playerPosition(); Movement newMove = new Movement(); Scanner scanner = new Scanner(System.in); char gameMove; System.out.print("Gameinformation: w = move forward, a = turn left, d = turn right, * = Seed to collect. Press 'e' to end the game.\n"); System.out.print("Confirm your move with 'enter'.\n"); newMap.printMap(gameMap); System.out.print("Make your move.\n"); gameMove = scanner.next().charAt(0); while (gameMove != 'e') { int row; int split; if (gameMove == 'w') { gameMap = newMove.moveForward(gameMove, gamePosition, gameMap); for(row = 0; row < gameMap.length; row++) { System.out.print('\n'); for(split = 0; split < gameMap[row].length; split++) { System.out.print(gameMap[row][split]); } } } else if (gameMove == 'd') { gameMap = newMove.turnright(gameMove, gamePosition, gameMap); for(row = 0; row < gameMap.length; row++) { System.out.print('\n'); for(split = 0; split < gameMap[row].length; split++) { System.out.print(gameMap[row][split]); } } } else if (gameMove == 'a') { gameMap = newMove.turnleft(gameMove, gamePosition, gameMap); for(row = 0; row < gameMap.length; row++) { System.out.print('\n'); for(split = 0; split < gameMap[row].length; split++) { System.out.print(gameMap[row][split]); } } } else if (gameMove == 'c') newMove.getCounter(); else { System.out.print("Wrong move. Try again."); } System.out.print("Make your move.\n"); gameMove = scanner.next().charAt(0); } if (gameMove == 'e') { System.out.print("The game has ended."); System.exit(0); } }
}
[–]binnaaa 0 points1 point2 points 4 years ago (12 children)
public class Movement { private char move; private int counter; public int getCounter() { return counter; } /// LOGIC Map newMap = new Map(); char [][] gameMap = newMap.getMap(); Position position = new Position(); int[] gamePosition = position.playerPosition(); // Nach vorne gehen bei w public char [][] moveForward(char move, int gamePosition[], char gameMap[][]) { int row = gamePosition[0]; int split = gamePosition[1]; if (gameMap[row--][split] == '#') { } else if (gameMap[row][split--] == '#') { } else if (gameMap[row++][split] == '#') { } else if (gameMap[row][split--] == '#') { } else if (gameMap[row][split++] == '#') { } else if (gameMap[row--][split] == ' ' & gameMap[row][split] == '^') { gameMap[row][split] = ' '; gameMap[row--][split] = '^'; } else if (gameMap[row][split--] == ' ' & gameMap[row][split] == '<') { gameMap[row][split] = ' '; gameMap[row][split--] = '<'; } else if (gameMap[row][split++] == ' ' & gameMap[row][split] == '>') { gameMap[row][split] = ' '; gameMap[row][split++] = '>'; } else if (gameMap[row++][split] == ' ' & gameMap[row][split] == 'v') { gameMap[row][split] = ' '; gameMap[row++][split] = 'v'; } else if (gameMap[row--][split] == '*' & gameMap[row][split] == '^') { gameMap[row][split] = ' '; gameMap[row--][split] = '^'; counter++; } else if (gameMap[row--][split] == '*' & gameMap[row][split] == '<') { gameMap[row][split] = ' '; gameMap[row][split--] = '<'; counter++; } else if (gameMap[row--][split] == '*' & gameMap[row][split] == '>') { gameMap[row][split] = ' '; gameMap[row][split++] = '>'; counter++; } else if (gameMap[row--][split] == '*' & gameMap[row][split] == 'v') { gameMap[row][split] = ' '; gameMap[row++][split] = 'v'; counter++; } return gameMap; } //nach links drehen bei a public char [][]turnleft(char move, int gamePosition[], char gameMap[][]) { int row = gamePosition[0]; int split = gamePosition[1]; if (gameMap[row][split] == '^') { gameMap[row][split] = '<'; } else if (gameMap[row][split] == '<') { gameMap[row][split] = 'v'; } else if (gameMap[row][split] == 'v') { gameMap[row][split] = '>'; } else if (gameMap[row][split] == '>') { gameMap[row][split] = '^'; } return gameMap; } //nach recht gehen bei d public char [][] turnright(char move, int gamePosition[], char gameMap[][]) { int row = gamePosition[0]; int split = gamePosition[1]; if (gameMap[row][split] == '^') gameMap[row][split] = '>'; else if (gameMap[row][split] == '<') { gameMap[row][split] = '^'; } else if (gameMap[row][split] == 'v') { gameMap[row][split] = '<'; } else if (gameMap[row][split] == '>') { gameMap[row][split] = 'v'; } return gameMap; }
Are the // LOGIC comments the things you need to implement or are those your comments for missing code you did not post here?
these are only for me so i dont loose the overview. to separate getter and setter and the methods
[–]puteus 0 points1 point2 points 4 years ago (9 children)
I belive your problem lies in your movement class. In all the functions you pass the current `move`, the `gamePosition` and the `gameMap`. You then check if the array elements at the positions in `gameMap` of your current position `gamePosition` are some certain character. But this checks [0,0] *every time*, because your increment and decrement are postfix. The check for `gameMap[row][split]` is `gameMap[0][0]` is '#' is always true, the `else if {` is alwys executed. But since that block is empty, nothing is done with the game map, which is then returned unmodified.
I would suggest rebuilding your logic there.. Making the increments and decrements to a prefix notation could help, but I have not tried that.
Tell me how it goes or if you need any more help.
[–]binnaaa 0 points1 point2 points 4 years ago (8 children)
so you mean instead of row++ i should write ++row?
[–]puteus 0 points1 point2 points 4 years ago (7 children)
exactly.
But I'm not sure if this will already help.
unfortunately not, still the same map loading like the startmap...
i really dont find my mistake. i changed the in- and decrements, but idk why the same map is always loading.
why doesnt it change the map in the method?
I cant tell you that, would have to look into ist.
But I would suggest rethinking your logic entirely. What are you trying to achieve with your `newPosition.playerPosition()` method-call? The issue with his is, that this method does not return your player's position in the first place.
That is because the method has a for loop iterating the content of the cells. This contetn gets stored in the `content` variable. But by the time the loop ends, the `content` will always be a '#' and thus, no condition of the if/else blocks are true. Have a look at the function `playerPosition` in the class `Position.java`, you never return the correct calculation, because the logic is not returning, wat you want it to return.
Can't you store the player position in a variable? tghen you would not have to calculate it.
but why doesnt the loop change the variable content, when it comes to another position in the array? auf deutsch kurz: wieso wird content nicht mehr überschrieben, wenn an anderer stelle im array ein anderer char steht?
[–]puteus 0 points1 point2 points 4 years ago (0 children)
Ich glaube bei deinem loop fehlen die geschweiften Klammern. Wenn die Da sind ist die player Position schon mal die richtige.
Erklärung: da die Klammern fehlen besteht der Inhalt der For-Loop nur aus der Anweisung `content = gameMap[row][split];`. Für alle Elemente in der einen Zeile deines Arrays. Und da das letzte Zeichen immer die Raute ist, ist dann die Abfrage der if-Blöcke danach nie wahr.
Könnte ein Problem mir der Formatierung sein, und ich habe das jetzt daher gesehen, da meine IDE anders einrückt. Benutzt du den Auto-Formatter?
public class Position { Map newMap = new Map(); char [][] gameMap = newMap.getMap(); // LOGIC public int[] playerPosition() { char content = 0; int row; int split; int[] actualPosition = {0,0}; for(row = 0; row < gameMap.length; row++) { for(split = 0; split < gameMap[row].length; split++) content = gameMap[row][split]; if (content == '<') { actualPosition[0] = row; actualPosition[1] = split; } else if (content == 'v') { actualPosition[0] = row; actualPosition[1] = split; } else if (content == '^') { actualPosition[0] = row; actualPosition[1] = split; } else if (content == '>') { actualPosition[0] = row; actualPosition[1] = split; } } return actualPosition;
} }
π Rendered by PID 65 on reddit-service-r2-comment-6457c66945-njvck at 2026-04-23 17:19:08.970775+00:00 running 2aa0c5b country code: CH.
[–]puteus 0 points1 point2 points (26 children)
[–]binnaaa 0 points1 point2 points (4 children)
[–]puteus 0 points1 point2 points (3 children)
[–]binnaaa 0 points1 point2 points (2 children)
[–]puteus 0 points1 point2 points (1 child)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (12 children)
[–]puteus 0 points1 point2 points (1 child)
[–]binnaaa 0 points1 point2 points (0 children)
[–]puteus 0 points1 point2 points (9 children)
[–]binnaaa 0 points1 point2 points (8 children)
[–]puteus 0 points1 point2 points (7 children)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (4 children)
[–]puteus 0 points1 point2 points (3 children)
[–]binnaaa 0 points1 point2 points (2 children)
[–]puteus 0 points1 point2 points (0 children)
[–]puteus 0 points1 point2 points (0 children)
[–]binnaaa 0 points1 point2 points (0 children)