Class PlayerVsPlayerController


  • @Controller
    @RequestMapping("game/players")
    @SessionAttributes("game")
    public class PlayerVsPlayerController
    extends java.lang.Object
    Class PlayerVsPlayerController is a Spring Boot Controller class witch allow to serve HTTP requests from pages with Player versus Player game.
    Path for requests "{pageContext}/game/players"
    Author:
    Arterm Koliushko, https://www.linkedin.com/in/artem-koliushko/
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String GAME_MODEL_ATTRIBUTE_NAME
      Constant with a name of the model attribute for game.
      private static java.lang.String GAME_PAGE_NAME
      Constant with a name of player versus algorithm game view.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) org.springframework.web.servlet.ModelAndView game​(org.springframework.ui.Model model, int cell)
      Allow to serve HTTP requests for requests "{pageContext}/game/players" by method POST.
      (package private) org.springframework.web.servlet.ModelAndView startGameWithPlayers()
      Allow to serve HTTP requests for requests "{pageContext}/game/players" by method GET.
      • Methods inherited from class java.lang.Object

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

      • GAME_PAGE_NAME

        private static final java.lang.String GAME_PAGE_NAME
        Constant with a name of player versus algorithm game view.
        See Also:
        Constant Field Values
      • GAME_MODEL_ATTRIBUTE_NAME

        private static final java.lang.String GAME_MODEL_ATTRIBUTE_NAME
        Constant with a name of the model attribute for game.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PlayerVsPlayerController

        public PlayerVsPlayerController()
    • Method Detail

      • startGameWithPlayers

        @GetMapping
        org.springframework.web.servlet.ModelAndView startGameWithPlayers()
        Allow to serve HTTP requests for requests "{pageContext}/game/players" by method GET.
        Returns:
        ModelAndView class with mane of the view of the Player versus Player game page with new PlayerVsPlayerGame as a Model attribute.
      • game

        @PostMapping
        org.springframework.web.servlet.ModelAndView game​(org.springframework.ui.Model model,
                                                          @RequestParam("cell")
                                                          int cell)
        Allow to serve HTTP requests for requests "{pageContext}/game/players" by method POST. Method will receive PlayerVsPlayerGame from model with number of cell where user want to make a move. Method Game.winningCheckAndMakingMove(int) will be called with user move. Current user will be changed and PlayerVsPlayerGame will be returned as Model attribute to Player versus Player game page view.
        Parameters:
        model - Spring framework interface which care PlayerVsPlayerGame as session attribute.
        cell - Number of cell on game field with acceptable values 1-9 where user want to make his move
        Returns:
        ModelAndView with name of Player versus Player game page view and PlayerVsPlayerGame in model.