Results 1 to 2 of 2
  1. #1
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default Help with Grid Layout

    Hello, I'm trying to write a game in Java. The Sea Battle game where you should hit and sink the opponents ships...
    It has to be in a field 10x10 squares and i had written the code for a square.
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    public class Tile extends JButton{
    public Tile() {
    super("");
    }
    public void paintComponent (Graphics g) {
    g.setColor (getForeground());
    }
    }
    But i have know idea what to do next. I know I should put them in a Grid Layout, but how the hell should I program the ships?
    Thanks.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Here's an idea. Try drawing your grid in the paintComponent method of a JPanel, the sea, and drawing images of the ships in the grid cells. Keep a boolean array that matches the grid structure. You can set/change the boolean values for availability of targets. Use keyboard navigation to maneuver your ship among the cells, to rotate and to fire.

Similar Threads

  1. Object locations via grid coordinates HELP.
    By deadman_uk in forum New To Java
    Replies: 4
    Last Post: 11-18-2007, 08:32 PM
  2. Help creating a changing grid
    By adlb1300 in forum New To Java
    Replies: 11
    Last Post: 10-24-2007, 01:41 PM
  3. JGraph Layout Pro 1.4.0.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-31-2007, 06:43 PM
  4. Grid Resources for Industrial Applications 5.1
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-24-2007, 09:57 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
  •