Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-12-2008, 03:09 AM
Member
 
Join Date: Feb 2008
Posts: 3
mars_red is on a distinguished road
Java Battleship Game Help PLEASE
i need help on how to make my program read the col and rows 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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with game applet in java barney Java Applets 3 02-13-2008 07:26 AM
Java BattleShip game help mars_red Advanced Java 0 02-12-2008 02:58 AM
Implementing "Game Over" in Minesweeper game based on Gridworld framework. JFlash New To Java 0 11-16-2007 01:02 AM
Help with java text game silvia New To Java 6 07-27-2007 08:58 PM
Help with my game in java lenny New To Java 1 07-23-2007 06:40 PM


All times are GMT +3. The time now is 12:56 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org