Git Product home page Git Product logo

group11_project1's Introduction

cs361 Project 1

This is the code you will use as a starting point for Project 1. The code you have been given has the front end for a battleship game. As is often the case when developing real-world software, you and your team have been given a front end, and are responsible for developing a back-end that will make the game work correctly.

Concepts

Two commonly used methods for a request-response between a client and server are: GET and POST.

GET - Requests data from a specified resource

POST - Submits data to be processed to a specified resource

Instructions

The game should operate as follows:

  1. Load the HTML page (provided for you in sampleBattleShip/src/main/resources/public/index.html)

  2. When the HTML page is loaded, it will send a GET request to the back-end.

  3. The back-end will create a new game model, and convert it to JSON before sending it to the front-end. If you want the game state to display without having to modify the front-end, the game state should look something like this:

{
    "aircraftCarrier": {
        "name": "AircraftCarrier",
        "length": 5,  
        "start": { "Across": 0,"Down": 0 },
        "end": {"Across": 0, "Down": 0}
    },
    "battleship": {
        "name": "Battleship",
        "length": 4,
        "start": { "Across": 0,"Down": 0 },
        "end": {"Across": 0, "Down": 0}
    },
    "cruiser": {
        "name": "Cruiser",
        "length": 3,
        "start": { "Across": 0,"Down": 0 },
        "end": {"Across": 0, "Down": 0}
    },
    "destroyer": {
        "name": "Destroyer",
        "length": 2,
        "start": { "Across": 0,"Down": 0 },
        "end": {"Across": 0, "Down": 0}
    },
    "submarine": {
        "name": "Submarine",
        "length": 2,
       "start": { "Across": 0,"Down": 0 },
        "end": {"Across": 0, "Down": 0}
    },
    "computer_aircraftCarrier": {
        "name": "Computer_AircraftCarrier",
        "length": 5,
        "start": { "Across": 2,"Down": 2 },
        "end": {"Across": 2, "Down": 7}
    },
    "computer_battleship": {
        "name": "Computer_Battleship",
        "length": 4,
        "start": { "Across": 2,"Down": 8 },
        "end": {"Across": 6, "Down": 8}
    },
    "computer_cruiser": {
        "name": "Computer_Cruiser",
        "length": 3,
        "start": { "Across": 4, "Down": 1 },
        "end": {"Across": 4, "Down": 4}
    },
    "computer_destroyer": {
        "name": "Computer_Destroyer",
        "length": 2,
        "start": { "Across": 7, "Down": 3 },
        "end": {"Across": 7, "Down": 5}
    },
    "computer_submarine": {
        "name": "Computer_Submarine",
        "length": 2,
        "start": { "Across": 9, "Down": 6 },
        "end": {"Across": 9, "Down": 8}
    },
    "playerHits": [],
    "playerMisses": [],
    "computerHits": [],
    "computerMisses": []
}
  1. The user will then place a ship on the board using the user interface. This will result in a POST being sent to the back-end. This post will be sent to a REST URL:
http://localhost:4567/placeShip/{shipname}/{across}/{down}/{horizontal | vertical}

an example request is:

http://localhost:4567/placeShip/aircraftCarrier/1/1/horizontal

This is a POST request, and it will also send the current game state via JSON (which was previously received from the back-end). The back end should correctly place the ship where the user has requested it, and then return a new game state. For this example request, the model response would include:

...
{"name":"AircraftCarrier","length":5,"start":{"Across":1,"Down":1},"end":{"Across":1,"Down":6}},
...
  1. The user will then fire at the computer ship. This will result in a POST being sent to the back-end. This post will be sent to a REST URL:
http://http://localhost:4567/fire/{across}/{down}

an example request is:

http://http://localhost:4567/fire/4/3

This is a POST request, and it will also send the current game state via JSON (which was previously received from the back-end). The back end should put tell the user if it was a hit or miss, and then it should fire at the user and tell them if they were hit or missed also. It should also then return a new game state. For this example request, the model response would include:

...
"playerHits":[],
"playerMisses":[{"Across":4,"Down":3}],
"computerHits":[{"Across":2,"Down":2}],
"computerMisses":[]}
...
  1. The POST requests will continue for each user input until the game state reaches the end of that particular game of Battleship.

Tips and tricks:

To implement this code, you will be using Java Spark.

You will make your life MUCH easier if you use GSON to seralize/deserialize the JSON objects to/from java objects.

You might also find the jquery documentation useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.