Results 1 to 2 of 2
  1. #1
    afarag is offline Member
    Join Date
    Apr 2014
    Posts
    4
    Rep Power
    0

    Angry Battleship Game implementations

    I am very confused on how I can use this class:

    Java Code:
    public class Coordinate{
    
    	public int x;
    	public int y;
    	
    	public Coordinate(int x, int y){
    		this.x = x;
    		this.y = y;
    	}
    	
    	
    }
    I have to use this in an interface that we have to use in our project programming battleship in this code:

    Java Code:
    public Coordinate fire() {
    		// TODO Auto-generated method stub
    		System.out.println("Player, your'e up!");
    		System.out.println("Enter attack coordinates(X and Y): ");
    		System.out.print("X coordinate: ");
    		y = IO.readInt();
    		System.out.print("Y coordinate: ");
    		x = IO.readInt();
    		y = y - 1;
    		x = x - 1;
    		while (player2board[y][x] == 'H' || player2board[y][x] == 'M'){
    			System.out.println("Coordinate already used, please enter a new coordinate");
    			System.out.print("X coordinate: ");
    			x = IO.readInt();
    			System.out.print("Y coordinate: ");
    			y = IO.readInt();
    			y = y - 1;
    			x = x - 1;
    		}
    		
    		
    		;
    		return null;
    		
    		
    	}
    How would I use Coordinate in the second code?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default Re: Battleship Game implementations

    The Coordinate class is a place to save x,y values. Instead of having an x and a y value in the code, have an instance of the Coordinate class that holds those two values.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Battleship game
    By afarag in forum New To Java
    Replies: 3
    Last Post: 04-13-2014, 07:48 AM
  2. Help with battleship game, please!
    By goodvibes in forum New To Java
    Replies: 5
    Last Post: 07-25-2012, 11:04 AM
  3. Help with Battleship Game
    By Lucid15 in forum New To Java
    Replies: 59
    Last Post: 04-11-2012, 07:37 PM
  4. Battleship Game - really need help
    By thrashsynergy in forum Java Applets
    Replies: 5
    Last Post: 04-25-2011, 07:21 PM
  5. Battleship game
    By kathyla18 in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 09:42 PM

Posting Permissions

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