Class GameController


  • @RestController
    @RequestMapping("games")
    @ExposesResourceFor(Game.class)
    public class GameController
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Game buyCard​(org.springframework.security.core.Authentication authentication, int gameId, java.lang.String cardName)
      Similar to the doaction method, players can post the card they want to buy.
      Game discardCard​(org.springframework.security.core.Authentication authentication, int gameId, java.util.List<java.lang.String> cardNames)
      When a player is attacked, they have to discard a few cards before they can proceed.
      Game doAction​(org.springframework.security.core.Authentication authentication, int gameId, java.lang.String cardName, java.util.List<java.lang.String> cards)
      This is a method that the user calls to do an action, with or without cards.
      Game endPhase​(org.springframework.security.core.Authentication authentication, int gameId)
      This is used if the player prematurely ends a phase or turn.
      Game get​(long id, org.springframework.security.core.Authentication authentication)
      The client pulls this on a timer automatically to refresh information about the game.
      java.util.List<java.lang.String> getPlaysFromLastTurn​(org.springframework.security.core.Authentication authentication, int gameId)
      This gets a simple list of strings describing the last turn taken by the other player.
      Game joinGame​(org.springframework.security.core.Authentication authentication)
      Starts new game.
      void notFound()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • joinGame

        @PostMapping(value="newgame",
                     produces="application/json")
        public Game joinGame​(org.springframework.security.core.Authentication authentication)
        Starts new game. When a client makes this query, it either creates a new game or joins an existing one, based on whether there are any games in the database in the Waiting state.
        Parameters:
        authentication -
        Returns:
      • get

        @GetMapping(value="gamestateinfo/{id}",
                    produces="application/json")
        public Game get​(@PathVariable
                        long id,
                        org.springframework.security.core.Authentication authentication)
        The client pulls this on a timer automatically to refresh information about the game.
        Parameters:
        id -
        authentication -
        Returns:
      • doAction

        @PostMapping(value="/action/{gameid}/{cardname}",
                     consumes="application/json",
                     produces="application/json")
        public Game doAction​(org.springframework.security.core.Authentication authentication,
                             @PathVariable("gameid")
                             int gameId,
                             @PathVariable("cardname")
                             java.lang.String cardName,
                             @Nullable @RequestBody
                             java.util.List<java.lang.String> cards)
        This is a method that the user calls to do an action, with or without cards. It calls the gameLogic service methods and returns an updated game object.
        Parameters:
        authentication -
        gameId -
        cardName -
        cards -
        Returns:
      • buyCard

        @PostMapping(value="/buy/{gameid}/{cardname}",
                     consumes="application/json",
                     produces="application/json")
        public Game buyCard​(org.springframework.security.core.Authentication authentication,
                            @PathVariable("gameid")
                            int gameId,
                            @PathVariable("cardname")
                            java.lang.String cardName)
        Similar to the doaction method, players can post the card they want to buy. GameLogic verifies the validity of this action and returns a game object.
        Parameters:
        authentication -
        gameId -
        cardName -
        Returns:
      • endPhase

        @PostMapping(value="/endphase/{gameid}",
                     consumes="application/json",
                     produces="application/json")
        public Game endPhase​(org.springframework.security.core.Authentication authentication,
                             @PathVariable("gameid")
                             int gameId)
        This is used if the player prematurely ends a phase or turn. The player does not have to end their turn, it will be done automatically in GameLogic in the doAction and Buy methods if the actions or buys are exhausted. However, if they wish, the players can call this method and skip. GameLogic performs a different endPhase depending on the current state of Game.
        Parameters:
        authentication -
        gameId -
        Returns:
      • discardCard

        @PostMapping(value="/discard/{gameid}",
                     consumes="application/json",
                     produces="application/json")
        public Game discardCard​(org.springframework.security.core.Authentication authentication,
                                @PathVariable("gameid")
                                int gameId,
                                @RequestBody
                                java.util.List<java.lang.String> cardNames)
        When a player is attacked, they have to discard a few cards before they can proceed. This method takes in that information in the request body, discards, and returns a game object.
        Parameters:
        authentication -
        gameId -
        cardNames -
        Returns:
      • getPlaysFromLastTurn

        @GetMapping("/plays/{gameid}")
        public java.util.List<java.lang.String> getPlaysFromLastTurn​(org.springframework.security.core.Authentication authentication,
                                                                     @PathVariable("gameid")
                                                                     int gameId)
        This gets a simple list of strings describing the last turn taken by the other player.
        Parameters:
        authentication -
        gameId -
        Returns:
      • notFound

        @ResponseStatus(NOT_FOUND)
        @ExceptionHandler(java.util.NoSuchElementException.class)
        public void notFound()