Beispiel #1
0
    def handleAction(self, string):
        action_player = int(string.split()[1])
        if self._active and\
            action_player == self._player_index:
            self.sendAction(string)

        GameService.handleAction(self, string)
Beispiel #2
0
 def update(self):
     if self.__connected == False:
         self.connect()
     else:
         self.handleConnection()
         if self.__started:
             GameService.update(self)
Beispiel #3
0
 def test_multiple_players(self):
     import copy
     player1 = Player("player1")
     player2 = Player("player2")
     service = GameService(10, 10, 5, [player1, player2])
     service.add_player_to_game([player2])
     service.set_board()
     #All players should share the same initial game board
     self.assertEqual(service._game._current_player, player2)
Beispiel #4
0
    def start(self):
        GameService._startGravity(self)

        players_number = self.requestPlayersNumber()

        for _ in range(players_number - 1):
            self._controlled_pieces.append(None)
            self._score.append(0)
            self._soft_drop_cells.append(0)
            self._hard_drop_cells.append(0)

        self.__started = True
Beispiel #5
0
 def test_game_services(self):
     player1 = Player("player1")
     player2 = Player("player2")
     gameService = GameService(10, 10, 50, [player1, player2])
     gameService.add_player_to_game([player2])
     self.assertEqual(gameService._game._rows, 10)
     gameService.set_board()
     self.assertEqual(len(gameService._game._mines), 50)
     gameService.update_board_with_reveal(0, 0)
     self.assertEqual(gameService._game._board[0][0]._isRevealed, True)
     gameService.update_board_with_flag(8, 8)
     self.assertEqual(gameService._game._board[8][8]._isRevealed, False)
     self.assertEqual(gameService._game._board[8][8]._isFlagged, True)
     self.assertEqual(gameService._game._result, 0)
Beispiel #6
0
    def __init__(self, grid_columns, grid_rows, host_ip, server_port):
        self.__host_ip = host_ip
        self.__server_port = server_port
        GameService.__init__(self, grid_columns, grid_rows)

        self.__connected = False
        self._active = False
        self._player_index = -1
        self.__started = False
        self.__server_update_interval = 1
        self.__last_server_update_time = 0

        self.__update_commands = {
            "start": self.start,
            "activate": self.activate,
        }
Beispiel #7
0
    def get(self, game_id):
        template = JINJA_ENVIRONMENT.get_template('lineup.html')
        game = GameService.game(game_id)
        game['date'] = game["date"].strftime("%Y-%m-%d")


        self.response.write(template.render({"game": game}))
Beispiel #8
0
def start_game(request, game_id):
    server = GameService.get_instance()
    if server.is_running():
        return HttpResponseBadRequest()
    game = shortcuts.get_object_or_404(Game, pk=game_id)
    server.start(game)
    return current_game(request)
Beispiel #9
0
 def test_game_services(self):
     player1 = Player("player1")
     player2 = Player("player2")
     gameService = GameService(10, 10, 50, [player1, player2])
     gameService.add_player_to_game([player2])
     self.assertEqual(gameService._game._rows, 10)
     gameService.set_board()
     self.assertEqual(len(gameService._game._mines), 50)
     gameService.update_board_with_reveal(0, 0)
     self.assertEqual(gameService._game._board[0][0]._isRevealed, True)
     gameService.update_board_with_flag(8, 8)
     self.assertEqual(gameService._game._board[8][8]._isRevealed, False)
     self.assertEqual(gameService._game._board[8][8]._isFlagged, True)
     self.assertEqual(gameService._game._result, 0)
Beispiel #10
0
def create_game(message):
    sid = request.sid
    game = GameService.create(message['game_name'])
    task = TaskService.create(
                      message['task_name'],
                      game['id'],
                    )
    UserService.create(sid, message['user_name'])
    UserTaskService.create_or_update(task['id'],
                                     sid,
                                     0)
    emit('send:game_data', {'game': game['uuid'], 'task': task['id']})
Beispiel #11
0
def current_game(request):
    server = GameService.get_instance()
    data = None
    if server.is_running():
        data = {
            'active': True,
            'time': server.get_time(),
            'game': model_to_dict(server.get_game())
        }
    else:
        data = {'active': False}
    return JsonResponse(data)
Beispiel #12
0
 def test_multiple_players(self):
     import copy
     player1 = Player("player1")
     player2 = Player("player2")
     service = GameService(10, 10, 5, [player1, player2])
     service.add_player_to_game([player2])
     service.set_board()
     #All players should share the same initial game board
     self.assertEqual(service._game._current_player, player2)
Beispiel #13
0
def create_game(level, players):
    """Create game according to game level and players
    """
    service = None
    if level==0:
        service = GameService(10, 10, 5, players)
    elif level==1:
        service =  GameService(16, 16, 40, players)
    elif level==2:
        service = GameService(20, 20, 80, players)
    service.add_player_to_game([players[0]])
    service.set_board()
    return service
Beispiel #14
0
def add_game():
    return json.dumps(gameService.add_game(request.json))
Beispiel #15
0
def end_game(request):
    GameService.get_instance().end()
    return current_game(request)
Beispiel #16
0
def restart_game(request):
    GameService.get_instance().restart()
    return current_game(request)
Beispiel #17
0
import pygame
from renderers import GraphicsRenderer
from services import GameService
from ui import UI

renderer = GraphicsRenderer(1280, 800)
service = GameService(10, 20)
ui = UI(service, renderer)

ui.run()
Beispiel #18
0
 def _placePiece(self, index):
     GameService._placePiece(self, index)
     if index == self._player_index:
         self.endTurn()
Beispiel #19
0
def delete_game():
    return json.dumps(gameService.remove_game(request.json))
Beispiel #20
0
def update_game():
    return json.dumps(gameService.modify_game(request.json))
Beispiel #21
0
def get_games():
    return json.dumps(gameService.get_all_games(request.args.get('name')))
Beispiel #22
0
def get_game(name):
    return json.dumps(gameService.get_game(name))