本文整理汇总了Python中Game.Game.start_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.start_game方法的具体用法?Python Game.start_game怎么用?Python Game.start_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game.Game
的用法示例。
在下文中一共展示了Game.start_game方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import start_game [as 别名]
class Server:
"""
Class Implementing the Game Server
"""
def __init__(self, port):
"""
__init__(Server, int) -> None
Initializes the Game Server
"""
self.game = Game("arena.txt")
self.lock = threading.Lock() # To control concurrent access to the game
self.connections = [] # List of incoming connections, each connection is a client_thread
self.soc = None # Socket to be used for communication
self.port = port # Port number on which to listen
self.started = False # Status of the server
self.can_recieve_commands = False
def start_server(self):
"""
start_server(Server) -> None
Starts the server and prepares it to accept new connections
"""
assert not self.started, "Server has already been started"
self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Open a socket
self.soc.bind((socket.gethostname(), self.port)) # Bind the socket
self.soc.listen(5) # Start listening, max 5 pending connection requests
self.started = True
connect_thread = threading.Thread(target = self.connect)
connect_thread.start()
key = "0"
while key != "1":
key = input("Enter 1 to start the game: ")
if key == "1":
self.can_recieve_commands = True
self.start_game()
def stop_server(self):
"""
stop_server(Server) -> None
Stops the server and closes all the connections
"""
self.started = False
def connect(self):
"""
connect(Server) -> None
Keeps on listening for new connections and connects to them as they are available
"""
while self.started:
(client_socket, address) = self.soc.accept()
client = ClientThread(self, client_socket, address)
self.connections.append(client)
def start_game(self):
"""
start_game(Server) ->
Starts the game on this server
"""
self.game.start_game()
self.send_arena()
def send_arena(self):
"""
send_arena(Server) -> None
Calls send_arena function on all the clients
"""
for connection in self.connections:
connection.send_arena()
示例2: Game
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import start_game [as 别名]
##this is always necessary to create a filled background
#background = pygame.Surface((Globals.screen_width, Globals.screen_height))
#background = background.convert()
#background.fill((255,255,255))
#game_screen.blit(background, (100,0)) #why is this necessary here?
#pygame.display.update() #this must be called before any changes can be made!
#
#pygame.time.delay(3000)
#
#
##this works #the coordinates here are relative to the SURFACE
#pygame.draw.rect(background, (0,0,0), (0, 100, 20, 20), 0)
#game_screen.blit(background, (100,0))
#pygame.display.update() #update must be called after drawing, otherwise we will never see it
#
##this works
##pygame.draw.rect(game_screen, (0,0,0), (150, 100, 20, 20), 0)
##pygame.display.update()
#
##this doesn't work
##pygame.draw.rect(background, (0,0,0), (150, 100, 20, 20), 0)
##pygame.display.update()
#pygame.time.delay(3000)
game = Game()
game.start_game()