Beispiel #1
0
 def piedra_tests(self):
     game = Game()
     self.assertEquals(game.play("piedra", "piedra"), "Empate.")
     self.assertEquals(game.play("piedra", "tijera"), "Gana jugador 1.")
     self.assertEquals(game.play("piedra", "lagarto"), "Gana jugador 1.")
     self.assertEquals(game.play("piedra", "papel"), "Gana jugador 2.")
     self.assertEquals(game.play("piedra", "spock"), "Gana jugador 2.")
Beispiel #2
0
async def websocket_endpoint(websocket: WebSocket, id_juego: str):
    game = Game.retrieve_from_database(id_juego)
    if game is None:
        return {
            'error': True,
            'mensaje': 'El juego no existe, verifique el ID'
        }

    await websocket.accept()

    while True:
        await asyncio.sleep(1)
        game = Game.retrieve_from_database(id_juego)
        mensaje = game.public_state()
        await websocket.send_json(mensaje)
Beispiel #3
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle)

        self.max_participants = 1

        self.jamath_activity = Game()
        self.build_toolbar()
        self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
        self.set_canvas(self._pygamecanvas)
        self._pygamecanvas.run_pygame(self.jamath_activity.run)
Beispiel #4
0
def informacion_del_juego(response: Response, id_juego: str):
    game = Game.retrieve_from_database(id_juego)

    if game is None:
        response.status_code = 400
        return {
            'error': True,
            'mensaje': 'El juego no existe, verifique el ID'
        }

    return game.public_state()
Beispiel #5
0
    def __init__(self, handle):
        Activity.__init__(self, handle)

        self.max_participants = 1

        self.jamath_activity = Game(get_activity_root())
        self.build_toolbar()
        self._pygamecanvas = sugargame.canvas.PygameCanvas(
            self,
            main=self.jamath_activity.run,
            modules=[pygame.display, pygame.font, pygame.mixer])
        self.set_canvas(self._pygamecanvas)
Beispiel #6
0
def nueva_partida(response: Response,
                  posiciones: int = 4,
                  publico: bool = True):
    """Se genera una nueva partida a través del API"""
    game = Game.create(posiciones, publico)

    # Si es un diccionario es porque hubo un error
    if isinstance(game, dict):
        response.status_code = 400
        return game

    return game.public_state()
def main():
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.init()
   
    screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
    #Set the title of the window:
    pygame.display.set_caption("EL VIAJE DE MARGERY")
    #Set the mouse invisible.
    pygame.mouse.set_visible(False)
    #Loop until the user clicks the close button.
    done = False
    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()
    try:
        game = Game(screen) #Create Game Object;
    except pygame.error:
        done = True
    # -------- Main Program Loop -----------
    while not done:
        done = game.eventHandler()
        # Game logic
        game.run_logic()
        # --- Drawing code should go here
        game.displayFrame(screen)
        # --- Go ahead and update the screen with what we've drawn.
        pygame.display.flip()
        # --- Limit to 30 frames per second
        clock.tick(40)
    # Close the window and quit.
    # If you forget this line, the program will 'hang'
    # on exit if running from IDLE.
    pygame.quit()
Beispiel #8
0
def iniciar(response: Response, id_juego: str):
    game = Game.retrieve_from_database(id_juego)
    if game is None:
        response.status_code = 400
        return {
            'error': True,
            'mensaje': 'El juego no existe, verifique el ID'
        }

    estado = game.start()

    if estado.get('error', None):
        response.status_code = 400

    return estado
Beispiel #9
0
def unirse(response: Response, id_juego: str, color: str, nickname: str):
    game = Game.retrieve_from_database(id_juego)
    if game is None:
        response.status_code = 400
        return {
            'error': True,
            'mensaje': 'El juego no existe, verifique el ID'
        }

    estado = game.join(color, nickname)

    if estado.get('error', None):
        response.status_code = 400

    return estado
Beispiel #10
0
def lanzar(response: Response,
           id_juego: str,
           player_key: Optional[str] = Header(None)):
    game = Game.retrieve_from_database(id_juego)
    if game is None:
        response.status_code = 400
        return {
            'error': True,
            'mensaje': 'El juego no existe, verifique el ID'
        }

    estado = game.lanzar(player_key)

    if estado.get('error', None):
        response.status_code = 400

    return estado
Beispiel #11
0
    print(
        "Conexión pérdida"
    )  #mensaje en consola cuando un jugador decide dejar de jugar y cierra
    try:
        del games[juegoId]
        print("Cerrando partida", juegoId)
    except:
        pass
    contadorId -= 1
    conn.close()


while True:
    conn, addr = s.accept()
    print(
        "Conectado a:", addr
    )  #mensaje en consola cuando el jugador logra conectarse a un servidor e iniciar partida

    contadorId += 1
    p = 0
    gameId = (contadorId - 1) // 2
    if contadorId % 2 == 1:
        games[gameId] = Game(gameId)
        print("Creando partida...")
    else:
        games[gameId].listo = True
        p = 1

    start_new_thread(threaded_client, (conn, p, gameId))
Beispiel #12
0
 def wrong_options_tests(self):
     game = Game()
     self.assertEquals(game.play("some", "option"), "Opciones incorrectas.")
     self.assertEquals(game.play("piedra", "some"), "Opciones incorrectas.")
     self.assertEquals(game.play("option", "papel"), "Opciones incorrectas.")