Results 1 to 8 of 8
Thread: [suggestions] minesweeper
- 12-26-2010, 06:14 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
[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.
-
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.
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.2. is it the right thing to put those box into 2dimensional array,if not can u suggest a better one? :o
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. how each box can communicate with their 8 neighbor boxes?
- 12-26-2010, 02:06 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
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.
- 12-27-2010, 10:54 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
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 }
- 12-29-2010, 02:03 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
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.
this is what ive done to my box.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); } }
- 12-29-2010, 02:45 AM #6
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
any one?:o
- 12-29-2010, 04:57 AM #7
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
i change my box to JLabel and it worked fine. :)
- 12-30-2010, 03:10 AM #8
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
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
-
Looking for suggestions
By tonino in forum New To JavaReplies: 5Last Post: 09-26-2010, 07:17 PM -
urgent...minesweeper problem
By neha_bat in forum AWT / SwingReplies: 8Last Post: 08-16-2010, 05:17 PM -
MineSweeper!
By CrushOverwrite in forum New To JavaReplies: 17Last Post: 02-24-2010, 02:34 PM -
Minesweeper problem! need help!
By jeffrey in forum New To JavaReplies: 1Last Post: 10-02-2009, 04:59 PM -
any suggestions?
By PureAwesomeness in forum New To JavaReplies: 4Last Post: 01-19-2009, 07:34 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks