Ask Computer Engineering Expert

Task:

You are to plan and then code the "True/False Game" as described by the information provided below. The assignment is worth 30% of your overall grade for CP1300. You are expected to work the assignment based on the following coding requirements and expected gameplay features.

Gameplay Features:

The "True/False game" is played on a 2D board of cells. The content of each cell is initially unknown by the player. The game is played by revealing the contents of each cell. A cell might be empty or contain a single flag. There are two types of flag: a true-flag, and a false- flag. A true-flag is a "treasure" the player wants to find, whereas a false-flag must never be revealed. Finding a false-flag causes the player to immediately lose the game. The player only wins the game if they reveal all cells except those that contain false-flags.

When a new game starts the board is initialised with a number of randomly placed flags. The number of flags depends on the difficulty level and the size of the board. So after the board is setup, some cells will be empty and some will contain a flag. There are 3 difficulty levels: "easy", "medium", and "hard". The board size is determined by a row value between 4 - 10 inclusive and a column value between 4 - 10 inclusive.

The number of flags assigned to the cells of a new board is decided as follows:

Difficulty level

Percentage of false-flags

Percentage of true-flags

Easy

5% of the board

1% of the board

Medium

10% of the board

5% of the board

Hard

20% of the board

10% of the board

Note: changing the size of the board does not change the difficulty level, and a new board must have at least 1 false-flag and 1 true-flag after it has been setup for gameplay.

During gameplay, the player is free to click on any cell on the board to reveal its content. Clicking on a cell that has already been revealed has no effect. If the player clicks on a cell that contains a true-flag then that flag is revealed (i.e. the player found a treasure). If the player clicks on an empty cell then all nearby cells that are also empty are revealed (we expect you to use a recursive method to implement this behaviour). Note: if the game is already over and the player clicks on the board then a popup message should be displayed to inform the player the game is over.

The player can change the size of the board at any time. When this happens, the game is restarted with a new board of randomly placed flags. Moreover, when the program is started the board should have 10x10 cells and the difficulty level should be "easy".

The Field class is used to represent the board. The Cell class is used to represent the cells in the board. The GameDisplay class is a resizable custom JPanel that displays the contents of the Cell objects currently on the Field. If a Cell object contains a flag then GameDisplay displays "T" or "F" for that cell depending on which flag the Cell object contains. If the Cell object does not contain a flag then GameDisplay will display a text string for that cell of the form "digit / digit". The first digit is the number of neighbouring Cell objects that contain false-flags. The second digit is the number of neighbouring Cell objects that contain true-flags. Let "neighbouring cells" be those that surround a particular cell on the board. Here is a simple example:

This board has 4x4 cells. The green cells are empty and have been revealed by the player. The light-grey cells have not yet had their content revealed. The dark-grey cells have been revealed and are empty but they have neighbouring cells that contain flags. Cells that display "1/0" have one neighbouring cell with a false-flag and zero with a true-flag. Cells that display "1/1" have one neighbouring cell with a false-flag and one with a true-flag.

2175_Figure.jpg

Note: more examples are available in the subject outline and a 10min screencast demo of the finished program.

So in this particular example, it is safe to click on the bottom left cell. Beyond that can you tell which other cells are safe to reveal? You should realise that it is possible for an empty cell to have between 0 to 8 neighbouring cells that contain flags.

Coding Requirements:

Your code must include the following classes:
- App - the main executable class. Use it to create and initialise the main program objects, and to control program behaviour.
- SizeDialog - a custom JDialog subclass that allows the player to change the size of the game board.
- MainFrame - a custom JFrame subclass that handles general setup, creation of the menu-bar, and the layout of the GameDisplay.
- GameDisplay - a custom JPanel subclass that displays the game board.
- Field - a class that models the game board as a 2D primitive array of Cell objects.
- Cell - a class that represents the contents of a single cell in the game.
- TestField - a class used to implement "manual unit testing" for Field and Cell.

Ensure that your assignment code covers the following list of requirements:
- Write your program using Java code that will work with JDK 1.7.
- Your code should have at least 2 packages to hold the classes.
- The App class should be placed in the default package.
- The source code text should have a consistent layout with respect to indentation and whitespace - making it easy to read.
- The code should include comments that help the reader understand the more complex parts of the code.
- A set of "manual unit tests" should be created that demonstrate the stability of the
Field and Cell classes.
- The names of variables in the code should be well-chosen so that they appropriately express the meaning of the values/objects they contain.
- Where appropriate, a class should use helper methods.

- The Field and Cell classes model the gameplay as defined above. Whereas the
GameDisplay class only visualises the gameplay.
- The menu-bar added to MainFrame should be provided that allows the board size and the difficulty level to be changed.
- The custom dialog class SizeDialog should be used to configure the size of the game board.
- Informative popup dialogs should be used to provide information to the player during game-play (don't use custom classes).
- The GUI should allow the player to click on cells to play the game.

Looking at a computer screen for hours does not help you solve coding problems. When dealing with a difficult part of the assignment, consider sketching your ideas on a piece of paper. This helps you develop those ideas without the distraction of writing code and thinking about syntax. Consider implementing the Field class using a primitive 2D array of Cell objects - nested for-loops will be useful. Also, nested for-each-loops are convenient for interacting with existing Cell objects. It's a good idea to pre-compute the count of nearby flags for each cell on the board. Helper methods come in handy for making code easier to understand and develop.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91984950

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As