2/10/2024 0 Comments Minesweeper java code simple![]() Can I have some pointers on how to do this? import javax.swing.* When I click a button, it changes every button on the screen instead of just the one I clicked. Then, if you check the neighborhood of a field for mines, you don't have to check if you are off-limits because you have that safety border, and because these fields are always empty, your count is still correct.Īs a starting point, here is how I would start (without any user interaction or game loop, but with calculation and display done): import have to make a Minesweeper GUI, but I cannot figure out how to make each button have it's own mouseAdapter. Don't show them, don't allow the user to access them. your 10x10 field would become internally 12x12), which are empty. map = (num > threshold) ? 9 : 0 Īnd last but not least a common trick for board games: Surround your board with an invisible border of one field (e.g. learn to use the ternary operator, e.g.don't write int r, c at the beginning of the method, just initialize the vars in the loop: for(int c=.the Random object should be reused, make it a static member.That may be okay if you are a beginner, but if you know how to initialize objects, you should use that knowledge. This solution is not very object oriented.Random rand_obj= new Random() // use Random class to create a rand_obj If ((col_pick map.length - 1) || (row_pick map.length - 1) ) ("Which row and column to play? ( -1 to quit) ") ShowMap() // show current map (all hidden) Scanner kb = new Scanner(System.in) // keyboard input Int r, c // each 'row' & 'column' in 2-D array Public static int threshold = 6 // low threshold = more mines Public static int col_pick // column picked to play ![]() ![]() Public static int row_pick // row picked to play Public static boolean played = new boolean // played moves Public static int map = new int // mine field is 10 cells It's not fully completed but it would helpful to know if I am on the right track or completely off base with where I am at. I got my 1 dimensional program to work just fine so I figured I just need a few tweaks to get the 2D to work as well. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |