예제 #1
0
    def play(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                event_handler(event)

            self.screen.fill(Colors.WHITE)
            player(screen=self.screen)
            pygame.display.flip()
예제 #2
0
#else:
server_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_connection.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_connection.connect((TEST_HOST, utils.PORT))  #sys.argv[1], utils.PORT))


def prompt():
    print('>', end=' ', flush=True)


print("Connected to server\n")
msg_prefix = ''

socket_list = [sys.stdin, server_connection]

player1 = game.player("Thomas")

while True:
    read_sockets, write_sockets, error_sockets = select.select(
        socket_list, [], [])
    for s in read_sockets:
        if s is server_connection:  # incoming message
            msg = s.recv(READ_BUFFER)
            if not msg:
                print("Server down!")
                sys.exit(2)
            else:
                if msg == utils.QUIT_STRING.encode():
                    sys.stdout.write('Bye\n')
                    sys.exit(2)
                elif b"<card>" in msg:
예제 #3
0
# coding: UTF-8
# token情報やチャンネルidなどの定数を別のファイルにおく
import const
# 関数関係
import game
# インストールした discord.py を読み込む
import discord

araki = game.player("あらき")
kim = game.player("きむ")

# 自分のBotのアクセストークンに置き換えてください
TOKEN = const.token

# 接続に必要なオブジェクトを生成
client = discord.Client()

# 起動時に動作する処理
@client.event
async def on_ready():
  print('...ready')

async def shori(message, player):
  if player.start_msg:
    player.start_msg = False
    await message.channel.send("-------------------------\n初期化済みです。\n-------------------------")
  if message.content == "half":
    await message.channel.send(player.half())
    return
  if message.content == "ls":
    await message.channel.send(player.string())
예제 #4
0
def runGame(strat, doors):
    return game(player(strat), doors)()
예제 #5
0
파일: render.py 프로젝트: whtahy/prototypes
def moves(state):
    for i, game_coord in enumerate(state.game.history):
        x, y = cell_coord(game_coord)
        blt.put(x, y, game.player(i))
예제 #6
0
 def test_player(self):
     assert player() in ['R', 'P', 'S', 'L', 'V']
예제 #7
0
def game():
    game = gm.game([gm.player('player1'), gm.player('player2')], 6)
    return game
예제 #8
0
def player():
    player = gm.player('player1')
    return player
예제 #9
0
def play():
    die = False
    win = False
    player = game.player()
    baggardy1 = True
    talkedToShopKeep = False
    workFound = False
    seenScorpians = False

    def shopKeeperTalk():
        leave = False
        game.addTextNicely(
            '"Hello, welcome to my store," The shopkeeper says with a smile')
        while not leave:
            option = game.askQuestion(
                "What would you like to say? ask to: shop/where can find work/leave",
                ["shop", "work", "where can find work", "leave"], player)
            if option == 0:
                oldMon = player.money
                game.shop(player, ["Rope", "Apples", "Ring", "Teeth"],
                          [10, 4, 50, 10])
                if oldMon > player.money:
                    game.addTextNicely('"Thank you for your purchase,"')
            elif option == 1 or option == 2:
                game.addTextNicely(
                    '"Well the barman at the tavern recieves bounties from the king, so probably best to ask there,"'
                )
                talkedToShopKeep = True
            else:
                leave = True

    def shop():
        if not die:
            game.addTextNicely("You enter the shop.")
            game.addTextNicely(
                "You see a shop filled with a myriad of items any traveller would want."
            )
            game.addTextNicely(
                "The shopkeeper and his dog sit patiently behind the well stocked counter."
            )
            option = game.askQuestion("What would you like to do? talk/leave",
                                      ["talk", "leave"], player)
            if option == 0:
                shopKeeperTalk()

    def talkBarman():
        if not die:
            game.addTextNicely("The barman looks at you.")
            if game.askQuestion("What will you do? talk/leave",
                                ["talk", "leave"], player) == 0:
                option = game.askQuestion(
                    "The barman still looks at you. Ask: drink/work/leave",
                    ["drink", "work", "leave"], player)
                if option == 0:
                    oldMon = player.money
                    game.shop(player,
                              ["Water", "Beer", "Apple Juice", "Whisky"],
                              [5, 10, 10, 20])
                    if oldMon > player.money:
                        game.addTextNicely(
                            "The barman gives you a small smile.")
                if option == 1:
                    game.addTextNicely(
                        "The barman crouches below the bar and hands you a piece of paper"
                    )
                    workFound = True
                    game.addTextNicely("You read the paper:")
                    game.addTextNicely(
                        "By the orders of King Heron, Searching for someone to slay the dragon that resides in Bristle Cave"
                    )
                    game.addTextNicely("REWARD: 10,000G")
                    player.quests[0].completeQuest()
                    player.addQuest("Slay the Dragon",
                                    "Kill the dragon in Bristle Cave")
                    game.addTextNicely("You may now leave Baggardy")

    def threatenScorpianMan():
        game.addTextNicely(
            "You tell the man to **********.                                               "
        )
        game.addTextNicely("He stabs you in the gut.")

    def talkGroup():
        game.addTextNicely(
            "As you begin to approach the group you can see hunting knives strapped to their legs, and scorpian tattoos on their arms."
        )
        seenScorpians = True
        if not game.askQuestion("What would you like to do? Talk/Leave",
                                ["talk", "leave"], player):
            game.addTextNicely(
                "As you draw near the men the one closest to you stands up and draws his knife on you."
            )
            if game.askQuestion("What will you do? apologise/threaten",
                                ["Apologise", "Threaten"], player):
                threatenScorpianMan()
                return (True)
            else:
                game.addTextNicely(
                    "You raise up your hands and tell him your sorry")
                game.addTextNicely('"Back off," He says')
                option = game.askQuestion(
                    "What will you do? back off/threaten",
                    ["leave", "back off", "threaten"], player)
                if option == 2:
                    threatenScorpianMan()
                    return (True)
        return (False)

    def tavern():
        game.addTextNicely(
            "The tavern is quiet, apart from a group of four men talking amoungst themselves in the corner."
        )
        game.addTextNicely(
            "The tavern owner is drying glasses behind the bar.")
        dead = False
        leave = False
        while not leave:
            option = game.askQuestion(
                "What do you want to do?"
                "Talk to: barman/group of men/leave",
                ["barman", "men", "group of men", "leave"], player)
            if option == 0:
                talkBarman()
            elif option == 1 or option == 2:
                dead = talkGroup()
                if dead:
                    leave = True
            else:
                leave = True
        return (dead)

    def blacksmith():
        game.addTextNicely("You see a blacksmith hard at work")
        if not game.askQuestion("What will you do? talk/leave",
                                ["talk", "leave"], player):
            game.addTextNicely('"Do you need some weapons lad?" She says')
            leave = False
            while not leave:
                option = game.askQuestion("What will you say? shop/work/leave",
                                          ["shop", "work", "leave"], player)
                if option == 0:
                    game.shop(player, ["Sword", "Lance"], [50, 50])
                if option == 1:
                    game.addTextNicely("Don't know anything bout that sorry")
                else:
                    leave = True

    def road():
        dead = False
        game.addTextNicely("You begin your journey towards Bristle Cave")
        game.addTextNicely("It will take two days on foot")
        game.addTextNicely(
            "After several hours along your way you spot a carraige that has crashed"
        )
        if not (game.askQuestion("Investigate? Y/N", ["Y", "N"], player)):
            game.addTextNicely(
                "As you get closer to the carriage you see a lone hatchet lodged into the carriages side"
            )
            game.addTextNicely(
                "There is an image of a scorpian carved onto the hatchets head"
            )
            option = game.askQuestion(
                "What will you do? ???/leave",
                ["axe", "hatchet", "take hatchet", "take axe", "leave"],
                player)
            if option >= 0 and option <= 4:
                game.addTextNicely("Acquired Hatchet")
                player.inventory.append("hatchet")
        game.addTextNicely(
            "After leaving the carriage behind you realise that night will soon fall."
        )
        if game.askQuestion("What will you do? continue/camp",
                            ["continue", "camp"], player):
            if game.askQuestion("Will you set a fire? Y/N", ["y", "n"],
                                player):
                game.addTextNicely(
                    "You wake up the next morning feeling cold, but otherwise fine."
                )
            else:
                game.addTextNicely(
                    "Bandits spot your fire, and they murder and rob you in your sleep."
                )
                dead = True
        else:
            game.addTextNicely(
                "You continue on your way towards Bristle Cave.")
            game.addTextNicely(
                "Sometime late into the night you are ambushed by bandits!")
            if game.askQuestion("What will you do? run/fight",
                                ["run", "fight"]):
                if player.inventory == []:
                    game.addTextNicely("You have nothing to fight with!")
                    game.addTextNicely("The bandits slaughter you")
                    dead = True
                else:
                    text = ""
                    for i in player.inventory:
                        text += i + ", "
                    option = game.askQuestion(
                        "What will you fight with? " + text, player.inventory,
                        player)
                    if player.inventory[option] == "hatchet":
                        game.addTextNicely(
                            "You draw the hatchet, and hold it steady in your hands"
                        )
                        game.addTextNicely(
                            "The bandits pause and glance at each other before taking off!"
                        )
                    elif player.invenory[option] == "sword" or player.inventory[
                            option] == "lance":
                        game.addTextNicely(
                            "You draw your " + player.inventory[option] +
                            " and manage to fight off the bandits!")
                    else:
                        game.addTextNicely(
                            "Your weapon was not enough to fight off the bandits!"
                        )
                        dead = True
            else:
                game.addTextNicely("The bandits catch you and kill you.")
                dead = True
            return (dead)

    def attackDragon():

        option = game.chooseInventoryItem("Choose a weapon", player)
        if option == None:
            game.addTextNicely("You cannot defeat the dragon with no weapon.")
            return (False)
        if player.inventory[option] == "hatchet" or player.inventory[
                option] == "lance" or player.inventory[option] == "sword":
            game.addTextNicely("You sneak upon the dragon and stab the " +
                               player.inventory[option] + " into it's heart!")
            game.addTextNicely("You Win!")
            return (True)

    def cave():
        win = False
        game.addTextNicely("You reach Bristle Cave early afternoon.")
        game.addTextNicely("You enter the cave, it is dark and quiet.")
        game.addTextNicely(
            "After walking for a bit you come across a sleeping dragon")
        option = game.askQuestion("What do you do? yell/attack",
                                  ["yell", "attack"], player)
        if option == 1:
            win = attackDragon()
        else:
            game.addTextNicely(
                "You yell and the dragon wakes up and kills you ")
            win = False
        return (win)

    player.name = game.askQuestion("What is your name?")
    player.playerClass = game.askQuestion(
        "What is your profession? Knight/Mercenary/Wizard",
        ["Knight", "Mercenary", "Wizard"], player)
    game.addTextNicely(
        "You are low on funds and are looking for work, you have just arrived in the town of Baggardy."
    )
    player.addQuest("Find Work", "Find some work in the town of Baggardy")
    bagOptions = ["shop", "tavern", "blacksmith"]
    bagText = "Where would you like to go? shop/tavern/blacksmith (You can also type help to see other commands)"
    while baggardy1 and not die:
        game.addTextNicely(
            "In the town the best places to look for work would be the shop, tavern, or blacksmith."
        )

        option = game.askQuestion(bagText, bagOptions, player)

        if option == 0:
            shop()
        elif option == 1:
            die = tavern()
            if player.quests[0].complete == True:
                bagOptions.append("leave")
                bagOptions.append("leave Baggardy")
                bagText = "Where would you like to go? shop/tavern/blacksmith/leave Baggardy (You can also type help to see other commands)"
        elif option == 2:
            blacksmith()
        else:
            baggardy1 = False
    if not die:
        die = road()
    if not die:
        win = cave()
    return (win)
예제 #10
0
def runGame(strat, doors, n):
    results = [game(player(strat), doors)() for i in xrange(n)]
    return float(sum(results)) / len(results)
예제 #11
0
                            user_color = YELLOW
                            ai_color = RED
                            break
                        elif quitButton.collidepoint(mouse):
                            sys.exit()

        if flag == 2:
            user = C4.RED
            user_color = RED
            player2 = C4.YELLOW
            player2_color = YELLOW
            ai = False

    else:
        game_over = C4.terminal(board)
        player = C4.player(board)
        for c in range(C4.columns):
            for r in range(C4.rows):
                pygame.draw.rect(screen, BLUE,
                                 (c * square_size, r * square_size +
                                  square_size, square_size, square_size))
                pygame.draw.circle(
                    screen, BLACK,
                    (c * square_size + square_size // 2,
                     r * square_size + square_size + square_size // 2), radius)

        for c in range(C4.columns):
            for r in range(C4.rows):
                if board[r][c] == C4.RED:
                    pygame.draw.circle(
                        screen, RED,