Exemplo n.º 1
0
    def __init__(self, host: str=None):
        '''
        Parameters:
            host : str with ip to connect to or None if server

        Example:
        game = Game() # Creates a new game instance which will be server
        game2 = Game("localhost") # New instance that will connect to host on local machine
        '''

        self._score = [0, 0]  # The current score. First index is current player, second is the opponent
        self._myturn = None

        self.host = host    # None if server, ip string if client

        self.win = gui.BoxesWindow(GRID_SIZE[0], GRID_SIZE[1])

        # Init connection
        if self.isServer():
            self._connection = network.server()
        else:
            self._connection = network.client(self.host)

        self.myturn = self.isServer()  # Server starts

        # Connect data recieved signal to our function and start network thread
        self._connection.data_recv.connect(self.on_recv)
        self._connection.start()

        # TODO: check that connection succeeded

        # Connect signal when a line is clicked in the ui to game logic
        self.win.gridWidget.lineClicked.connect(self.line_clicked)
Exemplo n.º 2
0
import constants

import renderer
import event_handler
import network
import world

server = False
for arg in sys.argv:
    
    if arg == '-s' or arg == '-server':
        server = True

try:
    if server:  net = network.server( constants.port )
    else:       net = network.client( "pymud.no-ip.org", constants.port )
except AttributeError, e:
    print "ERROR: in connection, %s" % e
    sys.exit(-1)

pygame.init()
rend = renderer.renderer( vector3( constants.width, constants.height ) )
hand = event_handler.handler()
scene = world.world( rend, hand, net )

while True:
    
    event = hand.process()
    if event and event.type == pygame.QUIT:
        break
    scene.update()
Exemplo n.º 3
0
import constants

import renderer
import event_handler
import network
import world

server = False
for arg in sys.argv:
    
    if arg == '-s' or arg == '-server':
        server = True

try:
    if server:  net = network.server( constants.port )
    else:       net = network.client( "127.0.0.1", constants.port )
except AttributeError, e:
    print "ERROR: in connection, %s" % e
    sys.exit(-1)

pygame.init()
rend = renderer.renderer( vector3( constants.width, constants.height ) )
hand = event_handler.handler()
scene = world.world( rend, hand, net )

while True:
    
    event = hand.process()
    if event and event.type == pygame.QUIT:
        break
    scene.update()