def run(self): max_score = int(self.option[9][0]) pygame.init() # SET DISPLAY global ghorme_counter display = pygame.display.set_mode((width, height)) title = "" for i in range(len(self.option[5])): title += self.option[5][i] + " " pygame.display.set_caption(title) # WALL walla = [] for i in self.map: walak = wall.Wall(display) walak.x = (i[0] - 1) * (width / mapw) walak.y = (i[1] - 1) * (height / maph) walak.set_border() walla.append(walak) # OBJECT #---------------------------------------------------------------------- # WORM1 #---------------------------------------------------------------------- w = worm.Worm(display, int(self.option[12][0]), int(self.option[12][1]), int(self.option[10][0])) w.first_dir_x, w.first_dir_y = w.dir_x, w.dir_y w.player_name = self.option[0][0] w.joon = 3 #---------------------------------------------------------------------- # WORM2 #---------------------------------------------------------------------- s = worm.AIWorm(display, int(self.option[13][0]), int(self.option[13][1]), int(self.option[11][0])) s.dir_x = 0 s.dir_y = -1 s.color = 0, 0, 255 s.first_dir_x = s.dir_x s.first_dir_y = s.dir_y s.joon = 6 s.control_up, s.control_right, s.control_down, s.control_left = pygame.K_w, pygame.K_d, pygame.K_s, pygame.K_a s.nitrogen_key = pygame.K_LSHIFT s.player_name = "computer" #---------------------------------------------------------------------- # FOODS #---------------------------------------------------------------------- g = food.GhormeSabzi(display) #---------------------------------------------------------------------- # TEXT #---------------------------------------------------------------------- # font= pygame.font.SysFont(name="Feast of Flesh BB",size= 20) #font_h3= pygame.font.SysFont(name="Feast of Flesh BB",size= 60) font = pygame.font.Font('data/FEASFBRG.ttf', 20) font_h3 = pygame.font.Font('data/FEASFBRG.ttf', 60) # dg=pygame.font.Font() color_text = int(self.option[7][0]), int(self.option[7][1]), int( self.option[7][2]) #w.color) text_player1 = font.render(w.player_name, True, color_w_porrang_rect_score) text_player2 = font.render(s.player_name, True, color_s_porrang_rect_score) text_player_w_win = font_h3.render(w.player_name + " WIN!", True, color_w_porrang_rect_score) text_player_s_win = font_h3.render(s.player_name + " WIN!", True, color_s_porrang_rect_score) text_pause = font_h3.render("PAUSE", True, color_text) text_start = font_h3.render("PRESS SPACE...", True, color_text) #---------------------------------------------------------------------- # MUSIC #---------------------------------------------------------------------- pygame.mixer.pre_init(44100, 16, 2, 4096) background_music = pygame.mixer.Sound('data/sound/background.ogg') todifar_music = pygame.mixer.Sound('data/sound/todifar.ogg') tnt_music = pygame.mixer.Sound('data/sound/tnt.ogg') eat_music = pygame.mixer.Sound('data/sound/eat.wav') next_level_music = pygame.mixer.Sound('data/sound/eat.wav') # SET VOLUME background_music.set_volume(float(self.option[3][0])) todifar_music.set_volume(float(self.option[4][0])) tnt_music.set_volume(float(self.option[4][0])) eat_music.set_volume(float(self.option[4][0])) background_music.play(-1) #---------------------------------------------------------------------- c = 0 x = (width / 2) / 2 e = 80 tt = 0 while True: c = -5 # The time of game if self.state == 'play': self.time += self.step # Check to :score >0 if w.score < 0: w.score = 0 if s.score < 0: s.score = 0 # Check to :Joon<=7 if w.joon >= 7: w.joon = 7 if s.joon >= 7: s.joon = 7 display.fill(background_color) if self.end_level: self.state = "EndLevel" # USER FREINDLY #----------------------------------------------------------- display.blit(text_player1, (x - 50, 100)) display.blit(text_player2, (width - x - 50, 100)) pygame.draw.rect(display, color_w_kamrang_rect_score, (x - 50, 120, 100, 6)) pygame.draw.rect(display, color_s_kamrang_rect_score, (width - x - 50, 120, 100, 6.5)) pygame.draw.rect(display, color_w_porrang_rect_score, (x - 50, 120, w.score * max_score, 6)) pygame.draw.rect(display, color_s_porrang_rect_score, (width - x - 50, 120, s.score * max_score, 6.5)) pygame.draw.polygon(display, color_w_porrang_rect_score, ((x - 50 + e, y_zalamzimbo - 10), (x - 40 + e, y_zalamzimbo), (x - 50 + e, y_zalamzimbo))) pygame.draw.polygon(display, color_w_porrang_rect_score, ((x - 40 + e, y_zalamzimbo - 10), (x - 30 + e, y_zalamzimbo), (x - 40 + e, y_zalamzimbo))) pygame.draw.polygon(display, color_s_porrang_rect_score, ((width - x - 50 + e, y_zalamzimbo - 10), (width - x - 40 + e, y_zalamzimbo), (width - x - 50 + e, y_zalamzimbo))) pygame.draw.polygon(display, color_s_porrang_rect_score, ((width - x - 40 + e, y_zalamzimbo - 10), (width - x - 30 + e, y_zalamzimbo), (width - x - 40 + e, y_zalamzimbo))) if w.nitrogen_counter == 0: pygame.draw.polygon(display, color_w_kamrang_rect_score, ((x - 50 + e, y_zalamzimbo - 10), (x - 40 + e, y_zalamzimbo), (x - 50 + e, y_zalamzimbo))) pygame.draw.polygon(display, color_w_kamrang_rect_score, ((x - 40 + e, y_zalamzimbo - 10), (x - 30 + e, y_zalamzimbo), (x - 40 + e, y_zalamzimbo))) if w.nitrogen_counter == 1: pygame.draw.polygon(display, color_w_kamrang_rect_score, ((x - 40 + e, y_zalamzimbo - 10), (x - 30 + e, y_zalamzimbo), (x - 40 + e, y_zalamzimbo))) if s.nitrogen_counter == 0: pygame.draw.polygon(display, color_s_porrang_rect_score, ((width - x - 50 + e, y_zalamzimbo - 10), (width - x - 40 + e, y_zalamzimbo), (width - x - 50 + e, y_zalamzimbo))) pygame.draw.polygon(display, color_s_porrang_rect_score, ((width - x - 40 + e, y_zalamzimbo - 10), (width - x - 30 + e, y_zalamzimbo), (width - x - 40 + e, y_zalamzimbo))) if s.nitrogen_counter == 1: pygame.draw.polygon(display, color_s_porrang_rect_score, ((width - x - 40 + e, y_zalamzimbo - 10), (width - x - 30 + e, y_zalamzimbo), (width - x - 40 + e, y_zalamzimbo))) for i in range(7): c += 10 self.draw_joon(display, color_w_kamrang_rect_score, x - 50 + c, y_zalamzimbo - 5) c = -5 for i in range(7): c += 10 self.draw_joon(display, color_s_kamrang_rect_score, width - x - 50 + c, y_zalamzimbo - 5) c = -5 for i in range(w.joon): c += 10 if w.joon <= 7: self.draw_joon(display, color_w_porrang_rect_score, x - 50 + c, y_zalamzimbo - 5) c = -5 for i in range(s.joon): c += 10 if s.joon <= 7: self.draw_joon(display, color_s_porrang_rect_score, width - x - 50 + c, y_zalamzimbo - 5) c = -5 #------------------------------------------------------------------ #DRAWING & MOVEING w.draw() s.draw() # Check to accident if w.check_to_accident(s.x, s.y): s.erase() tnt_music.play() if s.check_to_accident(w.x, w.y): w.erase() tnt_music.play() # Draw wall & check worms to accident for i in walla: i.draw() for i in walla: if i.check(w.x, w.y): w.erase() todifar_music.play(1) break for i in walla: if i.check(s.x, s.y): s.erase() todifar_music.play(1) break # Event # FOOD #------------------------------------------ # Ghorme Sabzi #------------------------------------------ g.draw() xekh = s.x - g.x yekh = s.y - g.y if self.state == "play": s.analize(xekh, yekh, w, 20, self.aitype) w.move() s.move() if g.check(w, w.x, w.y): w.score += 1 w.eat() eat_music.play() ghorme_counter += 1 g.erase() g = food.GhormeSabzi(display) if g.check(s, s.x, s.y): s.score += 1 s.eat() eat_music.play() ghorme_counter += 1 g.erase() g = food.GhormeSabzi(display) for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE and self.state == "start": self.state = "play" elif event.key == pygame.K_SPACE and self.state == "play": self.state = "pause" elif event.key == pygame.K_SPACE and self.state == "pause": self.state = "play" if self.state == "play": w.analize(event) if w.joon < 0 or s.score == max_score: w.game_over = True self.end_level = True # play sound display.blit(text_player_s_win, (width / 2 - 170, height / 2 - e)) if tt == 0: self.write_log('\n' + 'vscom' + ',' + str(self.level) + ',' + s.player_name + ',' + str(s.score) + ',' + w.player_name + ',' + str(w.score)) tt += 1 if s.joon < 0 or w.score == max_score: s.game_over = True self.end_level = True # play sound display.blit(text_player_w_win, (width / 2 - 150, height / 2 - e)) if tt == 0: self.write_log('\n' + 'vscom' + ',' + str(self.level) + ',' + w.player_name + ',' + str(w.score) + ',' + s.player_name + ',' + str(s.score)) tt += 1 if self.state == "start": display.blit(text_start, (width / 2 - 140, height / 2 - 50)) if self.state == "pause": display.blit(text_pause, (width / 2 - 70, height / 2 - 50)) pygame.display.update() time.sleep(self.step)
def run(self): max_score=int(self.option[9][0]) pygame.init() #SET DISPLAY global ghorme_counter display = pygame.display.set_mode((width,height )) title="" for i in range(len(self.option[5])): title+=self.option[5][i]+ " " pygame.display.set_caption(title) #WALL walla=[] for i in self.map: walak=wall.Wall(display) walak.x=(i[0]-1)*(width/mapw) walak.y=(i[1]-1)*(height/maph) walak.set_border() walla.append(walak) #OBJECT #----------------------------------------------------------------------------- #WORM1 #----------------------------------------------------------------------------- w=worm.Worm(display,int(self.option[12][0]),int(self.option[12][1]),int(self.option[10][0])) w.first_dir_x,w.first_dir_y=w.dir_x,w.dir_y w.player_name= self.option[0][0] w.joon=int(self.option[6][0]) #------------------------------------------------------------------------------ #WORM2 #------------------------------------------------------------------------------ s=worm.Worm(display,int(self.option[13][0]),int(self.option[13][1]),int(self.option[11][0])) s.dir_x=0 s.dir_y=-1 s.color=0,0,255 s.first_dir_x=s.dir_x s.first_dir_y=s.dir_y s.joon=int(self.option[6][0]) s.control_up,s.control_right,s.control_down,s.control_left=pygame.K_w,pygame.K_d,pygame.K_s,pygame.K_a s.nitrogen_key=pygame.K_LSHIFT s.player_name= self.option[1][0] #----------------------------------------------------------------------------- #FOODS #----------------------------------------------------------------------------- g=food.GhormeSabzi(display) j=food.Joon(display) n=food.Nitrogen(display) d=food.Dombor(display) na=food.Nitroafzon(display) #---------------------------------------------------------------------------- #TEXT #---------------------------------------------------------------------------- # font= pygame.font.SysFont(name="Feast of Flesh BB",size= 20) #font_h3= pygame.font.SysFont(name="Feast of Flesh BB",size= 60) font = pygame.font.Font('data/FEASFBRG.ttf',20) font_h3 = pygame.font.Font('data/FEASFBRG.ttf',60) # dg=pygame.font.Font() color_text=int(self.option[7][0]),int(self.option[7][1]),int(self.option[7][2]) text_player1=font.render(w.player_name,True,color_w_porrang_rect_score)#w.color) text_player2=font.render(s.player_name,True,color_s_porrang_rect_score) text_player_w_win=font_h3.render(w.player_name+" WIN!",True,color_w_porrang_rect_score) text_player_s_win=font_h3.render(s.player_name+" WIN!",True,color_s_porrang_rect_score) text_pause=font_h3.render("PAUSE",True,color_text) text_start=font_h3.render("PRESS SPACE...",True,color_text) #---------------------------------------------------------------------------- #MUSIC #---------------------------------------------------------------------------- pygame.mixer.pre_init(44100, 16, 2, 4096) background_music = pygame.mixer.Sound('data/sound/background.ogg') todifar_music=pygame.mixer.Sound('data/sound/todifar.ogg') tnt_music=pygame.mixer.Sound('data/sound/tnt.ogg') eat_music=pygame.mixer.Sound('data/sound/eat.wav') next_level_music=pygame.mixer.Sound('data/sound/eat.wav') #SET VOLUME background_music.set_volume(float(self.option[3][0])) todifar_music.set_volume(float(self.option[4][0])) tnt_music .set_volume(float(self.option[4][0])) eat_music.set_volume(float(self.option[4][0])) background_music.play(-1) #------------------------------------------------------------------------------ c=0 x=(width/2)/2 e=80 tt=0 while True: c=-5 #The time of game self.time+=self.step #Check to :score >0 if w.score<0: w.score=0 if s.score<0: s.score=0 #Check to :Joon<=7 if w.joon>=7: w.joon=7 if s.joon >=7: s.joon=7 display.fill(background_color) if self.end_level: self.state="EndLevel" #USER FREINDLY #----------------------------------------------------------- display.blit(text_player1 ,(x-50,100) ) display.blit(text_player2 , (width-x-50,100)) pygame.draw.rect(display,color_w_kamrang_rect_score,(x-50,120,100,6)) pygame.draw.rect(display,color_s_kamrang_rect_score,(width-x-50,120,100,6.5)) pygame.draw.rect(display,color_w_porrang_rect_score,(x-50,120,w.score*max_score,6)) pygame.draw.rect(display,color_s_porrang_rect_score,(width-x-50,120,s.score*max_score,6.5)) pygame.draw.polygon(display,color_w_porrang_rect_score,((x-50+e,y_zalamzimbo-10),(x-40+e,y_zalamzimbo),(x-50+e,y_zalamzimbo))) pygame.draw.polygon(display,color_w_porrang_rect_score,((x-40+e,y_zalamzimbo-10),(x-30+e,y_zalamzimbo),(x-40+e,y_zalamzimbo))) pygame.draw.polygon(display,color_s_porrang_rect_score,((width-x-50+e,y_zalamzimbo-10),(width-x-40+e,y_zalamzimbo),(width-x-50+e,y_zalamzimbo))) pygame.draw.polygon(display,color_s_porrang_rect_score,((width-x-40+e,y_zalamzimbo-10),(width-x-30+e,y_zalamzimbo),(width-x-40+e,y_zalamzimbo))) if w.nitrogen_counter==0: pygame.draw.polygon(display,color_w_kamrang_rect_score,((x-50+e,y_zalamzimbo-10),(x-40+e,y_zalamzimbo),(x-50+e,y_zalamzimbo))) pygame.draw.polygon(display,color_w_kamrang_rect_score,((x-40+e,y_zalamzimbo-10),(x-30+e,y_zalamzimbo),(x-40+e,y_zalamzimbo))) if w.nitrogen_counter==1: pygame.draw.polygon(display,color_w_kamrang_rect_score,((x-40+e,y_zalamzimbo-10),(x-30+e,y_zalamzimbo),(x-40+e,y_zalamzimbo))) if s.nitrogen_counter==0: pygame.draw.polygon(display,color_s_porrang_rect_score,((width-x-50+e,y_zalamzimbo-10),(width-x-40+e,y_zalamzimbo),(width-x-50+e,y_zalamzimbo))) pygame.draw.polygon(display,color_s_porrang_rect_score,((width-x-40+e,y_zalamzimbo-10),(width-x-30+e,y_zalamzimbo),(width-x-40+e,y_zalamzimbo))) if s.nitrogen_counter==1: pygame.draw.polygon(display,color_s_porrang_rect_score,((width-x-40+e,y_zalamzimbo-10),(width-x-30+e,y_zalamzimbo),(width-x-40+e,y_zalamzimbo))) for i in range(7): c+=10 self.draw_joon(display, color_w_kamrang_rect_score,x-50+c , y_zalamzimbo-5) c=-5 for i in range(7): c+=10 self.draw_joon(display, color_s_kamrang_rect_score,width-x-50+c , y_zalamzimbo-5) c=-5 for i in range(w.joon): c+=10 if w.joon<=7: self.draw_joon(display, color_w_porrang_rect_score,x-50+c , y_zalamzimbo-5) c=-5 for i in range(s.joon): c+=10 if s.joon<=7: self.draw_joon(display, color_s_porrang_rect_score,width-x-50+c , y_zalamzimbo-5) c=-5 #----------------------------------------------------------------------- #DRAWING & MOVEING w.draw() s.draw() if self.state=="play": w.move() s.move() #Check to accident if w.check_to_accident(s.x, s.y): s.erase() tnt_music.play() if s.check_to_accident(w.x, w.y): w.erase() tnt_music.play() #Draw wall & check worms to accident for i in walla: i.draw() for i in walla: if i.check(w.x,w.y): w.erase() todifar_music.play(1) break for i in walla: if i.check(s.x,s.y): s.erase() todifar_music.play(1) break #Event #FOOD #------------------------------------------ #Ghorme Sabzi #------------------------------------------ if ghorme_counter<max_of_ghorme: g.draw() if g.check(w, w.x, w.y): w.score+=1 w.eat() eat_music.play() ghorme_counter+=1 if ghorme_counter<max_of_ghorme: g=food.GhormeSabzi(display) if g.check(s, s.x, s.y): s.score+=1 s.eat() eat_music.play() ghorme_counter+=1 if ghorme_counter<max_of_ghorme: g=food.GhormeSabzi(display) if ghorme_counter==max_of_ghorme: self.end_level=False#ino badan bezaram True bazi ba tamom shodan ghorme sabziya tamom mishe va #------------------------------------------ #------------------------------------------ #jooooooon #------------------------------------------ if self.time%10.0<0.01 : self.joon_show=True self.start_j_time=self.time if self.time>(self.start_j_time+8.0): self.joon_show=False if self.joon_show: j.draw(display) else: j.erase(display) if j.check(w, w.x, w.y): w.joon+=1 j.erase(display) eat_music.play() j=food.Joon(display) if j.check(s, s.x, s.y): s.joon+=1 j.erase(display) eat_music.play() j=food.Joon(display) #------------------------------------------- #------------------------------------------- #Nitrogen #------------------------------------------- n.draw() if self.time>= 7and self.time%7.0<0.01 : self.show_nitrogen=True # print "hfghfg" self.start_n_time=self.time n.draw() if n.check(w, w.x, w.y): n.erase() eat_music.play() self.start_eat_n=self.time n=food.Nitrogen(display) w.eat_nitrogen() if self.time==self.start_eat_n+ 0.1: w.un_eat_nitrogen() if n.check(s, s.x, s.y): n.erase() eat_music.play() self.start_eat_n=self.time n=food.Nitrogen(display) s.eat_nitrogen() if self.time==self.start_eat_n+ 0.1: s.un_eat_nitrogen() #--------------------------------------- #------------------------------------------- #Dombor #------------------------------------------- if ghorme_counter>0 and ghorme_counter%2==0: d.draw() if d.check(w,w.x,w.y): w.eat_dombor() d.erase() eat_music.play() if d.check(s,s.x,s.y): s.eat_dombor() eat_music.play() d.erase() #-------------------------------------------- #Nitro Afzon #-------------------------------------------- na.draw() if na.check(w, w.x, w.y): w.score+=1 eat_music.play() if w.nitrogen_counter<2: w.nitrogen_counter+=1 na=food.Nitroafzon(display) if na.check(s, s.x, s.y): s.score+=1 eat_music.play() if s.nitrogen_counter<2: s.nitrogen_counter+=1 na=food.Nitroafzon(display) #-------------------------------------------------- #Check Event #-------------------------------------------------- for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE and self.state=="start": self.state="play" elif event.key == pygame.K_SPACE and self.state=="play": self.state="pause" elif event.key == pygame.K_SPACE and self.state=="pause": self.state="play" if self.state=="play": w.analize(event) s.analize(event) if w.joon<0 or s.score==max_score: w.game_over=True self.end_level=True #play sound display.blit( text_player_s_win,(width/2-120,height/2-e)) if tt==0: self.write_log('\n'+'2player'+','+str(self.level)+','+s.player_name+','+str(s.score)+','+w.player_name+','+str(w.score)) tt+=1 if s.joon <0 or w.score==max_score: s.game_over=True self.end_level=True if tt==0: self.write_log('\n'+'2player'+','+str(self.level)+','+w.player_name+','+str(w.score)+','+s.player_name+','+str(s.score)) #play sound display.blit( text_player_w_win,(width/2-150,height/2-e)) tt+=1 if self.state=="start": display.blit( text_start,(width/2-140,height/2-50)) if self.state=="pause": display.blit( text_pause,(width/2-70,height/2-50)) pygame.display.update() time.sleep(self.step) if self.state=='EndLevel': background_music.stop() next_level_music.play() level3=Snake() level3.map=level3.read_map('data/map/level3.txt') level3.run()
def run(self): print "run the client" print "and please wait to connect ... " HOST = self.ip print "Server IP :", HOST pygame.init() display = pygame.display.set_mode((500, 500)) w = worm.Worm(display, 200, 200, 25) w.lag = lag w.head_r = 4 w.dir_x = 0 * w.lag w.dir_y = -1 * w.lag w.first_dir_x = 0 * w.lag w.first_dir_y = -1 * w.lag w.first_dir_x, w.first_dir_y = w.dir_x, w.dir_y w.player_name = self.name w.joon = 3 g = food.GhormeSabzi(display) g.r = 4 pygame.display.set_caption("NET SNAKE") moket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) moket.bind((HOST, 50001)) moket.listen(1) connm, addrm = moket.accept() print 'Connected by', addrm connm.send(w.player_name) print w.player_name + " SENT" hach = connm.recv(1024) print hach + " RECEIVED " cotlet = socket.socket(socket.AF_INET, socket.SOCK_STREAM) cotlet.bind((HOST, 50002)) cotlet.listen(1) connc, addrc = cotlet.accept() print 'Connected by', addrc # Symbolic name meaning all # Arbitrary non-privileged s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, 50009)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr #print 'Connected by', addrjoon print "reading data..." font = pygame.font.Font('data/FEASFBRG.ttf', 20) font_h3 = pygame.font.Font('data/FEASFBRG.ttf', 60) text_servername = font.render(w.player_name, True, color_w_porrang_rect_score) text_client = font.render(hach, True, color_s_porrang_rect_score) color_text = 255, 255, 255 text_server_win = font_h3.render(w.player_name + " WIN!", True, color_w_porrang_rect_score) text_client_win = font_h3.render(hach + " WIN!", True, color_s_porrang_rect_score) text_pause = font_h3.render("PAUSE", True, color_text) text_start = font_h3.render("PRESS SPACE...", True, color_text) print "data analized" x = (width / 2) / 2 max_score = 10 c = 0 e = 80 clientjoon = 3 clientscore = 0 while 1: c = -5 data = '' while 1: data = conn.recv(1024) #connjoon.send(str(w.joon)) conn.send(str(w.body_list)) # data2 = conn2.recv(1024) #if not data: break # print "hghjgh" break # print data #Check to :score >0 if w.score < 0: w.score = 0 if clientscore < 0: clientscore = 0 #Check to :Joon<=7 if clientjoon >= 7: clientjoon = 7 if w.joon >= 7: w.joon = 7 display.fill((0, 0, 0)) ghormexoy = "&" + str(g.x) + "&" + str(g.y) + "&" + str( w.score) + "&" + str(w.joon) + "&" + str( clientscore) + "&" + str(clientjoon) + "&" + str( self.state) + "&" connc.send(ghormexoy) #text display.blit(text_servername, (x - 50, 100)) display.blit(text_client, (width - x - 50, 100)) pygame.draw.rect(display, color_w_kamrang_rect_score, (x - 50, 120, 100, 6)) pygame.draw.rect(display, color_w_porrang_rect_score, (x - 50, 120, w.score * max_score, 6)) pygame.draw.rect(display, color_s_kamrang_rect_score, (width - x - 50, 120, 100, 6.5)) pygame.draw.rect( display, color_s_porrang_rect_score, (width - x - 50, 120, clientscore * max_score, 6.5)) for i in range(7): c += 10 self.draw_joon(display, color_w_kamrang_rect_score, x - 50 + c, y_zalamzimbo - 5) c = -5 for i in range(7): c += 10 self.draw_joon(display, color_s_kamrang_rect_score, width - x - 50 + c, y_zalamzimbo - 5) c = -5 for i in range(w.joon): c += 10 if w.joon <= 7: self.draw_joon(display, color_w_porrang_rect_score, x - 50 + c, y_zalamzimbo - 5) c = -5 for i in range(clientjoon): c += 10 if clientjoon <= 7: self.draw_joon(display, color_s_porrang_rect_score, width - x - 50 + c, y_zalamzimbo - 5) c = -5 clientbodylist = datatolist(data) #barkhord ba khodesho check mikone for i in range(1, len(clientbodylist)): pygame.draw.circle( display, (0, 0, 255), (clientbodylist[i][0], clientbodylist[i][1]), 4) if clientbodylist[0][0] == clientbodylist[i][ 0] and clientbodylist[0][1] == clientbodylist[i][1]: print "client khord be khodesh khak to saresh" clientjoon -= 1 clientscore -= 1 if self.state == 2: if g.r + 4 > ((((g.y - clientbodylist[0][1])**2) + ((g.x - clientbodylist[0][0])**2))**(1 / 2.0)): g.erase() clientscore += 1 print "client khord" g = food.GhormeSabzi(display) g.r = 4 if g.r + 4 > ((((g.y - w.y)**2) + ((g.x - w.x)**2))**(1 / 2.0)): g.erase() w.score += 1 print "server khord" g = food.GhormeSabzi(display) g.r = 4 # def check(self,who, x, y): # if self.r+who.head_r>((((self.y-who.y)**2)+((self.x-who.x)**2))**(1/2.0)): # return True # return False # if self.state == 2: w.draw() w.move() if self.state == 1: display.blit(text_start, (width / 2 - 140, height / 2 - 50)) if self.state == 3: display.blit(text_pause, (width / 2 - 70, height / 2 - 50)) if w.score == max_score or clientjoon == 0: self.state = 4 display.blit(text_server_win, (width / 2 - 120, height / 2 - e)) if clientscore == max_score or w.joon == 0: self.state = 4 display.blit(text_client_win, (width / 2 - 150, height / 2 - e)) g.draw() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() conn.close() # conn2.close() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE and self.state == 1: self.state = 2 elif event.key == pygame.K_SPACE and self.state == 2: self.state = 3 elif event.key == pygame.K_SPACE and self.state == 3: self.state = 2 if self.state == 2: w.analize(event) time.sleep(0.01) pygame.display.update() conn.close() conn.close()