Esempio n. 1
0
    def connect_to_server(self, game_window: GameWindow,
                          thread_receive_broadcast: Thread):

        print(f'>>>> Attempting connection with user name: {self.user_name}')
        self.sock.connect(self.server_address)

        # After connecting: attempt a connection handshake to sync string user_names and integer player_id
        con_attempt = packets.ConnectionAttempt(self.user_name)
        self.sock.send(con_attempt.to_bytes())

        # Wait for receiving a confirmation
        data = self.sock.recv(self.BUFFERSIZE)
        if data:
            data = packets.load(data)

        # If confirmation received, start the thread that listens to server updates
        if type(data) is packets.ConnectionConfirmed and data.confirmed:
            self.connected = True
            self.player_id = data.player_id

            game_window.player_id = data.player_id
            game_window.connection = True
            game_window.player_name = data.user_name

            print(
                '>>>> Connection to server successful. Starting broadcast receive thread.'
            )
            thread_receive_broadcast.start()

        else:
            print('Connection denied.')
Esempio n. 2
0
 def __open_game_window(self, timer_interval):
     old_game_window = self.game_window
     self.game_window = GameWindow(timer_interval)
     #        self.game_window.on_updated = self.game_window_updated
     self.game_window.on_closed = self.game_window_closed
     if old_game_window:
         self.__close_game_window()
Esempio n. 3
0
def main():
    Log.debug("=== Running Dance Dance Sensei ===")
    if not os.path.isfile("config.toml"):
        Log.debug("Config not found, copying default config")
        shutil.copyfile("default_config.toml", "config.toml")

    config = toml.load("config.toml")

    if 'game' not in config:
        config['game'] = {}
        config['game']['default_game'] = games[0].code
        toml.dump(config, open("config.toml", "w"))

    if os.path.exists('sequence'):
        print("Sliently moving")
        print(os.path.expanduser("~\.dds"))

    ## Find game from config
    game_id = config['game']['default_game']
    game = first(games, lambda x: x.code == game_id)

    state = GameState(game, config)
    window = GameWindow(state)

    pygame.init()

    ## Get window size
    width = config['display']['width']
    height = config['display']['height']
    screen = pygame.display.set_mode((width, height))

    clock = pygame.time.Clock()

    def pygamethread():
        try:
            while state.is_running:
                for event in pygame.event.get():
                    state.handle_event(event)
                    window.handle_event(event)

                ## Drawing
                screen.fill(pygame.Color('black'))

                state.update()
                state.render(screen)

                ## End drawing
                pygame.display.update()
                clock.tick(60)
        except Exception:
            traceback.print_exc()

        pygame.quit()
        state.is_running = False
        window.quit()

    threading.Thread(None, pygamethread).start()

    window.mainloop()
Esempio n. 4
0
    def actionHLB(self):
        self.level = "hard"
        # Create a new game window
        self.game_window = GameWindow(16, 32, 80, 500, 500, 1600, 800, 1600,
                                      800, self, self.level)
        self.game_window.show()

        # Close this window
        self.win.close()
Esempio n. 5
0
    def actionMLB(self):
        self.level = "mid"
        # Create a new game window
        self.game_window = GameWindow(16, 16, 40, 500, 500, 1000, 800, 800,
                                      700, self, self.level)
        self.game_window.show()

        # Close this window
        self.win.close()
Esempio n. 6
0
    def actionELB(self):
        self.level = "easy"
        # Create a new game window
        self.game_window = GameWindow(8, 8, 10, 500, 500, 800, 600, 800, 700,
                                      self, self.level)
        self.game_window.show()

        # Close this window
        self.win.close()
Esempio n. 7
0
    def actionPGB(self):
        self.level = "custom"
        self.game_window = GameWindow(self.width_value, self.height_value,
                                      self.mines_value, 500, 500, 1000, 800,
                                      800, 700, self, self.level)
        self.game_window.show()

        self.custom_win.close()
        self.win.close()
Esempio n. 8
0
    def __init__(self, theme="Default"):
        super().__init__()

        self.sound_on = True
        self.language = "English"
        self.default_names = ["Player 1", "Player 2"]
        self.player_names = ["", ""]
        self.theme = theme
        self.stylesheets = StyleSheets(theme)
        self.AI_player = "Player 1"

        self.setWindowTitle("CenterSide")

        self.width = 1280
        self.height = 720

        self.setFixedSize(self.width, self.height)

        os.chdir("assets")

        self.background = QLabel(self)
        self.background.setPixmap(QPixmap("background.png"))
        self.background.resize(self.width, self.height)

        self.grid = QLabel(self)
        self.grid.setPixmap(QPixmap("SVG/grid.svg"))
        self.grid.setAlignment(Qt.AlignCenter)
        self.grid.resize(self.width, self.height)
        self.grid.hide()

        self.icon_play = QIcon("play_button.png")
        self.icon_options = QIcon("options_button.png")
        self.icon_help = QIcon("help_button.png")
        self.icon_quit = QIcon("quit_button.png")

        self.blank_piece = QIcon("SVG/blank.svg")
        self.p1_piece = QIcon("SVG/color1.svg")
        self.p2_piece = QIcon("SVG/color2.svg")
        self.p1_piece_opaque = QIcon("SVG/color1_opaque.svg")
        self.p2_piece_opaque = QIcon("SVG/color2_opaque.svg")
        self.deny = QIcon("SVG/deny.svg")
        self.deny_opaque = QIcon("SVG/deny_opaque.svg")

        self.p1_deny = QPixmap("SVG/color1_deny.svg")
        self.p2_deny = QPixmap("SVG/color2_deny.svg")
        self.p1_deny_opaque = QPixmap("SVG/color1_deny_opaque.svg")
        self.p2_deny_opaque = QPixmap("SVG/color2_deny_opaque.svg")

        self.logo = QIcon("SVG/CenterSide_icon.svg")
        self.setWindowIcon(self.logo)

        self.build_assets()

        self.menu_window = MenuWindow(self)
        self.setCentralWidget(GameWindow(self, "local"))

        self.show()
Esempio n. 9
0
def main():
    """ Main method """

    window = GameWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

    simulation_parameters = SimulationParameters(
        population_count=650,
        person_size=7,
        frames_to_result=200,
        chance_of_infection=0.6,
        chance_for_immunity=1.0,
        chance_for_death=0.05,
        initial_top_speed=250,
        reporting_interval=10,
        initial_infected_people=1,
        initial_immune_people=0,
        vertical_walls=4,
        door_size=100,
    )
    # for chance_of_infection in [0.4, 0.7]:
    #   simulation_parameters.chance_of_infection = chance_of_infection

    window.setup(simulation_parameters)
    arcade.run()
    plot_results(window)

    window.close()
Esempio n. 10
0
 def check_hovered_state(self, buttons_list):
     # iterates through the buttons list and checks which buttons are clicked
     for img in buttons_list:  # check which buttons are in hovered state
         if img.hovered:
             self.click_sound.play()
             if img.state == PLAY:  # move to the desired window
                 self.instruction_window = True
             elif img.state == NEXT:
                 print("starting game")
                 self.running = False
                 GameWindow(self.player_name)
             elif img.state == EXIT:
                 sys.exit(0)
             elif img.state == OPTIONS:
                 pass
             elif img.state == HIGHSCORE:
                 self.running = False
                 HighScoreWindow(self.player_name)
Esempio n. 11
0
def main():

    # Instantaiate client and game GUI objects:
    client = Client(user_name=names.get_first_name())
    game_window = GameWindow(client=client)

    # Communicate with server on separate threads:
    thread_receive = Thread(target=client.receive_game_state_broadcast,
                            args=(game_window, ),
                            daemon=True)
    thread_connect = Thread(target=client.connect_to_server,
                            args=(game_window, thread_receive),
                            daemon=True)

    # The receive thread will be started once the connect thread is successful.
    thread_connect.start()

    # Run the arcade game engine
    arcade.run()

    return 0
Esempio n. 12
0
    parser.add_argument('-yinv',
                        '--invert_y',
                        action='store_true',
                        help='invert the y-axis on the mouse')
    args = parser.parse_args()

    fullscreen = args.fullscreen
    resolution = args.resolution
    msaa = args.msaa
    yinv = args.invert_y

    mario_graphics_dir = Path(os.path.realpath(__file__)).parent

    font_filename = 'super-mario-64.ttf'
    font_name = 'Super Mario 64'
    font_path = str((mario_graphics_dir / 'fonts' / font_filename).resolve())
    pyglet.font.add_file(font_path)

    game_window = GameWindow(mario_graphics_dir,
                             fullscreen=fullscreen,
                             resolution=resolution,
                             y_inv=yinv,
                             vsync=False,
                             msaa=msaa,
                             resizable=True,
                             show_fps=False,
                             font=font_name)

    ## Main game loop
    pyglet.app.run()
Esempio n. 13
0
import sys
from PyQt5.QtWidgets import QApplication
from Menu_window import MenuWindow
from game_window import GameWindow

if __name__ == '__main__':
    app = QApplication([])

    Menu_window = MenuWindow()
    game_window = GameWindow()

    Menu_window.show_game_signal = game_window.show_game_signal

    Menu_window.show()

    sys.exit(app.exec_())
Esempio n. 14
0
import sys
from PyQt5.QtWidgets import QApplication
from ventana_inicial import MenuWindow
from game_window import GameWindow
from nueva import Tienda
from intento_crear_lista_mapa import Mapa

if __name__ == '__main__':
    app = QApplication([])
    mapa = Mapa()
    tienda = Tienda()
    menu_window = MenuWindow()
    game_window = GameWindow()
    menu_window.mandar_mapa_signal = mapa.mandar_mapa_signal
    game_window.show_tienda_signal = tienda.show_tienda_signal
    menu_window.show_game_signal = game_window.show_game_signal
    Tienda.show_game_signal = game_window.show_game_signal
    menu_window.show()
    sys.exit(app.exec_())
Esempio n. 15
0
import sys
from map_generation.draw_map import draw_image_map_v2

if __name__ == "__main__":
    args = sys.argv
    if len(args) == 2:
        from game_window import GameWindow
        img_name = args[1]
        game = GameWindow("teste", 1600, 900, img_name)
        game.on_execute()
    elif len(args) == 3:
        img_path = args[1]
        if args[2] == "obj":
            vertices, vertex_format, indices = draw_image_map_v2(
                img_path, 100, 100, 99)

        else:
            raise Exception(f"map can't be exported to the type {sys[2]}")
Esempio n. 16
0
import sys, pygame
from game_window import GameWindow

pygame.init()
window = GameWindow()
window.run()
Esempio n. 17
0
class MainWindow:
    setup_ui = Ui_MainWindow()
    custom_ui = Ui_CustomWindow()

    def __init__(self):
        self.win = QMainWindow()
        self.setup_ui.setupUi(self.win)
        self.win.setWindowTitle("Penguin Minesweeper")
        self.setup_ui.easyLevelButton.clicked.connect(self.actionELB)
        self.setup_ui.midLevelButton.clicked.connect(self.actionMLB)
        self.setup_ui.hardLevelButton.clicked.connect(self.actionHLB)
        self.setup_ui.customButton.clicked.connect(self.actionCB)

        self.custom_win = QMainWindow()
        self.custom_ui.setupUi(self.custom_win)
        self.custom_win.setWindowTitle("Custom")

    def show(self):
        self.win.show()

    def actionELB(self):
        self.level = "easy"
        # Create a new game window
        self.game_window = GameWindow(8, 8, 10, 500, 500, 800, 600, 800, 700,
                                      self, self.level)
        self.game_window.show()

        # Close this window
        self.win.close()

    def actionMLB(self):
        self.level = "mid"
        # Create a new game window
        self.game_window = GameWindow(16, 16, 40, 500, 500, 1000, 800, 800,
                                      700, self, self.level)
        self.game_window.show()

        # Close this window
        self.win.close()

    def actionHLB(self):
        self.level = "hard"
        # Create a new game window
        self.game_window = GameWindow(16, 32, 80, 500, 500, 1600, 800, 1600,
                                      800, self, self.level)
        self.game_window.show()

        # Close this window
        self.win.close()

    def actionCB(self):
        self.width_value = 8
        self.height_value = 8
        self.mines_value = 8
        self.custom_ui.setupUi(self.custom_win)
        self.custom_win.setWindowTitle("Custom")
        self.custom_win.show()
        self.custom_ui.widthPlusButton.clicked.connect(self.actionWPB)
        self.custom_ui.widthMinusButton.clicked.connect(self.actionWMB)
        self.custom_ui.heightPlusButton.clicked.connect(self.actionHPB)
        self.custom_ui.heightMinusButton.clicked.connect(self.actionHMB)
        self.custom_ui.minesPlusButton.clicked.connect(self.actionMPB)
        self.custom_ui.minesMinusButton.clicked.connect(self.actionMHB)
        self.custom_ui.playGameButton.clicked.connect(self.actionPGB)
        self.custom_ui.cancelButton.clicked.connect(self.actionCNB)

    def actionWPB(self):
        if self.width_value != 40:
            self.width_value += 1
            self.custom_ui.widthNumber.setProperty("intValue",
                                                   self.width_value)

    def actionWMB(self):
        if self.width_value != 8:
            self.width_value -= 1
            self.custom_ui.widthNumber.setProperty("intValue",
                                                   self.width_value)

    def actionHPB(self):
        if self.height_value != 40:
            self.height_value += 1
            self.custom_ui.heightNumber.setProperty("intValue",
                                                    self.height_value)

    def actionHMB(self):
        if self.height_value != 8:
            self.height_value -= 1
            self.custom_ui.heightNumber.setProperty("intValue",
                                                    self.height_value)

    def actionMPB(self):
        if self.mines_value != 200:
            self.mines_value += 1
            self.custom_ui.minesNumber.setProperty("intValue",
                                                   self.mines_value)

    def actionMHB(self):
        if self.mines_value != 8:
            self.mines_value -= 1
            self.custom_ui.minesNumber.setProperty("intValue",
                                                   self.mines_value)

    def actionPGB(self):
        self.level = "custom"
        self.game_window = GameWindow(self.width_value, self.height_value,
                                      self.mines_value, 500, 500, 1000, 800,
                                      800, 700, self, self.level)
        self.game_window.show()

        self.custom_win.close()
        self.win.close()

    def actionCNB(self):
        self.custom_win.close()
Esempio n. 18
0
class Application(object):
    NETOWRK_TIMEOUT = (1 / 30.)

    def __init__(self):
        self.config_window = None
        self.game_window = None

        self.player_name = None
        self.host_address = None

        self.client_socket = None

        self.interpreter = None
        self.interpreter = server_client_interpreter.ServerClientInterpreter()
        self.interpreter.on_wait_for_opponent = self.interpreter_wait_for_opponent
        self.interpreter.on_game_starting = self.interpreter_game_starting
        self.interpreter.on_snapshot = self.interpreter_snapshot
        self.interpreter.on_game_finished = self.interpreter_game_finished

        self.__open_config_window()

    def run(self):
        pyglet.app.run()

    def close(self):
        if self.client_socket:
            self.client_socket.close()
            self.client_socket = None
        self.interpreter = None
        self.__close_game_window()
        self.__close_config_window()

    def __open_config_window(self):
        old_config_window = self.config_window
        self.config_window = ConfigWindow()
        self.config_window.on_configured = self.config_window_configured
        self.config_window.on_closed = self.config_window_closed
        if self.player_name:
            self.config_window.player_name_textbox.text = self.player_name
        if self.host_address:
            self.config_window.server_address_textbox.text = self.host_address
        if old_config_window:
            old_config_window.on_closed = None
            old_config_window.on_configured = None
            old_config_window.close()

    def __close_config_window(self):
        if self.config_window:
            self.config_window.close()
            self.config_window = None

    def __open_game_window(self, timer_interval):
        old_game_window = self.game_window
        self.game_window = GameWindow(timer_interval)
        #        self.game_window.on_updated = self.game_window_updated
        self.game_window.on_closed = self.game_window_closed
        if old_game_window:
            self.__close_game_window()

    def __close_game_window(self):
        if self.game_window:
            self.game_window.close()
            self.game_window = None

    def config_window_configured(self, player_name, server_address):
        self.player_name = player_name
        self.host_address = server_address

        if not self.client_socket:
            self.client_socket = TCPClient(server_address, 8888,
                                           self.NETOWRK_TIMEOUT)
            self.client_socket.on_connected = self.client_socket_connected
            self.client_socket.on_disconnected = self.client_socket_disconnected
            self.client_socket.on_sent = self.client_socket_sent
            self.client_socket.on_received = self.client_socket_received
            self.client_socket.on_error = self.client_socket_error
            self.client_socket.open()

    def client_socket_connected(self):
        try:
            self.config_window.show_info(
                'Servidor contactado, registrando jugador...')
            # TODO: deshabilitar controles de config_window

            self.client_socket.send(
                self.interpreter.build_registration(self.player_name))
        except Exception as e:
            #print "client_socket_connected error, type: %s, message: %s" % (e, e.args)
            print 'Exception: type = %s, args = %s, message = %s' % (
                type(e), e.args, e.message)

    def client_socket_disconnected(self):
        print 'client socket disconnected'
        self.client_socket.close()
        self.client_socket = None

        if not self.config_window:
            self.__open_config_window()
        self.config_window.show_warn('El servidor cerro la conexion')

        self.__close_game_window()

    def client_socket_error(self, message):
        print 'client socket error, message: %s' % (message)

        self.client_socket.close()
        self.client_socket = None

        self.__open_config_window()
        if type(message) is tuple:
            self.config_window.show_error(
                'El servidor cerro la conexion (%s)' % (message[0]))
        else:
            self.config_window.show_error(message)

        self.__close_game_window()

    def client_socket_sent(self):
        pass

    def client_socket_received(self, msg):
        try:
            self.interpreter.parse(msg)
        except Exception as e:
            #print "client_socket_received error, args: %s, message: %s" % (e.args, e.message)
            print 'Exception: type = %s, args = %s, message = %s' % (
                type(e), e.args, e.message)

    def interpreter_wait_for_opponent(self):
        '''
        se dispara cuando hay 1 jugador conectado y hay que esperar al segundo
        '''
        if self.config_window:
            self.config_window.show_info('Esperando oponente...')
        print 'wait for opponent'

    def interpreter_game_starting(self, interval, side, opponent):
        '''
        se dispara cuando hay 2 jugadores conectados
        @param interval: intervalo en que se deben enviar las actualizaciones al servidor
        @param side: lado de la cancha del jugador
        @param opponent: nombre del oponente
        '''
        self.__open_game_window(interval)
        self.__close_config_window()
        if side == 'left':
            self.game_window.player1_name_label.text = self.player_name
            self.game_window.player2_name_label.text = opponent
        elif side == 'right':
            self.game_window.player1_name_label.text = opponent
            self.game_window.player2_name_label.text = self.player_name
        print 'game starting'

    def interpreter_snapshot(self, b_x, b_y, p1_x, p1_y, p1_s, p2_x, p2_y,
                             p2_s):
        '''
        se dispara cuando se modificaron las posiciones de los elementos en el servidor
        @param side: lado de la cancha del jugador
        @param opponent: nombre del oponente
        '''
        if self.game_window:
            try:
                self.game_window.draw_snapshot(b_x, b_y, p1_x, p1_y, p1_s,
                                               p2_x, p2_y, p2_s)
            except Exception as e:
                print 'Exception: type = %s, args = %s, message = %s' % (
                    type(e), e.args, e.message)

        if self.game_window and self.game_window.direction:
            try:
                message = self.interpreter.build_direction_change(
                    self.game_window.direction)
                self.client_socket.send(message)
            except Exception as e:
                print 'Exception: type = %s, args = %s, message = %s' % (
                    type(e), e.args, e.message)

    def interpreter_game_finished(self, p1_name, p1_score, p2_name, p2_score):
        self.client_socket.close()
        self.client_socket = None
        self.__open_config_window()
        try:
            self.config_window.show_info(
                'Finalizo la partida. %s: %s, %s: %s' %
                (p1_name, p1_score, p2_name, p2_score))
        except Exception as e:
            print 'Exception: type = %s, args = %s, message = %s' % (
                type(e), e.args, e.message)

        self.__close_game_window()
        print 'game finished'

    #def game_window_updated(self, direction):
    #    '''
    #    se dispara de a intervalos regulares, para enviar el cambio de posicion de la paleta del jugador local
    #    @param direction: direccion hacia donde se mueve la paleta
    #    '''
    #    if self.game_window:
    #        try:
    #            message = self.interpreter.build_direction_change(direction)
    #            self.client_socket.send(message)
    #        except Exception as e:
    #            print 'Exception: type = %s, args = %s, message = %s' % (type(e), e.args, e.message)

    def game_window_closed(self):
        self.__open_config_window()
        self.client_socket.send(self.interpreter.build_deregistration())

    def config_window_closed(self):
        pass
Esempio n. 19
0
from PySide2.QtGui import *
from PySide2.QtWidgets import QApplication, QOpenGLWidget

from game import Game
from game_window import GameWindow

if __name__ == "__main__":
    app = QApplication([])
    palette = app.palette()
    color = QColor()
    palette.setColor(QPalette.Background, color.red())
    app.setPalette(palette)
    opengl_widget = QOpenGLWidget()
    game_widget = Game(opengl_widget)
    main_window = GameWindow(game_widget)

    exit(app.exec_())