Package com.nebhale.letsmakeadeal

Examples of com.nebhale.letsmakeadeal.Game


    private final Object monitor = new Object();

    public Game create() {
        synchronized (this.monitor) {
            Long id = this.idGenerator.getAndIncrement();
            Game game = new Game(id, createDoors());

            this.games.put(id, game);

            return game;
        }
View Full Code Here


        this.doorsResourceAssembler = doorsResourceAssembler;
    }

    @RequestMapping(method = RequestMethod.POST, value = "")
    ResponseEntity<Void> createGame() {
        Game game = this.gameRepository.create();

        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri());

        return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
    }
View Full Code Here

        return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{gameId}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE })
    ResponseEntity<GameResource> showGame(@PathVariable Long gameId) throws GameDoesNotExistException {
        Game game = this.gameRepository.retrieve(gameId);
        GameResource resource = this.gameResourceAssembler.toResource(game);

        return new ResponseEntity<GameResource>(resource, HttpStatus.OK);
    }
View Full Code Here

        return new ResponseEntity<Void>(HttpStatus.OK);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{gameId}/doors", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE })
    ResponseEntity<DoorsResource> showDoors(@PathVariable Long gameId) throws GameDoesNotExistException {
        Game game = this.gameRepository.retrieve(gameId);
        DoorsResource resource = this.doorsResourceAssembler.toResource(game);

        return new ResponseEntity<DoorsResource>(resource, HttpStatus.OK);
    }
View Full Code Here

    @RequestMapping(method = RequestMethod.POST, value = "/{gameId}/doors/{doorId}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_XML_VALUE })
    ResponseEntity<Void> modifyDoor(@PathVariable Long gameId, @PathVariable Long doorId, @RequestBody Map<String, String> body)
        throws MissingKeyException, GameDoesNotExistException, IllegalTransitionException, DoorDoesNotExistException {
        DoorStatus status = getStatus(body);
        Game game = this.gameRepository.retrieve(gameId);

        if (DoorStatus.SELECTED == status) {
            game.select(doorId);
        } else if (DoorStatus.OPEN == status) {
            game.open(doorId);
        } else {
            throw new IllegalTransitionException(gameId, doorId, status);
        }

        return new ResponseEntity<Void>(HttpStatus.OK);
View Full Code Here

    private final InMemoryGameRepository gameRepository = new InMemoryGameRepository();

    @Test
    public void test() throws GameDoesNotExistException {
        Game game = this.gameRepository.create();
        assertSame(game, this.gameRepository.retrieve(game.getId()));
        this.gameRepository.remove(game.getId());
    }
View Full Code Here

TOP

Related Classes of com.nebhale.letsmakeadeal.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.