Esempio n. 1
0
 def __init__(self, screen):
     self.screen = screen
     self.font = py.font.Font(None, 32)
     self.font_title = pygame.font.SysFont(None, 65)
     self.text_title = self.font_title.render("Tennis Game!", True, BLACK)
     self.clock = pygame.time.Clock()
     self.background = pygame.image.load(
         r'C:\Users\berta\PycharmProjects\pythonProject\TennisGameProjectSecondTry\main\background.png'
     )
     self.fps_cap = 30
     self.button_1 = pw.Button(self.screen,
                               WIDTH_MENU / 2 - 270,
                               500,
                               100,
                               100,
                               text='Start',
                               fontSize=30,
                               margin=20,
                               inactiveColour=(255, 0, 0),
                               pressedColour=(0, 255, 0),
                               radius=10,
                               onClick=start_the_game)
     self.button_2 = pw.Button(self.screen,
                               WIDTH_MENU / 2 + 270,
                               500,
                               100,
                               100,
                               text='Quit!',
                               fontSize=30,
                               margin=20,
                               inactiveColour=(255, 0, 0),
                               pressedColour=(0, 255, 0),
                               radius=10,
                               onClick=quit_the_game)
Esempio n. 2
0
 def __init__(self, master, button_kwargs):
     super().__init__(master, (0, 0), master.surface.get_size(), color=(0, 0, 0, 128))
     self.game_state = Game_state()
     self.button_resume = pygame_widgets.Button(self, (710, 320), (500, 100), text="Resume", **button_kwargs)
     self.button_resume.add_handler(E_BUTTON_BUMPED, button_wrapper(self.button_resume_click))
     self.button_resume.set(shortcut_key=K_SPACE)
     self.button_menu = pygame_widgets.Button(self, (710, 420), (500, 100), text="Main menu", **button_kwargs)
     self.button_restart = pygame_widgets.Button(self, (710, 520), (500, 100), text="Restart", **button_kwargs)
     self.button_restart.set(shortcut_key=K_RETURN)
     self.button_options = pygame_widgets.Button(self, (710, 670), (500, 100), text="Options", **button_kwargs)
     self.button_options.add_handler(E_BUTTON_BUMPED, button_wrapper(self.button_options_click))
     self.button_exit = pygame_widgets.Button(self, (710, 770), (500, 100), text="Exit", **button_kwargs)
     self.button_exit.add_handler(E_BUTTON_BUMPED, button_wrapper(master.quit))
     self.button_exit.set(shortcut_key=K_F4)
     self.disconnect()
Esempio n. 3
0
 def __init__(self, auto1):
     # инициализация окна
     pygame.init()
     self.auto = auto1
     self.FPS = pygame.time.Clock()
     self.screen = pygame.display.set_mode((self.width, self.height))
     self.bg = pygame.image.load("background.bmp")
     pygame.display.set_caption('Naval')
     self.running = True
     self.need_exit = False
     self.exit_button = pw.Button(self.screen,
                                  self.offset_x_exit_game,
                                  self.offset_y_buttons,
                                  80,
                                  self.gauge,
                                  text='Выход',
                                  fontSize=18,
                                  margin=2,
                                  inactiveColour=(136, 149, 216),
                                  pressedColour=(136, 255, 216),
                                  radius=5,
                                  onClick=lambda: self.exit_pressed())
     self.new_button = pw.Button(self.screen,
                                 self.offset_x_new_game,
                                 self.offset_y_buttons,
                                 80,
                                 self.gauge,
                                 text='Заново',
                                 fontSize=18,
                                 margin=2,
                                 inactiveColour=(136, 149, 216),
                                 pressedColour=(136, 255, 216),
                                 radius=5,
                                 onClick=lambda: self.restart_pressed())
     self.auto_button = pw.Button(self.screen,
                                  self.offset_x_auto,
                                  self.offset_y_buttons,
                                  80,
                                  self.gauge,
                                  text='Авто',
                                  fontSize=18,
                                  margin=2,
                                  inactiveColour=(136, 149, 216),
                                  pressedColour=(136, 255, 216),
                                  radius=5,
                                  onClick=lambda: self.auto_pressed())
     self.new_game()
def setup ():
    

    # %% crete pygame window
    Window_size = [0,0] 
    
    Window_size [0] = 256*4
    Window_size [1] = 256+80 
    
    screen = pygame.display.set_mode( Window_size )
    screen.fill((128,128,128))
    
    update_view (screen,1,sum(number_of_im))
    
    #%% input widgets 
    
    global slider_first_frame    

    slider_first_frame = pw.Slider(
                screen, 25, 256 + 20, 200, 10, min = 1, max = sum(number_of_im),step = 1,initial = 1)
    
    global text_first 
     
    text_first = pw.TextBox(
                screen ,25, 256 + 35, 60, 40, fontSize=24)
    
    text_first.draw()    
    slider_first_frame.draw()

    


    global slider_last_frame    

    slider_last_frame = pw.Slider(
                screen, 1024-256+25, 256 + 20, 200, 10, min = 1, max = sum(number_of_im),step = 1,initial = sum(number_of_im))
    
    global text_last 
     
    text_last = pw.TextBox(
                screen ,1024-256+25, 256 + 35, 60, 40, fontSize=24)
    
    text_last.draw()
    slider_last_frame.draw()

    global button_done    

    button_done = pw.Button(
               screen, 512 - 25, 256 +20, 50, 40, text='done',
               fontSize=22, margin=10,
               inactiveColour=(128, 200, 128),
               pressedColour=(0, 255, 0), radius=20,
               onClick=lambda: Set_done_cmd(False))     


    pygame.display.update() 
    
    
    return screen 
Esempio n. 5
0
def draw_board(the_board, swapSide, randomSwap):
    pygame.init()
    pygame.display.set_caption("Play the chess game")
    colors = [(255, 255, 255), (0, 255, 0)]  # Set up colors [white, green]

    n = len(the_board)  # This is an NxN chess board.
    surface_sz = 480  # Proposed physical surface size.
    sq_sz = surface_sz // n  # sq_sz is length of a square.
    print(sq_sz)
    # surface_sz = n * sq_sz     # Adjust window to exactly fit n squares.
    x_offset_of_Board = 150
    y_offset_of_Board = 150
    board_field_names = generateFieldNames(n, swapSide)
    blackFigures, whiteFigures = initFigures()
    surface = pygame.display.set_mode((800, 650))
    colorOfTheSurface = (0, 0, 0)
    surface.fill(colorOfTheSurface)
    myFont = pygame.font.SysFont("Courier", 50, bold=True)
    mySmallFont = pygame.font.SysFont("Courier", 20, bold=True)
    return_to_menu = pw.Button(surface,
                               10,
                               550,
                               130,
                               65,
                               text='Back',
                               fontSize=20,
                               margin=20,
                               inactiveColour=(100, 100, 100),
                               pressedColour=(255, 0, 0),
                               radius=14,
                               onClick=lambda: print('Click'))

    fieldForUser = generateFieldForUser(
        board_field_names)  # initialization a first quest for user
    chessBoard = chessboardSquareNotation(n, sq_sz, x_offset_of_Board,
                                          y_offset_of_Board,
                                          generateFieldNames(n, swapSide),
                                          swapSide)
    the_text = mySmallFont.render(generateText(""), True, (255, 255, 255),
                                  colorOfTheSurface)
    textWithPoints = mySmallFont.render(generateText(""), True,
                                        (255, 255, 255), colorOfTheSurface)
    userPoints = 0
    insertFiguresIntoChessboard(whiteFigures,
                                blackFigures,
                                surface,
                                chessBoard,
                                sq_size=n)
    while True:
        # surface.blit(backgroundIMG, (0,0))
        return_to_menu.draw()
        # Draw a fresh background (a blank chess board)
        for row in range(n):  # Draw each row of the board.
            c_indx = row % 2  # Change starting color on each row
            for col in range(n):  # Run through cols drawing squares
                the_square = (col * sq_sz + x_offset_of_Board,
                              row * sq_sz + y_offset_of_Board, sq_sz, sq_sz)
                surface.fill(colors[c_indx], the_square)
                c_indx = (c_indx + 1) % 2

        insertFiguresIntoChessboard(whiteFigures,
                                    blackFigures,
                                    surface,
                                    chessBoard,
                                    sq_size=n)

        newText = myFont.render("Where is: " + generateText(fieldForUser),
                                True, (255, 255, 255), colorOfTheSurface)
        surface.blit(newText, (200, 80))
        ev = pygame.event.poll()
        if ev.type == pygame.MOUSEBUTTONDOWN:

            if ev.button is 1:  # 1- left button of the mouse
                pos = pygame.mouse.get_pos()
                pos_of_click = ev.dict['pos']
                if pos_of_click[0] >= return_to_menu.getX(
                ) and pos_of_click[0] < return_to_menu.getX(
                ) + return_to_menu.width and pos_of_click[
                        1] >= return_to_menu.getY() and pos_of_click[
                            1] < return_to_menu.getY() + return_to_menu.height:
                    return userPoints
                if pos_of_click[0] >= x_offset_of_Board and pos_of_click[
                        0] < x_offset_of_Board + surface_sz and pos_of_click[
                            1] >= y_offset_of_Board and pos_of_click[
                                1] < y_offset_of_Board + surface_sz:
                    print(pos_of_click)
                    field_name = getNameOfField(board_field_names,
                                                pos_of_click,
                                                x_offset_of_Board,
                                                y_offset_of_Board, sq_sz)
                    if field_name == fieldForUser:
                        the_text = mySmallFont.render(
                            generateText("Passed: " + field_name), True,
                            (255, 255, 255), colorOfTheSurface)
                        userPoints += 1
                        textWithPoints = mySmallFont.render(
                            generateText("Points: " + str(userPoints)), True,
                            (255, 255, 255), colorOfTheSurface)
                        if randomSwap is False:
                            print(swapSide)
                            board_field_names = generateFieldNames(n, swapSide)
                            chessBoard = chessboardSquareNotation(
                                n, sq_sz, x_offset_of_Board, y_offset_of_Board,
                                board_field_names, swapSide)
                            fieldForUser = generateFieldForUser(
                                board_field_names)
                        else:
                            board_field_names = generateFieldNames(
                                n, bool(random.randint(0, 1)))
                            chessBoard = chessboardSquareNotation(
                                n, sq_sz, x_offset_of_Board, y_offset_of_Board,
                                board_field_names, swapSide)
                            fieldForUser = generateFieldForUser(
                                board_field_names)
                    else:
                        the_text = mySmallFont.render(
                            generateText("This is:" + field_name), True,
                            (255, 255, 255), colorOfTheSurface)
                        surface.blit(the_text, (645, 550))
                        return userPoints

        insertFiguresIntoChessboard(whiteFigures,
                                    blackFigures,
                                    surface,
                                    chessBoard,
                                    sq_size=n)
        surface.blit(textWithPoints, (645, 500))
        surface.blit(the_text, (645, 550))
        pygame.display.flip()  # displaying pygame window
Esempio n. 6
0
# Set font/text for coins
font = pygame.font.SysFont('arial', 20)
def updateCoins(coins=0):
    text = font.render('Coins: {}'.format(coins), True, BLACK)
    screen.blit(text, [10, (GRID_SIZE+GRID_MARGIN) * GRID_NUM + GRID_MARGIN * 2, BOARD_SIZE, SCORE_HEIGHT])
def updateResult(msg):
    text = font.render(msg, True, BLACK)
    screen.blit(text, [10, (GRID_SIZE+GRID_MARGIN) * GRID_NUM + GRID_MARGIN * 10, BOARD_SIZE, SCORE_HEIGHT])
def drawCoin(rect):
    coin = pygame.transform.scale(pygame.image.load('./coin.jpg'),(GRID_SIZE,GRID_SIZE))
    screen.blit(coin, rect)

# Restart button
restart = pw.Button(
        screen, GRID_SIZE * (GRID_NUM-3), (GRID_SIZE+GRID_MARGIN) * GRID_NUM + GRID_MARGIN * 4, 90, 30, text='Restart',
        fontSize=20, margin=10, inactiveColour=GREEN, pressedColour=BLUE, radius=5,
        onClick=lambda: start())
# Quit button
quit = pw.Button(
        screen, GRID_SIZE * (GRID_NUM-1), (GRID_SIZE+GRID_MARGIN) * GRID_NUM + GRID_MARGIN * 4, 50, 30, text='Quit',
        fontSize=20, margin=10, inactiveColour=GREEN, pressedColour=BLUE, radius=5,
        onClick=lambda: exit())


def start():
    # Create board and players
    board = Board(GRID_NUM, RATIO)
    searcher = Player("Searcher", 0, 0,"./searcher.png",3,3)
    monster = Player("Monster", GRID_NUM-1, GRID_NUM-1,"./monster.jpg",BOARD_SIZE-50,BOARD_SIZE-50)
    board.board[searcher.row][searcher.col].players.append(searcher.name)
    board.board[monster.row][monster.col].players.append(monster.name)
Esempio n. 7
0
 def __init__(self, pos, size, parent_surface, **kargs):
     super().__init__(pos, size, parent_surface)
     self._widget = pygame_widgets.Button(parent_surface, *pos, *size,
                                          **kargs)
Esempio n. 8
0
  plt.close('all')

pog.init() # pygame stuff

window = pog.display.set_mode((w, h), DOUBLEBUF)
screen = pog.display.get_surface()
screen = pog.display.set_mode((w, h))
titleText = pogW.TextBox(window, (1080-450)/2, 15, 450, 25, fontSize=15)
surf = None

lbSlider = pogW.Slider(window, 650, 150, 300, 10, min=0, max=10, step=0.1) # interactive sliders and stuff in the program
nSlider = pogW.Slider(window, 650, 250, 300, 10, min=0, max=10, step=1)
lbText = pogW.TextBox(window, 650, 110, 150, 25, fontSize=15) # lambda text
nText = pogW.TextBox(window, 650, 210, 200, 25, fontSize=15) # n text
pText = pogW.TextBox(window, 75, 77, 200, 25, fontSize=15) # player text
dataB = pogW.Button(window, 100, 650, 200, 50, text='Random Graph', margin=2, onClick=clickPlot)
pog.display.set_caption('aiyah bruh')
pog.display.flip()

plotToScreen(X, data[dataInd], globalN)

run = True
while run: # actions to run throughout the program: update the screen if lambda or num. features is changed or if the dataset is changed (basically when the user interacts with the window)
  if pastLb != globalLb or pastN != globalN: # window only does normal equation if the parameters update since normal equation is computationally expensive
    plotToScreen(X, data[dataInd], globalN)
    #frameNum = 0

  time.sleep(0.01) # max framerate is 100 FPS
  events = pog.event.get()
  screen.fill(bgCol) # white BG color
  screen.blit(surf, (0, 30)) # render plt plot on surface to PyGame window
Esempio n. 9
0
    def __init__(self, results):
        self.results = results
        self.screen = pg.display.set_mode((640, 480))

        self.font = pg.font.Font(None, 32)
        self.input_boxes = [
            pg.Rect(150, 50, 140, 32),
            pg.Rect(150, 100, 140, 32),
            pg.Rect(150, 150, 140, 32)
        ]
        self.color_inactive = pg.Color('lightskyblue3')
        self.color_active = pg.Color('dodgerblue2')
        self.color = [
            self.color_inactive,
            self.color_inactive,
            self.color_inactive
        ]
        self.labels_text_for_input_boxes = [
            'min: ',
            'max: ',
            'quantity: '
        ]

        self.active = [False, False, False]
        self.text = ['', '', '']
        self.done = False

        self.checkboxes = [
            Checkbox(
                self.screen, 150, 230,
                caption='Random initial order', color=self.color_inactive,
                text_offset=(125, 0), font_color=self.color_inactive,
                font_size=32
            ),
            Checkbox(
                self.screen, 150, 270,
                caption='Descending initial order', color=self.color_inactive,
                text_offset=(140, 0), font_color=self.color_inactive,
                font_size=32
            ),
            Checkbox(
                self.screen, 150, 310,
                caption='Ascending initial order', color=self.color_inactive,
                text_offset=(135, 0), font_color=self.color_inactive,
                font_size=32
            )
        ]
        self.checkboxes[0].checked = True

        self.buttons = [
            pw.Button(
                self.screen, 150, 400, 100, 50, text='Run one sample',
                fontSize=18,
                inactiveColour=self.color_inactive,
                pressedColour=self.color_active,
                onClick=lambda: self.loading(True)
            ),
            pw.Button(
                self.screen, 290, 400, 100, 50, text='Run benchmark',
                fontSize=18,
                inactiveColour=self.color_inactive,
                pressedColour=self.color_active,
                onClick=lambda: self.loading(False)
            )
        ]
Esempio n. 10
0
    def setup(self):

        ## setups images

        self.update_disp_image_data()

        self.px = pygame.surfarray.make_surface(self.disp_data)

        image_size = self.px.get_rect()[2:]

        Window_size = image_size

        Window_size[0] = Window_size[0] + 400
        Window_size[1] = Window_size[1] + 5

        self.screen = pygame.display.set_mode(Window_size)
        self.screen.fill((128, 128, 128))
        self.screen.blit(self.px, self.px.get_rect())

        self.button_done = pw.Button(self.screen,
                                     Window_size[0] - 400 + 50,
                                     5,
                                     100,
                                     50,
                                     text='Done',
                                     fontSize=22,
                                     margin=10,
                                     inactiveColour=(255, 0, 0),
                                     pressedColour=(0, 255, 0),
                                     radius=20,
                                     onClick=lambda: self.Set_done_cmd(False))
        self.button_done.draw()

        self.slider_threshold = pw.Slider(self.screen,
                                          Window_size[0] - 400 + 25,
                                          110,
                                          150,
                                          10,
                                          min=0,
                                          max=1,
                                          step=.05,
                                          initial=0.5)
        self.slider_threshold.draw()

        self.text_threshold = pw.TextBox(self.screen,
                                         Window_size[0] - 400 + 0,
                                         60,
                                         50,
                                         40,
                                         fontSize=24)
        self.text_threshold.draw()

        text_threshold_describe = pw.TextBox(self.screen,
                                             Window_size[0] - 400 + 60,
                                             50,
                                             60,
                                             40,
                                             fontSize=16,
                                             borderColour=(128, 128, 128),
                                             colour=(128, 128, 128))
        text_threshold_describe.setText('Threshold')
        text_threshold_describe.draw()

        self.slider_min_dist = pw.Slider(self.screen,
                                         Window_size[0] - 400 + 25,
                                         180,
                                         150,
                                         10,
                                         min=1,
                                         max=100,
                                         step=1,
                                         initial=20)
        self.slider_min_dist.draw()

        self.text_min_dist = pw.TextBox(self.screen,
                                        Window_size[0] - 400 + 0,
                                        130,
                                        50,
                                        40,
                                        fontSize=24)
        self.text_min_dist.draw()

        text_min_dist_describe = pw.TextBox(self.screen,
                                            Window_size[0] - 400 + 60,
                                            120,
                                            60,
                                            40,
                                            fontSize=16,
                                            borderColour=(128, 128, 128),
                                            colour=(128, 128, 128))
        text_min_dist_describe.setText('Minimum Distance ')
        text_min_dist_describe.draw()

        self.slider_SVM = pw.Slider(self.screen,
                                    Window_size[0] - 400 + 225,
                                    60,
                                    150,
                                    10,
                                    min=.00,
                                    max=1,
                                    step=0.01,
                                    initial=0.5)
        self.slider_SVM.draw()

        self.text_SVM = pw.TextBox(self.screen,
                                   Window_size[0] - 400 + 200,
                                   10,
                                   60,
                                   40,
                                   fontSize=24)
        self.text_SVM.draw()

        text_SVM_describe = pw.TextBox(self.screen,
                                       Window_size[0] - 400 + 260,
                                       0,
                                       100,
                                       40,
                                       fontSize=16,
                                       borderColour=(128, 128, 128),
                                       colour=(128, 128, 128))
        text_SVM_describe.setText('SVM limit')
        text_SVM_describe.draw()

        self.slider_gauss = pw.Slider(self.screen,
                                      Window_size[0] - 400 + 25,
                                      320,
                                      150,
                                      10,
                                      min=0,
                                      max=10,
                                      step=1,
                                      initial=1)
        self.slider_gauss.draw()

        self.text_gauss = pw.TextBox(self.screen,
                                     Window_size[0] - 400 + 0,
                                     270,
                                     60,
                                     40,
                                     fontSize=24)
        self.text_gauss.draw()

        text_gauss_describe = pw.TextBox(self.screen,
                                         Window_size[0] - 400 + 60,
                                         260,
                                         100,
                                         40,
                                         fontSize=16,
                                         borderColour=(128, 128, 128),
                                         colour=(128, 128, 128))
        text_gauss_describe.setText('# Gauss')
        text_gauss_describe.draw()

        if self.number_of_frames == 1:
            self.number_of_frames = 2

        self.slider_frame_number = pw.Slider(self.screen,
                                             Window_size[0] - 400 + 25,
                                             450,
                                             150,
                                             10,
                                             min=0,
                                             max=self.number_of_frames - 1,
                                             step=1,
                                             initial=0)
        self.slider_frame_number.draw()

        self.text_frame_number = pw.TextBox(self.screen,
                                            Window_size[0] - 400 + 0,
                                            400,
                                            60,
                                            40,
                                            fontSize=24)
        self.text_frame_number.draw()
        text_frame_number_describe = pw.TextBox(self.screen,
                                                Window_size[0] - 400 + 60,
                                                390,
                                                100,
                                                40,
                                                fontSize=16,
                                                borderColour=(128, 128, 128),
                                                colour=(128, 128, 128))
        text_frame_number_describe.setText('Frame Number')
        text_frame_number_describe.draw()

        self.button_train = pw.Button(self.screen,
                                      Window_size[0] - 400 + 250,
                                      100,
                                      100,
                                      50,
                                      text='Train',
                                      fontSize=22,
                                      margin=10,
                                      inactiveColour=(255, 0, 0),
                                      pressedColour=(0, 255, 0),
                                      radius=20,
                                      onClick=lambda: self.Set_train_cmd(True))
        self.button_train.draw()

        self.slider_custom_SVM = pw.Slider(self.screen,
                                           Window_size[0] - 400 + 225,
                                           210,
                                           150,
                                           10,
                                           min=.05,
                                           max=1,
                                           step=0.02,
                                           initial=0.5)
        self.slider_custom_SVM.draw()

        self.text_custom_SVM = pw.TextBox(self.screen,
                                          Window_size[0] - 400 + 200,
                                          160,
                                          60,
                                          40,
                                          fontSize=24)
        self.text_custom_SVM.draw()

        text_custom_SVM_describe = pw.TextBox(self.screen,
                                              Window_size[0] - 400 + 260,
                                              170,
                                              100,
                                              40,
                                              fontSize=16,
                                              borderColour=(128, 128, 128),
                                              colour=(128, 128, 128))
        text_custom_SVM_describe.setText('Custom SVM limit')
        text_custom_SVM_describe.draw()

        self.slider_window_size = pw.Slider(self.screen,
                                            Window_size[0] - 400 + 225,
                                            300,
                                            150,
                                            10,
                                            min=8,
                                            max=64,
                                            step=2,
                                            initial=32)
        self.slider_window_size.draw()

        self.text_window_size = pw.TextBox(self.screen,
                                           Window_size[0] - 400 + 200,
                                           250,
                                           60,
                                           40,
                                           fontSize=24)
        self.text_window_size.draw()

        text_window_size_describe = pw.TextBox(self.screen,
                                               Window_size[0] - 400 + 260,
                                               260,
                                               100,
                                               40,
                                               fontSize=16,
                                               borderColour=(128, 128, 128),
                                               colour=(128, 128, 128))
        text_window_size_describe.setText('window size')
        text_window_size_describe.draw()
Esempio n. 11
0
def main():
    global game_state, window, main_menu_buttons, counter, label_info, pause_menu, gamefield
    Textures.load()
    best_score = get_best()
    game_state = Game_state()
    Game_state.update = game_state_update
    window = pygame_widgets.Window(flags=FULLSCREEN,
                                   bg_color=Textures.window,
                                   fps=constants.FPS)
    window.add_handler(KEYDOWN,
                       lambda e: restart(game_state.mode) if e.key == K_RETURN
                       and game_state.state in ['win', 'gameover'] else None,
                       self_arg=False,
                       delay=1)
    window.add_handler(KEYDOWN, pause, self_arg=False)
    window.add_handler(QUIT,
                       lambda: set_best(best_score),
                       self_arg=False,
                       event_arg=False)
    window.add_handler(KEYDOWN,
                       lambda e: screenshot() if e.key == K_F2 else None,
                       self_arg=False)
    # window.add_handler(constants.E_STATE_CHANGED,
    #                    lambda e: restart(None) if e.key == 'mode' and e.new_value is None else None, self_arg=False)
    window.handlers[QUIT].reverse()
    window.add_handler(constants.E_GAME_FINISHED,
                       lambda: set_best(best_score),
                       self_arg=False,
                       event_arg=False)
    window.add_handler(constants.E_STATE_CHANGED,
                       info,
                       self_arg=True,
                       event_arg=True)
    # button_exit = pygame_widgets.Button(window, (0, 18), (100, 17), text="Exit")
    # button_exit.add_handler(E_BUTTON_BUMPED, button_wrapper(window.quit))

    BUTTON_KWARGS = Args(
        font_name='TrebuchetMS',
        font_size=50,
        bold=True,
        font_color=THECOLORS['white'],
        bg_normal=THECOLORS['transparent'],
        bg_mouseover=button_bg(THECOLORS['transparent'], THECOLORS['red'], 10),
        bg_pressed=button_bg(THECOLORS['transparent'], THECOLORS['red4'], 10),
        cursor_mouseover=pygame_widgets.auxiliary.cursors.hand,
        cursor_pressed=pygame_widgets.auxiliary.cursors.hand)[1]
    main_menu_buttons = [
        pygame_widgets.Button(window, (710, 350), (500, 100),
                              text="Original",
                              **BUTTON_KWARGS),
        pygame_widgets.Button(window, (710, 450), (500, 100),
                              text="Test",
                              **BUTTON_KWARGS),
        pygame_widgets.Button(window, (710, 600), (500, 100),
                              text="Options",
                              **BUTTON_KWARGS),
        pygame_widgets.Button(window, (710, 700), (500, 100),
                              text="Exit",
                              **BUTTON_KWARGS),
    ]
    for button in main_menu_buttons[:-2]:
        button.add_handler(E_BUTTON_BUMPED,
                           button_wrapper(button_mode_click, self_arg=True))
    main_menu_buttons[-2].add_handler(E_BUTTON_BUMPED,
                                      button_wrapper(button_options_click))
    main_menu_buttons[-1].add_handler(E_BUTTON_BUMPED,
                                      button_wrapper(window.quit))

    counter = Live_counter(window, (0, 36))
    label_info = pygame_widgets.Label(window,
                                      visible=False,
                                      font="trebuchet_ms",
                                      font_size=60,
                                      alignment_x=1,
                                      alignment_y=1,
                                      font_color=THECOLORS['white'],
                                      bold=True,
                                      italic=True)
    label_score = pygame_widgets.Label(window, (0, 72),
                                       auto_res=True,
                                       font_color=THECOLORS['yellow'],
                                       bold=True,
                                       text="Score: 0")
    label_best = pygame_widgets.Label(window, (0, 90),
                                      auto_res=True,
                                      font_color=THECOLORS['yellow'],
                                      bold=True,
                                      text=f"Best: {best_score}")
    pause_menu = Pause_menu(window, BUTTON_KWARGS)
    pause_menu.button_menu_click = pause_button_menu_click
    pause_menu.button_restart_click = pause_button_restart_click
    gamefield = None

    while True:
        # window.handle_events(*event.get())
        for event in pygame.event.get():
            if event.type == ACTIVEEVENT and event.state in (
                    2, 7
            ) and game_state.mode is not None and game_state.state == 'playing':
                pause_menu.activate()
            else:
                window.handle_event(event)
        label_score.set(text=f"Score: {game_state.points}")
        if game_state.points > best_score:
            best_score = game_state.points
            label_best.set(text=f"Best: {best_score}")
        window.update_display()
        pygame_widgets.new_loop()
Esempio n. 12
0
                elif 'wikipedia'in query:
                        speak('searching wikipedia')
                        query=query.replace('wikipedia','')
                        result=wikipedia.summary(query,2)
                        text(result,green,0,400)
                        speak(result)
                elif 'open youtube'in query:
                        webbrowser.open('https://www.youtube.com')
                elif 'open google'in query:
                        webbrowser.open('https://www.google.com')
                        
                elif 'open facebook'in query:
                        webbrowser.open('https://www.facebook.com')
                elif 'open twitter'in query:
                        webbrowser.open('https://www.twitter.com')
button=pw.Button(display,393,460,60,90,text="Init(:)",fontsize=3,margin=20,inactivecolor=(50,50,50),pressedcolor=(255,255,255),radius=150,onClick=lambda:mainloop())
              
while True:
      display.blit(pygame.transform.scale(background,(800,600)),(0,0))
      display.blit(pygame.transform.scale(terminal,(200,200)),(0,400))
      display.blit(pygame.transform.scale(jarvis,(500,500)),(180,100))

      pygame.display.update()
      event=pygame.event.get()
      for event in event:
        if event.type==QUIT:
                quit()
                sys.exit()
                display.update()
      button.listen(event)
      button.draw()
Esempio n. 13
0
    font = pygame.font.SysFont('tahoma', 30)
    views = ['sat', 'map', 'sat,skl']
    now = 0

    def change_view():
        global now
        now = (now + 1) % 3
        write_image()

    button_play = pygame_widgets.Button(screen,
                                        125,
                                        320,
                                        300,
                                        50,
                                        text='Изменить тип',
                                        fontSize=50,
                                        inactiveColour=(255, 204, 219),
                                        pressedColour=(255, 204, 219),
                                        onClick=change_view,
                                        textColour=(0, 0, 0),
                                        hoverColour=(255, 204, 219),
                                        font=font,
                                        textHAlign='centre')
    write_image()
    fps = 50
    clock = pygame.time.Clock()
    while True:
        events = pygame.event.get()
        for i in events:
            if i.type == pygame.QUIT:
                os.remove('map.png')
                pygame.quit()
Esempio n. 14
0
def draw_board(the_board):
    pygame.init()
    pygame.display.set_caption("Play the chess game")
    colors = [(255, 255, 255), (0, 255, 0)]  # Set up colors [white, green]

    n = len(the_board)  # This is an NxN chess board.
    surface_sz = 480  # Proposed physical surface size.
    sq_sz = surface_sz // n  # sq_sz is length of a square.
    print(sq_sz)
    # surface_sz = n * sq_sz     # Adjust window to exactly fit n squares.
    x_offset_of_Board = 150
    y_offset_of_Board = 150
    board_field_names = generateFieldNames(n)
    blackFigures, whiteFigures = initFigures()
    surface = pygame.display.set_mode((800, 650))
    colorOfTheSurface = (0, 0, 0)
    surface.fill(colorOfTheSurface)
    return_to_menu = pw.Button(surface,
                               10,
                               550,
                               130,
                               65,
                               text='Back',
                               fontSize=20,
                               margin=20,
                               inactiveColour=(100, 100, 100),
                               pressedColour=(255, 0, 0),
                               radius=14,
                               onClick=lambda: print('Click'))

    chessBoard = chessboardSquareNotation(n, sq_sz, x_offset_of_Board,
                                          y_offset_of_Board,
                                          generateFieldNames(n))
    white_position, black_position, figurePos = insertFiguresIntoChessboard(
        whiteFigures, blackFigures, surface, chessBoard, sq_size=n)
    print(white_position)
    print(black_position)
    print(figurePos)
    move = 0
    while True:
        return_to_menu.draw()
        # Draw a fresh background (a blank chess board)
        for row in range(n):  # Draw each row of the board.
            c_indx = row % 2  # Change starting color on each row
            for col in range(n):  # Run through cols drawing squares
                the_square = (col * sq_sz + x_offset_of_Board,
                              row * sq_sz + y_offset_of_Board, sq_sz, sq_sz)
                surface.fill(colors[c_indx], the_square)
                c_indx = (c_indx + 1) % 2

        # insertFiguresIntoChessboard(whiteFigures, blackFigures, surface, chessBoard, sq_size=n)

        ev = pygame.event.poll()
        if ev.type == pygame.MOUSEBUTTONDOWN:

            if ev.button is 1:  # 1- left button of the mouse
                pos = pygame.mouse.get_pos()
                pos_of_click = ev.dict['pos']
                if pos_of_click[0] >= return_to_menu.getX(
                ) and pos_of_click[0] < return_to_menu.getX(
                ) + return_to_menu.width and pos_of_click[
                        1] >= return_to_menu.getY() and pos_of_click[
                            1] < return_to_menu.getY() + return_to_menu.height:
                    break
                elif pos_of_click[0] >= x_offset_of_Board and pos_of_click[
                        0] < x_offset_of_Board + surface_sz and pos_of_click[
                            1] >= y_offset_of_Board and pos_of_click[
                                1] < y_offset_of_Board + surface_sz:
                    field_name = getNameOfField(board_field_names,
                                                pos_of_click,
                                                x_offset_of_Board,
                                                y_offset_of_Board, sq_sz)
                    print(field_name)
                    clickInFieldToMoveFigure(pos_of_click[0], pos_of_click[1],
                                             field_name, figurePos)

        if move == 0:
            insertFiguresIntoChessboard(whiteFigures,
                                        blackFigures,
                                        surface,
                                        chessBoard,
                                        sq_size=n)
        else:
            newChessboardLayout(whiteFigures,
                                blackFigures,
                                surface,
                                chessBoard,
                                sq_size=n)
        pygame.display.flip()  # displaying pygame window
Esempio n. 15
0
def setup(Frame,Refence_dict):        
     
     im = Frame  
     
     im   = (im - (np.min(im))) 
     im = 255 * (im / np.max(im))
     
     clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
     im = clahe.apply(im.astype(np.uint8))
     
     
     
     w, h = im.shape
     ret = np.empty((w, h, 3), dtype=np.uint8)
     ret[:, :, 2] = im
     ret[:, :, 1] = im
     ret[:, :, 0] = im 
     
     px = pygame.surfarray.make_surface(ret)
     
     image_size = px.get_rect()[2:]

     Window_size = image_size 
    
     Window_size [0] = Window_size [0] + 200
     Window_size [1] = Window_size [1] + 5
     
     screen = pygame.display.set_mode( Window_size )
     screen.fill((128,128,128))
     screen.blit(px, px.get_rect())
     
     
     
     global button_done     

     button_done = pw.Button(
                screen, Window_size [0] - 200 + 50, 80, 100, 50, text='Done',
                fontSize=22, margin=10,
                inactiveColour=(255, 0, 0),
                pressedColour=(0, 255, 0), radius=20,
                onClick=lambda: Set_done_cmd(False) )
        
     
     global button_redo     

     button_redo = pw.Button(
                screen, Window_size [0] - 200 + 50, 10, 100, 50, text='Redo',
                fontSize=22, margin=10,
                inactiveColour=(255, 0, 0),
                pressedColour=(0, 255, 0), radius=20,
                onClick=lambda: Set_redo_cmd(True)) 
     
     global slider_contrast    

     slider_contrast= pw.Slider(
                screen, Window_size [0] - 200 + 25, 150, 150, 10, min = 0, max = 511,step = 1)
     
     
     
     global text_contrast 
     
     text_contrast = pw.TextBox(
                screen, Window_size [0] - 200 + 25, 170, 60, 40, fontSize=24)
     
     text_contrast_describe = pw.TextBox(
                screen, Window_size [0] - 200 + 85, 170, 100, 40, fontSize=16,
                borderColour=(128, 128, 128),colour=(128, 128, 128))
     text_contrast_describe.setText('Contrast')
     text_contrast_describe.draw()
     
     
     global slider_brightness    

     slider_brightness= pw.Slider(
                screen, Window_size [0] - 200 + 25, 230, 150, 10, min = 0, max = 511, step = 1)
     
     
     global text_brightness
     
     text_brightness = pw.TextBox(
                screen, Window_size [0] - 200 + 25, 250, 60, 40, fontSize=24)
     
     
     text_brightness_describe = pw.TextBox(
                screen, Window_size [0] - 200 + 85, 250, 100, 40, fontSize=16,
                borderColour=(128, 128, 128),colour=(128, 128, 128))
     text_brightness_describe.setText('Brightness')
     text_brightness_describe.draw()
     
     
     global text_frame_number
     
     text_frame_number = pw.TextBox(
                screen, Window_size [0] - 200 + 25, 430, 60, 40, fontSize=24)
     
     if len(Refence_dict)!= 1:
         global slider_frame_number    
    
         slider_frame_number= pw.Slider(
                    screen, Window_size [0] - 200 + 25, 410, 150, 10, min = 0, max = len(Refence_dict)-1, step = 1,initial = 1)
         
         text_frame_describe = pw.TextBox(
                    screen, Window_size [0] - 200 + 85, 430, 100, 40, fontSize=16,
                    borderColour=(128, 128, 128),colour=(128, 128, 128))
         text_frame_describe.setText('Frame Number')
         text_frame_describe.draw()
     

    
     slider_contrast.draw()     
     slider_brightness.draw()

     
     text_contrast.draw()
     text_brightness.draw()  
    
     button_done.draw()
     
     button_redo.draw()
     
     if len(Refence_dict)!= 1:
         text_frame_number.draw()
         slider_frame_number.draw()
     
     
     return screen, px
    def setup(self):

        ## setups images

        self.update_disp_image_data()
        self.update_disp_image_label()

        SHOW_IMG = np.concatenate([self.disp_data, self.disp_Label], axis=0)

        self.px = pygame.surfarray.make_surface(SHOW_IMG)

        image_size = self.px.get_rect()[2:]

        Window_size = image_size

        Window_size[0] = Window_size[0] + 400
        Window_size[1] = Window_size[1] + 5

        self.screen = pygame.display.set_mode(Window_size)
        self.screen.fill((128, 128, 128))
        self.screen.blit(self.px, self.px.get_rect())

        self.button_done = pw.Button(self.screen,
                                     Window_size[0] - 400 + 50,
                                     5,
                                     100,
                                     50,
                                     text='Done',
                                     fontSize=22,
                                     margin=10,
                                     inactiveColour=(255, 0, 0),
                                     pressedColour=(0, 255, 0),
                                     radius=20,
                                     onClick=lambda: self.Set_done_cmd(False))
        self.button_done.draw()

        self.slider_x = pw.Slider(self.screen,
                                  Window_size[0] - 400 + 25,
                                  110,
                                  150,
                                  10,
                                  min=0,
                                  max=100,
                                  step=1)
        self.slider_x.draw()

        self.text_x = pw.TextBox(self.screen,
                                 Window_size[0] - 400 + 0,
                                 60,
                                 100,
                                 40,
                                 fontSize=24)
        self.text_x.draw()

        text_x_describe = pw.TextBox(self.screen,
                                     Window_size[0] - 400 + 100,
                                     50,
                                     100,
                                     40,
                                     fontSize=16,
                                     borderColour=(128, 128, 128),
                                     colour=(128, 128, 128))
        text_x_describe.setText('X tilt')
        text_x_describe.draw()

        self.slider_y = pw.Slider(self.screen,
                                  Window_size[0] - 400 + 25,
                                  180,
                                  150,
                                  10,
                                  min=0,
                                  max=100,
                                  step=1)
        self.slider_y.draw()

        self.text_y = pw.TextBox(self.screen,
                                 Window_size[0] - 400 + 0,
                                 130,
                                 100,
                                 40,
                                 fontSize=24)
        self.text_y.draw()

        text_y_describe = pw.TextBox(self.screen,
                                     Window_size[0] - 400 + 100,
                                     120,
                                     100,
                                     40,
                                     fontSize=16,
                                     borderColour=(128, 128, 128),
                                     colour=(128, 128, 128))
        text_y_describe.setText('Y tilt')
        text_y_describe.draw()

        self.slider_n = pw.Slider(self.screen,
                                  Window_size[0] - 400 + 25,
                                  250,
                                  150,
                                  10,
                                  min=1,
                                  max=10,
                                  step=1,
                                  initial=self.n)
        self.slider_n.draw()

        self.text_n = pw.TextBox(self.screen,
                                 Window_size[0] - 400 + 0,
                                 200,
                                 60,
                                 40,
                                 fontSize=24)
        self.text_n.draw()

        text_n_describe = pw.TextBox(self.screen,
                                     Window_size[0] - 400 + 60,
                                     190,
                                     100,
                                     40,
                                     fontSize=16,
                                     borderColour=(128, 128, 128),
                                     colour=(128, 128, 128))
        text_n_describe.setText('Number of clusters')
        text_n_describe.draw()

        self.slider_gauss = pw.Slider(self.screen,
                                      Window_size[0] - 400 + 25,
                                      320,
                                      150,
                                      10,
                                      min=0,
                                      max=10,
                                      step=1,
                                      initial=0)
        self.slider_gauss.draw()

        self.text_gauss = pw.TextBox(self.screen,
                                     Window_size[0] - 400 + 0,
                                     270,
                                     60,
                                     40,
                                     fontSize=24)
        self.text_gauss.draw()

        text_gauss_describe = pw.TextBox(self.screen,
                                         Window_size[0] - 400 + 60,
                                         260,
                                         100,
                                         40,
                                         fontSize=16,
                                         borderColour=(128, 128, 128),
                                         colour=(128, 128, 128))
        text_gauss_describe.setText('# Gauss')
        text_gauss_describe.draw()

        if self.number_of_frames == 1:
            self.number_of_frames = 2

        self.slider_frame_number = pw.Slider(self.screen,
                                             Window_size[0] - 400 + 25,
                                             450,
                                             150,
                                             10,
                                             min=0,
                                             max=self.number_of_frames - 1,
                                             step=1,
                                             initial=0)
        self.slider_frame_number.draw()

        self.text_frame_number = pw.TextBox(self.screen,
                                            Window_size[0] - 400 + 0,
                                            400,
                                            60,
                                            40,
                                            fontSize=24)
        self.text_frame_number.draw()
        text_frame_number_describe = pw.TextBox(self.screen,
                                                Window_size[0] - 400 + 60,
                                                390,
                                                100,
                                                40,
                                                fontSize=16,
                                                borderColour=(128, 128, 128),
                                                colour=(128, 128, 128))
        text_frame_number_describe.setText('Frame Number')
        text_frame_number_describe.draw()
Esempio n. 17
0
def play():
    napredek_array = []

    dack_back_uno_card = pygame.image.load('card_images/uno_cover.png')
    #define all buttons
    if show_graphics:
        skip_button = pygame_widgets.Button(
            gameDisplay,
            display_width / 2.0 - 30,
            display_height / 2.0 - 120,
            80,
            30,
            text='Skip',
            fontSize=30,
            margin=10,
            inactiveColour=(255, 0, 0),
            pressedColour=(0, 255, 0),
            radius=20,
            onClick=lambda: skip_button_pressed(main_board, player_1))

        pick_color_red = pygame_widgets.Button(
            gameDisplay,
            display_width - 200,
            display_height / 2.0 - 140,
            100,
            50,
            text='Red',
            fontSize=30,
            margin=10,
            inactiveColour=(255, 0, 0),
            pressedColour=(0, 255, 0),
            radius=20,
            onClick=lambda: pick_color(player_1, 'red'))

        pick_color_green = pygame_widgets.Button(
            gameDisplay,
            display_width - 200,
            display_height / 2.0 - 45,
            100,
            50,
            text='Green',
            fontSize=30,
            margin=10,
            inactiveColour=(0, 255, 0),
            pressedColour=(0, 255, 0),
            radius=20,
            onClick=lambda: pick_color(player_1, 'green'))

        pick_color_blue = pygame_widgets.Button(
            gameDisplay,
            display_width - 200,
            display_height / 2.0 + 45,
            100,
            50,
            text='Blue',
            fontSize=30,
            margin=10,
            inactiveColour=(0, 0, 255),
            pressedColour=(0, 255, 0),
            radius=20,
            onClick=lambda: pick_color(player_1, 'blue'))

        pick_color_yellow = pygame_widgets.Button(
            gameDisplay,
            display_width - 200,
            display_height / 2.0 + 140,
            100,
            50,
            text='Yellow',
            fontSize=30,
            margin=10,
            inactiveColour=(255, 255, 0),
            pressedColour=(0, 255, 0),
            radius=20,
            onClick=lambda: pick_color(player_1, 'yellow'))

    if play_as_agent:
        # Widgets for settings
        widg_sim = widgets.IntText(value=100, description="Simulations:")
        widg_algo = widgets.Dropdown(options=["monte-carlo", "q-learning"],
                                     value="monte-carlo",
                                     description="Algorithm:")
        widg_new_model = widgets.Dropdown(options=[True, False],
                                          value=False,
                                          description="New Model:")
        widg_comment = widgets.Dropdown(options=[True, False],
                                        value=False,
                                        description="Show Game:")

        # Widgets for parameters
        widg_epsilon = widgets.FloatSlider(value=0.05,
                                           min=0,
                                           max=1,
                                           step=0.01,
                                           description="Epsilson:",
                                           readout_format=".2f")
        widg_step = widgets.FloatSlider(value=0.2,
                                        min=0,
                                        max=1,
                                        step=0.01,
                                        description="Step Size:",
                                        readout_format=".2f")

        agent_info = {
            "epsilon": widg_epsilon.value,
            "step_size": widg_step.value,
            "new_model": widg_new_model.value
        }

        if algorithm == "q-learning":
            agent = ag.QLearningAgent()
        else:
            agent = ag.MonteCarloAgent()
        agent.agent_init(agent_info)

    wins_player_1 = 0
    wins_player_2 = 0

    wins_player_1_cur_round = 0
    wins_player_2_cur_round = 0

    wins_player_1_cur_round_1000 = 0
    wins_player_2_cur_round_1000 = 0

    for round_idx in range(rounds_play):
        if round_idx == 0:
            print("started playing game")

        if round_idx % 1000 == 0 and round_idx > 0:
            print("round: ", round_idx)
            print("wins player 1: ", wins_player_1_cur_round_1000)
            print("wins player 2: ", wins_player_2_cur_round_1000)

            wins_player_1_cur_round_1000 = 0
            wins_player_2_cur_round_1000 = 0

        if round_idx % 10000 == 0 and round_idx > 0:
            print("round: ", round_idx)
            print("wins player 1: ", wins_player_1_cur_round)
            print("wins player 2: ", wins_player_2_cur_round)
            napredek_array.append(
                (wins_player_1_cur_round /
                 (wins_player_1_cur_round + wins_player_2_cur_round)))

            wins_player_1_cur_round = 0
            wins_player_2_cur_round = 0

        player_1_score = 0
        player_2_score = 0

        for ingame_round in range(ingame_rounds):

            main_player_draw_a_card = False
            cur_picked_color = None
            put_card_on_top_after_color_choice = None

            main_board = board()

            if play_as_agent:
                if ingame_round == 0:
                    player_1_actions = dict()
                    player_1 = agentPlayer(main_board,
                                           actions=player_1_actions)
                else:
                    player_1_actions = dict()
                    player_1 = agentPlayer(main_board,
                                           actions=player_1_actions)

            elif not play_as_agent:
                player_1 = player(main_board)

            for _ in range(num_of_bot_players):
                player(main_board)

            game_running = True

            while game_running:

                #time.sleep(wait_each_turn)

                cur_player = main_board.get_cur_player()

                if show_graphics:
                    gameDisplay.fill(light_gray)
                    display_cards_in_hand(player_1)

                if not play_as_agent:
                    #all events that happened
                    events = pygame.event.get()
                    for event in events:
                        if event.type == pygame.QUIT:
                            exit()

                        cur_mouse_x, cur_mouse_y = pygame.mouse.get_pos()

                        #markup cards if they can be played and player hovers over them
                        for card in player_1.hand:
                            if card.hover_over_card(
                                    cur_mouse_x,
                                    cur_mouse_y,
                                    main_board.cur_top_card,
                                    player_turn=cur_player == player_1):
                                draw_rect_around_image(card.card_image)
                            else:
                                #update only if player is not chosing color
                                if put_card_on_top_after_color_choice != card:
                                    card.update_image()

                        # if player_turn and player hasn't drawn a new card jet, it can draw a card
                        if cur_player == player_1 and not main_player_draw_a_card:
                            if cur_mouse_x >= deck_card_x and cur_mouse_y >= deck_card_y and cur_mouse_x <= (
                                    deck_card_x + card_width
                            ) and cur_mouse_y <= (deck_card_y + card_height):
                                draw_rect_around_image(dack_back_uno_card)
                            else:
                                dack_back_uno_card = pygame.image.load(
                                    'card_images/uno_cover.png')

                        #player clicked on card
                        if cur_player == player_1 and event.type == pygame.MOUSEBUTTONDOWN:
                            main_player_picked_something = False

                            for card in player_1.hand:
                                if card.hover_over_card(
                                        cur_mouse_x,
                                        cur_mouse_y,
                                        main_board.cur_top_card,
                                        player_turn=cur_player == player_1):
                                    card.update_image()

                                    if card.value != 13 and card.value != 14:
                                        main_board.put_card_on_top(card)
                                        player_1.hand.remove(card)
                                        player_1.update_card_positions()
                                        main_player_picked_something = True
                                        break
                                    else:
                                        put_card_on_top_after_color_choice = card
                                        break

                            # if player_turn
                            if cur_player == player_1 and not main_player_draw_a_card:
                                if cur_mouse_x >= deck_card_x and cur_mouse_y >= deck_card_y and cur_mouse_x <= (
                                        deck_card_x +
                                        card_width) and cur_mouse_y <= (
                                            deck_card_y + card_height):
                                    player_1.draw_cards(1)
                                    main_player_draw_a_card = True
                                    put_card_on_top_after_color_choice = None
                                    dack_back_uno_card = pygame.image.load(
                                        'card_images/uno_cover.png')

                            if main_player_picked_something:
                                reset_player_1_status(player_1)
                                main_board.next_player()

                    #display and add listener to skip turn button
                    if main_player_draw_a_card:
                        skip_button.listen(events)
                        skip_button.draw()

                    #display pick color buttons if necessarry
                    if put_card_on_top_after_color_choice != None:
                        pick_color_red.listen(events)
                        pick_color_red.draw()
                        pick_color_green.listen(events)
                        pick_color_green.draw()
                        pick_color_blue.listen(events)
                        pick_color_blue.draw()
                        pick_color_yellow.listen(events)
                        pick_color_yellow.draw()

                elif play_as_agent:

                    events = pygame.event.get()
                    for event in events:

                        if cur_player == player_1 and event.type == pygame.MOUSEBUTTONDOWN:
                            #print("make player 1 move")
                            #prev_player_1_score = player_1.count_card_score_in_hand()

                            success = player_1.play_agent(
                                agent,
                                num_cards_oponent=len(
                                    main_board.players[1].hand))
                            """
                            if success:
                                cur_player_1_score = player_1.count_card_score_in_hand()

                                cur_reward = min((prev_player_1_score - cur_player_1_score) / 50, 0)

                                agent.update_single_action(player_1.state, player_1.action, reward=cur_reward)
                            """

                            if main_player_draw_a_card or success:
                                main_player_picked_something = True
                                main_player_draw_a_card = False

                                reset_player_1_status(player_1)
                                main_board.next_player()

                            elif not success and not main_player_draw_a_card:
                                player_1.draw_cards(1)
                                main_player_draw_a_card = True

                            if show_graphics:
                                player_1.update_card_positions()

                            break

                #put card on top after player color choice
                if put_card_on_top_after_color_choice != None and player_1.chosen_color != None:
                    main_board.put_card_on_top(
                        put_card_on_top_after_color_choice,
                        color_if_change_color=player_1.chosen_color)
                    player_1.hand.remove(put_card_on_top_after_color_choice)
                    player_1.update_card_positions()

                    reset_player_1_status(player_1)
                    main_board.next_player()

                #if bot plays
                if cur_player != player_1:
                    main_board.make_bot_move()

                #display card in the middle
                display_up_card(card_on_middle_x, card_on_middle_y,
                                main_board.cur_top_card)

                #display deck card in the middle
                if show_graphics:
                    gameDisplay.blit(dack_back_uno_card,
                                     (deck_card_x, deck_card_y))

                    #display bot player information
                    player_infos = main_board.get_bot_players_info()

                    for i, player_info in enumerate(player_infos):
                        cur_bot_display_info = 'Bot player ' + str(
                            i + 1) + ': ' + str(player_info) + ' cards'
                        textsurface = myfont.render(cur_bot_display_info, True,
                                                    (0, 0, 0))
                        gameDisplay.blit(textsurface, (0, 30 * i))

                        if player_info == 1:
                            cur_bot_one_card_display_info = 'Bot player ' + str(
                                i + 1) + ' has only one card left!'
                            textsurface_one_card = myfont.render(
                                cur_bot_one_card_display_info, True,
                                (255, 0, 0))
                            gameDisplay.blit(
                                textsurface_one_card,
                                (display_width / 2.0 - 160,
                                 display_height / 2.0 + 80 + 20 * i))

                    #display current player
                    if main_board.cur_player == 0:
                        cur_player_text = "It's your turn"
                    else:
                        cur_player_text = "It player " + str(
                            main_board.cur_player) + " turn"
                    textsurface = myfont.render(cur_player_text, True,
                                                (0, 0, 255))
                    gameDisplay.blit(
                        textsurface,
                        (display_width / 2.0 - 55, display_height / 2.0 - 200))

                    #display cur card color
                    if main_board.cur_top_card.color == 'red':
                        color = (255, 0, 0)
                    elif main_board.cur_top_card.color == 'green':
                        color = (0, 255, 0)
                    elif main_board.cur_top_card.color == 'blue':
                        color = (0, 0, 255)
                    elif main_board.cur_top_card.color == 'yellow':
                        color = (255, 255, 0)
                    else:
                        color = (255, 255, 0)

                    textsurface = myfont.render(main_board.cur_top_card.color,
                                                True, color)
                    gameDisplay.blit(textsurface,
                                     (display_width / 2.0 - 14, 10))

                #check for victory
                player_that_won = main_board.check_for_victory()

                game_running = player_that_won == -1

                if player_that_won != -1:
                    cur_score_player_1 = player_1.count_card_score_in_hand()
                    player_2_score += main_board.players[
                        1].count_card_score_in_hand()
                    player_1_score += cur_score_player_1

                    if cur_score_player_1 < 5:
                        cur_reward = (10 - cur_score_player_1) / 10
                    elif cur_score_player_1 < 30:
                        cur_reward = (30 - cur_score_player_1) / 100
                    else:
                        cur_reward = 0

                    player_1.identify_state(
                        num_cards_oponent=len(main_board.players[1].hand))

                    if player_1.state != None and player_1.action != None:
                        agent.update(player_1.state,
                                     player_1.action,
                                     reward=cur_reward)
                    else:
                        print("couldn't update!")
                        print(player_1.state)
                        print(player_1.action)

                    assert main_board.players[0] == player_1
                    assert main_board.players[1] != player_1

                if show_graphics:
                    pygame.display.update()

                    clock.tick(FPS)

        if player_1_score < player_2_score:
            wins_player_1 += 1
            wins_player_1_cur_round += 1
            wins_player_1_cur_round_1000 += 1
        elif player_1_score == player_2_score:
            wins_player_1 += 1
            wins_player_2 += 1
            wins_player_1_cur_round += 1
            wins_player_2_cur_round += 1
            wins_player_1_cur_round_1000 += 1
            wins_player_2_cur_round_1000 += 1
        else:
            wins_player_2 += 1
            wins_player_2_cur_round += 1
            wins_player_2_cur_round_1000 += 1

    print("\nwins player 1: ", wins_player_1)
    print("wins player 2: ", wins_player_2)

    print(napredek_array)

    agent.save_agent()

    pygame.quit()
Esempio n. 18
0
def mainMenu():
    pygame.init()
    surface = pygame.display.set_mode((800, 650))
    colorOfTheSurface = (0, 200, 120)
    surface.fill(colorOfTheSurface)
    # titleIMG = pygame.image.load("images/mainTheme1.png")
    backgroundIMG = pygame.image.load("images/chessMainMenu.jpg")
    isNewGame = True
    myFont = pygame.font.SysFont("Courier", 30, bold=True)
    start_button = pw.Button(surface,
                             230,
                             150,
                             350,
                             100,
                             text='TRAIN FIELDS',
                             fontSize=40,
                             margin=20,
                             inactiveColour=(110, 110, 110),
                             pressedColour=(255, 0, 0),
                             radius=14,
                             onClick=lambda: print('Click'))
    gameplay_button = pw.Button(surface,
                                230,
                                270,
                                350,
                                100,
                                text='PLAY THE GAME',
                                fontSize=40,
                                margin=20,
                                inactiveColour=(110, 110, 110),
                                pressedColour=(255, 0, 0),
                                radius=14,
                                onClick=lambda: print('Click'))
    learn_tactics = pw.Button(surface,
                              230,
                              390,
                              350,
                              100,
                              text='LEARN TACTICS',
                              fontSize=40,
                              margin=20,
                              inactiveColour=(150, 110, 110),
                              pressedColour=(255, 0, 0),
                              radius=14,
                              onClick=lambda: print('Click'))
    while True:
        pygame.display.set_caption("menu")
        surface.fill(colorOfTheSurface)
        surface.blit(pygame.transform.scale(backgroundIMG, (800, 650)), (0, 0))
        ev = pygame.event.poll()
        start_button.draw()
        gameplay_button.draw()
        learn_tactics.draw()
        # surface.blit(pygame.transform.scale(titleIMG, (600,200)),(surface.get_height()/6, 50))
        if ev.type == pygame.QUIT:
            break
        if ev.type == pygame.MOUSEBUTTONDOWN:
            pos_of_click = ev.dict['pos']
            if start_button.getX() < pos_of_click[0] < start_button.getX(
            ) + start_button.width and start_button.getY(
            ) + start_button.height > pos_of_click[1] > start_button.getY():
                startGame()
            elif gameplay_button.getX(
            ) < pos_of_click[0] < gameplay_button.getX(
            ) + gameplay_button.width and gameplay_button.getY(
            ) + gameplay_button.height > pos_of_click[
                    1] > gameplay_button.getY():
                # play()  # first option from PlayMode.py
                draw_board(8)  # option from objective/main.py
        pygame.display.flip()  # displaying pygame window

    pygame.quit()
Esempio n. 19
0
    return 0


# -------------------- FUNÇÕES -----------------------#

# -------------------- BOTÕES -----------------------#

botao_sound = pygame.mixer.Sound('jogo/img/sound_effect/menu_botao.wav')

botao_de_quit = pw.Button(screen,
                          425,
                          475,
                          130,
                          70,
                          text='Sair',
                          fontSize=50,
                          textColour=(0, 0, 0),
                          margin=20,
                          inactiveColour=(150, 150, 150),
                          pressedColour=(0, 255, 0),
                          radius=20,
                          onClick=lambda: pygame.quit())

botao_de_jogar = pw.Button(screen,
                           420,
                           375,
                           140,
                           70,
                           text='Jogar',
                           fontSize=50,
                           textColour=(0, 0, 0),