Java Swing代写:FIT2034 Hunt the Snark

Introduction

用Java Swing作为GUI,按照所给的游戏逻辑编写一个名为Hunt the Snark的游戏。

Objectives

The purpose of this assignment is to assess your progress towards attainment of a selection of the learning objectives from weeks 1-11, and put into practice concepts learnt in semester on a single integrated problem.
On successful completion of this assignment you should have demonstrated that you are able to:

  • Write classes with instance and class-level attributes and methods
  • Encapsulate data, state information, and behaviours within an object.
  • Write programs consisting of multiple classes which interact to fulfill some functional specifications
  • Use a variety of API classes which perform input and output using files using a variety of techniques
  • Use ArrayList objects, to manage a simple collection of objects and/or primitive data values
  • Handle caught exceptions in an appropriate manner
  • Perform simple formatting of data for output
  • Create a GUI for the user to interact with
  • Understand the importance of separating business logic from GUI code.

Overview of Assignment Task

For this assessment you will be creating a simple game called Hunt the Snark. In Hunt the Snark the player must hunt for a creature known as the Snark.
This creature is a vicious beast that roams the swamplands of Seaford. In order to aid in the hunt for this beast you have been given a number of chances to successfully guest the location of the Snark within the swamp. After each shot you are provided with feedback as to how accurate your aim was.

Submission Requirements

Assignments are to be submitted via Moodle on or before the due date (See front page).
You must create a ZIP file containing the entire eclipse folder. In addition to the application itself, the submitted project folder should also include a ReadMe file and a UML Diagram outlining all classes in your project and their relationships.
The ReadMe file should contain information on any additional features you have chosen to include. It should also include references to any externally sourced code or images in the application.
(NOTE: If you choose to use externally sourced code you will be required to attend an interview with your tutor to show that you understand how the code works and be able to make modifications to it based on differing requirements)
Failure to reference any assets or code that is not your own will result in an immediate mark of 0 for the entire assignment. Should there be any concerns with this you may be asked to attend a follow up interview after submitting your assignment should it be deemed necessary by the marking staff.

Graphical User Interface

The application Hunt the Snark should contain AT MINIMUM 2 user interface screens. These screens are the options screen and the main game screen. These are detailed below.

Options Screen

(Example GUI. You can design your own)
The options screen is the starting screen of the game. When the application launches this screen will appear and ask the user to select a number of gameplay options before continuing to the game proper.

Required Features

  • Ability for user to enter a name to use during the game
  • A drop down list to select the size of the swamp to search (Minimum 5, 7 & 9)
  • 3 Radio Buttons in a group to select the number of Snarks present in the swamp (1, 3 & 5)
  • A checkbox to indicate whether or not to start the game with additional items enabled (Should default to yes)
  • A button labelled “Load” that loads previous player data (If present) and changes the above UI elements accordingly
  • A button labelled “Play” that takes the player to the main game screen. This should include validation to ensure that the user has actually entered options for everything above.
  • Labels to indicate what each of the options are
  • Clicking the close window button (Default Windows or OSX one) should exit the application correctly.

Suggestions for Optional features (You can have different ones if you want)

  • Give the user the ability to choose the location & file to load player data from

Main Game Screen

(Example GUI. You can design your own)
The main game screen is the screen where the game itself will take place. When the main game screen first opens the user should click on the “New Game” button to initialize the game grid (Top-Left). Once this is done the user can then start clicking on the swamp to find the Snark.

Required Features

  • A grid of buttons each representing part of the swamp. The user will click on these to see if the Snark is hiding under them.
    • These should have an image depending on the state of the grid (Un-searched, Snark found, item found, etc)
    • Once clicked once the user should not be allowed to click the same button again
    • Clicking an empty grid button should decrease the number of shots a player has
  • A “Name” label to show the current player’s name
  • A “Snarks Caught” label indicating the number of Snarks that have been caught this round.
  • A “Clue’s” Text area that displays current and previous clues to the player (Hint’s to location of the Snark)
  • A “Options” button to bring up the Options Screen again (Does not have to save state of this screen)
  • A “Save” button to save the current player instance (Primarily preferences) for use in another round.
  • A “New Game” button to start a new game of Hunt The Snark

Suggestions for Optional features (You can have different ones if you want)

  • Give the user the ability to choose the location to save to
  • Include a compass image for representing location of Snark relative to the player’s position

Game Logic (Typical Run of the Game)

  • Options menu loads up upon first opening the game
  • User must enter a name or hit the load button to load up previous save. (Other options will have default values)
  • Clicking the “Play” button will close the Options screen and open the Main Game screen.
  • User clicks “New Game” button to begin the game (Initializes Game Grid)
  • User clicks on a button in the game grid. A check is made to see what kind of Game Grid it is (Item, Snark, Hint, Empty)
    • If not a Snark then directions are shown pointing to the nearest Snark (North-West, South, etc.)
    • Ammo should be deducted only if the grid is empty (Snark, Item, Hint do not use ammo)
  • If all the Snarks are caught the user is told they have won and must click new game to start a new round
  • If the user runs out of ammo they are then told they have lost and must click new game to start a new round
  • Clicking the “Save” button will save the current Player Data and Preferences to file

Required Classes

At minimum your project should contain the following classes. You can contain as many as you feel are appropriate

Options GUI

  • GUI Class for the options menu
  • Contain references to all required UI elements and classes
  • Handle input & output
  • Pass data onto appropriate classes (Preferences & Player)

Main Game GUI

  • GUI Class for the main game menu
  • Contain references to all required UI elements and classes
  • Handle input & output
  • Interact with Game Controller to control game state

Game Controller

  • Contains core game logic
  • Contains 2 Dimensional Array of GameObjects (The Game Grid)
  • Contains reference to Player Object
  • Contains reference to ItemFactory (See below)
  • Method for generating a new GameGrid and populating it with required GameObjects
  • Handles checking if the selected GameGrid contains something (Snark, Item, Empty)
  • Handles saving Player Object to file

ItemFactory

  • Loads up list of bonus items from text file
  • Creates an ArrayList of GameObjects loaded from a text file (See below)
  • When given a random number will return a COPY of the object at the specified index

Preferences

  • Holds preferences for the current user (From options menu)
  • Implements Serialiazable
  • Contains grid size
  • Contains default number of snarks present
  • Contains whether or not bonus items are available

Player

  • Holds current Player’s name and Preferences
  • Implements Serializable
  • Contains Player Name (String)
  • Contains Preferences

GameObject

  • Base class for all objects used in GameGrid (Snark, Item, etc).
  • Contains enum of GAMEOBJECT_TYPE

Snark

  • The Snark(s)
  • Extends GameObject
  • Sets enum to SNARK

Bonus Item

  • Bonus Items that can be found
  • Extends GameObject
  • Sets enum to BONUS_ITEM

Ammo

  • Item that grants player additional ammo upon finding
  • Extends Bonus Item
  • Contains number of extra shots

Cannon

  • Cannon that grants the player a slash shot (Hits multiple grid squares)
  • Contains number of blast radius (Number of squares surrounding shot)

Hint

  • A hint to the player pointing towards either a Snark or Bonus Item
  • Extends GameObject
  • Sets enum to HINT
  • Contains the type of hint (Item or Snark)

Snark Nest

  • A nest of Snarks. Hitting this causes more Snarks to appear
  • Extends GameObject
  • Sets enum to SNARK_NEST
  • Number of Snarks to release

Loading Items from File

You project must contain the ability to load up a list of objects from file. These objects include but are not limited to Snark Nests, Hints, Ammo and Cannons. Each of these items should be unique and when loaded from file should be placed into an ArrayList of GameObjects. All bonus items within the actual game will come from this List (Copies not references). A single run of the game does not need to have ALL items on the game grid (Can contain multiple of the same bonus item)
The base for the Item File is included below. You need to include at minimum these items but you can add as many as you feel necessary.

SNARK_NEST,1
AMMO,5
AMMO,1
AMMO,3
CANNON,1
CANNON,3
HINT,SNARK_HINT
HINT,ITEM_HINT

The code for loading in the Item List will be robust enough and contain error handling to deal with the different kinds of variables on each line.

Project Design

During the creation of this assignment you must ensure that you adhere to a number of coding requirements. These requirements are:

  • The GUI code and Logic code MUST be separated
  • Your program must make use of Inheritance and Polymorphism (Some suggestions below)
  • Your program must use Exception Handling and contain appropriate validation
  • You should make appropriate use of 2 Dimensional arrays and ArrayLists