2017-05-17 6 views
0

다른 훈련 예제 코드와 코드를 비교해 비교하고 모든 것이 일치합니다. 여기에 내 문제가 있습니다 : 건강 바가 있고 피해를 입으면 막대가 줄어 듭니다.파이썬 3 ASCII 코드 219 문제

문제는 내 코드에서 술집이 놓여 있지 않은 상태에서 파이프 라인을 사용하면 항상 동적으로 움직입니다. 내가 사용할 때/파이프 바 항상 넣어두고 아무 문제. 나는 파이어 암 (Pycharm)을 사용하여 터미널 도구에 아스키 코드 219가 마음에 들지 않는다고 생각하고있다. 포럼을 읽는 것이 중요하다면 도구는 UTF-8로 설정된다. 아래의 예는 올바르게 형식화하지 않을 수도 있지만 맨 위 부분에 | /를 사용하면 █을 사용할 때 바뀌고 하단 부분은 괜찮습니다.

enter image description here

    ______________________________   __________ 
CARLOS: 2210/3260 |■■■■■■■■■■■■■■■■■  | 132/132 |//////////|  

         __________________     __________ 
CARLOS: 2219/3260 |///////////////// |  132/132 |//////////| 

코드 :

def get_stats(self): 
    hp_bar = "" 
    bar_ticks = (self.hp/self.maxhp) * 100/4 

    mp_bar = "" 
    mp_ticks = (self.mp/self.maxmp) * 100/10 

    while bar_ticks > 0: 
     hp_bar += '█' 
     bar_ticks -= 1 

    #num_spaces_needed = (100/4) - len(hp_bar) 
    #str_spaces_needed = "" 
    #while num_spaces_needed > 0: 
     #str_spaces_needed += " " 
     #num_spaces_needed -= 1 

    while len(hp_bar) < 25: 
     hp_bar += " " 

    while mp_ticks > 0: 
     mp_bar += "/" 
     mp_ticks -= 1 

    while len(mp_bar) < 10: 
     mp_bar += " " 

    hp_string = str(self.hp) + "/" + str(self.maxhp) 
    current_hp = "" 

    if len(hp_string) < 9: 
     decreased = 9 - len(hp_string) 

     while decreased > 0: 
      current_hp += " " 
      decreased -= 1 

     current_hp += hp_string 
    else: 
     current_hp = hp_string 

    mp_string = str(self.mp) + "/" + str(self.maxmp) 
    current_mp = "" 

    if len(mp_string) < 7: 
     decreased = 7 - len(mp_string) 
     while decreased > 0: 
      current_mp += " " 
      decreased -= 1 

     current_mp += mp_string 

    else: 
     current_mp = mp_string 

    print("      _______________________________    __________ ") 
    print(bcolors.BOLD + self.name + " " + 
      current_hp + " |" + bcolors.BAR + hp_bar + bcolors.ENDC + "| " + 
      current_mp + " |" + bcolors.OKBLUE + mp_bar + bcolors.ENDC + "| ") 
+2

가 [mcve] 실제 코드의주십시오. – jonrsharpe

+2

* ascii * 219 ??? 무슨 소리 야? –

+1

** 코드에 이미지를 첨부하지 마십시오. 항상 형식이 지정된 텍스트로 코드를 게시하십시오. btw ** –

답변

-1

이 스크립트의 상단에 다음과 같은 시도 :

import sys 

reload(sys) 
sys.setdefaultencoding('utf8') 
+0

import sys가 작동하지 않는 것 같습니다. – Carlos