def test_game_controller_check_user_input(): mazeObject = Maze("tests/test1.txt", 'P') game_controller = GameController(mazeObject) game_controller.check_user_input('d', 0, 0) game_controller.check_user_input('a', 0, 0) game_controller.check_user_input('w', 0, 0) game_controller.check_user_input('x', 0, 0)
def on_game_started(self, event): module_logger.info("MainMenuController: on_game_started called.") model = GameModel(self.event_dispatcher) view = GameView(self.event_dispatcher) controllers = [] game_controller = GameController(model, self.event_dispatcher) mouse_controller = MouseController(self.event_dispatcher) controllers.append(game_controller) controllers.append(mouse_controller) event = MVCChangeEvent(model, view, controllers) self.event_dispatcher.dispatch_event(event)
def run_game(): """Инициализируем игру""" pygame.init() # Считываем конфиг config = configparser.ConfigParser() config.read("configs/config.ini") # Настройка окна width = int(config['WINDOW']['Width']) height = int(config['WINDOW']['Height']) title = config['WINDOW']['Title'] screen = pygame.display.set_mode((width, height)) pygame.display.set_caption(title) GameController(screen, config)
def test_entire_game_with_two_AI(self): new_game = Game() new_game.game_mode = 2 token_1 = XToken() token_2 = OToken() tokens = (token_1, token_2) new_game.add_token_options(tokens) game_controller = GameController() game_controller.assign_game(new_game) player_one = Player() player_two = Player() players = [player_one, player_two] game_controller.add_players_to_game(players) player_one_controller = AIPlayerController() player_two_controller = AIPlayerController() player_one_controller.assign_player(player_one) player_two_controller.assign_player(player_two) player_controllers = [player_one_controller, player_two_controller] player_one_controller.determine_name() player_two_controller.determine_name() random.shuffle(player_controllers) game_controller.assign_tokens(player_controllers) new_game.print_players() grid = Grid(3, 3) grid_controller = GridController() grid_controller.assign_grid(grid) while not new_game.game_over: game_controller.play_round(player_controllers, grid_controller)
from controllers.user_controller import UserController from controllers.question_controller import QuestionController from controllers.category_controller import CategoryController from controllers.game_controller import GameController from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from config import DB_PATH app = Flask(__name__) user_controller = UserController() question_controller = QuestionController() category_controller = CategoryController() game_controller = GameController() app.config["SQLALCHEMY_DATABASE_URI"] = DB_PATH app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False db = SQLAlchemy(app) from models import ( CategoryModel, UserModel, GameModel, OptionModel, QuestionModel, )
""" Run the game from this file """ from controllers.game_controller import GameController game = GameController() game.run()
from domain.situation import Situation from validators.game_validator import GameValidator from controllers.game_controller import GameController from ui.console import Console situation = Situation() game_validator = GameValidator() game_controller = GameController(situation, game_validator) console = Console(game_controller) console.start_game()
try: settings_file = open("settings.properties", "r") interface_option = settings_file.readline().strip() if len(interface_option) == 0: raise IOError("Interface option not given, check settings.properties file.") interface = interface_option.split("=")[1] difficulty_option = settings_file.readline().strip() if len(difficulty_option) == 0: raise IOError("Difficulty option not given, check settings.properties file.") difficulty = difficulty_option.split("=")[1] if difficulty != "medium" and difficulty != "hard": raise IOError("The difficulty option in settings.properties must be either 'medium' or 'hard'.") game_controller = GameController(player, computer, difficulty) if interface == "console": console = Console(game_controller) console.start_game() elif interface == "gui": gui = GUI(game_controller) gui.start_game() else: raise IOError("The interface option in settings.properties must be either 'console' or 'gui'.") settings_file.close() except IOError as io_error: raise io_error
app.install(JsonPlugin()) app.install(ErrorFilterPlugin()) app.install( BottleSQLAlchemySessionPlugin(engine=ENGINE, commit=False, create_session_by_default=True)) app.install(AuthPlugin(auth_service)) app.install(EnableCors()) converter = PyJsonConverter() app.install(BottlePyJsonPlugin(converter)) app.install(ControllerPlugin()) logger = ConsoleLogger() auth_controller = AuthController(app, logger, auth_service) game_controller = GameController(app, game_service, logger) @app.route('/<:re:.*>', method='OPTIONS') def cors(): print('After request hook.') response.headers['Access-Control-Allow-Origin'] = '*' if __name__ == "__main__": run( app, host='localhost', port=8080, # reloader=True, debug=True,
def run(self): """ This is the main method for our application. It runs an infinite loop, unless the user decides to quit. The `SystemExit` exception is raised by the child controllers. """ pygame.init() print(self._maze.locations) clock = pygame.time.Clock() welcome_controller = WelcomeController( self.window, self._maze.row * GridSize.SIZE, self._maze.col * GridSize.SIZE + GridSize.SIZE, GridSize.SIZE) running = False welcome_controller.run() pygame.display.update() welcome_controller.get_input() running = True # initialize pygame elements self._maze.create_player() self._maze.create_maze_exit() self._maze.create_wall() self._maze.create_items() while running: pygame.display.update() clock.tick(20) self.window.fill((0, 0, 0)) game_controller = GameController(self._maze, self._window) game_controller.run() # check if time runs out if self._maze._time_left <= 0: running = False # check if player reaches the exit if pygame.sprite.collide_rect(self._maze.player, self._maze.maze_exit): running = False game_over_controller = GameOverController(self.window, self._maze) game_over_controller.run() pygame.display.update() # ask for player name if game_over_controller._maze_result: self._maze.add_name_score() while True: key = game_over_controller.get_user_input() if key == "q": pygame.quit()