示例#1
0
def main():
    state = GameState(deck=make_deck(), player_hand=[], dealer_hand=[])
    random.shuffle(state.deck)
    initial_deal(state)

    while True:
        show_cards(state)
        if has_blackjack(state.player_hand):
            print(f'YOU GOT A BLACKJACK!')
            if check_play_again() is True:
                set_table(state, check_deck(state))
                continue
            else:
                break

        hit_or_not = get_hit_or_stay(state)
        hit(hit_or_not, state)

        if hit_or_not == Play.Hit and hand_total(state.player_hand) < 21:
            continue

        winner = get_winner(state)
        display_winner(winner, state)

        if check_play_again() is True:
            set_table(state, check_deck(state))
            continue
        else:
            break
示例#2
0
  def __init__(self, serial = None):
    parser = argparse.ArgumentParser(description='BraidsTag gun logic.')
    parser.add_argument('-s', '--serial', type=str, help='serial device to which the arduino is connected')

    self.args = parser.parse_args()

    self.player = None
    self.logic = StandardGameLogic()
    self.gameState = GameState()

    self.serverConnection = Client(self)
    self._sendToServer(proto.HELLO.create())

    if serial:
      self.serial = serial
      self.responsiveSerial = True
    else:
      if not self.args.serial:
        raise ArgumentError("You must specify -s if you do not start in fakeGun mode")

      try:
        import serial
        self.serial = serial.Serial(self.args.serial, 115200)
        self.responsiveSerial = True
      except ImportError:
        #We'll have to open this as a file
        print("WARNING: No serial module, assuming the serial argument is a normal file for testing")
        self.serial = open(self.args.serial)
        self.responsiveSerial = False
      except serial.serialutil.SerialException:
        #Try just opening this as a file
        self.serial = open(self.args.serial)
        self.responsiveSerial = False

    self.connectToArduino()
示例#3
0
    def __init__(self):
        parser = argparse.ArgumentParser(description='BraidsTag gun logic.')
        parser.add_argument(
            '-s',
            '--serial',
            type=str,
            help='serial device to which the arduino is connected',
            required=True)
        #parser.add_argument('-p', '--playerID', type=self._stringToPlayerID, help='player id', default=1)
        #parser.add_argument('-t', '--teamID', type=int, choices=xrange(1, 8), help='team id', default=1)

        self.args = parser.parse_args()

        self.serverConnection = Client(self)
        self._sendToServer(proto.HELLO.create(-1, -1))

        try:
            self.serial = serial.Serial(self.args.serial, 115200)
            self.properSerial = True
        except serial.serialutil.SerialException:
            #Try just opening this as a file
            self.serial = open(self.args.serial)
            self.properSerial = False

        def playerDead():
            print "Out of lives!"

        self.logic = StandardGameLogic()
        self.logic.playerDead.connect(playerDead)
        self.gameState = GameState()

        self.connectToArduino()
示例#4
0
    def __init__(self):
        parser = argparse.ArgumentParser(description='BraidsTag gun logic.')
        parser.add_argument(
            '-s',
            '--serial',
            type=str,
            help='serial device to which the arduino is connected')
        #parser.add_argument('-p', '--playerID', type=self._stringToPlayerID, help='player id', default=1)
        #parser.add_argument('-t', '--teamID', type=int, choices=xrange(1, 8), help='team id', default=1)
        parser.add_argument('-d',
                            '--debugGun',
                            help='use the debuggin gun UI',
                            default=False,
                            action='store_true')

        self.args = parser.parse_args()

        self.player = None

        self.serverConnection = Client(self)
        self._sendToServer(proto.HELLO.create())

        if self.args.debugGun:
            import fakeGun
            self.serial = fakeGun.showUI()
            self.responsiveSerial = True
        else:
            if not self.args.serial:
                raise ArgumentError(
                    "You must specify -s if you do not specify -d")

            try:
                import serial
                self.serial = serial.Serial(self.args.serial, 115200)
                self.responsiveSerial = True
            except ImportError:
                #We'll have to open this as a file
                print "WARNING: No serial module, assuming the serial argument is a normal file for testing"
                self.serial = open(self.args.serial)
                self.responsiveSerial = False
            except serial.serialutil.SerialException:
                #Try just opening this as a file
                self.serial = open(self.args.serial)
                self.responsiveSerial = False

        def playerDead():
            print "Out of lives!"

        self.logic = StandardGameLogic()
        self.logic.playerDead.connect(playerDead)
        self.gameState = GameState()

        self.connectToArduino()
示例#5
0
文件: server.py 项目: hpointu/awale
    def __init__(self):
        super(AwlServer, self).__init__()
        self.game = GameState()
        print("Creating server")

        self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        #self._s.setblocking(0)
        self._s.bind((self.IP, self.PORT))
        self._s.listen(1)

        self.ins = [self._s]
        self.outs = []
        self.clients = {}
        self.players = {}
示例#6
0
def load_game_state(state_row, world):
    return GameState(
        world=world,
        location_name=state_row[0],
        inventory=[Thing(name=x) for x in json.loads(state_row[1])])
示例#7
0
 def setUp(self):
     self.gl = StandardGameLogic()
     self.gameState = GameState()
     self.gameState.setGameTime(120)
示例#8
0
def game_state():
    gameState = GameState()
    gameState.setGameTime(120)
    return gameState
示例#9
0
key = Thing(name="rusty key")
home = Location(name="Home",
                description="Home is where the heart is!",
                exits={
                    "east": (None, "Street"),
                    "down": (key, "Basement")
                })
street = Location(name="Street",
                  description="The street next to your house.",
                  exits={"west": (None, "Home")},
                  items={key.name: key})
basement = Location(name="Basement",
                    description="You found the basement!",
                    exits={"up": (None, "Home")})
world = pmap({x.name: x for x in [home, street, basement]})
initial_state = GameState(location_name="Home", world=world)
in_street = initial_state.set(location_name="Street")
in_street_with_key = in_street.transform(["world", "Street", "items"],
                                         lambda _: {}, ["inventory"],
                                         lambda _: [key])


def test_take_not_found():
    assert take(initial_state, "some item") is None


def test_take_something():
    in_street = initial_state.set(location_name="Street")
    assert take(in_street, "rusty key") == in_street_with_key