Results 1 to 5 of 5
Thread: urgent help please
- 03-08-2011, 12:35 AM #1
Member
- Join Date
- Jan 2011
- Posts
- 12
- Rep Power
- 0
urgent help please
this above is my code for a game, i have other classes that get hold of the map etc.Java Code:import java.util.*; public class GameLogic{ Map m; Random gen; char[][] map; int x = 0; int y = 0; int collected = 0; int gold; public GameLogic(String file){ Map m = new Map(file); map = m.getMap(); gold = m.getGold(); startGame(); } private void startGame(){ System.out.println("Welcome"); setStartPoint(); print(map); } private void setStartPoint(){ gen = new Random(); Boolean isFree = false; int height = (map.length); int width = map[0].length; while (isFree == false){ int randomHeight = gen.nextInt(height - 1); int randomWidth = gen.nextInt(width - 1); if (map[randomHeight][randomWidth] != '#'){ x = randomHeight; y = randomWidth; isFree = true; } } } public void winCheck(){ if (collected >= gold && map[x][y]== 'E'){ print(map); System.out.println("YOU WIN THE GAME!!!!"); System.exit(0); } else return; } public int goldCollected(){ return collected; } public String returnGold(){ return String.valueOf(gold); } public char[][] returnMap(){ return map; } public void print(char[][] printMap){ char temp = map[x][y]; map[x][y] = 'P'; for (int i = 0; i< (printMap.length); i++){ System.out.println(printMap[i]); } map[x][y] = temp; } /****GAMELOGIC****/ public String commandHello(){ System.out.println("GOLD"); return ("GOLD " + gold); } public String commandPickup(){ if (map[x][y] == 'G'){ collected ++; return ("SUCCESS, GOLD COINS: " +collected); } else{ return ("FAIL"); } } public void moveNorth(char[][] printMap){ char temp = map[x][y]; if(map[x-1][y]!= '#'){ map[x][y] = '.'; map[x-1][y] = 'P'; for (int i = 0; i< (printMap.length); i++){ System.out.println(printMap[i]); } } map[x-1][y] = temp; } public char moveSouth(){ char pos = map[x][y]; if(map[x+1][y] != '#'){ pos = map[x+1][y]; return pos; }else{ System.out.println("Can't move into a wall"); pos = map[x][y]; } return pos; } public char moveEast(){ char pos = map[x][y]; if(map[x][y+1] != '#'){ pos = map[x][y+1]; return pos; }else{ System.out.println("Can't move into a wall"); pos = map[x][y]; } return pos; } public char moveWest(){ char pos = map[x][y]; if(map[x][y-1] != '#'){ pos = map[x][y-1]; return pos; }else{ System.out.println("Can't move into a wall"); pos = map[x][y]; } return pos; } }
basically, when run together it will print something like this:
#####
#......#
#..P..#
#......#
#...G.#
#####
but more ordered
hoping someone could show me how i can get the P to move north?
now this code prints out a new map with the P in the new position, but obviously if i was to tell it to move north again it wouldn't, as it would go back to working off the old map.
i want to use the print map function to alter the existing map with the P one place north, please help
- 03-08-2011, 12:49 AM #2
Why is it urgent? Is the world going to implode if you do not get an answer within 5 seconds? No, then it is not urgent. marking your posts as such is guaranteed to decrease your chances of getting help.
No you don't. All the print map method should do is print the map. All the logic to move the player should be elsewhere.i want to use the print map function to alter the existing map
- 03-08-2011, 12:56 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 12
- Rep Power
- 0
thought urgent might catch people's eyes a little better. it managed to get you to reply, :p
i'm sorry, but i have spent a lot of time on this, and can't get my head around what needs to be done.
surely at some stage I have to reprint the map, or are you saying I should create a tempMapPrint() method or something along these lines?
-
Many of us avoid answering posts marked "Urgent", myself included, because it implies that the post is more important than other posts here. Well it's not. If you really want to induce us to help, post a useful descriptive title. For more on this, please see this link: How to ask questions the smart way -- in particular the section marked "Don't flag your question as 'urgent' even if it is for you."
- 03-08-2011, 03:35 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Similar Threads
-
[URGENT]SHA Encryption System...need urgent helps
By java_idiot in forum New To JavaReplies: 6Last Post: 05-02-2010, 10:04 AM -
Please Help me urgent help please
By ravjot28 in forum New To JavaReplies: 2Last Post: 01-30-2010, 01:59 PM -
Urgent Help!!
By Winniee in forum New To JavaReplies: 5Last Post: 02-17-2009, 03:32 AM -
very urgent
By nehaa in forum NetworkingReplies: 12Last Post: 01-23-2009, 05:46 PM -
Hi, need some urgent help!
By jdark in forum New To JavaReplies: 2Last Post: 04-18-2008, 06:50 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks