示例#1
0
    def prepareGame(self):
        if self.camera:
            # Disable Mouse Control for camera
            self.disableMouse()

            self.camera.setPos(0, 0, 500)
            self.camera.lookAt(0, 0, 0)

        self.gameData = GameData(True)

        # game data
        self.broadcastData(('gamedata', self.gameData.packageData()))
        self.broadcastData(('state', 'preround'))
        print "Preparing Game"
        self.gameTime = 0
        self.tick = 0

        usersData = []
        for user in self.currentPlayers:
            user.gameData = UserData()
            usersData.append(user.gameData)
        print usersData
        self.game = Game(self, usersData, self.gameData)
        self.taskMgr.doMethodLater(0.5, self.roundReadyLoop, 'Game Loop')
        print "Round ready State"
示例#2
0
def save_game(exit=False):
    gamedata = GameData(
        **{
            "player": player,
            "dungeon_room": dungeon.cur_room,
            "bonus_tasks": bonus_tasks,
            "savefile": savefile
        })
    json_serialization.save_file(gamedata, savefile)
    print("Game saved to " + savefile)
    if not exit:
        village.show()
示例#3
0
文件: game.py 项目: bull313/pokerAI
 def __init__(self):
     """
     Properties
     """
     self._blinds_maxed_out = False  ### Are the blinds at the highest value?
     self._board_name_idx = 0  ### List address for the name of the board
     self._game_data = GameData()  ### Poker Data Interface Object
     self._game_play_code = GameCode.NEW_GAME  ### What kind of game are we playing or playing back (new/load)?
     self._game_save = None  ### Object that manages saving a game finished or in progress
     self._game_theater = None  ### Plays back a finished game
     self._hand_actions = list(
     )  ### List of actions that were made in a hand
     self._ui = GameUI()  ### User Interface Object
     self._num_remaining_players = 0  ### Number of remaining players in the game
示例#4
0
 def testSaveData(self):
     g = GameData('PlanetWars')
     g_id = g.get_next_game_id()
     result = {}
     if random.randint(0, 1) == 0:
         result = {1: 1, 2: 2}
     else:
         result = {2: 1, 1: 2}
     player1 = random.randint(1, 8)
     player2 = random.randint(1, 8)
     g.save_game(g_id, result, 'bla', {
         player1: self.names[player1],
         player2: self.names[player2]
     })
示例#5
0
 def updateLobby(self, task):
     temp = self.showbase.client.getData()
     for package in temp:
         if len(package) == 2:
             print 'Received: ', str(package)
             if package[0] == 'reset':
                 self.showbase.users = []
                 print 'cleared users'
             elif package[0] == 'client':
                 self.showbase.users.append(User(package[1]))
                 for user in self.showbase.users:
                     print user.name, user.ready
                 print 'all users'
             elif package[0] == 'ready':
                 for user in self.showbase.users:
                     if user.name == package[1][0]:
                         user.ready = package[1][1]
                 for user in self.showbase.users:
                     print user.name, user.ready
                 print 'all users'
             elif package[0] == 'disconnect':
                 for user in self.showbase.users:
                     if user.name == package[1]:
                         self.showbase.users.remove(user)
                 for user in self.showbase.users:
                     print user.name, user.ready
                 print 'all users'
             elif package[0] == 'gamedata':
                 self.showbase.gameData = GameData()
                 self.showbase.gameData.unpackageData(package[1])
             elif package[0] == 'state':
                 print 'state: ', package[1]
                 if package[1] == 'preround':
                     self.showbase.startRound()
                     return task.done
     return task.again
示例#6
0
        return None, gamedata
    def next(self, next_state):
        pass


class Retailer(StateHandler):
    def __init__(self,gamedata):
        StateHandler.__init__(self, Retailer.start, [Retailer.start, Retailer.list, Retailer.choose], Retailer.quit, gamedata)


Retailer.start = Start()
Retailer.list = List()
Retailer.choose = Choose()
Retailer.quit = Quit()


if __name__ == '__main__':
    gamedata = GameData()
    gamedata.player = Player()
    gamedata.player.strength = 25
    gamedata.player.defense = 20
    gamedata.player.agility = 20
    gamedata.player.speed = 35
    gamedata.player.name = "Horst"
    gamedata.player.inventory = [Item(name="Potion", price=50, influenced_attribute="hp", value="30"),
                                 Item(name="Potion", price=50, influenced_attribute="hp", value="30"),
                                 Item(name="Potion", price=50, influenced_attribute="hp", value="30")]
    player_file = util.create_player_file(gamedata)
    gamedata.player = util.load_player("player.json")
    ret = Retailer(gamedata)
    ret_gd = ret.run()
示例#7
0
        threading.Thread.__init__(self)
        self.game_data = game_data
        self.game_data_lock = game_data_lock

    def run(self):
        tcpserver.main(self.game_data, self.game_data_lock)


class WebThread(threading.Thread):
    def __init__(self, game_data, game_data_lock):
        threading.Thread.__init__(self)
        self.game_data = game_data
        self.game_data_lock = game_data_lock

    def run(self):
        webserver.main(self.game_data, self.game_data_lock)


if __name__ == '__main__':
    from gamedata import GameData
    game_data = GameData('PlanetWars')
    game_data_lock = threading.Lock()

    try:
        tcpthread = TCPThread(game_data, game_data_lock)
        tcpthread.start()
        webthread = WebThread(game_data, game_data_lock)
        webthread.start()
    except KeyboardInterrupt:
        pass
示例#8
0
def main():
    game_data = GameData()

    try:
        game_data.initialize(settings.ck2_install_dir, settings.mod_dir)
    except InstallDirNotFoundError:
        print('Did not find CK2 install dir:', settings.ck2_install_dir)
        print('Please modify settings.py to use the correct path.')
        sys.stdin.readline()
        sys.exit()
    except Exception:
        if settings.debug:
            raise
        else:
            print('Error initializing game data.')
            print('Check that the locations in settings.py are correct.')
            print(
                'Otherwise please post to the Paradox Interactive Forums thread,',
            )
            print('noting any mods you are using.')
            sys.stdin.readline()
            sys.exit()

    filename = settings.save_file
    if filename == '':
        print('\nPlease enter the name of your save file, without the .ck2: ')

        filename = sys.stdin.readline().strip()

    print('\n')

    if filename[-4:] != '.ck2':
        filename += '.ck2'
    if not os.path.exists(filename):
        print('Could not find save file: ', filename + '.ck2')
        sys.stdin.readline()
        sys.exit()

    try:
        game_data.read_save(filename + '.ck2', settings.generate_titles)
    except Exception:
        if settings.debug:
            raise
        else:
            print('Error reading save file.')
            print('Please ensure that your save is UNENCRYPTED.')
            print('If that is not the problem, please post to the Paradox')
            print(
                'Interactive Forums thread, upload your save and note any mods'
            )
            print('you are using.')
            sys.stdin.readline()
            sys.exit()

    if not game_data.mark_characters(settings.real_fathers):
        sys.stdin.readline()
        sys.exit()

    gedcom_writer = GedcomWriter()

    try:
        gedcom_writer.initialize(game_data)
    except Exception:
        if settings.debug:
            raise
        else:
            print('Error generating GEDCOM family information.')
            print(
                'Please post to the Paradox Interactive Forums thread, upload')
            print('your save and note any mods you are using.')
            sys.stdin.readline()
            sys.exit()

    try:
        gedcom_writer.write_gedcom(filename + '.ged')
    except Exception:
        if settings.debug:
            raise
        else:
            print('Error writing GEDCOM file.')
            print(
                'Please post to the Paradox Interactive Forums thread, upload')
            print('your save and note any mods you are using.')
            sys.stdin.readline()
            sys.exit()
示例#9
0
 def testLoadData(self):
     g = GameData('PlanetWars')
     print()
     print("last_game_id: %s" % g.last_game_id)
     print(g.games)
     print(g.results)
示例#10
0
#!/usr/bin/python3

# Created on 5/11/2021

from sys import exit
import webbrowser
from time import sleep
from random import randint
from other.colors import print_green, print_yellow, print_red, print_s, print_health
from classes import Player, Difficulty
from gamedata import GameData
from other.sounds_effects import GameSounds

player1 = Player()  # Player Instance
game_data = GameData()  # load/save functions Instance
sounds = GameSounds()  # audio that will be played Instance

# constants:
EXIT_MERCHANT_MENU = str(len(player1.weapon_dict))


def load_or_save_data():
    game_data.load_game(player1)


def game_intro_description():
    sounds.intro_sound()
    print_s('''This is a zombie survival game where you must make the best decisions possible in order to live.
As a survivor, you will encounter zombies, weapons, people, and a merchant to buy from with an
in-game currency. Every decision you make has a cause and effect while some lead you to fortune and others will 
lead you to death.\n''', 2.5)
示例#11
0
文件: main.py 项目: Herbsi/pathfinder
def main():
    parser = argparse.ArgumentParser(description="P0 Adventure")
    parser.add_argument(
        "--savefile",
        dest="savefile",
        default="game.json",
        help="The save file. default: 'game.json'",
    )
    parser.add_argument(
        "--new-game",
        dest="new_game",
        default=False,
        action="store_true",
        help="Create a new save file.",
    )
    parser.add_argument(
        "-b",
        dest="bonus_tasks",
        default=False,
        action="store_true",
        help="enable bonus tasks",
    )
    parser.add_argument(
        "--print-bonus",
        dest="print_bonus",
        default=False,
        action="store_true",
        help="print bonus task list and exit",
    )
    args = parser.parse_args()

    if args.print_bonus:
        print_bonus_tasks()
        return

    # your code starts here
    save = args.savefile
    if args.new_game:
        user = Player()
        user.createNewCharacter()
        gamedata = GameData(player=user, savefile=save, bonus_tasks=args.bonus_tasks)
        if args.bonus_tasks:
            totengraeber = Gravedigger()
            gamedata.gravedigger = totengraeber
            truhe = Chest()
            gamedata.chest = truhe

    else:
        gamedata = load_gamedata(save)
        user = gamedata.player
        if args.bonus_tasks:
            totengraeber = gamedata.gravedigger
            truhe = gamedata.chest

    schmied = Shopkeeper(name="blacksmith", inventory=blacksmith_items)
    druide = Shopkeeper(name="druid", inventory=druid_items)
    prog0 = Village(
        player=user, bonus_tasks=args.bonus_tasks, blacksmith=schmied, druid=druide
    )

    if args.bonus_tasks:
        prog0.gravedigger = totengraeber
        prog0.chest = truhe

    while True:
        user_choice = village(prog0)

        if user_choice == 5:
            dung0 = Dungeon(player=user, bonus_tasks=args.bonus_tasks)
            if args.bonus_tasks:
                dung0.gravedigger = totengraeber
            dungeon(dung0)
        elif user_choice == 6:
            save_gamedata(gamedata, save),
            print("Game saved to {}".format(save))
        elif user_choice == 0:
            quit(gamedata, save)
            break
        else:
            raise KeyError(
                "main.py Something went wrong with the user choosing what to do!"
            )

    sys.exit(0)