Results 1 to 5 of 5
  1. #1
    marksey07 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default urgent help please

    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;
    	}
    }
    this above is my code for a game, i have other classes that get hold of the map etc.

    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

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,759
    Rep Power
    7

    Default

    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.

    i want to use the print map function to alter the existing map
    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.

  3. #3
    marksey07 is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default

    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?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by marksey07 View Post
    thought urgent might catch people's eyes a little better. it managed to get you to reply, :p
    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."

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Quote Originally Posted by Junky View Post
    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.

    how about if the world is going to implode in 10 seconds? Urgent safe to use then? :D BTW, I wish there was a troll face.

Similar Threads

  1. [URGENT]SHA Encryption System...need urgent helps
    By java_idiot in forum New To Java
    Replies: 6
    Last Post: 05-02-2010, 10:04 AM
  2. Please Help me urgent help please
    By ravjot28 in forum New To Java
    Replies: 2
    Last Post: 01-30-2010, 01:59 PM
  3. Urgent Help!!
    By Winniee in forum New To Java
    Replies: 5
    Last Post: 02-17-2009, 03:32 AM
  4. very urgent
    By nehaa in forum Networking
    Replies: 12
    Last Post: 01-23-2009, 05:46 PM
  5. Hi, need some urgent help!
    By jdark in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 06:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •