Beispiel #1
0
 def keepalive(self):
     with self.__class__._lock:
         try:
             if not self.__class__._tse or not self.__class__._tse.info:
                 log.debug('TSE war nicht korrekt initialisiert')
                 # TSE beim Start nicht vorhanden gewesen!
                 self.__class__._tse = worm.Worm(
                     clientid=conf['clientid'],
                     time_admin_pin=conf['timeadminpin'])
                 self.tse_prepare(adminpuk=conf['adminpuk'],
                                  adminpin=conf['adminpin'])
             if not self.info.hasPassedSelfTest or self.info.timeUntilNextSelfTest < 1500:
                 log.debug('TSE-Selbsttest ist jetzt nötig')
                 self.tse_runSelfTest()
             self.tse_updateTime()
         except TSEException as e:
             if e.errno == 2:  # TSE nicht verfügbar
                 log.info('Keine TSE vorhanden')
                 pass
             elif e.errno == 0x1011:  # client not registered
                 log.info(
                     'Die TSE meldet, dass diese Client-ID bisher nicht registriert ist'
                 )
                 self.tse_prepare(adminpuk=conf['adminpuk'],
                                  adminpin=conf['adminpin'])
Beispiel #2
0
 def __init__(self):
     self.master = False
     if not self.__class__._tse:
         log.info('start new TSE controller thread!')
         self.__class__._tse = worm.Worm(clientid=conf['clientid'], time_admin_pin=conf['timeadminpin'])
         self.__class__._lock = Lock()
         self.__class__._stop = Event()
         self.__class__._thread = Thread(target=self.worker)
         self.__class__._thread.start()
         self.master = True
Beispiel #3
0
 def start(self):
     """ Initiate all player and worm states """
     for player in self.players:
         #TODO: make this algorithm better
         pos = (random.randint(0, self.grid_size),
                random.randint(0, self.grid_size))
         player.worm = worm.Worm(
             pos,
             random.choice((worm.EAST, worm.NORTHEAST, worm.NORTHWEST,
                            worm.SOUTHEAST, worm.SOUTHWEST, worm.WEST)))
Beispiel #4
0
def main(team_blue, team_red, language):
    pygame.init()
    pygame.mixer.init()

    health_font = pygame.font.SysFont("monospace", 12)
    name_font = pygame.font.SysFont("monospace", 12)
    team_health_font = pygame.font.SysFont("monospace", 22, bold=True)
    time_font = pygame.font.SysFont("monospace", 30, bold=True)

    screen_x = constants.SCREEN_WIDTH
    screen_y = constants.SCREEN_HEIGHT
    speed = 0
    screen = pygame.display.set_mode((screen_x, screen_y))
    pygame.display.set_caption("Ormstunga")
    won = False
    RedWin = False
    BlueWin = False
    # Starting weapon of choice
    g_menu = GunMenu.GunMenu
    img = g_menu.BAZOOKA

    player_list = []

    for p in team_blue:
        player = worm.Worm(language)
        player.team = 'BLUE'
        player.name = p
        player_list.insert(random.randint(0, len(team_blue)), player)

    for p in team_red:
        player = worm.Worm(language)
        player.team = 'RED'
        player.name = p
        player_list.insert(random.randint(0, len(team_red)), player)
    red_team = Team.Team([x for x in player_list if x.team == 'RED'])
    blue_team = Team.Team([x for x in player_list if x.team == 'BLUE'])

    red_team_logo = pygame.transform.scale(
        pygame.image.load('Pics/Menu/team_red_logo.png'), (100, 24))
    blue_team_logo = pygame.transform.scale(
        pygame.image.load('Pics/Menu/team_blue_logo.png'), (100, 24))
    red_team_wins = pygame.transform.scale(pygame.image.load('Pics/rtw.png'),
                                           (500, 200))
    blue_team_wins = pygame.transform.scale(pygame.image.load('Pics/btw.png'),
                                            (500, 200))
    play_again = pygame.transform.scale(
        pygame.image.load('Pics/play_again.png'), (155, 47))

    active_sprite_list = pygame.sprite.Group()
    #background = pygame.Surface(screen.get_size())
    current_level = LandScape.LandScape01(player_list)
    for man in player_list:
        if man.team == 'BLUE':
            man.rect.x = random.randint(1100, 1200)
        else:
            man.rect.x = random.randint(250, 400)
        man.rect.y = 50 - man.rect.height
        man.level = current_level
        man.aim = aim.Aim(man)
        active_sprite_list.add(man)
        active_sprite_list.add(man.aim)

    clock = pygame.time.Clock()

    team_played = True

    red_team_cycle = itertools.cycle(red_team.members)
    blue_team_cycle = itertools.cycle(blue_team.members)

    player = get_player(red_team_cycle, blue_team_cycle, team_played)
    player.is_playing = True
    player.start_time = pygame.time.get_ticks()
    team_played = not team_played
    PlayerDel = False

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

        for RedWorm in red_team.members:
            if RedWorm.life <= 0 and player_list != []:
                player_list.remove(RedWorm)
                RedWorm.kill()
                RedWorm.aim.kill()
                PlayerDel = True

        for BlueWorm in blue_team.members:
            if BlueWorm.life <= 0 and player_list != []:
                player_list.remove(BlueWorm)
                BlueWorm.kill()
                BlueWorm.aim.kill()
                PlayerDel = True

        if PlayerDel:
            pl_team = player.team
            if pl_team == 'BLUE':
                blue_team.update([x for x in player_list if x.team == 'BLUE'])
                blue_team_cycle = itertools.cycle(blue_team.members)
                team_played = True
            else:
                red_team.update([x for x in player_list if x.team == 'RED'])
                red_team_cycle = itertools.cycle(red_team.members)
                team_played = False
            player = get_player(red_team_cycle, blue_team_cycle, team_played)
            player.is_playing = True
            team_played = not team_played
            player.start_time = pygame.time.get_ticks()
            PlayerDel = False

        active_sprite_list.update()
        current_level.update()
        current_level.draw(screen)
        active_sprite_list.draw(screen)

        time = time_font.render(str(int(player.time)), 2, (255, 255, 0))
        screen.blit(time, (20, 680))

        red_team_health = team_health_font.render(str(red_team.team_health), 2,
                                                  (255, 255, 255))
        blue_team_health = team_health_font.render(str(blue_team.team_health),
                                                   2, (255, 255, 255))

        screen.blit(red_team_health, ((screen_x / 2) - 30, 30))
        screen.blit(blue_team_health, ((screen_x / 2) + 30, 30))

        screen.blit(red_team_logo, ((screen_x / 2) - 140, 30))
        screen.blit(blue_team_logo, ((screen_x / 2) + 78, 30))

        for players in player_list:
            if players.is_playing:
                pn = name_font.render(str(players.name), 2, (255, 255, 255))
                screen.blit(pn, (players.rect.x, players.rect.y - 40))
            else:
                if players.team == 'BLUE':
                    pn = name_font.render(str(players.name), 2, (0, 0, 255))
                    screen.blit(pn, (players.rect.x, players.rect.y - 40))
                else:
                    pn = name_font.render(str(players.name), 2, (255, 0, 0))
                    screen.blit(pn, (players.rect.x, players.rect.y - 40))

            health = health_font.render(str(players.life), 2, (255, 255, 255))
            screen.blit(health, (players.rect.x, players.rect.y - 20))
        if not won:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.go_left()
                if event.key == pygame.K_RIGHT:
                    player.go_right()
                if event.key == pygame.K_SPACE:
                    player.jump()
                if event.key == pygame.K_UP:
                    player.aim.go_up()
                if event.key == pygame.K_DOWN:
                    player.aim.go_down()
                if event.key == pygame.K_1:
                    img = g_menu.BAZOOKA
                    player.current_gun = g_menu.BAZOOKA
                if event.key == pygame.K_2:
                    img = g_menu.GRENADE
                    player.current_gun = g_menu.GRENADE
                if event.key == pygame.K_3:
                    img = g_menu.HOLYBOMB
                    player.current_gun = g_menu.HOLYBOMB
                # shoot on keypad 0 down
                if event.key == pygame.K_KP0:
                    red_team.update(
                        [x for x in player_list if x.team == 'RED'])
                    blue_team.update(
                        [x for x in player_list if x.team == 'BLUE'])
                    b = False
                    if len(red_team.members) > 0 and len(
                            blue_team.members) > 0:
                        keys = pygame.key.get_pressed()
                        f = True
                        while keys[pygame.K_KP0] and f:
                            speed += 0.00005
                            for e in pygame.event.get():
                                if e.type == pygame.KEYUP:
                                    player.bullet = Bullets.Bullet(
                                        active_sprite_list, player, language)
                                    player.bullet.shoot(speed)
                                    active_sprite_list.add(player.bullet)
                                    player.is_playing = False
                                    player = get_player(
                                        red_team_cycle, blue_team_cycle,
                                        team_played)
                                    player.is_playing = True
                                    team_played = not team_played
                                    player.start_time = pygame.time.get_ticks()
                                    f = False
                                    speed = 0
                                    break
                    else:
                        if len(blue_team.members) == 0:
                            won = True
                            RedWin = True
                        if len(red_team.members) == 0:
                            won = True
                            BlueWin = True
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.change_x < 0:
                    player.stop()
                if event.key == pygame.K_RIGHT and player.change_x > 0:
                    player.stop()

            # Stop if player time is over
            player.time = turntime - (pygame.time.get_ticks() -
                                      player.start_time) / 1000
            if player.time <= 0:
                player.is_playing = False
                player = get_player(red_team_cycle, blue_team_cycle,
                                    team_played)
                team_played = not team_played
                player.is_playing = True
                player.start_time = pygame.time.get_ticks()

            # Dying
            if int(player.rect.y) > screen_y and player_list != []:
                player_list.remove(player)
                player.kill
                player.aim.kill
                pl_team = player.team
                if not won:
                    if pl_team == 'BLUE':
                        blue_team.update(
                            [x for x in player_list if x.team == 'BLUE'])
                        blue_team_cycle = itertools.cycle(blue_team.members)
                        team_played = True
                    else:
                        red_team.update(
                            [x for x in player_list if x.team == 'RED'])
                        red_team_cycle = itertools.cycle(red_team.members)
                        team_played = False
                    player = get_player(red_team_cycle, blue_team_cycle,
                                        team_played)
                    player.is_playing = True
                    team_played = not team_played
                    player.start_time = pygame.time.get_ticks()

            if len(blue_team.members) == 0:
                won = True
                RedWin = True
            if len(red_team.members) == 0:
                won = True
                BlueWin = True

        mouse = pygame.mouse.get_pos()

        if RedWin:
            screen.blit(red_team_wins, ((screen_x / 2) - 250, 200))
            screen.blit(play_again, ((screen_x / 2) - 77.5, 400))
            if (screen_x / 2) - 77.5 < mouse[0] < (
                    screen_x / 2) + 77.5 and 400 < mouse[1] < 447:
                if pygame.mouse.get_pressed()[0]:
                    GameMenu.game_menu()
        elif BlueWin:
            screen.blit(blue_team_wins, ((screen_x / 2) - 250, 200))
            screen.blit(play_again, ((screen_x / 2) - 77.5, 400))
            if (screen_x / 2) - 77.5 < mouse[0] < (
                    screen_x / 2) + 77.5 and 400 < mouse[1] < 447:
                if pygame.mouse.get_pressed()[0]:
                    GameMenu.game_menu()

        screen.blit(img.value, (screen_x - img.value.get_width(),
                                screen_y - img.value.get_height()))

        pygame.display.flip()

        clock.tick(60)
Beispiel #5
0
    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()
Beispiel #6
0
    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)
Beispiel #7
0
import config
import sys
import os.path
from encodings.base64_codec import base64_encode

sys.path.insert(
    0,
    os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                 'lib'))

import worm

TSE = worm.Worm(clientid=config.clientId, time_admin_pin=config.PIN_TIME_ADMIN)

if len(sys.argv) > 1 and sys.argv[1] == '--info':
    print('Kapazität:', TSE.info.capacity)
    print('Development-Firmware? =>', TSE.info.isDevelopmentFirmware)
    print('Benutzter Speicher:', TSE.info.size)

    print('Gültige Zeit gesetzt? =>', TSE.info.hasValidTime)
    print('Selbsttest gemacht? =>', TSE.info.hasPassedSelfTest)
    print('Ist das CTSS-Interface aktiv? =>', TSE.info.isCtssInterfaceActive)
    print('Initialisierungs-Status:', TSE.info.initializationState)

    print('Transaktion läuft grade? =>', TSE.info.isDataImportInProgress)

    print('PUK schon gesetzt? =>', TSE.info.hasChangedPuk)
    print('Admin-PIN schon gesetzt? =>', TSE.info.hasChangedAdminPin)
    print('Time-Admin-PIN schon gesetzt? =>', TSE.info.hasChangedTimeAdminPin)

    print('Zeit bis zum nächsten Selbsttest:', TSE.info.timeUntilNextSelfTest)
Beispiel #8
0
    def run(self):
        HOST = self.ip

        pygame.init()

        display = pygame.display.set_mode((500, 500))

        w = worm.Worm(display, 400, 400, 25)
        w.lag = lag
        w.head_r = 4
        w.dir_x = 0 * w.lag
        w.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
        w.color = 0, 0, 255

        moket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        moket.connect((HOST, 50001))
        moket.send(w.player_name)
        print "connected"
        sss = moket.recv(1024)

        cotlet = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        cotlet.connect((HOST, 50002))
        print "connected"

        PORT = 50009

        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))
        print "connected"

        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(sss, 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(sss + "  WIN!", True,
                                         color_s_porrang_rect_score)
        text_pause = font_h3.render("PAUSE", True, color_text)
        text_start = font_h3.render("please wait", True, color_text)
        x = (width / 2) / 2
        max_score = 10
        c = 0
        pygame.display.set_caption("NET SNAKE")
        e = 80
        while True:
            c = -5
            s.send(str(w.body_list))
            data = s.recv(1024)

            serverbody_list = datatolist(data)
            display.fill((0, 0, 0))

            ghormexoy = cotlet.recv(1024)

            gxoy = xoyyab(ghormexoy)
            print gxoy

            #text

            display.blit(text_client, (width - x - 50, 100))
            display.blit(text_servername, (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, gxoy[2] * 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, gxoy[4] * max_score, 6.5))

            state = gxoy[6]

            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(gxoy[3]):
                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(gxoy[5]):
                c += 10
                if gxoy[5] <= 7:
                    self.draw_joon(display, color_s_porrang_rect_score,
                                   width - x - 50 + c, y_zalamzimbo - 5)
            c = -5

            for i in serverbody_list:

                pygame.draw.circle(display, (255, 0, 0), (i[0], i[1]), 4)

            if state == 2:
                w.draw()
                w.move()

            if state == 1:
                display.blit(text_start, (width / 2 - 140, height / 2 - 50))

            if state == 3:
                display.blit(text_pause, (width / 2 - 70, height / 2 - 50))

            pygame.draw.circle(display, (255, 255, 255), (gxoy[0], gxoy[1]), 4)

            if gxoy[2] == max_score or gxoy[5] == 0:
                display.blit(text_server_win,
                             (width / 2 - 120, height / 2 - e))
            if gxoy[4] == max_score or gxoy[3] == 0:
                display.blit(text_client_win,
                             (width / 2 - 150, height / 2 - e))

            for event in pygame.event.get():
                if event.type == QUIT:

                    s.close()
                    # s2.close()

                    pygame.quit()

                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if state == 2:
                        w.analize(event)

            pygame.display.update()
            time.sleep(0.001)
Beispiel #9
0
import pyglet
import worm
import obstacle
import collisionSolver

from pyglet.window import key

score = 0

window = pyglet.window.Window(800, 600)

main_batch = pyglet.graphics.Batch()

obstacles = set()
player = worm.Worm(window, 100, 100, main_batch)
collision_solver = collisionSolver.CollissionSolver(player, obstacles)


def player_out_boundaries():
    return player.x_position < 0 or player.x_position > window.width - player.width or \
           player.y_position < 0 or player.y_position > window.height - player.height


def init():
    new_obstacle = obstacle.Obstacle(window, x=100, y=100, batch=main_batch)
    obstacles.add(new_obstacle)
    collision_solver.add_obstacles(obstacles)


@window.event
def on_draw():
Beispiel #10
0
    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()