def __init__(self): """ The game stores: a 2-D Array called board. board contains either 1 for empty space or the piece object for a speicifc sqaure. a 2-D Array called strBoard. strBoard has the string representation of board "" for empty space, and "p" for a Pawn 2 player objects which keep track of their captures Number of moves made in moveCount prevMove to keep track of last move made playerInCheck. flag for when a player is in check Checkmate. flag for a checkmate endedGame. flag used in endGame signaling the game has ended. used so specific things do not happen if the game has already ended flags for file mode game or interative mode fname. file path passed in as input for file mode """ #Intialize game object self.playerTurn = "lower" self.lowerPlayer = Player.Player("lower") self.upperPlayer = Player.Player("UPPER") self.moveCount = 0 self.playerInCheck = False self.prevMove = "" self.Checkmate = False self.endedGame = False if self.file_mode == False: self.initBoard() return
async def get_players(self, ctx): ctr = self.bot.gcDict.get(ctx.message.author.guild.id) players = ctr.getPlayers() string = "" for player in players: string += player.getId() + "\n" e = discord.Embed(title=f'{string}') await ctx.send(f"Jugadores conectados: \n", embed=e)
def add(): try: player = Player(username=request.form['username'], password=sha256_crypt.encrypt( request.form['password']), castle_id=request.form['castle'], email=request.form['email']) db.session.add(player) db.session.commit() return redirect(url_for('login')) except: return ('User already exists !!')
def add_player(self, account_id, steam_id, profile_url, real_name=None, persona_name=None, avatar=None): new_player = Player(account_id=account_id, steam_id=steam_id, real_name=real_name, persona_name=persona_name, avatar=avatar, profile_url=profile_url) Database.session.add(new_player) Database.session.commit() return new_player
def pull_players(self) -> list or bool: """ Returns a list of all players from DB :return: list or false """ file_path = check_file_path(self.file_path_players, self.file_path_players_temp) if file_path: file_stream = open(file_path) player_dict = {} for player in file_stream: player_dict[player.strip()] = Player(player.strip()) return player_dict return file_path
def push_players(self, new_player: Player, player_dict: dict) -> bool: """ Adds the new_player to the DB :param new_player: Player :param player_dict: dict :return: bool """ write_stream = open(self.file_path_players_temp, "a") if player_dict: for key, player in player_dict.items(): write_stream.write(player.raw_data() + "\n") write_stream.write(new_player.raw_data() + "\n") write_stream.close() os.remove(self.file_path_players) os.rename(self.file_path_players_temp, self.file_path_players) return True
def pull_high_scores(self) -> list or bool: """ Returns a list of all high scores from DB :return: list or false """ file_path = check_file_path(self.file_path_high_scores, self.file_path_high_scores_temp) if file_path: file_stream = open(file_path) high_scores = [] for high_score in file_stream: high_score = high_score.split(',') new_high_score = HighScore(Player(high_score[0]), high_score[1], high_score[2], high_score[3].strip()) high_scores.append(new_high_score) return high_scores return file_path
async def l(self, ctx): # if gameController.playing: authorId = ctx.message.author.guild.id ctr = self.bot.gcDict.get(authorId) if ctr is not None: if len(ctr.getPlayers()) == 1: await ctx.send( ":x: Are u playing alone?, please use !end-game to end your lonely game dude" ) return player = ctr.getPlayerById(ctx.message.author.name) ctr.leaveGame(player) if (player.getId() == ctr.getTurnOwner().getId()): ctr.endTurn(player) await self.msgStatus(ctx) elif (ctr.returnCareCaca() is not None): await self.msgStatus(ctx) else: await ctx.send( ":x: Nobody is playing now. If you want to start a game, use ``!start-game``" )
async def asign_member_to_object_player(self, member): pl = player.Player(member.name) print(f'Object player {pl.getId()} has been assigned to {member.name}') # gameController.setPlayer(pl) self.bot.gcDict[member.guild.id].setPlayer(pl)
Q = 12 K = 13 JK = 30 # Test without flash dck = Deck(True) # setHands h0 = dck.popAListByValues([6, JK, 8]) h1 = dck.popAListByValues([6, 10, J]) h2 = dck.popAListByValues([6, 2, 7]) h3 = dck.popAListByValues([6, 7, A]) # setPlayers p0 = Player(0) p0.setManyCardsToHand(h0) p1 = Player(1) p1.setManyCardsToHand(h1) p2 = Player(2) p2.setManyCardsToHand(h2) p3 = Player(3) p3.setManyCardsToHand(h3) pl = [p0, p1, p2, p3] # setGameController ctr = GameController() for p in pl: ctr.setPlayer(p) ctr.changeDeck(dck)
from Models import Player, initiate, turn, check_if_out, role, Parking monopoly = [] players = {} p_count = int(input('How many players: ')) b = initiate() free_parking = Parking() for i in range(p_count): players[i] = Player('{}_{}'.format('player', i)) while len(players) > 1: for i in range(len(players)): check_if_out(players[i]) if not players[i].out and not players[i].jail: r_count = 0 result = turn(players, players[i], r_count, b, free_parking) print() print('Money:', players[i].money) print('Properties:', end=' ') for p in players[i].properties: print(p, end=' | ') print() elif players[i].out: print('{} is out'.format(players[i].name)) elif players[i].jail and players[i].jail_counter < 3: print('{} is in jail'.format(players[i].name)) print('Role to be released next turn!') print() d1, d2 = role()