Skip to content

andreadp02/GuessThePhrase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Review Assignment Due Date

Exam #3: "Indovina la frase"

Student: s346392 Di Prima Andrea

React Client Application Routes

  • Route /: Homepage
  • Route /rules: Game rules page
  • Route /game: Game page for both full and demo game. Visiting this route does not automatically start a game; instead, there is a button to manually start a new game session.
  • Route /login: User authentication page

API Server

  • POST /api/sessions

    • Request body:
    {
      username: user1,
      password: password
    }
    
    • Response:
    • 201 Created. The body content is the following:
      {
        id: 1,
        email: user1@gmail.com,
        username: user1,
        coins: 100,
        gamesCount: 1,
      }
    
    • 422 Unprocessable Content on validation failure:
    { errors: [
        {
          type: 'field',
          value: '',
          msg: "E' richiesto l'username",
          path: 'username',
          location: 'body'
        }
      ]
    }
    
  • GET /api/sessions/current

    • Request body: none
    • Response:
      • 200 OK with the current authenticated user:
      {
        id: 1,
        email: user1@gmail.com,
        username: user1,
        coins: 100,
        gamesCount: 1,
      }
      
      • 401 Unauthorized if not authenticated:
      { error: "Non autenticato" }
      
  • DELETE /api/sessions/current

    • Request body: none
    • Response:
      • 200 OK with empty body (logout completed)
  • GET /api/game/letters

    • Request body: none
    • Response:
      • 200 OK with the list of consonants and their costs:
      [
        { letter: "B", cost: 2 },
        { letter: "C", cost: 3 },
        ...
      ]
      
      • 500 Internal Server Error on unexpected errors:
      { error: string }
      
  • POST /api/game/start

    • Request body: none
    • Response:
      • 201 Created with the new game info:
      {
        grid: [5, 2, 7, 4],
        gameID: "1"
      }
      
      • 409 Conflict if a game is already running or coins are insufficient (for authenticated users):
      { error: "Monete insufficienti" }
      
      • 500 Internal Server Error on unexpected errors
  • POST /api/game/guessletter/:letter

    • URL params:

      • letter: a single alphabetic character (A–Z or a–z)
    • Request body: none

    • Response:

      • 200 OK with the attempt result:
      // Demo game, lettera presente
      { correct: true, letter: "R", positions: [0, 3] }
      
      // Demo game, lettera assente
      { correct: false }
      
      // Gioco autenticato, lettera presente (include le monete aggiornate)
      { correct: true, letter: "R", positions: [0, 3], coins: 97 }
      
      // Gioco autenticato, lettera assente (include le monete aggiornate)
      { correct: false, coins: 94 }
      
    • 422 Unprocessable Content on validation failure:

      {
      "errors": [
          {
              "type": "field",
              "value": "1",
              "msg": "La lettera deve essere un carattere alfabetico singolo",
              "path": "letter",
              "location": "params"
          }
      ]
      }
      
    • 400 Bad Request for game errors such as already tried letter, vowel already attempted, or insufficient coins to attempt the letter:

      { error: "Lettera già tentata" }
      
    • 500 Internal Server Error on unexpected errors

  • POST /api/game/guessphrase

    • Request body:
    { phrase: "frase con solo lettere e spazi" }
    
    • Response:

      • 200 OK:
      // Frase corretta (demo):
      { win: true, phrase: "..." }
      
      // Frase corretta (utente autenticato)
      { win: true, phrase: "...", coins: 200 }
      
      // Tempo scaduto all'arrivo della richiesta
      { win: false, timeElapsed: true }
      
    • 422 Unprocessable Content on validation failure:

      {
      "errors": [
          {
              "type": "field",
              "value": "frase corta",
              "msg": "La frase deve essere lunga tra 30 e 50 caratteri",
              "path": "phrase",
              "location": "body"
          }
      ]
      

    }

    
    - `400 Bad Request` for game errors
    - `500 Internal Server Error` on unexpected errors
    
    
  • POST /api/game/end

    • Request body: none

    • Response:

    • 200 OK with final game outcome. Possible responses:

      // Demo, tempo scaduto
      { win: false, phrase: "...", timeElapsed: true }
      
      // Demo, tempo non scaduto (vince se la frase era corretta)
      { win: true, phrase: "..." }
      
      // Utente autenticato, tempo non scaduto
      { win: true,  phrase: "...", coins: 180 } // se aveva indovinato
      { win: false, phrase: "...", coins: 150 } // se non aveva indovinato
      
      // Utente autenticato, tempo scaduto (penalità)
      { win: false, phrase: "...", timeElapsed: true, coins: 130 }
      
    • 400 Bad Request for game errors (e.g., game not found)

    • 500 Internal Server Error on unexpected errors

Database Tables

  • Table users - contains id (PK), username, email, password, salt, coins, gamescount.
  • Table phrases - contains id (PK), phrase.
  • Table phrases_demo - contains id (PK), phrase.
  • Table letters - contains letter (PK), cost.

Main React Components

  • Homepage (in Homepage.jsx): Landing page with hero section and user info (for authenticated user).
  • Rules (in Rules.jsx): Game rules explanation component.
  • LoginForm (in LoginForm.jsx): User authentication form.
  • Game (in Game.jsx): Layout of game components and handlers for game events.
  • NotFound (in NotFound.jsx): 404 error page for invalid routes.
  • DefaultLayout (in DefaultLayout.jsx): Standard layout for most pages (not game).

Screenshot

Screenshot

Users Credentials

  • username: test@test.it, password: test (user who played some games).
  • username: user@user.it, password: user (user with 0 coins).
  • username: newuser@user.it, password: user (user who played 0 games).

About

Individual project for Web Application I at Politecnico di Torino

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors