def card012(self, ind): '''This function will be binded to all the 13 cards in the Graphical User Interface''' self.debug("!"*50 + "Card 0-12 Function" + "!"*50) self.out_card = self.p2_deck[ind] self.debug("Out_card:{}".format(self.out_card)) self.debug("P2 deck:{}".format(self.p2_deck)) self.debug("Index:{}, Card:{}".format(ind, self.p2_deck[ind])) self.p2_deck.pop(ind) self.debug("P2 deck:{}".format(self.p2_deck)) self.p2_deck.sort() self.debug("P2 deck:{}".format(self.p2_deck)) self.debug("Message:{}".format(self.message)) for x in range(13): file = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.p2_deck[x])) self.main_list[x]['image'] = file self.main_list[x].image = file self.debug("{} >>> {}".format(str(self.main_list[x]), file.__repr__())) self.debug("Now p2_deck:{}\nLength{}".format(self.p2_deck, len(self.p2_deck))) img = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.out_card)) self.other_cd['image'] = img self.other_cd.image = img self.debug("The image of other card is set to {}".format(img.__repr__())) self.xan.send(self.message.encode()) self.xan.send(self.out_card.encode()) self.debug("Message and out_card successfully sent.") self.debug("Thread_start function is started successully.") self.thread_start() self.button_over() self.debug("!" * 50 + "End Card 0-12 Function" + "!" * 50)
def deck2_but_func(self): '''This function is going to be binded with the deck button of the dealers desk deck.''' self.debug("<"*50 + "Deck 2 Button" + ">"*50) self.show['command'] = '' self.debug("Show command set to none.") self.trash.append(self.current_card) self.message = 'Player 2 goes for the deck' self.debug("Trash:{}\nLength{}".format(self.trash, len(self.trash))) self.current_card = self.deck_card self.debug("Current_card:{} is set to deck_card:{}".format(self.current_card, self.deck_card)) img = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.current_card)) self.deck_but['image'] = img self.deck_but.image = img self.debug("The image of deck button is set to {}".format(img.__repr__())) self.deck_but2['command'] = self.show['command'] = '' self.debug("The commands of deck_but2, four_but, show are set to ***None*** ") if self.permit == 1: self.four_but['command'] = self.four_but self.message += "Joker Revealed." else: self.four_but['command'] = '' self.deck_but['command'] = self.deck_but_func self.debug("The command of self.deck_but is set to self.deck_but_function.") self.throw['command'] = self.throw_func self.debug("The command of the throw button is set to throw function.") self.cur_but['image'] = self.bgc self.cur_but.image = self.bgc self.debug("The bg of current button is back ground.") self.cur_but['command'] = '' self.debug("The command of current button is set to ***None***") self.debug("<"*50 + "Deck 2 Button" + ">"*50)
def receiving(self ): self.debug("$"*50 + "Started Receiving" + "$"*50) self.four_but['command'] = self.four_sub print("Waiting for the card.") self.debug("Waiting for the card.") self.message = self.xan.recv(1024) self.current_card = self.xan.recv(1024) self.deck_card =self.xan.recv(1024) self.message = self.message.decode() self.current_card = self.current_card.decode() self.deck_card = self.deck_card.decode() self.debug("Successfully Received.\nMessage:{}\nCurrent Card:{}\nDeck Card:{}".format(self.message, self.current_card, self.deck_card)) if self.message == 'SHOW': self.lose() img = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.current_card)) self.cur_but['image'] = img self.cur_but.image = img self.mes_label['text'] = self.message self.debug("The image of the current button is set to {}".format(img.__repr__())) self.debug("The funcition initial is going to be executed next.") self.initial() self.show['command'] = self.show_func self.debug("$"*50 + "End of receiving method" + "$" * 50)
def throw_func(self): '''This function will be binded to the throw button of the dealer's desk''' self.debug("#"*50 + "Throw Function" + "#"*50) self.deck_but['command'] = self.deck_but2['command'] = self.four_but['command'] = self.show['command'] = '' self.debug("The commands of deck_but,deck_but2,four_but,show are set to ***None***") self.out_card = self.current_card self.debug("Out card:{} is set to current card:{}".format(self.out_card, self.current_card)) self.deck_but['image'] = self.bgc self.deck_but.image = self.bgc self.debug("Message is set to::{}".format(self.message)) self.deck_but['command'] = '' img = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.out_card)) self.other_cd['image'] = img self.other_cd.image = img self.debug("Image of other card is set to {}".format(img.__repr__())) self.xan.send(self.message.encode()) self.debug("Message is sent successfully.") self.xan.send(self.out_card.encode()) self.debug("Out_card is sent successfully.") self.throw['command'] = '' self.debug("Throw command is set to ***None***") self.debug("Thread_start is going to be executed.") self.thread_start() self.debug("#"*50 + "End Throw Function" + "#"*50)
def gui(self): '''This method is contains the structure of the graphical user interface.''' self.debug("_"*50 + "GUI" + "_"*50) self.window = Toplevel() self.window.title('Xander Poker') self.window.config(bg='black') label = Label(self.window, text='Enter your address:-', bg='black', fg='white', font=('TlwgTypist', 13, 'bold')) label.pack() self.entry = Entry(self.window, font=('TlwgTypist', 13), bg='white', fg='black') self.entry.pack() self.entry.focus() frame = Frame(self.window, bg='black') frame.pack(pady=3) ok = Button(frame, text='OK', fg='white', bg='black', font=('TlwgTypist', 13, 'bold'), command=self.ok_func) ok.pack(side=LEFT, padx=10) cancel = Button(frame, text='Cancel', fg='white', bg='black', font=('TlwgTypist', 13, 'bold'), command=self.cancel_func) cancel.pack(side=LEFT) self.window.mainloop() self.win.attributes('-fullscreen', 'true') self.debug("Ipv4 address is taken {}.".format(self.ip)) self.debug("self.socket method is going to be executed next") try: self.socket() except: print("entered") error_label = Label(self.win, text='Network Error', bg='lightgreen', fg='red', font=('TlwgTypist', 20, 'italic')) error_label.pack() steps = Label(self.win, text='1.Check whether you if the server started or not.\n2.Try disconnecting and reconnecting to the network.\n3.Wait for sometime for the Server to Refresh.\n4.Check whether you entered correct IP address or not and try again.', bg='lightgreen', fg='black', font=('Times', 13, 'italic')) steps.pack() quit = Button(self.win, text='Quit', bg='black', fg='lightgreen', font=('Times', 13, 'italic'), command=self.win.destroy) quit.pack() return None self.heading = Label(self.win, text = 'Start the Game', font = ('URWGothic', 30, 'italic'), bg = 'lightgreen', fg = 'black', cursor = 'hand1') self.debug("Heading 'Start the Game' is created and command set to self.receiving.") self.heading.pack(side = TOP) self.heading.bind('<Button-1>', self.head_func) self.heading.bind('<Enter>', self.head_enter) self.heading.bind('<Leave>', self.head_leave) # We have to create 13 buttons for 13 cards # First we will create a frame that contain thirteen cards and use grid layout to manage cards in the gui self.m_frame = Frame(self.win) # This is the main frame we are talking about earlier self.m_frame.config(background='lightgreen') self.m_frame.pack(side='left', anchor=SW) self.debug("A main frame is created for the 13 cards.") # We just declared the buttons so that we can use them in loop self.b0 = Button(self.m_frame) self.b0.grid(row=0, column=0) self.b1 = Button(self.m_frame) self.b1.grid(row=1, column=0) self.b2 = Button(self.m_frame) self.b2.grid(row=2, column=0) self.b3 = Button(self.m_frame) self.b3.grid(row=0, column=1) self.b4 = Button(self.m_frame) self.b4.grid(row=1, column=1) self.b5 = Button(self.m_frame) self.b5.grid(row=2, column=1) self.b6 = Button(self.m_frame) self.b6.grid(row=0, column=2) self.b7 = Button(self.m_frame) self.b7.grid(row=1, column=2) self.b8 = Button(self.m_frame) self.b8.grid(row=2, column=2) self.b9 = Button(self.m_frame) self.b9.grid(row=0, column=3) self.b10 = Button(self.m_frame) self.b10.grid(row=1, column=3) self.b11 = Button(self.m_frame) self.b11.grid(row=2, column=3) self.b12 = Button(self.m_frame) self.b12.grid(row=1, column=4) self.debug("All the 13 buttons are created in the main frame.") self.main_list = [self.b0, self.b1, self.b2, self.b3, self.b4, self.b5, self.b6, self.b7, self.b8, self.b9, self.b10, self.b11, self.b12] self.debug("Created a mainlist in which the buttons are appended {}".format(self.main_list)) self.debug("P2 deck sorter method going to be executed next.") self.p2_deck.sort() for x in range(13): file = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.p2_deck[x])) self.main_list[x]['image'] = file self.main_list[x].image = file self.main_list[x]['bg'] = 'black' self.main_list[x]['bd'] = 8 self.main_list[x]['relief'] = 'ridge' self.main_list[x]['activebackground'] = 'red' self.debug("{} >>> {}".format(str(self.main_list[x]), file.__repr__())) self.debug("Dealer's frame method is going to be executed next.") self.dealers_frame() self.debug("Waiting for the card.") self.current_card = self.xan.recv(1024) self.current_card = self.current_card.decode() self.debug("Received the card ***{}***".format(self.current_card)) self.c_file = PhotoImage(file='/usr/lib/Joker3/NewImages/{}.png'.format(self.current_card)) self.cur_but['image'] = self.ggc self.cur_but.image = self.ggc self.deck_but['image'] = self.bgc self.deck_but.image = self.bgc self.debug("The images of the current button and deck_button are set to the background images.") self.other_cd['image'] = self.c_file # Trash cards is in this button self.debug("The image of the other card is set to the current card.") self.debug("_"*50 + "End GUI" + "_"*50)