Beispiel #1
0
def score_screen():
    pygame.init()
    ai_settings = Settings()
    score_scr = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")

    music = pygame.mixer.Sound("Sounds/space_music.wav")

    play_button = Button(ai_settings, score_scr, "Start", (600, 50))

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, score_scr, stats)
    a = gm.store_score(stats, score_scr)

    y = 0

    gm.display_scores(a, score_scr, y)

    while True:
        music.play()
        gm.check_button_press(play_button, ai_settings, stats, sb)

        if stats.game_active:
            run_game()
        elif not stats.game_active:
            play_button.draw_button()
        pygame.display.flip()
Beispiel #2
0
    def records_loop(self, screen):
        """ 
        Draw records on the screen

        :param screen: screen of the game
        :type screen: pygame.Surface
        """
        clock = pygame.time.Clock()
        y_step = 35
        is_watching = True
        records = self.__plays__()
        btn = Button("assets/buttons/BackButton.png", ButtonType.Back, y_step * 16 + 53)
        while is_watching :
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    exit()
                if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                    if btn.is_clicked(event.pos):
                        is_watching  = False
                        return
            screen.fill(const.BLACK)
            btn.draw(screen)
            y = y_step
            for record in records:
                nick = const.font_renderer.render(str(record[0]), 1, const.FONT_COLOR)
                num = const.font_renderer.render(str(record[1]), 1, const.FONT_COLOR)
                screen.blit(nick, (100, y))
                screen.blit(num, (const.width - 100 - num.get_width(), y))
                y += y_step
            pygame.display.update()
            clock.tick(const.FPS)
Beispiel #3
0
 def initUI(self):
     self.set_initial_init()
     self.board = Board(self)
     self.menu = Menu(self)
     self.ok_button = Button('images/ok.png', self._ok, (265, 250), (65, 55), self)
     self.ok_button.close()
     self.back_to_menu_button = Button('images/back_to_menu', self._back_to_menu, (560, 0), (300, 55), self)
     self.back_to_menu_button.close()
     #self.close()
     self.setGeometry(200, 75, 860, 560)
     self.setWindowTitle('PyChess')
     self.setWindowIcon(QIcon('images/icon.png'))
     self.show()
Beispiel #4
0
    def __init__(self, config):

        self.hasQuit = False
        self.tickNumber = 0
        self.display = pg.display.set_mode(
            (config.screenSize[0], config.screenSize[1]))
        self.pivotMnger = PivotManager(config)
        self.clock = pg.time.Clock()
        self.initalPlrVel = config.initalPlayerVel
        self.initalPlrPos = config.screenSize[0] / 2 + 1j * config.screenSize[1]

        #screen height is height of top left corner from start (value will get more negative as player goes up)
        self.screenPosition = [0, 0]

        self.plr = Player(config, Teather(config), Booster(config),
                          self.initalPlrPos, self.initalPlrVel)
        self.bg = Background(config, self.screenPosition)

        self.config = config
        #used for reading and writing score
        self.fileName = os.path.basename(__file__)
        self.dirPath = os.path.realpath(__file__)[0:-len(self.fileName)]
        self.screenSize = config.screenSize
        self.screenVelSlope = config.screenVelSlope
        self.spf = 1 / config.fps

        self.scoreDivisor = config.scoreDivisor

        self.scoreDisplay = TextBox(
            'PLACEHOLDER', (255, 0, 0),
            (self.screenSize[0] / 15, self.screenSize[1] / 20),
            round(config.fontSize / 2))
        self.scoreDisplay.initalizeTextBox()

        self.resetButton = Button(
            (self.screenSize[0] / 2, 2 * self.screenSize[1] / 3),
            self.screenSize[0] / 8, self.screenSize[0] / 8, config.resetSymbol,
            (255, 0, 0), (255, 255, 255), True)
        self.resetText = TextBox(
            'PLACEHOLDER', (255, 0, 0),
            (self.screenSize[0] / 2, self.screenSize[1] / 3), config.fontSize)
        self.resetText.initalizeTextBox()

        self.startButton = Button(
            (self.screenSize[0] / 2, 2 * self.screenSize[1] / 3),
            self.screenSize[0] / 8, self.screenSize[0] / 8, config.playSymbol,
            (255, 0, 0), (255, 255, 255), True)
        self.startText = TextBox(
            'BOUNCY BOI', (255, 0, 0),
            (self.screenSize[0] / 2, self.screenSize[1] / 3), config.fontSize)
        self.startText.initalizeTextBox()
Beispiel #5
0
def start_screen():
    pygame.init()
    ai_settings = Settings()
    start_scr = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, start_scr, stats)

    music = pygame.mixer.Sound("Sounds/space_music.wav")

    play_button = Button(ai_settings, start_scr, "Start", (600, 50))
    score_button = Button(ai_settings, start_scr, "Highscore", (600, 750))
    score_button.msg_image_rect.center = 600, 750

    a = gm.display_alien_start_screen(ai_settings, start_scr)
    gm.score1(start_scr)

    while True:
        music.play()
        gm.check_button_press(play_button, ai_settings, stats, sb)
        if stats.game_active:
            run_game()
        elif not stats.game_active:
            play_button.draw_button()
            score_button.draw_button()

        a = gm.score_menu(score_button, ai_settings, stats, sb)
        if a is True:
            score_screen()

        pygame.display.flip()
Beispiel #6
0
def startScreen(clock):

    startButton = Button((screenSize[0] / 2, screenSize[1] / 2), 250, 250, [],
                         (255, 255, 255), False)
    titleTextBox = TextBox('NEON DRAGONS', (255, 0, 0),
                           [screenSize[0] / 2, screenSize[1] / 4],
                           config.textCharacterWidth)
    titleTextBox.initalizeTextBox()

    #playerNumber,startingSpeed,turningRadius,segmentLength,dashDistance
    p1 = Snake(1, config.snakeSpeed, config.menuTurningRadius,
               config.segmentLength, 100)
    p1.createSnake(5, config.menuTurningRadius)

    p2 = Snake(2, config.snakeSpeed, config.menuTurningRadius,
               config.segmentLength, 100)
    p2.createSnake(5, config.menuTurningRadius)

    while not (startButton.wasPressed or config.quit):
        for event in pg.event.get():
            # checks if player has quit
            if event.type == pg.QUIT:
                config.quit = True
        pg.Surface.fill(gameDisplay, (0, 0, 0))
        playersHandler(p1, p2, (0, 1, 0, 0, 0, 1, 0, 0), gameDisplay, 0)

        #displaying title
        titleTextBox.displayActiveLines(gameDisplay)
        if not titleTextBox.allLinesActivated:
            titleTextBox.activateRandomLine()

        clock.tick_busy_loop(frameRate)

        mousePos = pg.mouse.get_pos()
        mousePressed = pg.mouse.get_pressed()
        mouseIsOnButton = startButton.displayAndGetClicked(
            mousePos, mousePressed, gameDisplay)
        if mouseIsOnButton:
            p1.color = (255, 0, 0)
            p2.color = (255, 0, 0)
        else:
            p1.color = (255, 255, 255)
            p2.color = (255, 255, 255)
        pg.display.update()

    p1.color = (255, 0, 0)
    p2.color = (255, 0, 0)
    p1.changeTurningRadius(config.normalTurningRadius)
    p2.changeTurningRadius(config.normalTurningRadius)
    return (p1, p2, titleTextBox)
Beispiel #7
0
    def __transform_pawn__(self):
        self.pawn_can_transform = True
        img_start = 'images/w'
        if self.board.field.coords[self.pawn[0]][self.pawn[1]].color == Color.black:
            img_start = 'images/b'

        self.choose_queen_button = Button(img_start + 'Q.png',  self._choose_queen, (110, 220), (80, 80), self)
        self.choose_rook_button = Button(img_start + 'R.png', self._choose_rook, (210, 220), (80, 80), self)
        self.choose_bishop_button = Button(img_start + 'B.png', self._choose_bishop, (310, 220), (80, 80), self)
        self.choose_knight_button = Button(img_start + 'N.png', self._choose_knight, (410, 220), (80, 80), self)
        self.choose_queen_button.show()
        self.choose_rook_button.show()
        self.choose_bishop_button.show()
        self.choose_knight_button.show()
Beispiel #8
0
 def initUI(self):
     self.set_initial_init()
     self.board = Board(self)
     self.menu = Menu(self)
     self.ok_button = Button('images/ok.png', self._ok, (265, 250),
                             (65, 55), self)
     self.ok_button.close()
     self.back_to_menu_button = Button('images/back_to_menu',
                                       self._back_to_menu, (560, 0),
                                       (300, 55), self)
     self.back_to_menu_button.close()
     #self.close()
     self.setGeometry(200, 75, 860, 560)
     self.setWindowTitle('PyChess')
     self.setWindowIcon(QIcon('images/icon.png'))
     self.show()
 def __init__(self):
     self.background = self.background.convert()
     self.player = player.Player()
     self.title = self.font.render("Select Player", True, constants.RED)
     self.player_select = Button("Select Player", (350,600))
     self.level1 = Button("Fruit in a Barrel",(200,200))
     self.level2 = Button("Raining Fruit",(300,300))
     self.level3 = Button("Fruit Pop", (400,400))
     self.level4 = Button("Fruit Flies", (500,500))
     self.level1.status = "New"
     self.food1 = food.Food()
     self.food2 = food.Food()
     self.food1.rect.x = 900
     self.food1.rect.y = 150
     self.food2.rect.x = 150
     self.food2.rect.y = 500
 def __init__(self, screen, game, gameover, tilesize):
     
     self.TILESIZE = tilesize
     
     self.gameover = gameover
     self.screen = screen
     self.game = game
     
     self.taskbar = Taskbar(self.screen, self.game)
     self.turnButton = Button("Next turn",self.screen.get_width() - 250, self.screen.get_height() - (TASKBARHEIGHT//2) - 25, 200, 50, GREEN, LGREEN, self.screen, action = self.game.switchTurn)
     
     
     # Maximum values for drawing tiles as limited by window resolution
     reslimitx = int( self.screen.get_width() / self.TILESIZE )
     reslimity = int( ( self.screen.get_height() - TASKBARHEIGHT ) / self.TILESIZE )
     
     self.viewx = reslimitx if reslimitx < self.game.xsize else self.game.xsize
     self.viewy = reslimity if reslimity < self.game.ysize else self.game.ysize
     
     # Map dimensions
     self.mapx = self.game.xsize
     self.mapy = self.game.ysize
     
     # Offset from top left corner for drawing current view
     self.currentx = 0
     self.currenty = 0
Beispiel #11
0
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")

    music = pygame.mixer.Sound("Sounds/space_music.wav")

    play_button = Button(ai_settings, screen, "Play", (600, 50))
    barrier = Barrier(ai_settings, screen)
    ship = Ship(ai_settings, screen)

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    bullets = Group()
    aliens = Group()

    gm.create_fleet(ai_settings, screen, ship, aliens)
    gm.create_barriers(ai_settings, screen)

    while True:
        music.play()
        gm.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)
        bullets.update()
        ship.update()
        barrier.update()
        gm.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets)
        gm.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                          bullets)
        gm.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets)

        pygame.display.flip()
Beispiel #12
0
def high_score_screen(settings, stats, screen):
    """Display all high scores in a separate screen with a back button"""
    hs_screen = HighScoreScreen(settings, screen, stats)
    back_button = Button(settings, screen, 'Back To Menu', y_factor=0.85)

    while True:
        back_button.alter_text_color(*pg.mouse.get_pos())
        for event in pg.event.get():
            if event.type == pg.QUIT:
                return False
            elif event.type == pg.MOUSEBUTTONDOWN:
                if back_button.check_button(*pg.mouse.get_pos()):
                    return True
        screen.fill(settings.bg_color)
        hs_screen.show_scores()
        back_button.draw_button()
        pg.display.flip()
Beispiel #13
0
    def __transform_pawn__(self):
        self.pawn_can_transform = True
        img_start = 'images/w'
        if self.board.field.coords[self.pawn[0]][
                self.pawn[1]].color == Color.black:
            img_start = 'images/b'

        self.choose_queen_button = Button(img_start + 'Q.png',
                                          self._choose_queen, (110, 220),
                                          (80, 80), self)
        self.choose_rook_button = Button(img_start + 'R.png',
                                         self._choose_rook, (210, 220),
                                         (80, 80), self)
        self.choose_bishop_button = Button(img_start + 'B.png',
                                           self._choose_bishop, (310, 220),
                                           (80, 80), self)
        self.choose_knight_button = Button(img_start + 'N.png',
                                           self._choose_knight, (410, 220),
                                           (80, 80), self)
        self.choose_queen_button.show()
        self.choose_rook_button.show()
        self.choose_bishop_button.show()
        self.choose_knight_button.show()
def main():
    logger = logging.Logger("MainLogger")
    logging.basicConfig(filename="./logs/test.log")
    menu = Menu("Main menu", logger=logger)

    menu.add_element(Button(500, 500, 200, 400, "Test Button", "A TEST"))
Beispiel #15
0
class PyChess(QWidget):
    def __init__(self, parent=None):
        super(QWidget, self).__init__(parent)
        self.initUI()

    def initUI(self):
        self.set_initial_init()
        self.board = Board(self)
        self.menu = Menu(self)
        self.ok_button = Button('images/ok.png', self._ok, (265, 250), (65, 55), self)
        self.ok_button.close()
        self.back_to_menu_button = Button('images/back_to_menu', self._back_to_menu, (560, 0), (300, 55), self)
        self.back_to_menu_button.close()
        #self.close()
        self.setGeometry(200, 75, 860, 560)
        self.setWindowTitle('PyChess')
        self.setWindowIcon(QIcon('images/icon.png'))
        self.show()

    def set_initial_init(self):
        self.game_over = True
        self.pawn = None
        self.is_checkmate = False
        self.is_pat = False
        self.is_white_won = False
        self.is_black_won = False
        self.pawn_can_transform = False

    def _back_to_menu(self):
        self.back_to_menu_button.close()
        self.menu.is_active = True
        self.menu.start()

    def _ok(self):
        self.ok_button.close()
        self.is_white_won = False
        self.is_black_won = False
        self.is_pat = False
        self.repaint()

    def __transform_pawn__(self):
        self.pawn_can_transform = True
        img_start = 'images/w'
        if self.board.field.coords[self.pawn[0]][self.pawn[1]].color == Color.black:
            img_start = 'images/b'

        self.choose_queen_button = Button(img_start + 'Q.png',  self._choose_queen, (110, 220), (80, 80), self)
        self.choose_rook_button = Button(img_start + 'R.png', self._choose_rook, (210, 220), (80, 80), self)
        self.choose_bishop_button = Button(img_start + 'B.png', self._choose_bishop, (310, 220), (80, 80), self)
        self.choose_knight_button = Button(img_start + 'N.png', self._choose_knight, (410, 220), (80, 80), self)
        self.choose_queen_button.show()
        self.choose_rook_button.show()
        self.choose_bishop_button.show()
        self.choose_knight_button.show()

    def _choose_queen(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Queen(self.board.field.coords[self.pawn[0]][self.pawn[1]].color, self.board.field)
        self.close_buttons()

    def _choose_rook(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Rook(self.board.field.coords[self.pawn[0]][self.pawn[1]].color, self.board.field)
        self.close_buttons()

    def _choose_bishop(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Bishop(self.board.field.coords[self.pawn[0]][self.pawn[1]].color, self.board.field)
        self.close_buttons()

    def _choose_knight(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Knight(self.board.field.coords[self.pawn[0]][self.pawn[1]].color, self.board.field)
        self.close_buttons()

    def close_buttons(self):
        self.choose_bishop_button.close()
        self.choose_knight_button.close()
        self.choose_queen_button.close()
        self.choose_rook_button.close()
        self.pawn = None
        self.pawn_can_transform = False
        self.repaint()
        if not self.board.vs_player and self.board.info.color == self.board.computer.color:
            self.board.computer.move()
            self.repaint()
        self.check_game_state()

    def mousePressEvent(self, e):
        if not self.menu.is_active and not self.game_over:
            if e.buttons() == Qt.LeftButton and QCursor.pos().x() - self.geometry().x() < 560:
                square = int((QCursor.pos().x() - self.geometry().x()) / self.board.side_of_square), \
                           int((QCursor.pos().y() - self.geometry().y()) / self.board.side_of_square)
                if not self.board.button_pressed:
                    if self.board.field.coords[square[1]][square[0]] is not None and self.board.field.coords[square[1]][square[0]].color == self.board.info.color:
                        self.board.button_pressed = True
                        self.board.pressed_piece = square[1], square[0]
                        self.board.painted_squares = right_moves(square[1], square[0], self.board.field)
                        self.board.painted_squares.append((square[1], square[0]))
                else:
                    doing_move((self.board.pressed_piece[0], self.board.pressed_piece[1]),
                               (square[1], square[0]),
                               self.board.field, self.board.info)
                    self.board.button_pressed = False
                    self.board.painted_squares = []
                    self.board.pressed_piece = None
                    pawn = pawn_can_transform(self.board.field)
                    if pawn is not None:
                        self.pawn = pawn
                        self.__transform_pawn__()
                self.repaint()

            if not self.board.vs_player and self.board.computer.color == self.board.info.color and self.pawn == None:
                self.board.computer.move()
                self.repaint()

            self.check_game_state()

    def check_game_state(self):
        if is_pat_now(self.board.field, self.board.info.color):
            self.is_pat = True
            self.game_over = True
            self.ok_button.show()

        if not self.game_over and checkmate(Color.black, self.board.field):
            self.is_white_won = True
            self.ok_button.show()
            self.game_over = True

        if not self.game_over and checkmate(Color.white, self.board.field):
            self.is_black_won = True
            self.ok_button.show()
            self.game_over = True
        self.repaint()
Beispiel #16
0
 def add_menu_button(self, *args):
     self.menu_buttons.add(Button(*args))
Beispiel #17
0
def endScreen(clock, p1, p2):
    if p1.dead:
        if p2.dead:
            text = "MUTUAL KILL"
        else:
            text = "PLAYER 2 WINS"
    else:
        if p2.dead:
            text = "PLAYER 1 WINS"
        else:
            text = "MUTUAL KILL"

    p1.createSnake(5, config.menuTurningRadius)
    p2.createSnake(5, config.menuTurningRadius)

    endTextBox = TextBox(text, (255, 0, 0),
                         [screenSize[0] / 2, screenSize[1] / 4],
                         config.textCharacterWidth)
    endTextBox.initalizeTextBox()

    #fades in end text
    while not (endTextBox.allLinesActivated or config.quit):
        pg.display.update()
        endTextBox.activateRandomLine()
        pg.Surface.fill(gameDisplay, (0, 0, 0))

        endTextBox.displayActiveLines(gameDisplay)
        clock.tick_busy_loop(frameRate)
        for event in pg.event.get():
            if event.type == pg.QUIT:
                config.quit = True

    #adds in restart button
    endButton = Button((screenSize[0] / 2, screenSize[1] / 2), 250, 250, [],
                       (255, 255, 255), False)
    while not (endButton.wasPressed or config.quit):
        for event in pg.event.get():
            # checks if player has quit
            if event.type == pg.QUIT:
                config.quit = True
        pg.Surface.fill(gameDisplay, (0, 0, 0))
        playersHandler(p1, p2, (0, 1, 0, 0, 0, 1, 0, 0), gameDisplay, 0)
        endTextBox.displayActiveLines(gameDisplay)
        clock.tick_busy_loop(frameRate)
        #displays end text

        mousePos = pg.mouse.get_pos()
        mousePressed = pg.mouse.get_pressed()
        mouseIsOnButton = endButton.displayAndGetClicked(
            mousePos, mousePressed, gameDisplay)
        if mouseIsOnButton:
            p1.color = (255, 0, 0)
            p2.color = (255, 0, 0)
        else:
            p1.color = (255, 255, 255)
            p2.color = (255, 255, 255)
        pg.display.update()

    p1.color = (255, 0, 0)
    p2.color = (255, 0, 0)
    p1.changeTurningRadius(config.normalTurningRadius)
    p2.changeTurningRadius(config.normalTurningRadius)
    return (endTextBox)
Beispiel #18
0
def del_level():
    global chosen, container
    if chosen and chosen.image:
        os.remove('levels/{}.png'.format(chosen.number + 1))
        for p in container:
            for lvl in p:  # Shift others
                if lvl.number > chosen.number and lvl.image:
                    os.rename(f'levels/{lvl.number+1}.png',
                              f'levels/{lvl.number}.png')
        chosen = None
    update()


# Global variables
level_buttons = [
    Button("Edit level", 300, 700, (25, 65, 65), edit_level),
    Button("Add level", 530, 700, (25, 65, 65), add_level),
    Button("Del level", 760, 700, (25, 65, 65), del_level),
    Button("<-", 50, 700, (25, 65, 65), change_page, -1),
    Button("->", 1100, 700, (25, 65, 65), change_page, 1),
    Button(pygame.image.load('images/back.png'), 10, 10, (25, 65, 65), go_back)
]
done = False
page = 1  # current page
pages = 1  # all Pages
lvl_amount = 0
container = []
chosen = None
lvl_for_game = None
# =======================
class Gameview:
    
    '''
    Represents the game as shown to the player.
    
    Params:
    screen: Pygame screen
    game: Instance of Game class
    gameover: Gameover popup window
    tilesize: Size of each tile read from setup.txt
    
    Methods:
    draw(): Draws the view
    moveView(): Moves the current viewpoint
    
    '''
    
    
    def __init__(self, screen, game, gameover, tilesize):
        
        self.TILESIZE = tilesize
        
        self.gameover = gameover
        self.screen = screen
        self.game = game
        
        self.taskbar = Taskbar(self.screen, self.game)
        self.turnButton = Button("Next turn",self.screen.get_width() - 250, self.screen.get_height() - (TASKBARHEIGHT//2) - 25, 200, 50, GREEN, LGREEN, self.screen, action = self.game.switchTurn)
        
        
        # Maximum values for drawing tiles as limited by window resolution
        reslimitx = int( self.screen.get_width() / self.TILESIZE )
        reslimity = int( ( self.screen.get_height() - TASKBARHEIGHT ) / self.TILESIZE )
        
        self.viewx = reslimitx if reslimitx < self.game.xsize else self.game.xsize
        self.viewy = reslimity if reslimity < self.game.ysize else self.game.ysize
        
        # Map dimensions
        self.mapx = self.game.xsize
        self.mapy = self.game.ysize
        
        # Offset from top left corner for drawing current view
        self.currentx = 0
        self.currenty = 0
        
        
        
    def draw(self):
        
        
        self.screen.fill(BLACK)
        self.taskbar.draw()
        
        
        # Draw the "next turn" button
        
        if self.game.activePlayer.ID == 1:
            if self.game.activePlayer.actionsLeft():
                self.turnButton.color = GRAY
            else:
                self.turnButton.color = GREEN
            self.turnButton.draw()
        
        # Draw the tiles and units
        
        for i in range(self.viewy):
            for j in range(self.viewx):
                
                self.screen.blit(pygame.transform.scale( self.game.map[i+self.currenty][j+self.currentx].img, (self.TILESIZE,self.TILESIZE)), \
                                 (j * self.TILESIZE, i * self.TILESIZE))
                
                if self.game.map[i+self.currenty][j+self.currentx].unit:
                    
                    self.screen.blit(pygame.transform.scale( self.game.map[i+self.currenty][j+self.currentx].unit.sprite, (self.TILESIZE,self.TILESIZE)),\
                                 (j * self.TILESIZE, i * self.TILESIZE))
                
                if self.game.selectedTile:
                    if self.game.selectedTile.x == j+self.currentx and \
                       self.game.selectedTile.y == i+self.currenty:
                        pygame.draw.rect(self.screen, (255,255,255), (j*self.TILESIZE, i*self.TILESIZE, self.TILESIZE,self.TILESIZE), 2)
                
                
                
                # Process player clicks on the map tiles
                
                click = 1
                click, temp = self.game.map[i+self.currenty][j+self.currentx].click(self.screen, self.currentx, self.currenty, self.TILESIZE)
                if click == 1 and temp != None:
                    self.game.selectedTile = temp
                    self.taskbar.updateTexts()
                    
                    print("Tile at ({}, {})".format(self.game.selectedTile.x, self.game.selectedTile.y))
                    print("Pathable:", self.game.selectedTile.pathable)
                    if self.game.selectedTile.unit:
                        print("Has unit:", self.game.selectedTile.unit.name)
                        print("Moves left:", self.game.selectedTile.unit.moves)
                    print()
                
                
                elif click == 2 and temp != None:
                    if temp.unit:
                        self.game.dealDamage(self.game.selectedTile, temp)
                    else:
                        self.game.moveUnit(self.game.selectedTile, temp)
                        
                    self.taskbar.updateTexts()
                    
        
        # Check for game over
        
        if not self.game.player1.unitsLeft() and not self.game.gameover:
            self.gameover.winnerText.updateText("You lose!")
            self.game.gameover = True
            return 3
        
        if not self.game.player2.unitsLeft():
            self.gameover.winnerText.updateText("You win!")
            self.game.gameover = True
            return 3
        
        
        
        return 1          
        
    
    def moveView(self, direction):
        
        if (direction not in DIRECTIONS):
            return 0
        
        
        if (direction[0] + self.currentx) < 0 or \
            (direction[0] + self.currentx + self.viewx) > self.mapx:
            return 0
        
        if (direction[1] + self.currenty) < 0 or \
            (direction[1] + self.currenty + self.viewy) > self.mapy:
            return 0
 
           
        self.currentx += direction[0]
        self.currenty += direction[1]
        
        return 1
Beispiel #20
0
from entity import Player
from menu import Button
from background import Background

pygame.init()

screen_height = 600
screen_width = 900

window = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Dungeon Game")

# Main Menu Aspects
menu_bg = Background(0, 0, screen_height, screen_width,
                     'resources/menu/menu_bg.png')
start_button = Button(330, 270, 60, 240, 'start_button', 'resources/menu/')
exit_button = Button(330, 360, 60, 240, 'exit_button', 'resources/menu/')


def draw_menu():
    window.blit(menu_bg.image, (menu_bg.x, menu_bg.y))
    window.blit(start_button.image, (start_button.x, start_button.y))
    window.blit(exit_button.image, (exit_button.x, exit_button.y))
    pygame.display.update()


# Generate inital cave
cave = Cave(screen_height // 15, screen_width // 15)
bg = Background(0, 0, screen_height, screen_width)

# Character Creation
Beispiel #21
0
if __name__ == "__main__":
    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)
    RED = (142, 22, 0)
    GRAY = (200, 200, 200)
    state = State()
    clock = pygame.time.Clock()
    screen = pygame.display.set_mode((state.WIDTH, state.HEIGHT))

    # Экраны меню setup
    if state.screen_type == State.SCREEN_MENU or state.screen_type == State.SCREEN_PAUSE:
        # SCREEN_MENU
        button_size_1 = Button(Button.SIZE_3X3,
                               100,
                               80,
                               x=25,
                               y=25,
                               text="3x3",
                               is_selected=True)
        active_button_size = button_size_1
        button_size_2 = Button(Button.SIZE_4X4,
                               100,
                               80,
                               x=150,
                               y=25,
                               text="4x4")
        button_size_3 = Button(Button.SIZE_5X5,
                               100,
                               80,
                               x=275,
                               y=25,
Beispiel #22
0
class PlayerSelect():
    background = pygame.image.load(os.path.join('images', 'starburst_green.png'))
    font = constants.FONT
    title = None
    level1 = None
    level2 = None
    level3 = None
    level4 = None
    time = "Menu"
    player = None
    food1 = None
    food2 = None


    def __init__(self):
        self.background = self.background.convert()
        self.player = player.Player()
        self.title = self.font.render("Select Player", True, constants.RED)
        self.player_select = Button("Select Player", (350,600))
        self.level1 = Button("Fruit in a Barrel",(200,200))
        self.level2 = Button("Raining Fruit",(300,300))
        self.level3 = Button("Fruit Pop", (400,400))
        self.level4 = Button("Fruit Flies", (500,500))
        self.level1.status = "New"
        self.food1 = food.Food()
        self.food2 = food.Food()
        self.food1.rect.x = 900
        self.food1.rect.y = 150
        self.food2.rect.x = 150
        self.food2.rect.y = 500

    def update(self,pos):
        self.player.update(pos)
        self.player_select.update()
        self.level1.update()
        self.level2.update()
        self.level3.update()
        self.level4.update()

    def shot(self,pos):
        a = None
        if self.level1.rect.collidepoint(pos):
            a = 1
        elif self.level2.rect.collidepoint(pos):
            a = 2
        elif self.level3.rect.collidepoint(pos):
            a = 3
        elif self.level4.rect.collidepoint(pos):
            a = 4
        elif self.player_select.rect.collidepoint(pos):
            a = 5
        if a:
            self.food1.reset()
            self.food2.reset()
            self.food1.rect.x = 950
            self.food1.rect.y = 150
            self.food2.rect.x = 150
            self.food2.rect.y = 500
            return(a)

    def draw(self,screen):
        screen.blit(self.background,(0,0))
        screen.blit(self.title, (100,50))
        self.player_select.draw(screen)
        self.level1.draw(screen)
        self.level2.draw(screen)
        self.level3.draw(screen)
        self.level4.draw(screen)
        self.food1.draw(screen)
        self.food2.draw(screen)
        self.player.draw(screen)
Beispiel #23
0
def startup_screen(settings, stats, screen, menu_aliens, menu_ufos):
    """Display the startup menu on the screen, return False if the user wishes to quit,
    True if they are ready to play"""
    menu = Intro(settings, stats, screen)
    play_button = Button(settings, screen, 'Play Game', y_factor=0.75)
    hs_button = Button(settings, screen, 'High Scores', y_factor=0.85)
    intro = True

    while intro:
        play_button.alter_text_color(*pg.mouse.get_pos())
        hs_button.alter_text_color(*pg.mouse.get_pos())
        for event in pg.event.get():
            if event.type == pg.QUIT:
                return False
            elif event.type == pg.MOUSEBUTTONDOWN:
                click_x, click_y = pg.mouse.get_pos()
                stats.game_active = play_button.check_button(click_x, click_y)
                intro = not stats.game_active
                if hs_button.check_button(click_x, click_y):
                    ret_hs = high_score_screen(settings, stats, screen)
                    if not ret_hs:
                        return False
        screen.fill(settings.bg_color)
        menu.draw()
        hs_button.draw_button()
        play_button.draw_button()
        menu_aliens.draw()
        menu_ufos.draw()
        pg.display.flip()

    return True
Beispiel #24
0
                line += " +" + condit.match_string
            elif condit.operation == "exclude":
                line += " -" + condit.match_string
        line += "\n"
        f.write(line)
    f.close()
    os.startfile(os.path.dirname(os.path.realpath(__file__)) + "\\save.txt")
    main_menu.display()


def open_feed():
    webbrowser.open(feed_address)


# Main menu
main_menu_run = Button("Run", parse_feeds, 1)
main_menu_edit = Button("Edit Filters", filters_to_textfile, 2)
main_menu_all = Button("List All Filters And Conditions", list_all, 3)
main_menu_downloaded = Button("List All Downloaded Entries", list_downloaded,
                              4)
main_menu_feed = Button("Open Feed", open_feed, 5)
main_menu_exit = Button("Exit", sys.exit, 0)

main_menu_buttons = [
    main_menu_run, main_menu_edit, main_menu_all, main_menu_downloaded,
    main_menu_feed, main_menu_exit
]

main_menu = Menu("Main Menu", main_menu_buttons)

try:
Beispiel #25
0
class PyChess(QWidget):
    def __init__(self, parent=None):
        super(QWidget, self).__init__(parent)
        self.initUI()

    def initUI(self):
        self.set_initial_init()
        self.board = Board(self)
        self.menu = Menu(self)
        self.ok_button = Button('images/ok.png', self._ok, (265, 250),
                                (65, 55), self)
        self.ok_button.close()
        self.back_to_menu_button = Button('images/back_to_menu',
                                          self._back_to_menu, (560, 0),
                                          (300, 55), self)
        self.back_to_menu_button.close()
        #self.close()
        self.setGeometry(200, 75, 860, 560)
        self.setWindowTitle('PyChess')
        self.setWindowIcon(QIcon('images/icon.png'))
        self.show()

    def set_initial_init(self):
        self.game_over = True
        self.pawn = None
        self.is_checkmate = False
        self.is_pat = False
        self.is_white_won = False
        self.is_black_won = False
        self.pawn_can_transform = False

    def _back_to_menu(self):
        self.back_to_menu_button.close()
        self.menu.is_active = True
        self.menu.start()

    def _ok(self):
        self.ok_button.close()
        self.is_white_won = False
        self.is_black_won = False
        self.is_pat = False
        self.repaint()

    def __transform_pawn__(self):
        self.pawn_can_transform = True
        img_start = 'images/w'
        if self.board.field.coords[self.pawn[0]][
                self.pawn[1]].color == Color.black:
            img_start = 'images/b'

        self.choose_queen_button = Button(img_start + 'Q.png',
                                          self._choose_queen, (110, 220),
                                          (80, 80), self)
        self.choose_rook_button = Button(img_start + 'R.png',
                                         self._choose_rook, (210, 220),
                                         (80, 80), self)
        self.choose_bishop_button = Button(img_start + 'B.png',
                                           self._choose_bishop, (310, 220),
                                           (80, 80), self)
        self.choose_knight_button = Button(img_start + 'N.png',
                                           self._choose_knight, (410, 220),
                                           (80, 80), self)
        self.choose_queen_button.show()
        self.choose_rook_button.show()
        self.choose_bishop_button.show()
        self.choose_knight_button.show()

    def _choose_queen(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Queen(
            self.board.field.coords[self.pawn[0]][self.pawn[1]].color,
            self.board.field)
        self.close_buttons()

    def _choose_rook(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Rook(
            self.board.field.coords[self.pawn[0]][self.pawn[1]].color,
            self.board.field)
        self.close_buttons()

    def _choose_bishop(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Bishop(
            self.board.field.coords[self.pawn[0]][self.pawn[1]].color,
            self.board.field)
        self.close_buttons()

    def _choose_knight(self):
        self.board.field.coords[self.pawn[0]][self.pawn[1]] = Knight(
            self.board.field.coords[self.pawn[0]][self.pawn[1]].color,
            self.board.field)
        self.close_buttons()

    def close_buttons(self):
        self.choose_bishop_button.close()
        self.choose_knight_button.close()
        self.choose_queen_button.close()
        self.choose_rook_button.close()
        self.pawn = None
        self.pawn_can_transform = False
        self.repaint()
        if not self.board.vs_player and self.board.info.color == self.board.computer.color:
            self.board.computer.move()
            self.repaint()
        self.check_game_state()

    def mousePressEvent(self, e):
        if not self.menu.is_active and not self.game_over:
            if e.buttons() == Qt.LeftButton and QCursor.pos().x(
            ) - self.geometry().x() < 560:
                square = int((QCursor.pos().x() - self.geometry().x()) / self.board.side_of_square), \
                           int((QCursor.pos().y() - self.geometry().y()) / self.board.side_of_square)
                if not self.board.button_pressed:
                    if self.board.field.coords[square[1]][
                            square[0]] is not None and self.board.field.coords[
                                square[1]][
                                    square[0]].color == self.board.info.color:
                        self.board.button_pressed = True
                        self.board.pressed_piece = square[1], square[0]
                        self.board.painted_squares = right_moves(
                            square[1], square[0], self.board.field)
                        self.board.painted_squares.append(
                            (square[1], square[0]))
                else:
                    doing_move((self.board.pressed_piece[0],
                                self.board.pressed_piece[1]),
                               (square[1], square[0]), self.board.field,
                               self.board.info)
                    self.board.button_pressed = False
                    self.board.painted_squares = []
                    self.board.pressed_piece = None
                    pawn = pawn_can_transform(self.board.field)
                    if pawn is not None:
                        self.pawn = pawn
                        self.__transform_pawn__()
                self.repaint()

            if not self.board.vs_player and self.board.computer.color == self.board.info.color and self.pawn == None:
                self.board.computer.move()
                self.repaint()

            self.check_game_state()

    def check_game_state(self):
        if is_pat_now(self.board.field, self.board.info.color):
            self.is_pat = True
            self.game_over = True
            self.ok_button.show()

        if not self.game_over and checkmate(Color.black, self.board.field):
            self.is_white_won = True
            self.ok_button.show()
            self.game_over = True

        if not self.game_over and checkmate(Color.white, self.board.field):
            self.is_black_won = True
            self.ok_button.show()
            self.game_over = True
        self.repaint()