CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Ryan Woodward
Level 3
Vancouver
  • 26.10.2020
  • 256views
  • 1comment

Runs in intellij, can't pass the verification though

Question about the task Minesweeper (Part 7/16)
Games,  Level 0,  Lesson 0
Under discussion

At this stage, we'll deal with the logic to reveal cells. Let's create a corresponding method and a variable that will store the cell state (revealed or hidden).

When revealing a cell, the method will:

- draw a mine in the cell if it contains a mine;
- display the number of mined neighbors if the cell does not contain a mine;
- mark the cell as revealed in the model;
- change the cell color.

For convenience, we suggest adding the mine symbol to a separate constant. When the a cell be revealed? Correct! When you click on it with the left mouse button. To handle this click event, the engine has a special method: onMouseLeftClick(int, int).

Let's override it in our class. It will call the method that reveals a cell.

And, of course, run the program and enjoy the results of your work.

Requirements:
  • The MinesweeperGame class must have a private static final String MINE field that is initialized when it is declared. For example, you can use the UTF-16 symbol for a bomb: "\uD83D\uDCA3".
  • The MinesweeperGame class must have a private void openTile(int x, int y) method.
  • The openTile(int, int) method must draw MINE if the gameObject at the passed coordinates is a mine. Use the setCellValue(int, int, String) method.
  • The openTile(int, int) method must draw the number of adjacent mines if the gameObject at the passed coordinates is not a mine. Use the setCellNumber(int, int, int) method.
  • The GameObject class must have a public boolean isOpen field.
  • The openTile(int, int) method should set the isOpen field on the gameField element equal to true and use the setCellColor(int, int, Color) method to draw the cell background. For example, using Color.GREEN.
  • The MinesweeperGame class must override the Game parent class's onMouseLeftClick(int, int) method.
  • The onMouseLeftClick(int, int) method must call the openTile(int, int) method.
package com.codegym.games.minesweeper; public class GameObject { public int x, y; public boolean isMine; public int countMineNeighbors; public boolean isOpen; public GameObject(int a, int b, boolean m){ x = a; y = b; isMine = m; } }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
horst
Level 26 , Not in list
27 October 2020, 09:02useful
Looks pretty good to me. One quick guess: In your openTile()-method, are you accessing your gameField-array at the right coordinates? You are creating your array with the y-value as the outer array (i.e. the vertical axis of your field) and your x-value as the position in your inner array (i.e. the horizontal axis). You do the same with i and j in your countMineNeighbors()-method. However, in lines 72 and 76 you are putting the x-value as the outer and the y-value as the inner array's position. Try swapping those two.
+1
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.