CS 222 Spring 2016

Daily Tents, Part II

Due: March 24, Thursday, 11:00 am.

Language: Java

Submission:

  • Check your file encoding. It should be UTF-8
  • Commit your code to SVN

Assignment Explanation

Daily Tents Game is a puzzle game similar to Sudoku. Please go and play with the game to get familiar with it. Your task for this week is to implement the Daily Tents game.

  • For implementing the game, please think of only the logic of the game not the GUI.
  • This means you will have write a Console Based Daily Tents
  • Think of how you would prepare this puzzle and also how would you solve this puzzle. This will guide you.

Task 1

Write a CLI for the Daily Tents Game. Basically you will ask the user for coordinates from standard input and print the board of the game on the screen after each step. Use simply Tent: T, Tree: E while printing the board.

  1. Make a simple menu to print on the screen:
    • Press 1 to enter the dimension of the board
    • Press 2 to enter coordinates
    • Press 3 to exit the game
    • Press 4 to restart the game

When you get the dimension of the board, create a game and print the board on the screen and print this menu to the user again.

Here is a sample board for you

  | 2 | 0 | 1 | 0 | 2 |
  ------------------------
  | 2 | T | E |   |   | T |
  | 0 |   |   |   |   | E |
  | 2 | T | E | T | E |   |
  | 0 |   |   |   |   | E |
  | 1 |   |   |   |   | T |
  ------------------------

Task 2

Implement the game logic according to the rules defined on the game’s site.

Task 3

Refactor your code. In addition to appropriate naming, clean and short and well-defined functions, apply what you have learnt from formatting lecture. Make sure that you don’t have any code smells in your code.

General Flow of the Game

  1. Get the dimension of the board from the user. It will be 8,12,16 or 20. Keep asking the user until one of these dimensions is provided.
    1. Print the board (and the CLI menu)
    2. Get coordinates from the user. Check for validity of the coordinates continuously until the user enters valid coordinates
    3. Check for validity of rules (tents cannot be adjacent diagonally to a tree, it’s already occupied or not…etc)
      • Print an error message to the user for insertion attempt that breaks the rules. Ask the user for new coordinates until these conditions are satisfied
    4. Place a new tent at those coordinates if everything is ok
    5. Print the board on the screen and wait for new coordinates (print the CLI menu to the screen).
    6. Print the message “you won!” when game is finished
    7. If the user enters 3 exits the game
    8. If the user enters 4 restart the game with dimension provided before

Notice That

  • We don’t have any game type (easy, medium or hard).
  • The user should see the menu at each step (i.e. The user might want to quit playing in the middle of a game.)

Grading

  • Functionality (20)
    • CLI: Printing menu and board decently (2)
    • CLI: Correctly getting input from the user (5)
    • Correctly implementing the game (13)
  • Code Quality (25)
    • Names: 5
    • Functions: 8
    • Comments: 5
    • Format: 7