Exemplo n.º 1
0
    def test_can_close_at_start(self):

        events = [StubEvent(pygame.QUIT, 1, (1024, 0))]
        event_queue = StubEventQueue(events)
        gameloop = GameLoop(self.gamelogic, self.display,
                            self.colors, self.startview, event_queue, self.menu, self.shop, self.save)
        gameloop.start()
        self.assertEqual(gameloop.begin, False)
        self.assertEqual(gameloop.event_handler(), False)
Exemplo n.º 2
0
    def test_can_close_after_starting(self):

        events = [StubEvent(pygame.MOUSEBUTTONDOWN, 1, (320, 110)), StubEvent(
            pygame.MOUSEBUTTONDOWN, 1, (320, 110)), StubEvent(pygame.QUIT, 1, (0, 0))]
        event_queue = StubEventQueue(events)
        gameloop = GameLoop(self.gamelogic, self.display,
                            self.colors, self.startview, event_queue, self.menu, self.shop, self.save)
        gameloop.start()
        self.assertEqual(gameloop.begin, False)
        self.assertEqual(gameloop.event_handler(), False)
Exemplo n.º 3
0
 def update(self, screen_img):
     self.img = screen_img
     self.u_players_hp()
     self.u_yummi_attached()
     self.u_is_moving()
     self.u_can_learn_spell()
     self.u_player_pos()
     self.u_in_fountain()
     
     print(self._in_fountain)
     GameLoop.run_commands(self)
Exemplo n.º 4
0
def main():

    display = pygame.display.set_mode((640, 480))

    pygame.display.set_caption("Dungeon Crawler")
    level = Level(LEVEL_ROOM, CELL_SIZE)
    eventqueue = EventQueue()
    renderer = Renderer(display, level)
    clock = Clock()
    game_loop = GameLoop(level, renderer, eventqueue, clock, CELL_SIZE)

    pygame.init() # pylint: disable=no-member
    game_loop.start()
Exemplo n.º 5
0
def PlayGame(num_games=20):
    open_tf_session()
    print("TF session restored")
    load_data("dummy.csv")
    print("Loaded data")
    global gameloop
    total_wins = 0
    average_opponent_wins = 0
    total_games = 0
    global gameType
    print("Playing ", num_games, "to get win percentage")
    for i in range(0, num_games):
        wins, average_opponent, total = gameloop.run()
        total_wins += wins
        total_games += total
        average_opponent_wins += average_opponent
        gameloop = GameLoop(type=gameType, use_nn=True)

    file = open('metrics.txt', 'a')
    file.write(
        str(total_wins / total_games) + ',' +
        str(average_opponent_wins / total_games) + ',' + str(total_wins) +
        ',' + str(average_opponent_wins) + ',' + str(total_games) + ',' +
        (str(datetime.datetime.now())) + '\n')
    file.close()

    print("Win percentage: ", (total_wins / total_games))
    print("Opponent win percentage: ", (average_opponent_wins / total_games))
    print("Total wins = ", total_wins, 'Average Opponent wins = ',
          average_opponent_wins, 'Total games = ', total_games)
    save_actions()
    close_tf_session()

    return (total_wins / total_games)
Exemplo n.º 6
0
def main():
    """Main function of the game. Creates all the classes that GameLoop-class needs to run
    the game, and then starts the game by calling gameloop.start().
    """
    display = pygame.display.set_mode((1024, 640))
    pygame.display.set_caption("Clicker")
    pygame.font.init()
    colors = Colors()
    event_queue = EventQueue()
    startview = StartView(display, colors)
    menu = Menu(display, colors)
    logic = GameLogic()
    shop = Shop(display, colors, logic)
    save = SaveGame(logic)
    game_loop = GameLoop(logic, display, colors, startview, event_queue, menu,
                         shop, save)
    pygame.init()
    game_loop.start()
Exemplo n.º 7
0
from game_state_capture import load_data, save_actions
from get_predicted_reward import open_tf_session, close_tf_session
import datetime
import tensorflow as tf
from game_loop import GameLoop
gameType = 'cutthroat'
gameloop = GameLoop(type=gameType, use_nn=True)


def PlayGame(num_games=20):
    open_tf_session()
    print("TF session restored")
    load_data("dummy.csv")
    print("Loaded data")
    global gameloop
    total_wins = 0
    average_opponent_wins = 0
    total_games = 0
    global gameType
    print("Playing ", num_games, "to get win percentage")
    for i in range(0, num_games):
        wins, average_opponent, total = gameloop.run()
        total_wins += wins
        total_games += total
        average_opponent_wins += average_opponent
        gameloop = GameLoop(type=gameType, use_nn=True)

    file = open('metrics.txt', 'a')
    file.write(
        str(total_wins / total_games) + ',' +
        str(average_opponent_wins / total_games) + ',' + str(total_wins) +
Exemplo n.º 8
0
def main():
    """Screen init."""
    init()
    display.set_caption(TITLE)
    play = GameLoop()
    play.game_loop()
Exemplo n.º 9
0
from person import Person, Type
from game_loop import GameLoop

game = GameLoop()

while not game.finished():
    game.step()
Exemplo n.º 10
0
		players = [
			ComputerPlayer(paddles[0], max_speed = paddle_speed, difficulty = 0.1),
			SampledPlayer(
				I2cJoystickPlayer(paddles[1], usb.i2c.slave(0x52), 1, -128, paddle_speed / 128),
				interval = 0.01),
		]

		game = GameLoop(
			playing_area,
			Ball(
				playing_area.centre,
				[1.8, 0],
				playing_area.bounding_box,
				Tile(6, 6, [
					0b00110000,
					0b01111000,
					0b11111100,
					0b11111100,
					0b01111000,
					0b00110000])),
			players,
			score_font = font_5x8,
			message_font = font_5x8)

		with open("lophtware-128x64.raw", "rb") as logo_fd:
			logo = Tile.from_raw(logo_fd.read(), 128, 64)

		SplashScreen(logo).show(display)

		quit = False
		def on_keyboard_input(cmd):
Exemplo n.º 11
0
def main():
    screen_width = 640
    screen_height = 640
    screen = pygame.display.set_mode((screen_width, screen_height))
    pygame.display.set_caption("Faux Emblem")

    camera = Camera(0, 0)

    units = []
    units.append(
        Unit(1,
             4,
             name="Ferdinand",
             strength=8,
             speed=6,
             defense=5,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units[0].items.append(Item(3, 3, 0))
    units[0].items.append(Item(3, 3, 0))
    units[0].items.append(Item(3, 3, 0))
    units.append(
        Unit(1,
             5,
             name="Sylvain",
             strength=4,
             speed=2,
             defense=8,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(3,
             6,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(6,
             6,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(12,
             4,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(9,
             7,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))
    units.append(
        Unit(2,
             5,
             Alignment.ENEMY,
             offset_x=camera.offset_x,
             offset_y=camera.offset_y))

    pygame.font.init()
    font = pygame.font.SysFont("Arial", 20)
    font2 = pygame.font.SysFont("Arial", 14)

    clock = GameClock()

    level = [[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
             [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
             [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
             [0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1],
             [0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1],
             [0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1],
             [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1],
             [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1]]

    test_level = Level(level, units)
    tile_map = TileMap(level)

    test_level.get_movement_data_with_units(True)

    pathfinding = PathFinding(1, 1, test_level.movement_data)
    target_selector = TargetSelector()

    enemy_ai = Ai(units, pathfinding, test_level)

    game_loop = GameLoop(screen, SpriteRenderer(),
                         Cursor(1, 4, camera.offset_x, camera.offset_y),
                         MenuCursor(), EventQueue(), units,
                         MovementDisplay(pathfinding), font, font2, clock,
                         target_selector, camera, test_level, tile_map,
                         enemy_ai)

    pygame.init()
    game_loop.start()

    pygame.quit()
Exemplo n.º 12
0
from graphics_pos import graphics_pos
import loop_funcs


def pressAndRelease(key_str: str):
    keyboard.press_and_release(key_str)


HOST = '192.168.1.10'  # 192.168.1.10
PORT = 65432  # Port to listen on (non-privileged ports are > 1023)
MOUSE_STATE = False
CENTER_POS = (960, 540)
AUTO_HEAL_STATE = False
game_state = GameState()

GameLoop.add_command(loop_funcs.init_nexus_pos, 'init')
GameLoop.add_command(loop_funcs.auto_heal, 'play')
GameLoop.add_command(loop_funcs.level_up, 'play')
GameLoop.add_command(loop_funcs.flee_back, 'flee')
GameLoop.add_command(loop_funcs.player_backed, 'play')

GameLoop.add_listener(loop_funcs.listen_attached_player_death, 'play')
GameLoop.add_listener(loop_funcs.listen_player_attach_changes, 'flee')

print('added auto heal')
started = False
screen_reader = ScreenReader(game_state)
screen_reader.daemon = True

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))