def check_mx_range1(mx, my):
switch1 = 0
while switch1==0:
for mx_range1 in mousedata.mx_ranges1:
if mx_range1[0] < mx < mx_range1[1] and 890 < my < 920 and switch1==0:
switch1+=1
a11=0
b11=0
a11=str(mx_range1[2])
b11=str(mx_range1[3])
mousedata.dic_n[a11]+=1
#print(mx_range1)
#print(a11)
#print(b11)
print(mousedata.dic_n[a11])
return True
if False:
break
return False
Это может быть сложно сформулировать ... Хорошо, поэтому я делаю "пьяную политику", поэтому эти функции вызывают массив диапазонов и помещают их в словарь.
Словари следующие:
dic_s={'101': [868.0, 905.0], '102': [827.0, 905.0], '103': [785.0, 905.0], '104': [743.0, 905.0], '105': [701.0, 905.0], '106': [659.0, 905.0], '107': [617.0, 905.0], '108': [575.0, 905.0], '109': [533.0, 905.0], '110': [491.0, 905.0], '111': [449.0, 905.0], '112': [407.0, 905.0], '113': [365.0, 905.0], '114': [323.0, 905.0], '115': [281.0, 905.0], '116': [239.0, 905.0], '117': [197.0, 905.0], '118': [155.0, 905.0]}
dic_n={'1': 0, '2': 0, '3': 0, '4': 0, '5': 0, '6': 0, '7': 0, '8': 0, '9': 0, '10': 0, '11': 0, '12': 0, '13': 0, '14': 0, '15': 0, '16': 0, '17': 0, '18': 0, '19': 0, '20': 0, '21': 0, '22': 0, '23': 0, '24': 0, '25': 0, '26': 0, '27': 0, '28': 0, '29': 0, '30': 0, '31': 0, '32': 0, '33': 0, '34': 0, '35': 0, '36': 0, '37': 0, '38': 0, '39': 0, '40': 0, '41': 0, '42': 0, '43': 0, '44': 0, '45': 0, '46': 0, '47': 0, '48': 0, '49': 0, '50': 0, '51': 0, '52': 0, '53': 0, '54': 0, '55': 0, '56': 0, '57': 0, '58': 0, '59': 0, '60': 0, '61': 0, '62': 0, '63': 0, '64': 0, '65': 0, '66': 0, '67': 0, '68': 0, '69': 0, '70': 0, '71': 0, '72': 0}
dic_s относится к расположению 18 поверхностей, хотя на самом деле должно быть 72, а dic_n относится к числу нажатий на эту область.
Теперь основной код, который запускает счетчик чисел:
def run_game():
pygame.init()
#Font information
gamefont=pygame.freetype.Font("OpenSans-Bold.ttf",12)
#Number in font mx and my posion of mouse curser
gamestage=0
n=0
text_surface, rect = gamefont.render("0",(4, 8, 18))
text_surface1, rect = gamefont.render("0",(4, 8, 18))
#Main screen display options
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
pygame.display.set_caption("Drunkopoly")
b=screen.blit(board,(0,0))
#Beggining of the main game loop
while True:
#keyboard and mouse events
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if gamestage == 0 and gamestage <= 1:
gamestage += 1
mx, my =pygame.mouse.get_pos()
print(mx,my)
mousedata.check_mx_range1(mx,my)
pygame.display.flip()
if event.type == pygame.MOUSEBUTTONUP:
if gamestage != 0:
gamestage = 0
screen.blit(text_surface, (mousedata.dic_s['101']))
pygame.display.flip()
run_game()
Значит, мне нужно 72 поверхности с числами. Как я могу подойти к этому? Похоже, что Pygame может не справиться с 72 изображениями, брошенными в него.
имейте в виду, что это моя первая неделя, хотя я трачу 12 часов в день на программирование, хаха. Так что, если часть кода плохая, дайте мне знать, и есть вещи, которые я могу изменить как по стилю, так и по подходу, также дайте мне знать, общий совет также приветствуется.
Мне удалось заставить счетчик работать на одного, но для всех них это может быть слишком сложно.
dic_n['1']
text_surface, rect = gamefont.render(n,(4, 8, 18))
screen.blit(board,(0,0))
pygame.display.flip()