Beispiel #1
0
    def load_stuff(self):
        self.TXT_SERVER, self.TXT_SERVER_RECT = mygui.print_text('freesansbold.ttf', HEIGHT/15, "Server", WHITE, None, WIDTH/2, HEIGHT/10)
        self.TXT_IP, self.TXT_IP_RECT = mygui.print_text('freesansbold.ttf', HEIGHT/30, "Host IP : "+self.serIP, WHITE, None, WIDTH/2, HEIGHT/4)
        self.TXT_PORT, self.TXT_PORT_RECT = mygui.print_text('freesansbold.ttf', HEIGHT/30, "Port : " + str(self.serPort), WHITE, None, WIDTH/2, HEIGHT/4 + HEIGHT/10)
        self.TXT_CLIENTS, self.TXT_CLIENTS_RECT = mygui.print_text('freesansbold.ttf', HEIGHT/30, "# of Clients : "+ str(self.serClients), WHITE, None, WIDTH/2, HEIGHT/4 + HEIGHT/5)

        self.BUT_START = mygui.Button()
Beispiel #2
0
    def __init__(self, screen):

        self.serObj = serverThread.ServerThread()

        self.serIP = self.serObj.get_ip()
        self.serPort = self.serObj.get_port()
        self.serClients = self.serObj.get_num_of_clients()

        self.load_stuff()

        isButton = False
        self.gui(screen, isButton)

        quit = False
        while not quit :
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()

                elif event.type == MOUSEBUTTONDOWN and isButton:
                    if self.BUT_START.pressed(pygame.mouse.get_pos()):
                        quit = True
                        break

            self.serClients = self.serObj.get_num_of_clients()
            if self.serClients>0 :
                if not isButton:
                    isButton = True
                    self.BUT_START = mygui.Button()
                    self.BUT_START.create_button(screen, BACK_BUTTON, WIDTH/3, 2*HEIGHT/3, WIDTH/3.2,    HEIGHT/6.85,    0,  "Start", TEXT_BUTTON)

            else:
                if isButton:
                    screen.blit(BG0, (self.BUT_START.rect.left-10,self.BUT_START.rect.top-10), (self.BUT_START.rect.left-10,self.BUT_START.rect.top-10,self.BUT_START.rect.width+20,
                                        self.BUT_START.rect.height+20))
                    del self.BUT_START
                    isButton = False


            screen.blit(BG0, self.TXT_CLIENTS_RECT.topleft, self.TXT_CLIENTS_RECT)
            self.TXT_CLIENTS, self.TXT_CLIENTS_RECT = mygui.print_text('freesansbold.ttf', HEIGHT/30, "# of Clients : "+ str(self.serClients), WHITE, None, WIDTH/2, HEIGHT/4 + HEIGHT/5)
            screen.blit(self.TXT_CLIENTS, self.TXT_CLIENTS_RECT)

            pygame.display.update()

        serverGame.main(screen, self.serObj.clients)
Beispiel #3
0
def test(screen):

    players = {0:[]}
    players[0] = player.Player(0,"Safal")
    players[1] = player.Player(1,"Avantika")
    players[2] = player.Player(2,"Lalit")
    players[3] = player.Player(3,"Kariryaa")

    myTurn = 2
    turn = 1
    numberOfPlayers = 4

    PICSIZE = (int(HEIGHT/4.8), int(HEIGHT/4.8)) # 100 * 100
    TBLTOPLEFT = (int(HEIGHT/6), int(HEIGHT/6)) # (80, 80)
    TBLWIDTH = HEIGHT
    TBLHEIGHT = HEIGHT/2

    BOY0 = (70,30)
    BOY1 = (170,0)
    BOY2 = (270,0)
    BOY3 = (370,0)
    BOY4 = (470,30)
    BOY5 = (70,250)
    BOY6 = (170,280)
    BOY7 = (270,280)
    BOY8 = (370,280)
    BOY9 = (470,250)
    BOY10= (30,140)
    BOY11= (510,140)
    BOYS = (BOY0, BOY1, BOY2, BOY3, BOY4, BOY5, BOY6, BOY7, BOY8, BOY9, BOY10, BOY11 )

    #Order in which players sit
    ORDER= (7, 2, 10, 11, 4, 5, 0, 9, 1, 8, 3, 6)

    # List of coordinates for the button below player picture
    BOYBUT = []
    BOYTXT = []
    for i in range(12):
        BOYBUT.append((BOYS[i][0]+5, BOYS[i][1]+86))
        BOYTXT.append((BOYS[i][0]+50, BOYS[i][1]+94,BOYS[i][1]+108))

    NAMES = []
    MONEY = []
    for o in players:
        NAMES.append(players[o].name)
        MONEY.append(players[o].money)


    bg1 = pygame.image.load("images/bg1.jpg")
    bg1 = pygame.transform.scale(bg1, (WIDTH, HEIGHT))

    tableScale = 2
    pkt1 = pygame.image.load("images/pkt0.png")
    pkt1 = pygame.transform.scale(pkt1, (int(tableScale*HEIGHT/2), HEIGHT/2)) #480 * 240



    boy0 = pygame.image.load("images/boy1.png")
    boy0 = pygame.transform.scale(boy0, PICSIZE)

    boy1 = pygame.image.load("images/boy2.png")
    boy1 = pygame.transform.scale(boy1, PICSIZE)

    boy2 = pygame.image.load("images/boy3.png")
    boy2 = pygame.transform.scale(boy2, PICSIZE)

    boy3 = pygame.image.load("images/boy4.png")
    boy3 = pygame.transform.scale(boy3, PICSIZE)


    but1 = pygame.image.load("images/but1.png")
    but1 = pygame.transform.scale(but1, (90,30))


    screen.blit(bg1, (0,0))
    screen.blit(pkt1, TBLTOPLEFT)

    #Putting players across the table
    temp = 0
    for i in ORDER:
        temp+=1
        screen.blit(boy0, BOYS[i])
        if temp == numberOfPlayers:
            break


    temp = 0
    for i in ORDER:
        temp+=1
        screen.blit(but1, BOYBUT[i])
        if temp == numberOfPlayers:
            break

    temp = 0
    for i in ORDER:
        temp+=1
        textMoney, textMoneyRect = mygui.print_text('freesansbold.ttf', 13, MONEY[i], WHITE, None,BOYTXT[i][0],BOYTXT[i][2] )
        textName, textNameRect = mygui.print_text('freesansbold.ttf', 13, NAMES[i], WHITE, None,BOYTXT[i][0],BOYTXT[i][1] )
        screen.blit(textMoney, textMoneyRect)
        screen.blit(textName, textNameRect)

        if temp == numberOfPlayers:
            break




    pygame.display.update()
    time.sleep(5)


    #
    # screen.blit(bg1, BOY0, BOY0+PICSIZE)
    # screen.blit(pkt1, TBLTOPLEFT, (0,0,PICSIZE[0]-TBLTOPLEFT[0]+BOY0[0],PICSIZE[1]-TBLTOPLEFT[1]+BOY0[1]))

    # screen.blit(bg1, BOY1, BOY1+PICSIZE)
    # screen.blit(pkt1, (BOY1[0],TBLTOPLEFT[1]), (BOY1[0]-TBLTOPLEFT[0],0,PICSIZE[0],BOY1[1]+PICSIZE[1]-TBLTOPLEFT[1]))

    # screen.blit(bg1, BOY2, BOY2+PICSIZE)
    # screen.blit(pkt1, (BOY2[0],TBLTOPLEFT[1]), (BOY2[0]-TBLTOPLEFT[0],0,PICSIZE[0],BOY2[1]+PICSIZE[1]-TBLTOPLEFT[1]))

    # screen.blit(bg1, BOY3, BOY3+PICSIZE)
    # screen.blit(pkt1, (BOY3[0],TBLTOPLEFT[1]), (BOY3[0]-TBLTOPLEFT[0],0,PICSIZE[0],BOY3[1]+PICSIZE[1]-TBLTOPLEFT[1]))

    # screen.blit(bg1, BOY4, BOY4+PICSIZE)
    # screen.blit(pkt1, (BOY4[0],TBLTOPLEFT[1]), (BOY4[0]-TBLTOPLEFT[0],0,PICSIZE[0]-TBLWIDTH+BOY4[0],PICSIZE[1]-TBLTOPLEFT[1]+BOY4[1]))

    # screen.blit(bg1, BOY10, BOY10+PICSIZE)
    # screen.blit(pkt1, (TBLTOPLEFT[0],BOY10[1]), (0,BOY10[1]-TBLTOPLEFT[1],PICSIZE[0]-TBLTOPLEFT[0]+BOY10[0],PICSIZE[1]))

    # screen.blit(bg1, BOY11, BOY11+PICSIZE)
    # screen.blit(pkt1, (BOY11[0],BOY11[1]), (BOY11[0]-TBLTOPLEFT[0],BOY11[1]-TBLTOPLEFT[1],TBLWIDTH+TBLTOPLEFT[0]-BOY11[0],PICSIZE[1]))




    # screen.blit(bg1, BOY5, BOY5+PICSIZE)
    # screen.blit(pkt1, (TBLTOPLEFT[0],BOY5[1]), (0,BOY5[1]-TBLTOPLEFT[1],PICSIZE[0]-TBLTOPLEFT[0]+BOY5[0],TBLTOPLEFT[1]+PICSIZE[1]-BOY5[1]))

    # screen.blit(bg1, BOY6, BOY6+PICSIZE)
    # screen.blit(pkt1, (BOY6[0],BOY6[1]), (BOY6[0]-TBLTOPLEFT[0],BOY6[1]-TBLTOPLEFT[1],PICSIZE[0],TBLTOPLEFT[1]+PICSIZE[1]-BOY6[1]))
    #
    # screen.blit(bg1, BOY7, BOY7+PICSIZE)
    # screen.blit(pkt1, (BOY7[0],BOY7[1]), (BOY7[0]-TBLTOPLEFT[0],BOY7[1]-TBLTOPLEFT[1],PICSIZE[0],TBLTOPLEFT[1]+PICSIZE[1]-BOY7[1]))
    #
    # screen.blit(bg1, BOY8, BOY8+PICSIZE)
    # screen.blit(pkt1, (BOY8[0],BOY8[1]), (BOY8[0]-TBLTOPLEFT[0],BOY8[1]-TBLTOPLEFT[1],PICSIZE[0],TBLTOPLEFT[1]+PICSIZE[1]-BOY8[1]))
    #
    # screen.blit(bg1, BOY9, BOY9+PICSIZE)
    # screen.blit(pkt1, (BOY9[0],BOY9[1]), (BOY9[0]-TBLTOPLEFT[0],BOY9[1]-TBLTOPLEFT[1],TBLWIDTH+TBLTOPLEFT[0]-BOY9[0],TBLTOPLEFT[1]+PICSIZE[1]-BOY9[1]))





    pygame.display.update()
    time.sleep(5)
Beispiel #4
0
    def __init__(self, screen):

        BOXIPWIDTH = WIDTH/3.2
        BOXIPHEIGHT = HEIGHT/16
        BOXPORTWIDTH = WIDTH/3.2
        BOXPORTHEIGHT = HEIGHT/16

        #screen.fill(BACK_SCREEN)
        screen.blit(BG0, (0,0)) #Set background image

        textClient, textClientRect = mygui.print_text('freesansbold.ttf', HEIGHT/15, "Client", WHITE, None, WIDTH/2, HEIGHT/10)
        screen.blit(textClient, textClientRect)

        textIp, textIpRect = mygui.print_text('freesansbold.ttf', HEIGHT/30, "Enter IP : ", WHITE, None, WIDTH/2-BOXIPWIDTH/2-WIDTH/13,HEIGHT/4)
        screen.blit(textIp, textIpRect)

        textPort, textPortRect = mygui.print_text('freesansbold.ttf', HEIGHT/30, "Enter Port : ", WHITE, None, WIDTH/2-BOXPORTWIDTH/2-WIDTH/13,HEIGHT/4+HEIGHT/9.6)
        screen.blit(textPort, textPortRect)

        Button1 = mygui.Button()
        Button1.create_button(screen, BACK_BUTTON, WIDTH/2-WIDTH/6, HEIGHT/2, WIDTH/3, WIDTH/9  ,    0,        "Connect", TEXT_BUTTON)

        input_ip = mygui.TextBox((WIDTH/2-BOXIPWIDTH/2,HEIGHT/4-BOXIPHEIGHT/2,BOXIPWIDTH,BOXIPHEIGHT),command=None,clear_on_enter=True,inactive_on_enter=False)
        input_port = mygui.TextBox((WIDTH/2-BOXPORTWIDTH/2,HEIGHT/4+HEIGHT/10-BOXPORTHEIGHT/2,BOXPORTWIDTH,BOXPORTHEIGHT),command=None,
                        clear_on_enter=True,inactive_on_enter=False, active = False)

        quit = False
        connect = False
        while not quit:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == MOUSEBUTTONDOWN:
                    if Button1.pressed(pygame.mouse.get_pos()):
                        connect = True
                        quit = True
                        break
                input_ip.get_event(event)
                input_port.get_event(event)

            input_ip.draw(screen)
            input_port.draw(screen)
            pygame.display.update()

        if connect:
            serIP = input_ip.get_text()
            serPort = input_port.get_text()
            if serIP == "1":
                serIP = "10.42.0.45"
            elif serIP == "2":
                serIP = "172.24.136.242"

            if serPort =="":
                serPort = "1234"
            cliObj = clientThread.ClientThread(str(serIP),int(serPort), screen)

            #Button1.delete_button(screen, BACK_SCREEN)
            screen.blit(BG0, (WIDTH/2-WIDTH/6-10, HEIGHT/2-10), (WIDTH/2-WIDTH/6-10, HEIGHT/2-10,Button1.rect.width+20,Button1.rect.height+20)) #Remove Button surface
            del Button1

            textWait, textWaitRect = mygui.print_text('freesansbold.ttf', HEIGHT/25, "Waiting for server to begin...", WHITE, None, WIDTH/2,HEIGHT/2+HEIGHT/9.6)
            screen.blit(textWait, textWaitRect)
            pygame.display.update()

            begin = cliObj.sock.recv(1024)
            if begin == "begin":
                print "Unpaused"
                clientGame.ClientGame(cliObj.sock, screen)
Beispiel #5
0
    def load_stuff(self):
        self.BUT_SERVER = mygui.Button()
        self.BUT_CLIENT = mygui.Button()

        self.TXT_WELCOME, self.TXT_WELCOME_RECT = mygui.print_text('freesansbold.ttf', HEIGHT/15, "Welcome", WHITE, None, WIDTH/2, HEIGHT/10)
Beispiel #6
0
    def __init__(self, screen):

        BOXIPWIDTH = WIDTH / 3.2
        BOXIPHEIGHT = HEIGHT / 16
        BOXPORTWIDTH = WIDTH / 3.2
        BOXPORTHEIGHT = HEIGHT / 16

        #screen.fill(BACK_SCREEN)
        screen.blit(BG0, (0, 0))  #Set background image

        textClient, textClientRect = mygui.print_text('freesansbold.ttf',
                                                      HEIGHT / 15, "Client",
                                                      WHITE, None, WIDTH / 2,
                                                      HEIGHT / 10)
        screen.blit(textClient, textClientRect)

        textIp, textIpRect = mygui.print_text(
            'freesansbold.ttf', HEIGHT / 30, "Enter IP : ", WHITE, None,
            WIDTH / 2 - BOXIPWIDTH / 2 - WIDTH / 13, HEIGHT / 4)
        screen.blit(textIp, textIpRect)

        textPort, textPortRect = mygui.print_text(
            'freesansbold.ttf', HEIGHT / 30, "Enter Port : ", WHITE, None,
            WIDTH / 2 - BOXPORTWIDTH / 2 - WIDTH / 13,
            HEIGHT / 4 + HEIGHT / 9.6)
        screen.blit(textPort, textPortRect)

        Button1 = mygui.Button()
        Button1.create_button(screen, BACK_BUTTON, WIDTH / 2 - WIDTH / 6,
                              HEIGHT / 2, WIDTH / 3, WIDTH / 9, 0, "Connect",
                              TEXT_BUTTON)

        input_ip = mygui.TextBox(
            (WIDTH / 2 - BOXIPWIDTH / 2, HEIGHT / 4 - BOXIPHEIGHT / 2,
             BOXIPWIDTH, BOXIPHEIGHT),
            command=None,
            clear_on_enter=True,
            inactive_on_enter=False)
        input_port = mygui.TextBox(
            (WIDTH / 2 - BOXPORTWIDTH / 2, HEIGHT / 4 + HEIGHT / 10 -
             BOXPORTHEIGHT / 2, BOXPORTWIDTH, BOXPORTHEIGHT),
            command=None,
            clear_on_enter=True,
            inactive_on_enter=False,
            active=False)

        quit = False
        connect = False
        while not quit:
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
                elif event.type == MOUSEBUTTONDOWN:
                    if Button1.pressed(pygame.mouse.get_pos()):
                        connect = True
                        quit = True
                        break
                input_ip.get_event(event)
                input_port.get_event(event)

            input_ip.draw(screen)
            input_port.draw(screen)
            pygame.display.update()

        if connect:
            serIP = input_ip.get_text()
            serPort = input_port.get_text()
            if serIP == "1":
                serIP = "10.42.0.45"
            elif serIP == "2":
                serIP = "172.24.136.242"

            if serPort == "":
                serPort = "1234"
            cliObj = clientThread.ClientThread(str(serIP), int(serPort),
                                               screen)

            #Button1.delete_button(screen, BACK_SCREEN)
            screen.blit(BG0, (WIDTH / 2 - WIDTH / 6 - 10, HEIGHT / 2 - 10),
                        (WIDTH / 2 - WIDTH / 6 - 10, HEIGHT / 2 - 10,
                         Button1.rect.width + 20,
                         Button1.rect.height + 20))  #Remove Button surface
            del Button1

            textWait, textWaitRect = mygui.print_text(
                'freesansbold.ttf', HEIGHT / 25,
                "Waiting for server to begin...", WHITE, None, WIDTH / 2,
                HEIGHT / 2 + HEIGHT / 9.6)
            screen.blit(textWait, textWaitRect)
            pygame.display.update()

            begin = cliObj.sock.recv(1024)
            if begin == "begin":
                print "Unpaused"
                clientGame.ClientGame(cliObj.sock, screen)