CIS 110 Project

This project is REQUIRED/MANDATORY/COMPULSORY. You cannot drop your project score and you cannot use any late days on this project.

PROJECT DESCRIPTION


Important Note: Late days applied only to homework assignments; you may not submit the Project late. No exceptions.

A. Goals

This is a closed-ended project that provides you the opportunity to apply everything you have learned in 110 to one of the options below. You will be responsible for choosing one of the four given problems, analyzing that problem to determine how to solve it, decomposing the functionality of your program to identify its class structure and the API for each class, and then implementing and testing your program.

You are not permitted to work with a partner on this project.

Start early and reach out to the Instructors/TAs if you have any questions or concerns.

You may be tempted to use code directly from the internet or use such code as a base template. Please do not do so. We are extremely adept at catching such cases and strict action will be taken.

B. Project Organization

CIS 110 is an Introduction to programming in Java course. Java is by definition an object-oriented programming class. The purpose of this project is for you to demonstrate everything you have learnt in this class - with an emphasis on object-oriented programming. All of the project idea choices that you have are games that require object-oriented structure. When approaching this assignment, it will be very useful to refer back to the Snake and Tetris games that you created with Dr. Eaton in class.

C. Project Ideas

Your project must implement one of the following 4 ideas. You should look at the individual tabs for more information. Done properly, all of these ideas should have the same level of difficulty. In any case involving a cpu player, your A.I. strategy does not have to be complex and can be simply randomized.
  1. Battleship: implement a battleship game against a computer.
  2. Connect4: implement the game Connect4, with both a 2-player mode and a player vs. computer mode.
  3. 2048: implement 2048 player game using keyboard controls.
  4. Hangman: implement a game of Hangman without the visual component.

Battleship

In this project, you will implement a Battleship game.

Battleship is a board game involving a grid. Players begin by placing their ships onto a square 10x10 grid. Once the placement is over, players take turns guessing the opponent's grid squares onto which to fire. By hitting all of the grids of an opponent's ship, you will sink her ship. Guesses are of the form A-0 or J-9.

You must have one of each of the following five types of ships -

  1. Carrier - It must occupy 5 grid squares in sequence.
  2. Battleship - It must occupy 4 grid squares in sequence.
  3. Cruiser - It must occupy 3 grid squares in sequence.
  4. Submarine - It must occupy 3 grid squares in sequence.
  5. Destroyer - It must occupy 2 grid squares in sequence.

Your game does not have to look like the one above. To make it simple, you don't have to use images of the above ships on the grid. It is fine to use a simple shading along with a label - each shaded grid square of the ship should have a single letter in it, so "CARRI" would be placed in each of the fives squares belonging to the Carrier, "DE" for the Destroyer and so on.

Your battleship game must be one player so it will involve a simple cpu player. The simplest approach is to make the A.I. randomize so that it guesses randomly at grid squares and places its ships randomply as well. Feel free to make the A.I. more complex if you want.

Requirements -

  • Your game should contain 2 10x10 grids. One is the opponent's and the other is your own. (Look at the wikipedia link for more clarification). You should also have two lists of ships for both players, showing which ships which player has left.
  • It should be single player and have an A.I. player
  • Your game can either take input by clicking on the required grid or taking keyboard input.
  • The game should begin with a placement process where the user gets to place her ships and the A.I. does so randomly. The user's ships are shown on her grid but the other grid is empty since we should not know where the A.I. has hidden its ships.
  • After the placement process is the attacking process. Each player takes turns guessing which grid to fire at. The game should keep track of the attack history. It will show red squares for a miss and a green square for a successful hit. You should not be allowed to attack the same square twice.
  • Once you have sunk an opponent's ship the corresponding ship should be eliminated from the list of remaining ships for the opponent. The same is true if the opponent sinks your ship.
  • Once either side has sunk all of the opponent's ships, you must display an appropriate victory message and ask if the user wants to restart.

Connect 4 is a classic board game where two players (typically "red" and "yellow" or "red" and "black") take turns dropping disks in a grid of 7 columns by 6 rows. The discs fall to the lowest empty space in their column (possibly landing on top of other pieces). The winner of the game is the first to have 4 discs of their color in a row. This can be horizontally, vertically, or diagonally.

If you are unfamiliar with the game, this video should help out. It talks about how Connect Four is a solved game, and if you played against a correctly programmed computer who goes first, you will always lose.

In this program, you must program a Connect 4 game that uses mouse clicks as input that has both a 2-player mode and a 1-player mode. When your program starts, the game should have some start screen where the player can select either 2-player mode or 1-player mode using mouse clicks.

Players will interact in the game using mouse clicks. If a player clicks in a column, it should drop a piece into that column if possible. However, if the column is already full, the player cannot drop a piece in that column, nothing should happen (your program must not crash here). Once a player has successfully played a piece, their turn is over. The game should check if the move created four-in-a-row of the same color. If it has, the game is over, and your game should print the winner. If not, it should simply pass the turn to the other player.

If all 42 spaces in the grid are filled, the game is a draw, and no one wins. Below is an example of a draw.

In the 2 player mode, players will use mouseclicks to select which column they wish to drop their piece in and end that players turn. The game should then prompt that it is the others player turn. The game should clearly indicate which players turn it is using their disc color (for example, you could have text saying "It's reds turn"). The turns should go back and forth until the game ends.

In 1 player mode, the player can play against an automatic opponent that you program. This does not have to be a "good" AI, just some process by which moves are taken automatically without player input. The game should randomly decide to have either the human or the computer go first (since moving first is a big advantage). From there, the game proceeds until it ends.

In either case, when the game ends, the game should show some text indicating either who won or that the game was a draw. The game must then return to the "start" screen, where a player can once again choose either 1-player mode or 2-player mode.

Tips

Do not spend a lot of time working on the AI until after your program is working. You will not get extra credit if your AI can beat the instructor, though it can be fun to try. Focus on getting the game working first with 2 players.

Look back to HW01's StampSketch.java if you need a refresher on how to get the location of a mouse click.

Consider what objects you can use, as well as what functions you can use, to represent the board.

A. 2048

For this option you will be implementing the highly addictive (at least for me) 2048 game. Here is a link to a description of the game.

The best way to understand the game is to play it yourself. You can easily download it on your phone's appstore or google for a playing version online.

Requirements -

  • The user's screen should be a 4x4 grid. Each square on the grid either contains a number tile or not.
  • The user presses one of four keys - w, s, a, d which represent the directions up, down, left, right. All the current tiles on the board shift to the direction specified by the user's key press. If a number tile "crashes" into another tile with the same number - then they merge to form a single tile with twice the value.
  • During every turn, a new number tile consisting of 2 or 4 should enter the board. The tile must enter at any random, unoccupied position on the board.
  • If the grid is full of number tiles and there is no move possible for the user then the game is over. If the user has managed to bring a 2048 tile onto the board (by merging 2 1048 tiles) then the user wins.
  • The game should keep track of the number of moves made by the user and output this in the victory/defeat message.

Hangman is a vocabulary game. A link to the game is here.

Requirements -

  • The first step of the game consists of selecting a word. Here, the user should be provided with two options - either pick a word at random or let someone else manually enter a word. In either case the list of words is here. If the user picks a random word then it should be picked at random from the text file. If the user enters a word then it should be verified against the words in the list.
  • The user should now be prompted to enter the number of attempts allowed.
  • Once the word has been selected, the user should be shown a fill-in-the-letters sequence of boxes where the number of boxes is equal to the number of letters in the chosen word.
  • The U.I. should also contain a list of all the letters that have been attempted by the user.
  • The U.I. should also contain a counter of the number of attempts left for the user. This counter starts at the number entered by the user.
  • The user has the inputted number of attempts to enter a letter. If the letter is contained in the chosen word then the letters should be filled into the appropriate box(s). In either case the letter should be added to the list of attempts - if it is a miss then it should be written in red font and if it is a hit then it should be written in a green font. In the case of a miss the counter should be decremented.
  • If the user successfully guesses the word before the counter hits 0 then a victory message should be displayed followed by a option to restart.
  • If the counter hits 0 and the user has not guessed the word, the user should be prompted for a last guess and should be asked to enter the entire word using the keyboard. If it is correct then the user wins and follow the above step. If the user is wrong then display a defeat message and provide an option to restart.

When you are ready to submit, put all the code and files for your project in a folder and zip it. The zip file should be named according to the name of your project - battleship.zip, 2048.zip, connect4.zip, hangman.zip. Submit this file and the project readme through the dashboard.

Congratulations on finishing the last assignment of CIS 110. From Dr. Eaton and all the TAs, we hope you enjoyed the class.

This project was writted by Rohan Bhide. The game ideas do not belong to us.