Ejemplo n.º 1
0
def main():
    # Set up model component
    grid = model.Grid()
    # Set up view component
    game_view = view.GameView(600, 600)
    grid_view = view.GameGrid(game_view, len(grid.tiles))
    grid.add_listener(grid_view)
    # Handle control component responsibility here
    commands = keypress.Command(game_view)
    grid.place_tile()

    # Game continues until there is no empty
    # space for a tile
    while grid.find_empty():
        cmd = commands.next()
        if cmd == keypress.LEFT:
            grid.left()
        elif cmd == keypress.RIGHT:
            grid.right()
        elif cmd == keypress.UP:
            grid.up()
        elif cmd == keypress.DOWN:
            grid.down()
        else:
            assert cmd == keypress.UNMAPPED
        if cmd == keypress.UNMAPPED:
            pass  # If an unmapped key is pressed don't do anything-----------------------------------------Extra Credit
        elif grid.movement[0]:  # If a movement happened, grid.movement[0] will be True---------------------Extra Credit
            grid.place_tile()  # A new tile is placed only if a movement happened---------------------------Extra Credit

    game_view.lose(grid.score())
Ejemplo n.º 2
0
def main():
    pygame.mixer.init()
    pygame.mixer.music.\
        load('music/Game of Thrones - Main Theme (Extended) HD.mp3')
    pygame.mixer.music.play(-1)
    ev_manager = controller.EventManager()
    game_view = view.GameView(ev_manager)
    game = model.Game(ev_manager)

    mouse_controller = controller.MouseController(ev_manager, game_view, game)
    mouse_controller.notify(events.TickEvent())
    cpu_spinner = controller.CPUSpinnerController(ev_manager)

    human_player = model.Player(game)
    human_player.set_name("Human")

    game.players.append(human_player)
    game.set_active_player(human_player)

    cpu_player = model.AIPlayer(game)
    cpu_player.set_name("AI Player")
    game.players.append(cpu_player)
    game.main_player = game.players[0]

    ev_manager.post(events.MenuBuildEvent())
    cpu_spinner.run()
Ejemplo n.º 3
0
def main():
    # Set up model component
    grid = model.Board()
    # Set up view component
    game_view = view.GameView(600, 600)
    grid_view = view.GridView(game_view, len(grid.tiles))
    grid.add_listener(grid_view)
    # Handle control component responsibility here
    commands = keypress.Command(game_view)

    grid.place_tile(value=2)

    # Game continues until there is no empty
    # space for a tile
    while grid.has_empty():
        grid.place_tile()
        cmd = commands.next()
        if cmd == keypress.LEFT:
            grid.left()
        elif cmd == keypress.RIGHT:
            grid.right()
        elif cmd == keypress.UP:
            grid.up()
        elif cmd == keypress.DOWN:
            grid.down()
        elif cmd == keypress.CLOSE:
            # Ended game by closing window
            print(f"Your score: {grid.score()}")
            sys.exit(0)
        else: 
            assert cmd == keypress.UNMAPPED

    game_view.lose(grid.score())
Ejemplo n.º 4
0
def main():
    # Model component
    grid = model.Grid()
    # View component
    game_view = view.GameView(600, 600)
    grid_view = view.GridView(game_view, len(grid.tiles))
    grid.add_listener(grid_view)
    # Control component responsibility:
    commands = keypress.Command(game_view)
    grid.place_tile()

    # Continue the game until it is not empty.
    while grid.find_empty():
        grid.place_tile()
        cmd = commands.next()
        if cmd == keypress.LEFT:
            grid.left()
        elif cmd == keypress.RIGHT:
            grid.right()
        elif cmd == keypress.UP:
            grid.up()
        elif cmd == keypress.DOWN:
            grid.down()
        else:
            assert cmd == keypress.UNMAPPED

    game_view.lose(grid.score())
Ejemplo n.º 5
0
def main():
    # Set up model component
    grid = model.Grid()
    # Set up view component
    game_view = view.GameView(600, 600)
    grid_view = view.GameGrid(game_view, len(grid.tiles))
    grid.add_listener(grid_view)
    # Handle control component responsibility here
    commands = keypress.Command(game_view)
    grid.place_tile()

    # Game continues until there is no empty
    # space for a tile
    while grid.find_empty():
        grid.place_tile()
        cmd = commands.next()
        if cmd == keypress.LEFT:
            grid.left()
        elif cmd == keypress.RIGHT:
            grid.right()
        elif cmd == keypress.UP:
            grid.up()
        elif cmd == keypress.DOWN:
            grid.down()
        else:
            assert cmd == keypress.UNMAPPED

    game_view.lose(grid.score())
Ejemplo n.º 6
0
import model
import view

c = model.Character("characterdata.json")
c.vision=3
m = model.Map("mapdata_big.json")

gv = view.GameView(m,c)
gv.mainloop()
Ejemplo n.º 7
0
DEBUG = False

##se le pasa el mapa como fichero de configuracion
config = engine.GameConfig(cfg_file)
##la configuracion y la cantidad de jugadores
game = engine.Game(config, len(bots))
##Bots que ejecutan la IA del jugador y se comunican
actors = [
    botplayer.BotPlayer(game, i, cmdline, debug=DEBUG)
    for i, cmdline in enumerate(bots)
]

for actor in actors:
    actor.initialize()

viewg = view.GameView(game)

with open('pruebas.csv', mode='w') as pruebas:
    w_pruebas = csv.writer(pruebas,
                           delimiter=',',
                           quotechar='"',
                           quoting=csv.QUOTE_MINIMAL)

    cabecera = []
    cabecera.append('ronda')
    for act in range(len(bots)):
        cabecera.append(game.players[act].name)

    w_pruebas.writerow(cabecera)

    for iteration in range(len(bots)):
Ejemplo n.º 8
0
cfg_file = sys.argv[1]
bots = sys.argv[2:]
DEBUG = False

##se le pasa el mapa como fichero de configuracion
config = engine.GameConfig(cfg_file)
##la configuracion y la cantidad de jugadores
game = engine.Game(config, len(bots))
##Bots que ejecutan la IA del jugador y se comunican
actors = [botplayer.BotPlayer(game, i, cmdline, debug=DEBUG) for i, cmdline in enumerate(bots)]

for actor in actors:
    actor.initialize()

view = view.GameView(game)

round = 0
while True:
    game.pre_round()
    view.update()
    for actor in actors:
        actor.turn()
        view.update()
    game.post_round()
    print "########### ROUND %d SCORE:" % round,
    for i in range(len(bots)):
        print "P%d: %d" % (i, game.players[i].score),
    print
    time.sleep(1)
    round += 1
Ejemplo n.º 9
0
def main():
    """Main loop for the game"""
    Init()
    globals.paused = False

    server = ThreadedTCPServer(('0.0.0.0', 4919), ThreadedTCPRequestHandler)
    ip, port = server.server_address

    globals.environ_list = os.listdir('resource')
    print globals.environ_list

    # Start a thread with the server -- that thread will then start one
    # more thread for each request
    server_thread = threading.Thread(target=server.serve_forever)
    # Exit the server thread when the main thread terminates
    server_thread.daemon = True
    server_thread.start()
    print "Server loop running in thread:", server_thread.name

    globals.game_view = view.GameView()
    globals.image_view = view.ImageView()

    #Start with a neutral image being displayed
    globals.view = globals.image_view

    done = False
    last = 0
    clock = pygame.time.Clock()
    drawing.InitDrawing()
    #pygame.display.toggle_fullscreen()

    while not done:
        clock.tick(30)
        globals.time = pygame.time.get_ticks()

        drawing.NewFrame()
        globals.image_view.Update()
        globals.image_view.Draw()
        globals.game_view.Update()
        globals.game_view.Draw()
        globals.screen_root.Draw()
        globals.text_manager.Draw()
        #drawing.EndFrame()
        pygame.display.flip()

        eventlist = pygame.event.get()
        for event in eventlist:
            if event.type == pygame.locals.QUIT:
                done = True
                break
            elif (event.type == pygame.KEYUP):
                if event.key == pygame.K_f:
                    pygame.display.toggle_fullscreen()

            elif event.type == pygame.USEREVENT:
                #if globals.view is not globals.game_view:
                #    globals.view.hide()
                #    globals.view = globals.game_view
                globals.game_view.set_items(event.names, event.chosen,
                                            event.gone)
                globals.image_view.set_colour((0.5, 0.5, 0.5))
                globals.processing = False

            elif event.type == pygame.USEREVENT + 1:
                #if globals.view is not globals.image_view:
                #    globals.view.hide()
                #    globals.view = globals.image_view
                globals.game_view.clear_items()
                globals.image_view.set_dir(event.name)
                globals.image_view.set_colour((1, 1, 1))
Ejemplo n.º 10
0
 def __init__(self, SCREEN):
     self.board = model.GameBoard()
     self.SCREEN = SCREEN
     self.VIEW = view.GameView(SCREEN, self.board.getPieces())
     self.VIEW.drawBoard()
     self.board.addObserver(self.VIEW)