def __init__(self, game_id): self.game_id = game_id self.players = {} self.lock = RLock() self.game = awesome_sauce.Game(game_id) self.game.start() self.moved = set([])
def main(): def generateImages(): import json for counter in range(12): Game.init() Game.draw(0, 0) pygame.display.flip() pygame.image.save(screen, "../paths/trialPNG(%d).png" % (counter)) f = open("../paths/trialFRAME(%d).txt" % (counter), "w") f.write(json.dumps(Game.server.trial_def, indent=4, sort_keys=True)) f.close() Game.reset() pygame.init() screen = pygame.display.set_mode((1024, 768)) pygame.display.set_caption("Ball-Game") Game = game.Game(screen, 1337) Game.server.waitForClient() screen = pygame.display.set_mode((1024, 768), FULLSCREEN) RUN = True #RUN = False #generateImages() while RUN: Game.init() RUN = mainLoop(Game) Game.reset()
def test_game(): test_obj = game.Game() # before starting the game, there's no grid nor players assert not hasattr(test_obj, 'grid') assert len(test_obj.players) == 0 test_obj.start() # after starting the game, we have grid and players assert hasattr(test_obj, 'grid') assert hasattr(test_obj, 'players')
def __init__(self): """ Constructor for game server Asynch threadsafety via monitor pattern GameServer contains client connections and game instance clients are in dictionary, mapping username to websocket connection """ self.lock = asyncio.Lock() self.client_connections = dict() self.game = g.Game()
def game_start(): button("Start", 885, 515, buttonPosition, 0) button("Exit", 885, 580, buttonPosition, 1) pygame.display.update() gameExit = False while not gameExit:#Menu event handler for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONUP: pos = pygame.mouse.get_pos() if (bChecker(pos[0], pos[1], buttonPosition) == 0):#Check if mouse is on start button gameRun = game.Game(None) game_loop() if (bChecker(pos[0], pos[1], buttonPosition) == 1):#Check if mouse is on quit button gameExit = True if event.type == pygame.QUIT: gameExit = True
def test_a_match(): g1 = game.Game() g1.add_default_players() g1.start() max_turns = 100 alive = g1.get_alive_players() current_turns = 0 while len(alive) > 1 or current_turns < max_turns: for player in g1.players.values(): x, y = player.position new_x, new_y = random.randint(-2, 2), random.randint(-2, 2) while not player.position_in_grid_range(x + new_x, y + new_y): new_x, new_y = random.randint(-2, 2), random.randint(-2, 2) player.move(new_x, new_y) g1.make_a_turn() alive = g1.get_alive_players() current_turns += 1
def setUp(self): self.game = g.Game() self.game.entities = [ { "TEXT": "BABA", "IS": set([]), "HAS": [] }, { "TEXT": "KEKE", "IS": set([]), "HAS": [] }, { "TEXT": "BABA", "IS": set(["RED"]), "HAS": [] } ]
def test_conflicts(): g1 = game.Game() g1.add_default_players() g1.start() # make two players collide iterable = iter(g1.players.values()) first_player = next(iterable) second_player = next(iterable) first_player.position = [3, 3] second_player.position = [3, 3] # resolve conflict g1.resolve_conflicts() assert first_player.position != second_player.position assert first_player.health != second_player.health assert first_player.position == [3, 3] or second_player.position == [3, 3] assert len(g1.animations) == 1 assert g1.animations[0].get("origin") == [3, 3] assert g1.animations[0].get("positions") != [3, 3]
def play(shape: Tuple[int, int], cell_size: Tuple[int, int], init_salesman_list: List[Tuple[int, int]] = None, auto_controller: Optional[AutoController] = None): while True: if init_salesman_list is not None: board = Board( shape=shape, obstacle=int(0.1 * board_size(shape)), customer=int(0.05 * board_size(shape)), salesman=init_salesman_list, ) else: board = Board( shape=shape, obstacle=int(0.1 * board_size(shape)), customer=int(0.05 * board_size(shape)), salesman=int(0.01 * board_size(shape)), ) g = game.Game(board, cell_size) output = g.loop(auto_controller) if output == "r": continue break
import pygame from pygame.locals import * import time, math, sys, json from game import game as game pygame.mixer.pre_init(44100, -16, 2, 128) pygame.init() pygame.font.init() pygame.mixer.init(44100) config = json.load(open('config.json', 'r')) g = game.Game(config) g.run()
# -*- coding: utf-8 -*- """ Created on Wed Jul 22 05:51:34 2020 @author: MAQS """ from game import game as gm if __name__=="__main__": Game=gm.Game()
def Launch_Game(screen, controls, level=0): if level == 0: level = random.randint(1, 5) TheGame = game.Game(screen, controls, level) if TheGame.main_loop(): GotoMapScreen(screen, controls)
import importlib as il import tensorflow as tf import agent.agent as agent import game.game as game import os os.environ["CUDA_VISIBLE_DEVICES"] = "0" sess = tf.InteractiveSession() il.reload(game) il.reload(agent) # Start the game g = game.Game() # Start the agent a = agent.Agent(sess=sess, game=g) a.train()
import game.game as g game = g.Game(debug=True, debug_options={"PRINT_TREEIFY_KEYS": ["TEXT"]}) game.entities.append({"TEXT": "BABA", "IS": set(["RED"]), "HAS": []}) r1 = game.get_rule("NOT BABA IS YOU") print(game.cols_from([r1], ["TEXT"])) game.add_rule(r1) """ while True: game.update_rules() """
def create_game(): """Create a new game with the global parameters.""" global game game = game_m.Game(names, deck_size, hand_size, trump_suit, feature_type, buffer_features, only_ais)
from game import game if __name__ == '__main__': game = game.Game() game.gui.root.mainloop()
def main(): """ A small solar system. Create objects by holding mouse down and dragging for direction and power """ game = app.Game(width=720, height=720, minDt=10) game.gameLoop()
def game_loop(): #Build map for tests dimX = 8 dimY = 7 map1 = map.Map(dimX, dimY) posGrid = np.zeros((dimX,dimY), dtype = (int,2)) map1.setCell((1,1),color=cell.RED, type=cell.TOWER, strength=2) map1.setCell((2,1),color=cell.RED, type=cell.UNIT, strength=1) map1.setCell((1,5),color=cell.BLUE, type=cell.TOWER, strength=2) map1.setCell((2,5),color=cell.BLUE, type=cell.UNIT, strength=1) map1.setCell((6,1),color=cell.GREEN, type=cell.TOWER, strength=2) map1.setCell((5,1),color=cell.GREEN, type=cell.UNIT, strength=1) map1.setCell((6,5),color=cell.YELLOW, type=cell.TOWER, strength=2) map1.setCell((5,5),color=cell.YELLOW, type=cell.UNIT, strength=1) mapResources(map1) #Game Variables gameExit = False moving = False building = False pos = (-1,-1) #Game Objects game1 = game.Game(map1) curPlayer = game1.getCurrentPlayer() #Draw Buttons and map gameDisplay.fill(BLACK) button("Move", 750, 300, buttonPosition, 2) button("Attack", 925, 300, buttonPosition, 4) button("End Turn", 750, 375, buttonPosition, 3) button("Build Unit", 925, 375, buttonPosition, 7) drawText("Turn:", 800, 175, WHITE) pygame.draw.rect(gameDisplay,IDtoColor(curPlayer.getColor()),[800, 200, 50, 50]) disp_resources(curPlayer) draw_map(map1,posGrid) while not gameExit:#Game event handler for event in pygame.event.get(): if event.type == pygame.QUIT: gameExit = True if event.type == pygame.MOUSEBUTTONUP: mPos = pygame.mouse.get_pos() if pos != (-1, -1) and (bChecker(mPos[0], mPos[1], buttonPosition) == 2): #Move button moving = True building = False attacking = False if (bChecker(mPos[0], mPos[1], buttonPosition) == 3): #End Turn game1.endTurn() curPlayer = game1.getCurrentPlayer() pygame.draw.rect(gameDisplay,IDtoColor(curPlayer.getColor()),[800, 200, 50, 50]) moving = False disp_resources(curPlayer) pygame.display.update() if pos != (-1,-1) and (bChecker(mPos[0],mPos[1], buttonPosition) == 4): #Attack button attacking = True moving = False if (bChecker(mPos[0], mPos[1], buttonPosition) == 7): #Build unit button if ((map1.getType(pos) == 2) and map1.getRGB(pos) == IDtoColor(curPlayer.getColor())): #Only towers can build units and only during their turn if (curPlayer.getResources() > 0): building = True moving = False for i in range(dimX):#Checks every hex to see if clicked for q in range(dimY): if (mPos[0] >= posGrid[i,q][0] and mPos[0] <= 40 + posGrid[i,q][0]) and (mPos[1] >= posGrid[i,q][1] and mPos[1] <= 80 + posGrid[i,q][1]):#Checks if clicked on hex i,q if moving and pos != (-1,-1): if map1.getRGB(pos) == IDtoColor(curPlayer.getColor()):#Only able to move units whose turn it is if map1.getType((i,q)) == 1: if map1.getColor(pos) == map1.getColor((i,q)): pygame.draw.rect(gameDisplay,WHITE,[800, 500, 400, 200]) drawText("Would you like to combine?", 800, 500, BLACK) button("Yes", 800, 550, buttonPosition, 5) button("No", 1000,550, buttonPosition, 6) pygame.display.update() while(moving): for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONUP: mPos = pygame.mouse.get_pos() if (bChecker(mPos[0], mPos[1], buttonPosition) == 5): map1.makeMove(pos, (i,q)) pygame.draw.rect(gameDisplay, BLACK, [800, 500, 400, 200]) moving = False if (bChecker(mPos[0], mPos[1], buttonPosition) == 6): pygame.draw.rect(gameDisplay, BLACK, [800, 500, 400, 200]) moving = False if moving: map1.makeMove(pos, (i,q)) moving = False if building and map1.getType((i,q)) == 0: #Only Builds on empty if (i,q) in map1.getAdjacent(pos): #Only builds on adjacent curPlayer.changeResources(-1) #Subtract from players resources map1.setCell((i,q),color=cell.RED, type=cell.UNIT, strength=1) draw_map(map1, posGrid) disp_resources(curPlayer) pygame.display.update() building = False pos = (i,q) draw_map(map1, posGrid) pygame.display.update()