Exemple #1
0
def run():
    # Attempt to use custom board 
    global board
    global player
    setup_images()
    try:
        board = Board(game.GAME_WIDTH, game.GAME_HEIGHT)
    except (AttributeError) as e:
        board = Board()
        
    game.GAME_BOARD = board

    """
    try:
        board.register(player)
        update_list.append(player)
    except (AttributeError) as e:
        print "No player"
        player = None
    """

    # Set up an fps display
    try:
        if game.DEBUG == True:
            fps_display = pyglet.clock.ClockDisplay()
            draw_list.append(fps_display)
    except AttributeError:
        pass

    # Add the board and the fps display to the draw list
    draw_list.append(board)

    # Add the keyboard handler if it's ready
    key_handler = key.KeyStateHandler()
    game.KEYBOARD = key_handler
    game_window.push_handlers(key_handler)


    try:
        badguy_handler = game.badguy_handler
        def badguy_handler_wrapper(dt):
            badguy_handler()
        pyglet.clock.schedule_interval(badguy_handler_wrapper, 1/4.0)
    except AttributeError:
        print "No badguy handler"
        pass

    try:
        handler = game.keyboard_handler
        def handler_wrapper(dt):
            handler()
        pyglet.clock.schedule_interval(handler_wrapper, 1/10.0)
    except AttributeError:
        print "No keyboard handler"
        pass
        
    # Set up the update clock
    pyglet.clock.schedule_interval(update, 1/10.0)
    game.initialize()
    pyglet.app.run()
Exemple #2
0
def run():
    # Attempt to use custom board 
    global board
    global player
    setup_images()
    try:
        board = Board(game.GAME_WIDTH, game.GAME_HEIGHT)
    except (AttributeError) as e:
        board = Board()
        
    game.GAME_BOARD = board

    """
    try:
        board.register(player)
        update_list.append(player)
    except (AttributeError) as e:
        print "No player"
        player = None
    """

    # Set up an fps display
    try:
        if game.DEBUG == True:
            fps_display = pyglet.clock.ClockDisplay()
            draw_list.append(fps_display)
    except AttributeError:
        pass

    # Add the board and the fps display to the draw list
    draw_list.append(board)

    # Add the keyboard handler if it's ready
    key_handler = key.KeyStateHandler()
    game.KEYBOARD = key_handler
    game_window.push_handlers(key_handler)

    try:
        handler = game.keyboard_handler
        def handler_wrapper(dt):
            handler()
        pyglet.clock.schedule_interval(handler_wrapper, 1/10.0)
    except AttributeError:
        print "No keyboard handler"
        pass

    try:
        evil_handler = game.enemy_handler
        def enemy_handler(dt):
            evil_handler()
        pyglet.clock.schedule_interval(enemy_handler, 2.0)
    except AttributeError:
        print "No enemy handler"
        pass       
    
    # Set up the update clock
    pyglet.clock.schedule_interval(update, 1/10.)
    game.initialize()
    pyglet.app.run()
Exemple #3
0
def main():
    '''
    This is the starting function to start the game
    '''

    game.initialize(WIDTH, HEIGHT, TITLE)
    
    game.game_loop(FPS)
    
    return 0
Exemple #4
0
def main(initial_state = None):
    game.initialize()
    if initial_state:
        game.set_state(initial_state)
    state = game.state()
    state.play_music()
    while True:
        for event in pygame.event.get():
            state.handle_event(event)
        state.update()
        if state.refresh_screen:
            state.draw_to_screen()
            game.refresh_screen()
            state.refresh_screen = False
        state = game.state()
        game.tick()
    return
    def set_game(self, player_id, selected_game=[None, None]):
        """Sets game and respective player id"""

        if selected_game!=[None, None]:
            assert isinstance(player_id, int), 'player_id argument must be int type'
            assert isinstance(selected_game, list)
            assert len(selected_game)==2
            self.game_player_id = player_id
            self.game = game.initialize(selected_game[0], selected_game[1])
Exemple #6
0
def accept(user_id, user_name, channel):
    """Allows the challenged player to accept a challenge"""
    players = channel['players']
    player2 = channel['player2']
    player1 = channel['player1']

    if channel['ongoing_game'] is False:
        res = {
            "response_type": "ephemeral",
            "text": "To start a game type '/ttt challenge @username'"
        }

    if channel['ongoing_game'] is True:
        if user_name == player2:
            players |= {user_id}
            channel['ongoing_game'] = True
            channel['accepted_invite'] = True
            channel['turn'] = player2
            game.initialize(player1, player2)
            res = {
                "response_type":
                "in_channel",
                "attachments": [{
                    "text":
                    "Please use the following cell number to make your move.\n/ttt move # - to make a move\n/ttt end - to end the game\n"
                    + "```" + game.instructions() + "```" +
                    "\nHere is the current game board:\n" + "```" +
                    game.print_board(channel['board']) + "```",
                    "pretext":
                    "Challenge accepted. %s starts the game. Your marker is 'O'. Please read the instructions below:"
                    % player2,
                    "mrkdwn_in": ["text", "pretext"]
                }]
            }

        if user_name != player2:
            res = {
                "response_type": "ephemeral",
                "text": "You were not the challenged player.",
            }

    return res
def run():
    # Setup the images
    setup_images()

    # Create the game board
    try:
        board = Board(width=game.GAME_WIDTH, 
                      height=game.GAME_HEIGHT,
                      tile_width=TILE_WIDTH,
                      tile_height=TILE_HEIGHT,
                      screen_width=SCREEN_X,
                      screen_height=SCREEN_Y)


        board.IMAGES = IMAGES
        board.draw_board()

        

    except (AttributeError) as e:
        board = Board()
        
    game.GAME_BOARD = board
    


    # Set up an fps display
    try:
        if game.DEBUG == True:
            fps_display = pyglet.clock.ClockDisplay()
            draw_list.append(fps_display)
    except AttributeError:
        pass

    # Add the board and the fps display to the draw list
    draw_list.append(board)

    # Set up the update clock
    pyglet.clock.schedule_interval(update, 1/2.)
    game.initialize()
    pyglet.app.run()
Exemple #8
0
def main():
    state, msg = g.initialize(), ''
    while g.is_final_state(state) == 0:
        # display
        clear()
        print(msg)
        msg = ''
        g.display_board(state)
        # if state[1] == -1: sleep(0.6)
        # game logic
        if state[1] == 1:
            # old_pos, new_pos = (0, 0), (0, 0)
            # try:
            #     print('choose a piece to move:')
            #     old_pos = (int(input('   row = ')), int(input('   col = ')))
            #     print('choose where to move it:')
            #     new_pos = (int(input('   row = ')), int(input('   col = ')))
            # except:
            #     msg = INPUT_ERROR_MSG
            #     continue
            # if g.is_valid_transition(state, old_pos, new_pos):
            #     state = g.transition(state, old_pos, new_pos)
            # else:
            #     msg = MOVE_ERROR_MSG
            start = time()
            t = s.minimax(state)[0]
            state = g.transition(state, t[0], t[1])
            log.write(f'  Minimax: {round((time() - start) * 1000, 2)} ms\n')
        else:
            start = time()
            t = s.minimum_value(state)[0]
            state = g.transition(state, t[0], t[1])
            log.write(f'Apha beta: {round((time() - start) * 1000, 2)} ms\n\n')

    # end game
    clear()
    g.display_board(state)
    switch = {
        1:
        lambda: print(colored('⬤ ', 'white') + 'White won!'),
        -1:
        lambda: print(colored('⬤ ', 'grey') + 'Black won!'),
        2:
        lambda: print(
            colored('⬤ ', 'white') + 'White is blocked. It\'s a draw!'),
        -2:
        lambda: print(
            colored('⬤ ', 'grey') + 'Black is blocked. It\'s a draw!')
    }
    switch[g.is_final_state(state)]()
Exemple #9
0
'''
Created on Oct 25, 2014

@author: Richard
'''
import pygame, game
from battle import *
from random import choice

pygame.init()
game.initialize()
pygame.display.quit()
game.load_music("ff4.wav")
game.play_music()

weapons = [ShortSword(), LongBow(), Hadouken()]
ray = Ray(weapons)
ray = ray.battle_unit()
enemies = [Skeleton(), EvilSpirit(), Dragon()]
ray_weapons = ray.weapons()
prompt = "Choose a weapon: "
for i in range(len(ray_weapons)):
    prompt += "\n{0} = {1}".format(i + 1, ray_weapons[i].name)
prompt += "\n-> "

enemy = None
enemy_weapons = None

while ray.is_alive() and (enemy != None or enemies != []):
    if enemy == None:
        enemy = enemies.pop(0)
Exemple #10
0
'''
Created on Oct 12, 2014

@author: Richard
'''
from game import initialize
from main_program import main
from game_state import TitleState
initialize()
main(TitleState())
Exemple #11
0
#     Ghost1Path = os.path.join(os.getcwd(), 'images/Blinky.png')
#     Ghost2Path = os.path.join(os.getcwd(), 'images/Clyde.png'
#     Ghost3Path = os.path.join(os.getcwd(), 'images/Inky.png')
#     Ghost4Path = os.path.join(os.getcwd(), 'images/Pinky.png')
#
#     level=Levels.Level1()
#     sprite,sprite1 = level.setupPlayers(PlayerPath, [Ghost1Path, Ghost2Path, Ghost3Path, Ghost4Path])
#     pygame.display.set_mode(sprite)
#     pygame.display.set_mode(sprite1)
#     changeSpeed(speed, sprite)
#     for hero in sprite:
#         assert(hero.changeSpeed==[1,0])

# test_change_speed()

game.main(game.initialize())


def testValidGhos1tpath():
    if not os.path.exists(game.Ghost1Path):
        print("test failed")


def testValidPlayerpath():
    if not os.path.exists(game.PlayerPath):
        print("test failed")


def testValidGhos2tpath():
    if not os.path.exists(game.Ghost2Path):
        print("test failed")
Exemple #12
0
    pygame.draw.circle(window, random_c, (random_x, random_y), random_r)


#GUI

#Start Pygame
pygame.init()  #Starts pygame
window = pygame.display.set_mode(
    (SCREEN_X, SCREEN_Y))  # Created window to display game
window.fill((0, 0, 0))  #Makes the screen be black.
pygame.display.set_caption("Minesweeper")  # Sets menu bar title
pygame.font.init()  #Starts the font engine.

#Initialize Board
g.initialize(
    TILES_X, TILES_Y,
    NUM_BOMBS)  #This is a game.py functionality, it sets up the board.

run = True  #This controls the main game loop.
#Main game loop. The program does this over and over, drawing things to the screen repeatedly.
#Tiles are rectangles, drawn to the screen. Flags and bombs are just circles. Text (ie, for the numbers surrounding the bombs) are surface objects containing text.

x_mouse = 0  # Setting x and y mouse coordinates prior to game run prevents x_mouse not defined error
y_mouse = 0

while run:

    pygame.time.delay(
        50
    )  #This makes sure that the game doesn't run too fast. Disable at your own risk!
Exemple #13
0
def main():
    game.initialize()
    main_loop(MainState())
    return
Exemple #14
0
async def initialize_handler(request):
    game.initialize()
    return web.HTTPNoContent()
Exemple #15
0
#game.py
#rules.py
#search.py
#point.py
#piece.py

import board
import canvas
import widget
import game

if __name__ == "__main__":

    settings = widget.Widget()
    settings.main_loop()
    #if cancel_button pressed then don't start game
    if not settings.cancel_button_pressed() == True:
        #configure game setting
        choice = settings.get_game()
        turn = settings.get_turn()
        row = int(settings.get_row())
        column = int(settings.get_column())
        game_mode = settings.get_game()
        first_turn = settings.get_turn()
        board = board.Board(row, column)
        board.game_settings()
        #start game
        game = game.Game(board, game_mode, first_turn)
        game.initialize()
        canvas = canvas.Canvas(game, row, column)