Results 1 to 8 of 8
  1. #1
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Question [suggestions] minesweeper

    hey guys!,Im new to this forum and it is great! :eek: .Just wanna ask some suggestions for my project.I am planning to make a game called Minesweeper.
    Minesweeper (computer game) - Wikipedia, the free encyclopedia
    so these are my thoughts: :rolleyes:
    1. i want to make my box/square a JLabel (a class that's extends a JLabel).
    2. each box has its own attributes/values (bomb, number/clue, etc...);
    3. and place those box object in a 2d array.

    questions:
    1. is it ok if i use JLabel instead of JButton for the box?
    2. is it the right thing to put those box into 2dimensional array,if not can u suggest a better one? :o
    3. how each box can communicate with their 8 neighbor boxes?

    hope you can help me.
    advance thankyou.

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

    Default

    Quote Originally Posted by temyong View Post
    questions:
    1. is it ok if i use JLabel instead of JButton for the box?
    It's OK to do anything you wish as long as you can get it to work. Myself, I used neither, but had my "box" be a JPanel that used a CardLayout. This way it could start out displaying a JButton but then after button press it would display a JLabel.


    2. is it the right thing to put those box into 2dimensional array,if not can u suggest a better one? :o
    Again, any data collection will do as long as you can get it to work well. A 2 dimensional array can work just fine for this.


    3. how each box can communicate with their 8 neighbor boxes?
    They don't have to communicate, really. All you need is that on set up (or re-set up), you iterate through the 2-D array and count all the neighbor bombs.

  3. #3
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    don't know 'bout Cardlayout but i'll try to study it,hm.. no i will study it for sure..
    anyway thanks for the reps Fubarable.

  4. #4
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    So i decided to make my box a JLabel with a CardLayout and things are going good i think so.
    But i am having a little questions in mind. Since each box has its own pictures like bomb, numbers, flag(for button),etc.
    Will it be much better if the box get those Icon in the main game object instead of having each Icon variable in its self, for a good memory management?
    for example:
    Java Code:
    //the main game
    class MineSweeper{
         Icon[] icon;//the icon variables are in the main game class
    
         //method to get icon from this object to the box
         Icon getIcon(int index){
    
              //return requested icon to the caller
    
         }
    }
    
    //the box
    class MineBox{
         //object of the current main game
         MineSweeper game;
    
         JButton b = new JButton();
         b.setIcon(game.getIcon(/*request number*/));//requesting in the main game
    }

  5. #5
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    hey guys i am almost done with my minesweeper game :D but :( im having a little problem with setting the gaps of my box. I want each of the box place in a greed and set its gap to 1pixel. but it turns out having a big gap..
    how can i set the gap of the grid to 1 pixel only? btw im using GridLayout.
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    public class Box extends JPanel{
    	public Box(){
    		setLayout(new CardLayout());
    			//first panel
    		JPanel card1 = new JPanel();
    		Icon buttonIcon = new ImageIcon(getClass().getResource("0.png")); // this image is 30X30 pixel
    		JButton button = new JButton(buttonIcon);
    		button.setIcon(buttonIcon);
    		button.setPreferredSize(new Dimension(30,30));
    		card1.add(button);
    			//second panel
    		JPanel card2 = new JPanel();
    		Icon labelIcon = new ImageIcon(getClass().getResource("1.png")); //same size
    		JLabel value = new JLabel(labelIcon);
    		value.setPreferredSize(new Dimension(30,30));
    		card2.add(value);
    		
    		add(card1, "first card");
    		add(card2, "second card");
    	}
    	public static void main(String[] args){
    		JFrame frame = new JFrame();
    		GridLayout frameLayout = new GridLayout(5,5);
    			//set gaps to 1 pixel
    		frameLayout.setHgap(1);
    		frameLayout.setVgap(1);
    		frame.setLayout(frameLayout);
    		for(int i=0; i<25; i++){
    			frame.add(new Box()); 
    		}
    		
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setVisible(true);
    	}
    }
    this is what ive done to my box.

  6. #6
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    any one?:o

  7. #7
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    i change my box to JLabel and it worked fine. :)

  8. #8
    temyong is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    I'm almost done with my minesweeper, one last thing is making timer.basically the timer starts at 1 up to 999. And these are my questions:
    1. What class should i use to make a precise time (like thread.sleep, or swing timer or so)?
    2. Would it be better if I make my timer a different class?
    hope you answer my questions.

    edit: i have manage to make it with javax.swing.Timer class but is it precise enough?
    Last edited by temyong; 12-30-2010 at 03:44 AM.

Similar Threads

  1. Looking for suggestions
    By tonino in forum New To Java
    Replies: 5
    Last Post: 09-26-2010, 07:17 PM
  2. urgent...minesweeper problem
    By neha_bat in forum AWT / Swing
    Replies: 8
    Last Post: 08-16-2010, 05:17 PM
  3. MineSweeper!
    By CrushOverwrite in forum New To Java
    Replies: 17
    Last Post: 02-24-2010, 02:34 PM
  4. Minesweeper problem! need help!
    By jeffrey in forum New To Java
    Replies: 1
    Last Post: 10-02-2009, 04:59 PM
  5. any suggestions?
    By PureAwesomeness in forum New To Java
    Replies: 4
    Last Post: 01-19-2009, 07:34 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
  •