Results 1 to 13 of 13
  1. #1
    tomitu is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default game board design

    I am trying to design a ludo game board but I cant seem to get the lines and rectangles to allign properly....also having problems making the lines bold enough....attached is the code i have so far. also attached is what the finished code is supposed to look like.....thanks people

    Java Code:
    package ludoboard;
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    
    
    public class LudoBoard extends JPanel  {
        private Color colors[] = {Color.WHITE, Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW};
        public LudoBoard()
        {
            setBackground(Color.WHITE); //set the background color to white
        }//end ludoboard constructor
    
        public void paintComponent(Graphics g)
        {//Call paintComponent to ensure panel displays correctly
          super.paintComponent(g);
    
          int width = getWidth();//total width
          int height = getHeight();//total height
          int dy = getHeight()/15;
          int dx = getWidth()/15;
          int xcounterpin = 0;
          int ycounterpin = (getWidth()* 2)/5;
    
    
          //draw the main blue square
          g.setColor(Color.blue);
          g.fillRect(0, 0, (width * 2)/5, (height * 2)/5);
    
           //draw the main red square
          g.setColor(Color.red);
          g.fillRect((width * 3)/5, 0, width, (height * 2)/5);
          
          //draw the main yellow square
          g.setColor(Color.yellow);
          g.fillRect(0, (height * 3)/5, (width * 2)/5, height);
          
          //draw the main green square
          g.setColor(Color.green);
          g.fillRect((width * 3)/5,(height * 3)/5, width, height);
    
          //draw the 4 white squares
          g.setColor(Color.white);
          g.fillRect((width/15), (height/15), (width/15) * 4, (height/15) * 4);
    
          g.setColor(Color.white);
          g.fillRect((width/15), (height/15) * 10, (width/15) * 4, (height/15) * 4);
          
           g.setColor(Color.white);
          g.fillRect((width/15) * 10, (height/15), (width/15) * 4, (height/15) * 4);
    
           g.setColor(Color.white);
          g.fillRect((width/15) * 10, (height/15) * 10, (width/15) * 4, (height/15) * 4);
    
    
    
    
    
    
      for (int xcounter = 0; xcounter < 6; xcounter++)
          {
              g.setColor(Color.black);
              for (int ycounter = 1; ycounter <= 3; ycounter++)
    
                  g.drawRect(xcounterpin, (height * 2)/5 , dx, dy * ycounter);
              xcounterpin += dx;
          }
    
          for (int xcounter = 0; xcounter < 3; xcounter++)
          {
              g.setColor(Color.black);
              for (int ycounter = 1; ycounter <= 6; ycounter++)
    
                  g.drawRect(xcounterpin, 0 , dx, dy * ycounter);
              xcounterpin += dx;
          }
    
    for (int xcounter = 0; xcounter < 3; xcounter++)
          {
              g.setColor(Color.black);
              for (int ycounter = 1; ycounter <= 6; ycounter++)
    
                  g.drawRect(ycounterpin, (height * 3)/5 , dx, dy * ycounter);
              ycounterpin += dx;
          }
    
          for (int xcounter = 0; xcounter < 6; xcounter++)
          {
              g.setColor(Color.black);
              for (int ycounter = 1; ycounter <= 3; ycounter++)
    
                  g.drawRect(xcounterpin, (height * 2)/5 , dx, dy * ycounter);
              xcounterpin += dx;
          }
    
        }//end method paintComponent
    }//end class LudoBoard
    Moderator Edit: code tags added
    Attached Thumbnails Attached Thumbnails game board design-ludo_big.jpg  
    Last edited by Fubarable; 02-27-2010 at 04:24 PM. Reason: Code tags added to help with readability

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

    Default

    I'm not sure if this matters, but you have a lot of int division going on that may not give you the precision you need, unless your JPanel/LudoBoard is has side lengths that are evenly divisible by 60 (since you have division by 4, 5, 10, 15). A 600 x 600 board looks pretty decent to my eyes.

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

    Default

    Please read what JavaRanch says about cross-posting without being forthright about it: BeForthrightWhenCrossPostingToOtherSites

    The same etiquette applies here and in the other programming fora.

  4. #4
    tomitu is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default

    but i wanted it set up in such a way that the columns are independent of the size and are instead a percentage of the what ever size is given...i dont know if that makes sense

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

    Default

    You may wish to address the cross-post issue first before any further discussion occurs. Please read the JavaRanch link that I've provided above. One thing you should do is to post links (or pseudo-links) in all cross-posts to each other will do.

    Edit: or not. So long.
    Last edited by Fubarable; 02-27-2010 at 05:03 PM.

  6. #6
    tomitu is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default

    I have posted a similar question on sun's website.....Anyone that was offended by my not disclosing the information, i apologize......Now having said that that, if there is any constructive criticism in regards to my code, i would really appreciate...thank you

  7. #7
    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 tomitu View Post
    I have posted a similar question on sun's website.....Anyone that was offended by my not disclosing the information, i apologize......Now having said that that, if there is any constructive criticism in regards to my code, i would really appreciate...thank you
    Please be careful here. If you volunteer here, you will understand the rationale behind this basic etiquette. Or you could read the link as it will explain. If you think that my pointing this out to you and thereby increasing your chances of getting help here and elsewhere (or visa versa) is not constructive, then I'm not sure what you might consider is helpful. You've already lost Darryl's post in the other forum but might get it back if you change your attitude just slightly. Or you could further argue this point and this thread will degenerate into nothing more than this argument. Up to you.

    Best of luck. Sincerely.

  8. #8
    tomitu is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default

    dude, lighten up, its my first time using a forum, i said i was sorry, i dont even know how to take down the thread on the other forum or else i would have

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

    Default

    So you've chosen to argue the point. Poor choice.

    Good luck.

  10. #10
    tomitu is offline Member
    Join Date
    Feb 2010
    Posts
    5
    Rep Power
    0

    Default

    dude, i posted the question on two forums, big f*****g deal. i have said i am new to using forums, have apologized for it. I dont think i have broken any laws of the universe. i think you need to get over it and move on

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,338
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by tomitu View Post
    dude, i posted the question on two forums, big f*****g deal. i have said i am new to using forums, have apologized for it. I dont think i have broken any laws of the universe. i think you need to get over it and move on
    And you should at least post the links to your crossposted articles in (all?) your crosspost(s). Just suppose some nice person and me post an answer to your question. You'd be so delighted reading one of the answers that you'd forget about the other answer; that is not fair towards the other poster who spends time answering (in vain). We're all volunteers you know, you can't treat us like resources.

    kind regards,

    Jos

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by Fubarable View Post
    You've already lost Darryl's post in the other forum but might get it back if you change your attitude just slightly.
    No chance of that now.

    db

  13. #13
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by tomitu View Post
    dude, i posted the question on two forums, big f*****g deal. i have said i am new to using forums, have apologized for it. I dont think i have broken any laws of the universe. i think you need to get over it and move on
    No way. Ask for a refund.

    Oh, wait, forum help's a freebie.

    db

Similar Threads

  1. how can I draw a board in 2d array?
    By java_fun2007 in forum New To Java
    Replies: 8
    Last Post: 12-28-2011, 05:58 PM
  2. Developing an Hex-board strategy game
    By abegade in forum Java 2D
    Replies: 8
    Last Post: 05-03-2011, 11:16 AM
  3. Game design & where and how i should learn it
    By helpisontheway in forum New To Java
    Replies: 9
    Last Post: 01-14-2010, 03:45 AM
  4. Replies: 6
    Last Post: 12-15-2009, 02:33 AM
  5. Programming a Board Game
    By makanti in forum New To Java
    Replies: 7
    Last Post: 03-10-2009, 02:32 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
  •