CSE 115 - Spring 2010 - Banner
UB -
University at Buffalo, The State University of New York Computer Science and Engineering
  • CSE 115 - Spring 2010
CSE 115 - Spring 2010 - Navigation
CSE 115 - Spring 2010 - Announcements

Lab 6

CSE 115 - Spring 2010 - Lab 6

Introduction

It's time to start thinking bigger. It's time to start thinking strategically. It's time for the home-stretch. Over the course of the next three labs, you will be building the implementation for a fully-playable game of battleship. The labs will build off of each other, but each will leave the game at a unique state.


Objectives

For the remainder of the semester, the labs will bring together everything we have covered so far and introduce some new topics. For this lab, we will focus mainly on topics we have already covered:

  • Composition Relationship
  • Association Relationship
  • Realization Relationship
  • Graphics Programming
  • User-interactive components

Lab Functionality Description

In this lab, you will create a user interface for the game of battleship. If you have never played the game before, please make sure to do so by travelling to this site which allows you to play the game for free.

For our version of the game, you will need to implement the following functionality. The look and feel of the game is totally up to you. Feel free to get creative with images and even theme. This game does not have to be battling ships, but could be anything you'd like.

You will be creating two main sections of the game, yours and the opponents. These sections can be on one frame or multiple frames, the choice is yours - you will drive the entire creative direction of this last project, we will only indicate functionality.

Message Section

There should be a place on the game where the game can give messages to the user. This can be a separate frame that is always visible or a JTextArea on the main screen that messages can be displayed upon.

Opponents Section of the Screen

On this section, you are expected to have two parts: an indication of how many hits are needed for you to win against your opponent, and a "board" where you can see the hits and misses you have accumulated as you play the game. The "board" is ten rows by ten columns for both players.

"Your" section of the screen

On this section, you are expected to have three parts: an indication of how many hits are needed for your opponent to win against you; a "board" where you can see where your ships are placed and where you can see what hits and misses your opponent has accumulated as you play the game; and a series of buttons that allow you to place your ships on your board (remember that ships are able to be placed vertically or horizontally).


Lab Tasks

Check out the lab skeleton.

Look at the files that are already in the skeleton and determine how you will use them as you complete this assignment.

Open the App class in the editor. You need to create an instance of your Game class from within the App where indicated.

Game is the class that will be in charge of creating all the graphics for the game. Game will act as a mediator between what the user sees on the screen and the game engine that will really be controlling how the game is working. Notice that Game implements the IGame interface. You are required to implement these methods for this assignment.

Note that Game has some instance variables, one of type IGameEngine. You will need to write a class that implements IGameEngine and create a composition relationship between Game and this new class using the instance variable given. An important design note as you proceed through this lab and the follow-on labs. While the game is processing user input and other game-play rules, it will be interacting with the game engine. The only object that will directly interact with the Game is the game engine. This means that you may need to add more methods to the IGameEngine interface to get this project working.

Recall from the section above the graphical components you will need to make sure are on your game. Work to make your Game class create those components and give them the look and feel you would like them to have.

The opponent's board and the player's board need to react when clicked upon. The reaction should call the appropriate methods of the game engine. These methods can simply write a message to the message area indicating that they have been clicked upon. Remember, these listeners should talk to the game engine.

Ship buttons

Create your buttons so that they react when clicked upon. The reaction for this lab should be that a message is placed in the message area about which button was clicked. You have the ability to place five different ships on the board. One ship that takes five hits to sink, one that takes four hits to sink, two that take three hits to sink, and one that takes two hits to sink. Remember that your button listeners should communicate with the game engine. You should work to create only one listener for all the shape buttons. Think about how you can parameterize the information that these listeners need to perform their jobs.

If you are interested in finding images for your ships, you should do so this week and save them into your Lab 6 project so that you can use them in the next stage.

Ship Holder

When the player selects a ship button, that ship becomes the "current ship" and will be the next to be placed on the board. Therefore, you will need to create a holder for the current ship. This holder will be able to set and get the current ship. You will need to create a "Ship" type in your project. It is most strongly recommended that you create Ship as an interface. You should consider how you will use this interface to create the different ships and how the buttons will eventually interact with the holder to set the current ship.


Due dates

You will submit your Lab 6 assignment using the Web-CAT submission plugin from Eclipse. Lab 6 is due the day before your recitation meets the week of March 29th. You will be using your Lab 6 code for Labs 7 & 8.


CSE 115 - Spring 2010 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184