[Tutor] lan with python

Treloar, Nick Nick.Treloar at education.nsw.gov.au
Mon Feb 11 03:48:55 CET 2008


hey i was just wondering if any one could tell me if they know if you can make multi player games through lan with python heres the code i want to lan.
 
just hash out the sound files 
 
#NiCk TrEloaR PrOgRaMiNg Co.
#scissors paper rock
#10/6/07
from Tkinter import*
import pygame
 

from random import choice
class Application(Frame):
    def __init__(self,master):
        """Initalize Frame."""
        Frame.__init__(self,master)
        self.grid()
        self.create_widget()
        self.comput_count = 0
        self.user_count = 0
        pygame.mixer.init()
        self.gun = pygame.mixer.Sound("shotgun1.wav")
        self.bang = pygame.mixer.Sound("explosion.wav")
        self.laugh = pygame.mixer.Sound("evil_laf.wav")
        self.music = pygame.mixer.Sound("Unholy_confessions.wav")
        self.music.play()
        self.music.set_volume(0.4)
        self.bang.set_volume(1.0)
        self.laugh.set_volume(1.0)
        
        
 
        
        #creating user indstructions
    def create_widget(self):
        root.configure(bg = "green")
        #create description label
        Label(self,
              text="scissors paper rock                                                                      ", font  = ("Bauhaus 93", 28, "bold", )
              ).grid(row = 1,column = 0,sticky = W, columnspan = 4)
        
        #create the exit button
        self.exit_bttn = Button(self, text = "Exit", bg = "red", fg = "blue", font = ("Bauhaus 93", 12, "bold",), command = self.end )
        self.exit_bttn.grid(row = 16, column = 3, sticky = W)
        #create the rock button
        self.rock_bttn = Button(self, text = "rock", bg = "red", fg = "blue", font = ("Bauhaus 93", 12, "bold",), command = self.rock)
        self.rock_bttn.grid(row = 3, column = 0, sticky = W)
        #create the scissors button
        self.scissors_bttn = Button(self, text = "scissors", bg = "red", fg = "blue",  font = ("Bauhaus 93", 12, "bold",), command = self.scissors)
        self.scissors_bttn.grid(row = 5, column = 0, sticky = W)
        
        #create the paper  button
        self.paper_bttn = Button(self, text = "paper", bg = "red", fg = "blue", font = ("Bauhaus 93", 12, "bold",), command = self.paper)
        self.paper_bttn.grid(row = 7, column = 0, sticky = W)
        
    
        # reset button
        self.reset_bttn = Button(self, text  = "new game", bg  = "red", fg  = "blue", font  = ("Bauhaus 93", 12, "bold",), command = self.reset)
        self.reset_bttn.grid(row = 16, column = 0, sticky = W)
        
        # dynamite 
        self.reset_bttn = Button(self, text  = "dynamite", bg  = "red", fg  = "blue", font  = ("Bauhaus 93", 12, "bold",), command = self.dynamite)
        self.reset_bttn.grid(row = 8, column = 0, sticky = W)
       
        #dynamite lable
        Label(self,
              text="you can only use the dynamie button when you have a score of ten", font  = ("Bauhaus 93", 14, "bold", "underline", )
              ).grid(row = 17,column = 0,sticky = S, columnspan = 8)
        
        # help button
        self.reset_bttn = Button(self, text  = "help", bg  = "red", fg  = "blue", font  = ("Bauhaus 93", 12, "bold",), command = self.help1)
        self.reset_bttn.grid(row = 16, column = 2, sticky = W)
        
        
          
    def rock(self):
        if self.user_count ==(20):
            self.victory()
        if self.comput_count ==(20):
            self.loss()
        value = "rock"
        computer_guess = choice(["scissors", "paper", "rock"])
        
        if computer_guess == "rock":
            Label(self,
                  text = "this is a draw!!                                  ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            

        elif computer_guess == "paper":
            self.laugh.stop()
            self.laugh.play()
            Label(self,
                  text = "you lose paper smothers rock                    ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.comput_count = (self.comput_count+1)
            

        else:
            self.laugh.stop()
            self.gun.play()
            Label(self,
                  text = "you win rock smashes scissors                     ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.user_count = (self.user_count+1)
        self.ps = Label(self,
                  text=("player score",self.user_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 10,column = 0,sticky = W)
        self.cs = Label(self,
                  text=("computer score",self.comput_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 11,column = 0,sticky = W)   

    def scissors(self):
        if self.user_count ==(20):
            self.victory()
        if self.comput_count ==(20):
            self.loss()
        value = "scissors"
        computer_guess = choice(["scissors", "paper", "rock"])
        
        if computer_guess == "rock":
            self.laugh.stop()
            self.laugh.play() 
            Label(self,
                  text = "computer wins rock smashes scissors             ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.comput_count = (self.comput_count+1)

        elif computer_guess == "paper":
            self.laugh.stop()
            self.gun.play()
            Label(self,
                  text = "you win  scissors cut paper                    ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.user_count = (self.user_count+1)
            

        else:
            Label(self,
                  text = "this is a draw                                       ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            
            
        self.ps = Label(self,
                  text=("player score",self.user_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 10,column = 0,sticky = W)
        self.cs = Label(self,
                  text=("computer score",self.comput_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 11,column = 0,sticky = W)    
            

    def paper(self):
        if self.user_count ==(20):
            self.victory()
        if self.comput_count ==(20):
            self.loss()
        value = "paper"
        computer_guess = choice(["scissors", "paper", "rock"])
        
        if computer_guess == "rock":
            self.laugh.stop()
            self.gun.play()
            Label(self,
                  text = "you win paper smothers rock                       ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.user_count = (self.user_count+1)
            

        elif computer_guess == "paper":
            Label(self,
                  text = "this is a draw                                    ", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            

        else:
            self.laugh.stop()
            self.laugh.play()
            Label(self,
                  text = "computer wins scissors cut paper                  ", fg = "Blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.comput_count = (self.comput_count+1)
        self.ps = Label(self,
                  text=("player score",self.user_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 10,column = 0,sticky = W)
        self.cs = Label(self,
                  text=("computer score",self.comput_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 11,column = 0,sticky = W)   
        
    
    def reset(self):
        Label(self,
                  text=("                                                                                                "), font = ("Bauhaus 93", 16,)
                  ).grid(row = 9,column = 0,sticky = W)   
        self.user_count = 0 
        self.comput_count = 0
        self.create_widget()
        self.music.stop()
        self.music.play()
       
        
        
        self.ps = Label(self,
                  text="\t\t\t\t\t", font  = ("Bauhaus 93", 14, "bold", "underline", )            
                    ).grid(row = 10,column = 0,sticky = W)
        self.cs = Label(self,
                  text="\t\t\t\t\t", font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 11,column = 0,sticky = W)   
    def dynamite(self):
        
        if self.user_count==(10):
            self.bang.play()
            Label(self,
                  text = "you win dynamite kills every thing 5 times", fg = "blue", font = ("Bauhaus 93", 14, "bold"),
                  ).grid(row = 9, column = 0, sticky = W)
            self.user_count = (self.user_count+5)
            self.ps = Label(self,
                  text=("player score",self.user_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 10,column = 0,sticky = W)
        self.cs = Label(self,
                  text=("computer score",self.comput_count), font  = ("Bauhaus 93", 14, "bold", "underline", )
                  ).grid(row = 11,column = 0,sticky = W)
        

    def end(self):
        self.music.stop()
        root.destroy()

    def victory(self):
        Label(self,
                  text = "you are victorious press new game to play again", fg = "blue", font = ("Bauhaus 93",28 , "bold"),
                  ).grid(row = 1, column = 0, sticky = W, columnspan = 7)
    def loss(self):
        Label(self,
              text="you have been defeted press new game to start again", font  = ("Bauhaus 93", 28, "bold", "underline", )
              ).grid(row = 1,column = 0,sticky = W, columnspan = 7)
    def help1(self):
        global c1
        c1 = Toplevel(root)
        c1.title("Child One")
        c1.transient(root)
        Label(c1,text="help scissors paper rock is based on a simple principal n\n rock beats scissors, \n scissors beats paper \n and paper beats rock").grid()
          # create done button
        self.done_bttn = Button(c1, text = "done", bg = "red", fg = "blue",  font = ("Bauhaus 93", 12, "bold",), command = self.done)
        self.done_bttn.grid(row = 5, column = 0, sticky = W)
        c1.geometry("600x600")
        c1.configure(bg = "green")
      
    def done(self):
        c1.destroy()
        
        
        
        
root=Tk()
root.configure(bg = "green")
root.title("scissors paper rock")
root.geometry("950x550")
app = Application(root)
root.mainloop()
    
    
    
    
    
 

This message is intended for the addressee named and may contain privileged information or confidential information or both. If you are not the intended recipient please delete it and notify the sender. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080211/7f024e1c/attachment-0001.htm 


More information about the Tutor mailing list