Пример #1
0
def initialize_board(screen, player1, player2, against):
    """
    To initialize the board.
    """
    screen.fill(screenfill)
    srect = pygame.Rect(0, 5, hsize, 55)
    brect = pygame.Rect(margin_left, margin_top, box_width*3, box_height*3)
    pygame.draw.rect(screen, fill_color, srect)
    pygame.draw.rect(screen, fill_color, brect)
    #buttons
    title = TextInput("Tic-Tac-Toe", hsize//2 - 130, 10, white, 60)
    
    if against == "is_human":
        pl1, pl2 = "Player 1", "Player 2"
    elif against == "is_random":
        pl1, pl2 = "Player", "Random agent"
    elif against == "is_ai":
        pl1, pl2 = "Player", "AI agent"
        
    players_def1 = Button(pl1 +" - " + player1, hsize//2-300, 100, white, 36, fill_color)
    
    players_def2 = Button(pl2+" - " + player2, hsize//2+120, 100, white, 36, fill_color)    
    
    #vertical and horizontal lines
    pygame.draw.line(screen, white, (margin_left, margin_top+box_height), (hsize-margin_right, margin_top+box_height), 5)
    pygame.draw.line(screen, white, (margin_left, margin_top+box_height*2), (hsize-margin_right, margin_top+box_height*2), 5)
    pygame.draw.line(screen, white, (margin_left+box_width, margin_top), (margin_left+box_width, vsize-margin_bottom), 5)
    pygame.draw.line(screen, white, (hsize-margin_right-box_width, margin_top), (hsize-margin_right-box_width, vsize-margin_bottom), 5)
    
    title.add_text(screen)
    players_def1.add_button(screen)
    players_def2.add_button(screen)    
    return screen
Пример #2
0
def screen3(text="Generated Plots"):
    screen.fill((250, 250, 250))
    screen.blit(icon, (10, 10))
    tex = TextInput(text, 100, 250, blue)
    tex.add_text(screen)
    back.add_button(screen)
    title.add_button(screen)
Пример #3
0
def screen1(text="Enter reservoir properties: "):
    screen.fill((250, 250, 250))
    screen.blit(icon, (10, 10))
    rec = pygame.Rect(left_margin, top_margin - 10,
                      win_width - left_margin * 2,
                      win_height - top_margin * 1.15)
    pygame.draw.rect(screen, (10, 10, 200), rec, border_radius=25)
    solve.add_button(screen)
    clear.add_button(screen)
    tex = TextInput(text, 150, 150, blue)
    tex.add_text(screen)
    title.add_button(screen)
    add_texts(screen, texts)
    add_textboxes(screen, boxes)
Пример #4
0
def screen2(text="Generated Plots"):
    screen.fill((250, 250, 250))
    screen.blit(icon, (10, 10))
    screen.blit(plots, (80, 220))
    pspace.add_button(screen)
    ptime.add_button(screen)
    pspacetime.add_button(screen)
    back.add_button(screen)
    tex = TextInput(text, 50, 180, blue)
    tex2 = TextInput("Select a plot to view: ", 50, 750, blue)
    tex.add_text(screen)
    tex2.add_text(screen)
    title.add_button(screen)
Пример #5
0
    def _create_widgets(self):
        """
        Create the widgets and return the one that contains them all.
        :return: the background widget
        """
        # Create the background widget.
        bg = self._rm.get_image(BACKGROUND_IMAGE, self.screen.get_size())
        bg_widget = ImageWidget((0, 0), self.screen.get_size(), -1, bg)

        # Create the container for the input widgets.
        x = (self.screen.get_width() - INPUT_WIDTH - INPUT_PADDING[1] - INPUT_PADDING[3]) / 2
        y = self.screen.get_height() / 2
        w = INPUT_WIDTH + INPUT_PADDING[1] + INPUT_PADDING[3]
        h = self.screen.get_height() - y
        input_container = Widget((x, y), (w, h), 0)
        bg_widget.add_widget(input_container)

        # Create the input widgets.
        username_input = TextInput((0, 0), INPUT_WIDTH, 0, self._font, padding=INPUT_PADDING, color=INPUT_FORE_COLOR,
                                   fill=INPUT_FILL_COLOR, default_text="username",
                                   default_font=self._default_font)
        host_input = copy.copy(username_input)
        host_input.default_text = "host"
        host_input.position = (0, INPUT_OFFSET)
        port_input = copy.copy(username_input)
        port_input.default_text = "port"
        port_input.position = (0, 2*INPUT_OFFSET)
        input_container.add_widget(username_input)
        input_container.add_widget(host_input)
        input_container.add_widget(port_input)
        self._text_inputs = {"username": username_input, "host": host_input, "port": port_input}

        # Create the button widget.
        btn = special_widgets.simple_button((0, 3*INPUT_OFFSET), (w, 100), "Login", self._font)

        def btn_clicked(x, y):
            self._ev_manager.post(events.LoginRequestedEvent())
        btn.handle_clicked = btn_clicked
        input_container.add_widget(btn)

        # Create the connection failed warning.
        self._connection_failed_warning = special_widgets.warning_widget(None, (400, 100), "Connection failed",
                                                                         self._font, screen_size=self.screen.get_size())
        bg_widget.add_widget(self._connection_failed_warning)
        self._username_taken_warning = special_widgets.warning_widget(None, (400, 100), "Username already taken",
                                                                      self._font, screen_size=self.screen.get_size())
        bg_widget.add_widget(self._username_taken_warning)

        return bg_widget
Пример #6
0
        show_board(screen, player2.player + " won the game!!!", player1, player2)
        winner = player2
        loop2(player1, player2, cplayer, against)
 
    elif bool == False and rlist == []:
        message = "Game Over - Draw!"
        show_board(screen, message, player1, player2)
        loop2(player1, player2, cplayer, against)
        winner = None


#Buttons
title = Button("Tic-Tac-Toe", hsize//2 - 200, 100, white, 100, fill_color)
Xbutton = Button("X", hsize//2 - 160, 550, white, 100, fill_color)
Obutton = Button("O", hsize//2+100, 550, white, 100, fill_color)
choose = TextInput("Choose Player: ", hsize//2-200, 400, fill_color, 60)
again = Button("Play Again?", hsize//2 - 300, vsize//2, white, 60, fill_color)
newgame = Button("New Game", hsize//2+50, vsize//2, white, 60, fill_color()
versus_ai = Button("Versus AI", hsize//2-300, 500, white, 80, fill_color)
versus_hu = Button("Versus Human", hsize//2-300, 600, white, 80, fill_color)
versus_ra = Button("Versus Random agent", hsize//2-300, 700, white, 80, fill_color)


def first_screen(screen):
    screen.fill(screenfill)
    srect = pygame.Rect(0, 80, hsize, 100)
    trect = pygame.Rect(0, 450, hsize, 350)
    pygame.draw.rect(screen, fill_color, srect)
    title.add_button(screen)
    versus_ai.add_button(screen)
    versus_hu.add_button(screen)
Пример #7
0
 def as_text(self, attrs=None, **kwargs):
     """
     Returns a string of HTML for representing this as an <input type="text">.
     """
     return self.as_widget(TextInput(), attrs, **kwargs)
Пример #8
0
#pictures
icon = pygame.image.load("images/icon.png")
loader = pygame.image.load("images/loader.jpg")
plots = pygame.image.load("images/plots.jpeg")

#colors
blue = (0, 0, 220)
white = (255, 255, 255)
red = (200, 10, 10)
text_color = (255, 255, 255)
text_color2 = (20, 20, 20)

#texts
title = Button("Reservoir Simulator", 180, 50, white, 50, fill_color=blue)
stopper = Button("Stopper", 180, 500, white, 50, fill_color=red)
dx = TextInput("Block size(ft), dx", left_margin + 10, top_margin, text_color,
               30)
dt = TextInput("Time Step(days), dt", left_margin + 10, top_margin + spacing,
               text_color, 30)
A = TextInput("Area(ft²) A", left_margin + 10, top_margin + spacing * 2,
              text_color, 30)
k = TextInput("Permeability(md), k", left_margin + 10,
              top_margin + spacing * 3, text_color, 30)
u = TextInput("Viscosity(cp), u", left_margin + 10, top_margin + spacing * 4,
              text_color, 30)
B = TextInput("Oil FVF(rb/stb), B", left_margin + 10, top_margin + spacing * 5,
              text_color, 30)

ct = TextInput("Compressibility(/psi), ct", left_margin + spacing * 7,
               top_margin, text_color, 30)
ph = TextInput("Porosity, Ø", left_margin + spacing * 7, top_margin + spacing,
               text_color, 30)