def __init__(self): self.new_clients = [ ] #list of new sockets of which the user id is not known self.logged_name2sock = {} #dictionary mapping username to socket self.logged_sock2name = {} # dict mapping socket to user name self.all_sockets = [] self.group = grp.Group() self.players = p.Players() #start server self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.server.bind(SERVER) self.server.listen(5) self.all_sockets.append(self.server) #initialize past chat indices self.indices = {} # sonnet # self.sonnet_f = open('AllSonnets.txt.idx', 'rb') # self.sonnet = pkl.load(self.sonnet_f) # self.sonnet_f.close() self.sonnet = indexer.PIndex("AllSonnets.txt") self.gaming_players = [] #record the gaming players self.wolves = grp.Group() #add the wolves to a seperate chat group self.wg = [] self.dead = [] self.newkilled = '' self.newpoisoned = '' self.poll = {} self.pollNumber = 0 self.values = []
def start_game(self): play = self.__ask_to_play() if not play: return False player_one_type, player_two_type = play player_one, player_two = players.Players(self, player_one_type), players.Players(self, player_two_type) self.game_field.print_game_field() self.__update_status() self.__start_game_cycle(player_one, player_two) print() if self.status == "Draw": print("Draw") elif self.status == "X wins": print("X wins") elif self.status == "O wins": print("O wins") return True
def test_enumerate_players(self): # Setup, add some players to waiting list. laser_players = players.Players(1) laser_players.add_player('192.168.0.1') laser_players.add_player('192.168.0.2') laser_players.add_player('192.168.0.3') # Enumerate players and expect them in the order added. waiting = list(laser_players.enumerate_players()) self.assertListEqual(['192.168.0.1', '192.168.0.2', '192.168.0.3'], waiting)
def test_add_players_same_ip_are_combined(self): # Setup, add some players to waiting list (including a duplicate). laser_players = players.Players(1) laser_players.add_player('192.168.0.1') laser_players.add_player('192.168.0.1') laser_players.add_player('192.168.0.2') # Verify users are in expected order. self.assertEqual(0, laser_players.wait_position('192.168.0.1')) self.assertEqual(1, laser_players.wait_position('192.168.0.2'))
def test_add_players_wait_in_order(self): # Setup, add some players to waiting list. laser_players = players.Players(1) laser_players.add_player('192.168.0.1') laser_players.add_player('192.168.0.2') laser_players.add_player('192.168.0.3') # Verify users are in expected order. self.assertEqual(0, laser_players.wait_position('192.168.0.1')) self.assertEqual(1, laser_players.wait_position('192.168.0.2')) self.assertEqual(2, laser_players.wait_position('192.168.0.3'))
def test_update_decreases_playtime(self): # Setup, add a player and make them active. laser_players = players.Players(1) laser_players.add_player('192.168.0.1') start_active = unittest.mock.Mock() end_active = unittest.mock.Mock() laser_players.update(1, start_active, end_active) # Update with half second of time, then check current player is active # with half seconf of time left. laser_players.update(0.5, start_active, end_active) self.assertEqual(('192.168.0.1', 0.5), laser_players.active_player())
def test_remove_players_adjusts_order(self): # Setup, add some players to waiting list. laser_players = players.Players(1) laser_players.add_player('192.168.0.1') laser_players.add_player('192.168.0.2') laser_players.add_player('192.168.0.3') # Remove middle player, verify expected waiting list order. laser_players.remove_player('192.168.0.2') self.assertEqual(0, laser_players.wait_position('192.168.0.1')) self.assertEqual(1, laser_players.wait_position('192.168.0.3')) self.assertEqual(None, laser_players.wait_position('192.168.0.2'))
def test_update_moves_to_next_after_playetime_elapsed(self): # Setup, add two players and make the first active. laser_players = players.Players(1) laser_players.add_player('192.168.0.1') laser_players.add_player('192.168.0.2') start_active = unittest.mock.Mock() end_active = unittest.mock.Mock() laser_players.update(1, start_active, end_active) start_active.reset_mock() end_active.reset_mock() # Update with two seconds of time so the first player time is up, then # check next player is active. laser_players.update(2, start_active, end_active) end_active.assert_called_once_with('192.168.0.1') start_active.assert_called_once_with('192.168.0.2') self.assertEqual(('192.168.0.2', 1), laser_players.active_player())
def test_update_no_active_player_makes_next_active(self): # Setup, add some players to waiting list. laser_players = players.Players(1) laser_players.add_player('192.168.0.1') # Check none are yet active. self.assertEqual(None, laser_players.active_player()) # Setup, create mock callbacks that will remember how they were called. start_active = unittest.mock.Mock() end_active = unittest.mock.Mock() # Call update with 1 second of time elapsed. laser_players.update(0.5, start_active, end_active) # Check start active was called with the first in line IP, and that the # currently active player is the first one added (with 1 second of playtime # left). start_active.assert_called_once_with('192.168.0.1') end_active.assert_not_called() self.assertEqual(('192.168.0.1', 1), laser_players.active_player())
def setup(self): if (self.matchups.find_teams() == False): print("Schedule Not Updated.") return False self.teams = self.matchups.get_teams() self.players = players.Players(self.teams) self.lineups = self.players.get_lineup() self.all_goal = [] self.all_assist = [] self.all_point = [] self.goal_leaders = [] self.assist_leaders = [] self.point_leaders = [] return True
def __init__(self, server, port, nick, altnick, channel): self.nick = nick self.lobby = channel if altnick.find("%") >= 0: self.alt_nick = [] for i in range(64): self.alt_nick.append(altnick % (makeHashString(4))) else: self.alt_nick = [altnick] self.players = players.Players() self.channels = {} self.gamesWaiting = [] self.activeGames = {} self.playing = {} irc.IRC.__init__(self, server, port)
# # (c) 2017 kj/P1X # import world import renderer import time import players import config import sys import select import os wrd = world.World() ren = renderer.Renderer() plr = players.Players(wrd) cfg = config.Config() wrd.load_map('map_02.txt') width, height = wrd.get_map_dimensions() plr.set_master_id(plr.player_join(('HUMAN', 28, 12, 0, 3))) plr.player_join(('ROBOT1', 7, 4, 1, 1)) plr.player_join(('ROBOT2', 40, 12, 1, 1)) plr.player_join(('ROBOT3', 70, 8, 1, 1)) plr.player_join(('ROBOT4', 60, 9, 1, 1)) plr.player_join(('ROBOT5', 70, 10, 1, 1)) game_time = 0
window = Tk() window.title("RvB") my_battle = battlefield.Battlefield(window) self.canvas.create_circle(x1, y1, x2, y2, fill="black") player = player.Player(battlefield=my_battle, width=15, height=15, x_posn=300, y_posn=300, colour="red") players = players.Players(battlefield=my_battle, width=15, height=15, x_posn=575, y_posn=150, colour="blue") def game_flow(): my_players.move_next() window.after(50, game_flow) if (my_players.x_posn + my_players.width >= my_battle.width - 3): my_battle.move_item(player.circle, 20, 150, 35, 250) my_battle.move_item(players.circle, 575, 150, 590, 250) window.bind("w", players_B.move_up) window.bind("s", players_B.move_down) window.bind("a", players_B.move_left)
from flask import * from flask_socketio import * import paho.mqtt.publish as publish import config import players # Initialize flask app app = Flask(__name__) app.config.from_object(config) socketio = SocketIO(app) # Global state, keep an ordered dict of all the active players (i.e. people waiting to # play with the cat laser). The key for each user is their IP address so multiple # tabs open will still only give them one spot in line. laser_players = players.Players(app.config['PLAYTIME_SECONDS']) players_thread = None # Helper functions: def notify_wait_position(): """Broadcast to each waiting player their current position in line.""" for i, ip in enumerate(laser_players.enumerate_players()): # Make i 1-based instead of 0-based since the first person is actually # at position 1 instead of 0 in line. socketio.emit('wait_position', i + 1, room=ip) def start_active(ip): """Callback that's invoked when a player becomes the active player. Will send a socketio message to notify them of being active.
pygame.init() screen = pygame.display.set_mode(win_size, 0, 32) pygame.display.set_caption("Freet Strighter") color_red = (217, 47, 10) color_white = (255, 255, 255) colliding = False ryu_hitbox_cord = (0, 0) ken_hitbox_cord = (0, 0) has_perried = False done = False screen.blit(pygame.image.load(background), (0, 0)) # loading background # create players player_group = player_group.Player_Group() player_one = players.Players(700, 200, 10, 'ryu', 1) # ryu player one player_two = players.Players(400, 200, 10, 'ken', 2) # ken player two player_group.add(player_one, player_two) percur1 = player_one.cur_health * 100 / player_one.max_health percur2 = player_two.cur_health * 100 / player_two.max_health ken_ui = pygame.image.load('ui/KenName.png') ryu_ui = pygame.image.load('ui/RyuName.png') name_group = pygame.sprite.Group() ken_ui = name_sprites.Name_Sprites(550, 10, 'KenName') ryu_ui = name_sprites.Name_Sprites(860, 10, 'RyuName') name_group.add(ken_ui, ryu_ui) #create hitsprites
from werkzeug.routing import RequestRedirect app = Flask(__name__, static_folder="static") # Auth app.config['BASIC_AUTH_USERNAME'] = '******' app.config['BASIC_AUTH_PASSWORD'] = '******' basic_auth = BasicAuth(app) socketio = SocketIO(app) # Connect to Arm #arm = ArmInterface() #arm.begin_connection() global_list = {} current_players = players.Players() # Routing @app.route("/") def home(): return (render_template('home.html')) @app.route("/play") @app.route("/play/") def play_menu(): current_players.garbage_collector() return (render_template('play.html')) # return (str(current_players._players))
import board import deck import game import player import players if __name__ == '__main__': game = game.Game() game.start() game.debug_display() all_players_4 = players.Players() player_1 = player.Player("Yildiz") player_2 = player.Player("Steve") player_3 = player.Player("Aylin") player_4 = player.Player("Devran") all_players_4.add_player(player_1) all_players_4.add_player(player_2) all_players_4.add_player(player_3) all_players_4.add_player(player_4) all_players_4.display() all_players_3 = players.Players() all_players_3.add_player(player_1) all_players_3.add_player(player_2) all_players_3.add_player(player_3) all_players_3.display() all_players_2 = players.Players() all_players_2.add_player(player_1) all_players_2.add_player(player_2) all_players_2.display()