Class PlayerVsRandomController
- java.lang.Object
-
- com.neven.ticTacToeGame.controller.PlayerVsRandomController
-
@Controller @RequestMapping("game/random") @SessionAttributes("game") public class PlayerVsRandomController extends java.lang.Object
ClassPlayerVsRandomController
is a Spring Boot Controller class witch allow to serve HTTP requests from pages with Player versus Random(randomly filled empty game fields) game.
Path for requests "{pageContext}/game/random"- 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 the player versus algorithm game view.private static java.lang.String
GAME_START_PAGE_NAME
Constant with a name of the view where user should make a decision who will start the game, user or algorithm.private static java.lang.String
RANDOM_START_NAME
Constant with a String to verify does the Random start the game.private static java.lang.String
USER_START_NAME
Constant with a String to verify does a user start the game.
-
Constructor Summary
Constructors Constructor Description PlayerVsRandomController()
-
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/random" by method POST.(package private) org.springframework.web.servlet.ModelAndView
getGameWithRandom()
Allow to serve HTTP requests for requests "{pageContext}/game/random" by method GET.(package private) org.springframework.web.servlet.ModelAndView
startGameWithRandom(java.lang.String whoStart)
Allow to serve HTTP requests for requests "{pageContext}/game/random/{whoStart}" by method GET.
-
-
-
Field Detail
-
GAME_START_PAGE_NAME
private static final java.lang.String GAME_START_PAGE_NAME
Constant with a name of the view where user should make a decision who will start the game, user or algorithm.- See Also:
- Constant Field Values
-
GAME_PAGE_NAME
private static final java.lang.String GAME_PAGE_NAME
Constant with a name of the 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
-
USER_START_NAME
private static final java.lang.String USER_START_NAME
Constant with a String to verify does a user start the game.- See Also:
- Constant Field Values
-
RANDOM_START_NAME
private static final java.lang.String RANDOM_START_NAME
Constant with a String to verify does the Random start the game.- See Also:
- Constant Field Values
-
-
Method Detail
-
getGameWithRandom
@GetMapping @ResponseBody org.springframework.web.servlet.ModelAndView getGameWithRandom()
Allow to serve HTTP requests for requests "{pageContext}/game/random" by method GET.- Returns:
ModelAndView
class with mane of the view where user should make a decision who will start the game, user or Random.
-
startGameWithRandom
@GetMapping("/{whoStart}") org.springframework.web.servlet.ModelAndView startGameWithRandom(@PathVariable(name="whoStart") java.lang.String whoStart)
Allow to serve HTTP requests for requests "{pageContext}/game/random/{whoStart}" by method GET. Method will create thePlayerVsRandomGame
and depends on who will start it will callPlayerVsRandomGame.makeFirstMove()
method if game will be started randomly. Created game will be added as model attribute toModelAndView
with a name of player versus random game page view. If {whoStart} parameter will be wrong,ModelAndView
will be returned player versus random game start page name.- Parameters:
whoStart
- is a String value with an information who will start the game, "user" or "random".- Returns:
ModelAndView
with name of Player versus Random game page view andPlayerVsRandomGame
in model.
-
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/random" by method POST. Method will receivePlayerVsRandomGame
from model with a number of the cell where user want to make a move. MethodGame.winningCheckAndMakingMove(int)
will be called with user move.PlayerVsRandomGame
with a user and random move will be returned inModelAndView
with a name of player versus random game page view. If game wil be finished, returnedPlayerVsRandomGame
will care the result.- Parameters:
model
- Spring framework interface which carePlayerVsAlgorithmGame
angStatistic
as session attributes.cell
- Number of a cell on game field with acceptable values 1-9 where user want to make his move- Returns:
ModelAndView
with name of Player versus Random game page view andPlayerVsRandomGame
in model.
-
-