Thread: Battleship help

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    2

    Battleship help

    i need help on how to make my program read the col and how to place ships ..

    can anyone help here is what i have to work with.
    Code:
    public class Board {
    
    	// 0 = blank, 1 = "X", -1 = "O"
    	int grid[][];
    	String q = "  | A | B | C | D | E | F | G | H | I | J |";
    	String c = "  |___|___|___|___|___|___|___|___|___|___|";
    
    	Board() {
    
    		grid = new int[10][10];
    		for (int r = 0; r < grid.length; r++)
    			for (int c = 0; c < grid[r].length; c++)
    				grid[r][c] = 0;
    
    	}
    	
    	int getGrid(int c, int r) {
    		return grid[c][r];
    	}
    
    }
    
    
    
    	draw(human, comp);
    		input=IN.readLine();
    		int Variable = Integer.parseInt(IN.readLine());
    	}
    	
    	static void draw(Player P, Computer C) {
    		String eq = "  ========================================= =========================================\n";
    		String bar = "  _________________________________________ _________________________________________\n";
    
    		System.out.print("\t                       |  +_-_BATTLESHIP_-_+  |\n" + eq);
    		System.out.print("                   PLAYER                                   COMPUTER\n" + bar);
    	    String q ="  | A | B | C | D | E | F | G | H | I | J | | A | B | C | D | E | F | G | H | I | J |\n"+bar;
    		System.out.print(q);
    		String row = "  |___|___|___|___|___|___|___|___|___|___| |___|___|___|___|___|___|___|___|___|___|";
    
    		for (int r = 0; r < 10; r++) {
    			System.out.print((r + 1));
    			if (r < 9) System.out.print(" ");
    			for (int c = 0; c < 10; c++) {
    				System.out.print("| " + P.getMark(c, r) + " ");
    			}
    			System.out.print("| ");
    			for (int c = 0; c < 10; c++) {
    				System.out.print("| " + C.getMark(c, r) + " ");
    			}
    			System.out.print("|\n" +row+"\n");
    		}
    		
    	}
    	
    	
    public class Player {
    	Board fred = new Board();
    	Ship carrier = new Ship(5, "Aircraft Carrier");
    	Ship patrol =new Ship(2, "Patrol Boat");
    	Ship Cruiser= new Ship( 3, "Cruiser");
    	Ship Destroyer= new Ship(4, "Destroyer");
    	Ship Submarine = new Ship( 3, "Submarine");
    	// ships
    	
    	
    	char getMark(int c, int r) {
    		switch (fred.getGrid(c, r)) {
    		case 1:		return '*';	//hit
    		case -1:	return 'O';	//miss
    		case 50:		return 'A';//Aircraft Carrier 5
    		case 40:		return 'C';//Cruiser 3
    		case 30:		return 'D';//Destroyer 4
    		case 20:		return 'S';//Submarine 3 hits
    		case 10:		return 'P';//Patrol Boat 2 hits
    		default:	return ' ';
    		}
    	}
    }
    
    
    public class Ship{
    	String name;
    	int length;
    
    	 Ship(int L, String N){
    		length = L;
    		name = N;
    	 }
    	 
    	 int getLength() {
    		 
    		 return length;
    	 }
    	 
    	 String getName() {
    		 return name;
    	 }
    }

    Please help thanks in advance.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What is this? Some C++ .NET mix?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Looks like Java.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    12
    It's Java

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Battleship Game (Win32 EXP Needed)
    By ElWhapo in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 01-15-2005, 10:10 PM
  2. Battleship
    By mandingo in forum C++ Programming
    Replies: 7
    Last Post: 12-12-2004, 05:28 PM
  3. Battleship
    By luckygold6 in forum C++ Programming
    Replies: 25
    Last Post: 03-06-2003, 03:14 PM
  4. c++ battleship game
    By JTtheCPPgod in forum Game Programming
    Replies: 4
    Last Post: 01-05-2002, 11:12 AM
  5. Battleship
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 11-29-2001, 04:35 AM