示例#1
0
文件: mixins.py 项目: squeesh/magic
    def play_card_event(self, player, **kwargs):
        if self.mana_cost:
            if not GameController.can_spend_mana(player, self.mana_cost):
                GameController.print_message('ERROR cannot play card, not enough mana: %s\n' % self)
                return

        player.hand.remove(self)
        player.battlefield.append(self)
        player.spend_mana(self.mana_cost)
        GameController.print_message(GameController.get_mana_string(player))
        GameController.print_message('player played a card: %s\n' % self)
示例#2
0
def main():
    '''Initializes the grid, player's agent, and handles gameplay loop'''

    pygame.init()

    gc.initialize_squares()
    character = Macgyver(gc.START_SQUARE_ID, gc)
    dc.CHARACTER = character
    dc.GAME_CONTROLLER = gc

    dc.initialize_display()

    while gc.GAME_STATE == "Running":
        for event in pygame.event.get():
            if event.type == QUIT:
                gc.GAME_STATE = "Terminated"

            row_length = dc.WINDOW_WIDTH / dc.TILE_LENGTH

            if (event.type == KEYDOWN
                    and event.key in (K_LEFT, K_UP, K_RIGHT, K_DOWN)):

                if event.key == K_LEFT:
                    if character.position % row_length != 0:
                        character.move(-1)

                elif event.key == K_UP:
                    character.move(int(-row_length))

                elif event.key == K_RIGHT:
                    if character.position % row_length != row_length - 1:
                        character.move(1)

                elif event.key == K_DOWN:
                    character.move(int(row_length))

                character.touch_square()
                dc.refresh_display()

    while gc.GAME_STATE in ("Victory", "Defeat"):
        for event in pygame.event.get():
            if event.type == QUIT:
                gc.GAME_STATE = "Terminated"
    def play_card_event(self, player, **kwargs):
        if self.mana_cost:
            if not GameController.can_spend_mana(player, self.mana_cost):
                GameController.print_message(
                    'ERROR cannot play card, not enough mana: %s\n' % self)
                return

        player.hand.remove(self)
        player.battlefield.append(self)
        player.spend_mana(self.mana_cost)
        GameController.print_message(GameController.get_mana_string(player))
        GameController.print_message('player played a card: %s\n' % self)
 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 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)
示例#6
0
    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)
示例#7
0
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)
示例#8
0
文件: instants.py 项目: squeesh/magic
 def play_card_event(self, player, **kwargs):
     super(WarReport, self).play_card_event(player, **kwargs)
     count = GameController.get_battlefield_creature_count()
     count += GameController.get_battlefield_artifact_count()
     player.add_health(count)
示例#9
0
from controllers.game_controller import GameController

GameController.main_loop()
示例#10
0
文件: instants.py 项目: squeesh/magic
 def play_card_event(self, player, **kwargs):
     super(WarReport, self).play_card_event(player, **kwargs)
     count = GameController.get_battlefield_creature_count()
     count += GameController.get_battlefield_artifact_count()
     player.add_health(count)
示例#11
0
    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()
示例#12
0
""" Run the game from this file """
from controllers.game_controller import GameController

game = GameController()
game.run()
示例#13
0
文件: app.py 项目: Leviosar/sphinx
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,
)

示例#14
0
from models.game import Game
from models.grid import Grid
from models.player import Player
from view.o_token import OToken
from view.x_token import XToken

if __name__ == "__main__":
    while True:
        new_game = Game()

        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)

        game_controller.show_prompt()
        game_controller.determine_game_mode()

        player_one = Player()
        player_two = Player()
        players = [player_one, player_two]
        game_controller.add_players_to_game(players)

        player_one_controller = None
        player_two_controller = None
        if new_game.is_single_player():
            player_one_controller = HumanPlayerController()
            player_two_controller = AIPlayerController()
示例#15
0
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
示例#16
0
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,
示例#17
0
from controllers.game_controller import GameController

game = GameController()

game.launch()
示例#18
0
    def tap_land_event(self, player, **kwargs):
        if not self.tapped:
            GameController.add_mana(player=player, mana_type=self.mana_type)
            self.tapped = True
            GameController.print_message("tapped card: %s\n" % self)

        elif GameController.can_remove_mana(player=player, mana_type=self.mana_type):
            GameController.remove_mana(player=player, mana_type=self.mana_type)
            self.tapped = False
            GameController.print_message("untapped card: %s\n" % self)

        else:
            self.tapped = True
            GameController.print_message("Error untapping card, not enough mana: %s\n" % self)
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()
示例#20
0
    def tap_land_event(self, player, **kwargs):
        if not self.tapped:
            GameController.add_mana(player=player, mana_type=self.mana_type)
            self.tapped = True
            GameController.print_message("tapped card: %s\n" % self)

        elif GameController.can_remove_mana(player=player,
                                            mana_type=self.mana_type):
            GameController.remove_mana(player=player, mana_type=self.mana_type)
            self.tapped = False
            GameController.print_message("untapped card: %s\n" % self)

        else:
            self.tapped = True
            GameController.print_message(
                "Error untapping card, not enough mana: %s\n" % self)
示例#21
0
from controllers.game_controller import GameController
from game_config import GameConfig

localedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'locale')
translate = gettext.translation('2048',
                                localedir,
                                languages=['en-US', 'zh_CN'],
                                fallback=True)
translate.install()


def io_loop_thread(loop):
    loop.run_forever()


def stop_loop():
    loop = asyncio.get_event_loop()
    loop.stop()


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    io_loop = asyncio.get_event_loop()
    threading.Thread(target=io_loop_thread, args=(io_loop, )).start()
    config = GameConfig('config.json')
    GameController.initialize(config)
    GameController.new_game()
    GameController.run()
    io_loop.call_soon_threadsafe(stop_loop)