Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.join_message = None
        self.join_button = (Phrase.JOIN_BUTTON, 'JOIN')
        self.start_button = (Phrase.START_BUTTON, 'START')

        self.gm = GameManager(self)
Ejemplo n.º 2
0
 def __init__(self):
     self.receive_queue = Queue()
     self.send_queue = Queue()
     self.server_pipe, self.game_pipe = Pipe()
     self.clients = []
     self.server = ServerUDP()
     self.game_manager = GameManager()
     self.message_process = None
     self.receive_process = None
     self.send_process = None
Ejemplo n.º 3
0
 def __init__(self):
     self.receive_queue = Queue()
     self.send_queue = Queue()
     self.client_pipe, self.game_pipe = Pipe()
     self.client = ClientUDP()
     self.client.connect('127.0.0.1', 23333)
     self.game_manager = GameManager()
     self.message_process = Process(target=self.message_func, args=())
     self.receive_process = Process(target=self.receive_func, args=())
     self.send_process = Process(target=self.send_func, args=())
     self.message_process.start()
     self.receive_process.start()
     self.send_process.start()
Ejemplo n.º 4
0
    def __init__(self):
        super(MainWindow, self).__init__()

        #=========================================================================
        # Load data
        #=========================================================================
        QtGui.qApp.DataManager = DataManager()
        QtGui.qApp.DataManager.LoadUnitTypes()
        QtGui.qApp.DataManager.LoadBaseSizes()
        QtGui.qApp.DataManager.LoadMarkers()
        QtGui.qApp.DataManager.LoadIcons()
        QtGui.qApp.DataManager.LoadTerrain()

        #=========================================================================
        # Init game manager
        #=========================================================================
        QtGui.qApp.GameManager = GameManager()

        #=========================================================================
        # Init main window
        #=========================================================================
        self.resize(1280, 800)
        self.setWindowTitle("vbattle")

        #=========================================================================
        # Init child widgets and menus
        #=========================================================================
        self.setCentralWidget(MainWindowCentralWidget())
        self.setStatusBar(QtGui.QStatusBar())
        self.statusBar().showMessage("Ready.")
        self.setMenuBar(MainMenu())

        #self.dockWidget = ToolsDockWidget(self)
        #self.addDockWidget(Qt.TopDockWidgetArea, self.dockWidget)
        self.unitTb = UnitToolBar(self)
        self.addToolBar(self.unitTb)

        self.InitConnections()
Ejemplo n.º 5
0
	def main(self):
		self.start_time = round(time.time() * 1000)
		Main.get_logger("Starting all systems...")
		self.game_manager = GameManager()
		Main.get_logger("Getting configuration.")
		self.game_manager.config = Configuration()
		self.game_manager.config.load()
		Main.get_logger("Connecting to MySQL.")
		self.game_manager.pooling = Database()
		self.game_manager.pooling.connect(
			self.game_manager.config.get_value("database", "db.poolname"),
			self.game_manager.config.get_value("database", "db.poolsize"),
			self.game_manager.config.get_value("database", "db.hostname"),
			self.game_manager.config.get_value("database", "db.user"),
			self.game_manager.config.get_value("database", "db.password"),
			self.game_manager.config.get_value("database", "db.database")
		)
		Main.get_logger("Opening socket system.")
		self.game_manager.socket = SocketServer(self.game_manager, (self.game_manager.config.get_value("socket", "socket.host"), int(self.game_manager.config.get_value("socket", "socket.port"))))
		self.socket_thread = threading.Thread(target=self.game_manager.socket.serve_forever, args=())
		self.socket_thread.start()
		self.end_time = round(time.time() * 1000) - self.start_time
		Main.get_logger(f"Emulator started with {self.end_time}ms.\n")
Ejemplo n.º 6
0
    pygame.display.set_icon(pygame.image.load(
        WINDOW_ICON_PATH).convert_alpha())  # Icon

    # Currently displayed view
    view = MAIN_MENU_VIEW

    # Initialization of the main menu
    (main_menu_buttons, main_menu_sprites) = get_main_menu_elements()
    main_menu = MenuManager(screen, main_menu_buttons, main_menu_sprites)

    # Initialization of the levels menu
    (level_menu_buttons, level_menu_sprites) = get_level_menu_elements()
    level_menu = MenuManager(screen, level_menu_buttons, level_menu_sprites)

    # Initialisation of the game
    game = GameManager(screen)

    # Main loop
    while True:
        # Depending on the current view, we update the display
        if view == MAIN_MENU_VIEW:
            view = main_menu.mainloop()

        elif view == LEVEL_CHOICE_MENU_VIEW:
            (view, next_level) = level_menu.mainloop()

        elif view == GAME_VIEW:
            view = LEVEL_CHOICE_MENU_VIEW

            game.parse(next_level, 0)
            game.mainloop()
Ejemplo n.º 7
0
class MyChatHandler(ChatHandler):
    ONLY_ADMINS_COMMANDS = ['reset']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.join_message = None
        self.join_button = (Phrase.JOIN_BUTTON, 'JOIN')
        self.start_button = (Phrase.START_BUTTON, 'START')

        self.gm = GameManager(self)

    class CommandsEnum(ChatHandler.CommandsEnum):
        # <command_name> - (description, func to run)
        play = ('Start a new game', None)
        setdice = ('Set start dice count', None)
        # settimeout = ('Set timeout', None)
        reset = ('Reset', None)

    @is_state(MyDialogState.DEFAULT)
    def on_play(self, update: tg.Update):
        self.state = MyDialogState.WAITING_FOR_PLAYERS

        reply_markup = get_button_markup(self.join_button)

        self.join_message = self.send_message(**Phrase.WAIT_FOR_PLAYERS,
                                              reply_markup=reply_markup)

    def on_setdice(self, update: tg.Update):
        command = my.Command(self, update)

        try:
            cnt = int(command.entity_text)
            self.gm.dice_cnt = cnt
            self.send_message(**Phrase.ON_AGREE)
        except ValueError:
            raise BotMessageException(Phrase.ON_NO_COMMAND_ENTITY)

    def on_reset(self, _: tg.Update):
        self.state = MyDialogState.DEFAULT
        self.gm.reset_to_defaults()
        self.send_message(**Phrase.ON_AGREE,
                          reply_markup=tg.ReplyKeyboardRemove())

    def on_keyboard_callback_query(self, update: tg.Update):
        query = update.callback_query
        data = query.data.split()
        user = query.from_user

        if data[0] == 'START':
            if self.state == MyDialogState.WAITING_FOR_PLAYERS:
                self.gm.start_session()
                self.state = MyDialogState.GAME_IS_ON

        elif data[0] == 'JOIN':
            if self.state != MyDialogState.WAITING_FOR_PLAYERS:
                return

            if user not in self.gm.added_players:
                self.gm.added_players.append(user)

                new_text = self.join_message.text + '\n' + Phrase.on_user_joined(
                    user.name)['text']

                self.join_message = self.edit_message(
                    message=self.join_message,
                    text=new_text,
                )

            else:
                self.send_alert(query.id, text=Phrase.ALREADY_JOINED)

            if debug or len(
                    self.gm.added_players) > 1:  # Enough players to start
                reply_markup = get_button_markup(self.join_button,
                                                 self.start_button)

                self.edit_message(message=self.join_message,
                                  reply_markup=reply_markup)

        elif data[0] == 'DICE':
            if self.state != MyDialogState.GAME_IS_ON:
                return

            dice_set = self.gm.current_game.dice_manager[user.id]
            self.send_alert(query.id, text=str(dice_set))

        else:
            raise BotMessageException('unexpected callback_data string: ' +
                                      query.data)

    def reply(self, update: tg.Update, message_type: MESSAGE_TYPES):
        super().reply(update, message_type)

        print(update.message.text)

        if self.state == MyDialogState.GAME_IS_ON:
            self.gm.on_new_message(my.Message(self, update))
Ejemplo n.º 8
0
Attributes:
    na

Todo:
    * luck and skill metadprime
    * explanations in the word doc
    * hit or miss, how much credit to assign

Related projects:
    Adapted from initial toy project https://github.com/sonlexqt/whack-a-mole
    which is under MIT license

@author: DZLR3
"""

from game import GameManager
import pygame

if __name__ == "__main__":
    # Initialize the game
    pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=512)
    pygame.init()

    # Run the main loop
    my_game = GameManager()

    my_game.play_game()

    # Exit the game if the main loop ends
    pygame.quit()
Ejemplo n.º 9
0
    def send_path(self):
        index = self._view.currentIndex()
        path = self._model.item(index.row(), 2).text()

        debug(f'send {path} to GameManager')
        GameManager.instance(path)
Ejemplo n.º 10
0
from flask import Flask, render_template, request
from flask_socketio import SocketIO, join_room, leave_room, emit
from game import GameManager
from connect4 import Connect4Board
from cards import CardStack
import json
app = Flask(__name__)
socketio = SocketIO(app)
game_manager = GameManager()

html_escape_table = {
    "&": "&amp;",
    '"': "&#34;",
    "'": "&#39;",
    ">": "&gt;",
    "<": "&lt;",
}

def html_escape(text):
    return "".join(html_escape_table.get(c,c) for c in text)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/lobby', methods=['POST', 'GET'])
def lobby():
    player = request.remote_addr
    if request.method == 'POST':
        data = request.form
        name = data['name']
Ejemplo n.º 11
0
"""
A main entry point of the app
"""
import sys
import os

from game import GameManager, AssetsProvider, Window
from settings import Settings

if __name__ == '__main__':
    if getattr(sys, 'frozen', False):
        # noinspection PyProtectedMember
        # pyre-ignore[16]:
        os.chdir(sys._MEIPASS)  # pylint: disable=E0401, E1101, W0212

    window = Window(*Settings().get_window_size())

    asset_provider = AssetsProvider()

    game_manager = GameManager(window, asset_provider)

    window.loop(game_manager.game_loop)