Exemplo n.º 1
0
    def __init__(self, showbase):
        DirectObject.__init__(self)

        # Initialise Window
        self.showbase = showbase

        # total time since start of game, to keep ticks updating on time (rather, not before)
        self.totalTime = 0

        # packets queue
        self.incoming = deque()

        users = []
        for user in self.showbase.users:
            user.gameData = UserData(user.name == self.showbase.username)
            users.append(user.gameData)
        self.game = Game(self.showbase, users, self.showbase.gameData)
        self.gameHandler = GameHandler(self.showbase, self.game)

        self.tick = 0
        self.tempTick = 0

        # Set event handlers for keys
        # self.showbase.accept("escape", sys.exit)

        # send loading completion packet to the game server
        self.showbase.client.sendData(('round', 'sync'))

        # Add the game loop procedure to the task manager.
        self.showbase.taskMgr.add(self.gameLoop, 'Game Loop')
Exemplo n.º 2
0
    os.makedirs(os.path.join(logdir_path, "logs"))

logfile_handler = logging.handlers.WatchedFileHandler(logfile_path, 'a', 'utf-8')

logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO,
                    handlers=[logfile_handler])

if not re.match("[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN):
    logging.error("Bot token not correct - please check.")
    exit(1)

updater = Updater(token=BOT_TOKEN)
dispatcher = updater.dispatcher

game_handler = GameHandler().get_instance()


# -----------------
# Internal methods
# -----------------
def change_language(bot, update, lang_id):
    logger.info("Language changed to '{}' for user {}".format(lang_id, update.effective_user.id))
    bot.editMessageText(chat_id=update.callback_query.message.chat_id, text=translate("langChanged", lang_id),
                        message_id=update.callback_query.message.message_id, reply_markup=None)
    db = DBwrapper.get_instance()
    db.insert("languageID", lang_id, update.callback_query.from_user.id)


def callback_eval(bot, update):
    query_data = update.callback_query.data
Exemplo n.º 3
0
class Round(DirectObject):
    # Initialisation Function
    def __init__(self, showbase):
        DirectObject.__init__(self)

        # Initialise Window
        self.showbase = showbase

        # total time since start of game, to keep ticks updating on time (rather, not before)
        self.totalTime = 0

        # packets queue
        self.incoming = deque()

        users = []
        for user in self.showbase.users:
            user.gameData = UserData(user.name == self.showbase.username)
            users.append(user.gameData)
        self.game = Game(self.showbase, users, self.showbase.gameData)
        self.gameHandler = GameHandler(self.showbase, self.game)

        self.tick = 0
        self.tempTick = 0

        # Set event handlers for keys
        # self.showbase.accept("escape", sys.exit)

        # send loading completion packet to the game server
        self.showbase.client.sendData(('round', 'sync'))

        # Add the game loop procedure to the task manager.
        self.showbase.taskMgr.add(self.gameLoop, 'Game Loop')

    def destroy(self):
        self.showbase.taskMgr.remove('Game Loop')
        self.game.destroy()
        self.gameHandler.destroy()

    # Game Loop Procedure
    def gameLoop(self, task):
        dt = task.getDt()
        # update total time
        self.totalTime += dt
        # process any incoming network packets
        temp = self.showbase.client.getData()
        for packet in temp:
            # this part puts the next packets onto the end of the queue
            self.incoming.append(packet)

        # while there is packets to process
        while len(self.incoming):
            package = self.incoming.popleft()
            if len(package) == 2:
                # if username is sent, assign to client
                if package[0] == 'tick':
                    # not sure if this is the best way to do this but yea something to look into for syncing them all preround i guess
                    if package[1] == 0:
                        self.totalTime = 0
                    # check what tick it should be
                    self.tempTick = package[1]
                    # if this tick needs to be run (if frames are up to the server tick)
                    # if self.temp_tick * game_tick <= self.total_time:
                    # run tick
                    if not self.game.runTick(gameTick, self.tempTick):
                        print 'Game Over'
                        self.showbase.endRound()
                        return task.done
                        # else:
                        # otherwise put packet back on front of list and end frame processing
                        #	self.incoming.appendleft(package)
                        #	break
                elif package[0] == "game" and package[1] == "over":
                    print 'Game Over'
                    self.showbase.endRound()
                    return task.done
                else:
                    for user in self.showbase.users:
                        if user.name == package[0]:
                            user.gameData.processUpdatePacket(package[1])

        self.gameHandler.update(dt)

        # TODO: Not sure if this is the best place for this
        # self.gameHandler.getUpdates()

        # Return cont to run task again next frame
        return task.cont
Exemplo n.º 4
0
from database.db_wrapper import DBwrapper
from database.statistics import get_user_stats
from game.blackJack import BlackJack
from gamehandler import GameHandler
from lang.language import translate

__author__ = 'Rico'

BOT_TOKEN = "<your_bot_token>"

logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG)
updater = Updater(token=BOT_TOKEN)
dispatcher = updater.dispatcher

game_handler = GameHandler()
tg_bot = updater.bot


def start(bot, update):
    chat_id = update.message.chat_id
    user_id = update.message.from_user.id
    message_id = update.message.message_id
    first_name = update.message.from_user.first_name
    last_name = update.message.from_user.last_name
    username = update.message.from_user.username
    db = DBwrapper.get_instance()

    if not (db.is_user_saved(user_id)):
        # ask user for language:
        logger.info("New user")