def __init__(self, master, gameplay: FourInARowGameplay):
     Section.__init__(self, master, "Local Multiplaying", gameplay)
     self.form = Form(self)
     self.form.add_entry("P1", Text("P1 Name:", theme="form"), Entry(self))
     self.form.add_entry("P2", Text("P2 Name:", theme="form"), Entry(self))
     self.button_play = Button(self,
                               "Play",
                               theme=["option", "section"],
                               callback=self.play)
 def __init__(self, master, gameplay: FourInARowGameplay):
     Section.__init__(self, master, "Play as P2", gameplay)
     self.form = Form(self)
     self.form.add_entry("name", Text("Your Name:", theme="form"),
                         Entry(self))
     self.form.add_entry("IP", Text("IP address:", theme="form"),
                         Entry(self, width=15))
     self.form.add_entry("port", Text("Port:", theme="form"),
                         Entry(self, width=15))
     self.button_connect = Button(self,
                                  "Connect to P1",
                                  theme=["option", "section"],
                                  callback=self.connection)
     self.text_game_status = Text(font=RESOURCES.font("heavy", 30),
                                  shadow_x=1,
                                  shadow_y=1)
Ejemplo n.º 3
0
 def __init__(self, master, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     params_for_all_buttons = {
         "font": ("calibri", 30),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": YELLOW,
         "outline": 3
     }
     self.start_game = NavySetup(2)
     self.text_title = Text("Connect to Player 1", ("calibri", 50))
     self.ip = Entry(self, width=15, font=("calibri", 40), bg=GREEN, highlight_color=YELLOW, outline=2)
     self.text_ip_address = Text("IP address", ("calibri", 40), YELLOW)
     self.port = Entry(self, width=15, font=("calibri", 40), bg=GREEN, highlight_color=YELLOW, outline=2)
     self.text_port_of_connection = Text("Port", ("calibri", 40), YELLOW)
     self.text_connection = Text(font=("calibri", 25), color=YELLOW)
     self.text_connection.hide()
     self.button_connect = Button(self, "Connection", callback=self.connection, **params_for_all_buttons)
     self.button_cancel = Button(self, "Return to menu", callback=self.stop, **params_for_all_buttons)
     self.lets_play_countdown = CountDown(self, 3, "Connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")
 def __init__(self, master, gameplay: FourInARowGameplay):
     Section.__init__(self, master, "Play as P1", gameplay)
     self.form = Form(self)
     self.form.add_entry("P1", Text("Your Name:", theme="form"),
                         Entry(self))
     self.button_start_server = Button(self, theme=["option", "section"])
     self.text_game_status = Text(font=RESOURCES.font("heavy", 20),
                                  shadow_x=1,
                                  shadow_y=1)
     self.text_server_ip = Text(font=RESOURCES.font("afterglow", 45),
                                shadow_x=2,
                                shadow_y=1)
     self.text_server_port = Text(font=RESOURCES.font("afterglow", 45),
                                  shadow_x=2,
                                  shadow_y=1)
Ejemplo n.º 5
0
class PlayerClient(Dialog):

    def __init__(self, master, **kwargs):
        Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
        params_for_all_buttons = {
            "font": ("calibri", 30),
            "bg": GREEN,
            "hover_bg": GREEN_LIGHT,
            "active_bg": GREEN_DARK,
            "highlight_color": YELLOW,
            "outline": 3
        }
        self.start_game = NavySetup(2)
        self.text_title = Text("Connect to Player 1", ("calibri", 50))
        self.ip = Entry(self, width=15, font=("calibri", 40), bg=GREEN, highlight_color=YELLOW, outline=2)
        self.text_ip_address = Text("IP address", ("calibri", 40), YELLOW)
        self.port = Entry(self, width=15, font=("calibri", 40), bg=GREEN, highlight_color=YELLOW, outline=2)
        self.text_port_of_connection = Text("Port", ("calibri", 40), YELLOW)
        self.text_connection = Text(font=("calibri", 25), color=YELLOW)
        self.text_connection.hide()
        self.button_connect = Button(self, "Connection", callback=self.connection, **params_for_all_buttons)
        self.button_cancel = Button(self, "Return to menu", callback=self.stop, **params_for_all_buttons)
        self.lets_play_countdown = CountDown(self, 3, "Connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")

    def on_dialog_quit(self):
        self.disable_text_input()
        self.stop_connection()

    def place_objects(self):
        self.frame.move(center=self.center)
        self.text_title.move(centerx=self.frame.centerx, top=self.frame.top + 50)
        self.lets_play_countdown.move(center=self.text_title.center)
        self.ip.move(centerx=self.frame.centerx + self.frame.w // 10, bottom=self.frame.centery - 10)
        self.text_ip_address.move(centery=self.ip.centery, right=self.ip.left - 10)
        self.port.move(left=self.ip.left, top=self.ip.bottom + 20)
        self.text_port_of_connection.move(centery=self.port.centery, right=self.port.left - 10)
        self.text_connection.move(centerx=self.frame.centerx, top=self.port.bottom + 5)
        self.button_connect.move(centerx=self.frame.centerx - (self.frame.width // 4), bottom=self.frame.bottom - 10)
        self.button_cancel.move(centerx=self.frame.centerx + (self.frame.width // 4), bottom=self.frame.bottom - 10)

    def connection(self):
        self.text_connection.show()
        self.text_connection.message = "Connection..."
        self.draw_and_refresh()
        if not self.connect_to_server(self.ip.get(), int(self.port.get()), 3):
            self.text_connection.message = "Connection failed. Try again."
        else:
            self.text_connection.hide()
            self.text_title.hide()
            self.button_connect.state = self.button_cancel.state = Button.DISABLED
            self.button_connect.focus_leave()
            self.lets_play_countdown.start(at_end=self.play)

    def play(self):
        self.start_game.mainloop()
        self.stop()
    def __init__(self):
        MainWindow.__init__(self,
                            title=f"4 in a row - v{__version__}",
                            size=(1280, 720),
                            bg_color=BACKGROUND_COLOR,
                            resources=RESOURCES,
                            config=WINDOW_CONFIG_FILE)
        self.logo = Image(RESOURCES.IMG["logo"])

        Text.set_default_theme("default")
        Text.set_theme(
            "default", {
                "font": RESOURCES.font("heavy", 45),
                "color": YELLOW,
                "shadow": True,
                "shadow_x": 3,
                "shadow_y": 3
            })
        Text.set_theme("form", {
            "font": RESOURCES.font("heavy", 35),
        })
        Button.set_default_theme("default")
        Button.set_theme(
            "default", {
                "fg": YELLOW,
                "disabled_fg": WHITE,
                "shadow": True,
                "shadow_x": 3,
                "shadow_y": 3,
                "bg": BLUE,
                "hover_bg": (0, 175, 255),
                "active_bg": BLUE,
                "outline": 0,
                "highlight_color": WHITE,
                "highlight_thickness": 1,
                "border_bottom_left_radius": 45,
                "border_top_right_radius": 45,
                "x_add_size": 150,
                "offset": (0, -5),
                "hover_offset": (-10, 0),
                "active_offset": (0, 10),
            })
        Button.set_theme("title", {
            "font": RESOURCES.font("heavy", 70),
            "y_add_size": -50
        })
        Button.set_theme("option", {
            "font": RESOURCES.font("heavy", 40),
            "y_add_size": -20
        })
        Button.set_theme("section", {
            "bg": BLUE_DARK,
            "active_bg": BLUE_DARK,
            "disabled_bg": GRAY_LIGHT
        })
        Entry.set_default_theme("default")
        Entry.set_theme(
            "default", {
                "width": 12,
                "font": RESOURCES.font("afterglow", 25),
                "highlight_color": BLACK,
                "highlight_thickness": 3
            })

        gameplay = FourInARowGameplay(self)
        ai_level_selector = AILevelSelectorSection(self, gameplay)
        local_playing = LocalPlayingSection(self, gameplay)
        lan_playing_server = LANPlayingP1(self, gameplay)
        lan_playing_client = LANPlayingP2(self, gameplay)
        self.buttons = ButtonListVertical(offset=80, justify="right")
        self.buttons.add(
            Button(self,
                   "Play against AI",
                   theme="title",
                   callback=ai_level_selector.mainloop),
            Button(self,
                   "Multiplayer",
                   theme="title",
                   callback=local_playing.mainloop),
            Button(self,
                   "Play as P1 (LAN)",
                   theme="title",
                   callback=lan_playing_server.mainloop),
            Button(self,
                   "Play as P2 (LAN)",
                   theme="title",
                   callback=lan_playing_client.mainloop),
            Button(self, "Quit", theme="title", callback=self.stop),
        )
Ejemplo n.º 7
0
 def __init__(self, master, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     self.start_game = master.start_game
     self.text_title = Text("Connect to Player 1", font=("calibri", 50))
     self.form = Form(self)
     self.form.add_entry("IP", Text("IP address", font=("calibri", 40), color=YELLOW), Entry(self, width=15, font=("calibri", 30), bg=GREEN, highlight_color=YELLOW, outline=2))
     self.form.add_entry("Port", Text("Port", font=("calibri", 40), color=YELLOW), Entry(self, width=15, font=("calibri", 30), bg=GREEN, highlight_color=YELLOW, outline=2))
     self.text_connection = Text(font=("calibri", 25), color=YELLOW)
     self.text_connection.hide()
     self.button_connect = Button(self, "Connection", theme="option", callback=self.connection)
     self.button_cancel = Button(self, "Return to menu", theme="option", callback=self.stop)
     self.lets_play_countdown = CountDown(self, 3, "Connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")