如果用户在另一个文件中输入 0,如何在 pygame 中删除一个框?



好的,所以我对编码很陌生,这是我的第一个项目。对于心理学研究,我必须创建一个游戏板(看起来像一个危险板(,每个框中都有不同的提示(即想要孩子,猫的态度(。我基本上创建了游戏,以便一对夫妇的两个成员在文件 1 中完成一份问卷,其中使用文件写入文件 2 来记录响应。最后,在游戏板文件(文件 3(中,他们可以选择单击一个框以查看他们的合作伙伴对特定问题的回答。但是,当个人在文件 1 中填写问卷时,他们可以选择输入"0",表示他们不愿意回答。有没有办法对游戏板进行编程,以便如果有人不想回答文件 1 中的问题,该框会在文件 3 中消失?对不起,如果这令人困惑!这是我的文件 3 的代码。文件 1 只是从问卷调查者那里获取输入并将其写入文件 2。文件 2 只是这些响应的列表。

import pygame, sys, linecache, time
from pygame.locals import*
pygame init()
start_time = time.time()
black = (0, 0, 0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
darkBlue = (0,0,128)
white = (255,255,255)
pink = (255,200,200)
screen = pygame.display.set_mode((1400, 600)
pygame.display.set_caption("Getting to know you project")
screen.fill(black)
while True:
for event in pygame.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
end = time.time() - start
print("Selection took you " + str(end) + "seconds. n")
pygame.draw.line(screen, green, [0, 0], [1400, 0], 5)
pygame.draw.line(screen, green, [0, 200], [1400, 200], 5)
pygame.draw.line(screen, green, [0, 400], [1400, 400], 5)
pygame.draw.line(screen, green, [0, 600], [1400, 600], 5)
pygame.draw.line(screen, green, [0, 0], [1200, 0], 5)
pygame.draw.line(screen, green, [200, 0], [200, 600], 5)
pygame.draw.line(screen, green, [400, 0], [400, 600], 5)
pygame.draw.line(screen, green, [600, 0], [600, 600], 5)
pygame.draw.line(screen, green, [800, 0], [800, 600], 5)
pygame.draw.line(screen, green, [1200, 0], [1200, 600], 5)
pygame.draw.line(screen, green, [0, 0], [0, 600], 5)
pygame.draw.line(screen, green, [1000, 0], [1000, 600], 5)
pygame.draw.line(screen, green, [1400, 0], [1400, 600], 5)
sys_font = pygame.font.SysFont("None", 30)
rendered = sys_font.render('Wants Marriage', 0, (80, 200, 80))
screen.blit(rendered, (20, 40))
rendered2 = sys_font.render('Religiosity', 0, (80, 200, 80))
screen.blit(rendered2, (40, 240))
rendered3 = sys_font.render('Political', 0, (80, 200, 80))
screen.blit(rendered3, (55, 440))
rendered4 = sys_font.render('Wants Children', 0, (80, 200, 80))
screen.blit(rendered4, (230, 40))
rendered5 = sys_font.render('Likely to Move', 0, (80, 200, 80))
screen.blit(rendered5, (230, 240))
rendered6 = sys_font.render('Away', 0, (80, 200, 80))
screen.blit(rendered6, (265, 260))
rendered7 = sys_font.render('Urban/Rural', 0, (80, 200, 80))
screen.blit(rendered7, (240, 440))
rendered8 = sys_font.render('Preferences', 0, (80, 200, 80))
screen.blit(rendered8, (240, 460))
rendered9 = sys_font.render('Importance of Sex', 0, (80, 200, 80))
screen.blit(rendered9, (420, 40))
rendered10 = sys_font.render('Ideal Sex', 0, (80, 200, 80))
screen.blit(rendered10, (450, 240))
rendered11 = sys_font.render('Frequency', 0, (80, 200, 80))
screen.blit(rendered11, (440, 260))
rendered12 = sys_font.render('Importance of', 0, (80, 200, 80))
screen.blit(rendered12, (435, 440))
rendered14 = sys_font.render('Orientation', 0, (80, 200, 80))
screen.blit(rendered14, (30, 460))
rendered15 = sys_font.render('Alcohol', 0, (80, 200, 80))
screen.blit(rendered15, (665, 40))
rendered16 = sys_font.render('Frequency', 0, (80, 200, 80))
screen.blit(rendered16, (650, 60))
rendered17 = sys_font.render('Hobbies', 0, (80, 200, 80))
screen.blit(rendered17, (660, 240))
rendered18 = sys_font.render('Marijuana', 0, (80, 200, 80))
screen.blit(rendered18, (650, 440))
rendered19 = sys_font.render('Frequency', 0, (80, 200, 80))
screen.blit(rendered19, (645, 460))
rendered20 = sys_font.render('Novelty', 0, (80, 200, 80))
screen.blit(rendered20, (860, 40))
rendered21 = sys_font.render('Seeking', 0, (80, 200, 80))
screen.blit(rendered21, (860, 60))
rendered22 = sys_font.render('Activity Level', 0, (80, 200, 80))
screen.blit(rendered22, (835, 240))
rendered23 = sys_font.render('Jealousy', 0, (80, 200, 80))
screen.blit(rendered23, (850, 440))
rendered24 = sys_font.render('Communication', 0, (80, 200, 80))
screen.blit(rendered24, (1030, 40))
rendered25 = sys_font.render('Financial Style', 0, (80, 200, 80))
screen.blit(rendered25, (1030, 240))
rendered26 = sys_font.render('Division of', 0, (80, 200, 80))
screen.blit(rendered26, (1040, 440))
rendered27 = sys_font.render('Household Labor', 0, (80, 200, 80))
screen.blit(rendered27, (1020, 460))
rendered28 = sys_font.render('Home Tidiness', 0, (80, 200, 80))
screen.blit(rendered28, (1230, 40))
rendered29 = sys_font.render('Cat Attitudes', 0, (80, 200, 80))
screen.blit(rendered29, (1230, 240))
rendered30 = sys_font.render('Dog Attitudes', 0, (80, 200, 80))
screen.blit(rendered30, (1230, 440))
Rectplace = pygame.draw.rect(screen, (255, 0, 0), (60, 100, 60, 60))
Rect2 = pygame.draw.rect(screen, (255, 0, 0), (60, 300, 60, 60))
Rect3 = pygame.draw.rect(screen, (255, 0, 0), (60, 500, 60, 60))
Rect4 = pygame.draw.rect(screen, (255, 0, 0), (280, 100, 60, 60))
Rect5 = pygame.draw.rect(screen, (255, 0, 0), (280, 300, 60, 60))
Rect6 = pygame.draw.rect(screen, (255, 0, 0), (280, 500, 60, 60))
Rect7 = pygame.draw.rect(screen, (255, 0, 0), (480, 100, 60, 60))
Rect8 = pygame.draw.rect(screen, (255, 0, 0), (480, 300, 60, 60))
Rect9 = pygame.draw.rect(screen, (255, 0, 0), (480, 500, 60, 60))
Rect10 = pygame.draw.rect(screen, (255, 0, 0), (680, 100, 60, 60))
Rect11 = pygame.draw.rect(screen, (255, 0, 0), (680, 300, 60, 60))
Rect12 = pygame.draw.rect(screen, (255, 0, 0), (680, 500, 60, 60))
Rect13 = pygame.draw.rect(screen, (255, 0, 0), (880, 100, 60, 60))
Rect14 = pygame.draw.rect(screen, (255, 0, 0), (880, 300, 60, 60))
Rect15 = pygame.draw.rect(screen, (255, 0, 0), (880, 500, 60, 60))
Rect16 = pygame.draw.rect(screen, (255, 0, 0), (1080, 100, 60, 60))
Rect17 = pygame.draw.rect(screen, (255, 0, 0), (1080, 300, 60, 60))
Rect18 = pygame.draw.rect(screen, (255, 0, 0), (1080, 500, 60, 60))
Rect19 = pygame.draw.rect(screen, (255, 0, 0), (1280, 100, 60, 60))
Rect20 = pygame.draw.rect(screen, (255, 0, 0), (1280, 300, 60, 60))
Rect21 = pygame.draw.rect(screen, (255, 0, 0), (1280, 500, 60, 60))
pygame.display.update()
pos = pygame.mouse.get_pos()
pressed1, pressed2, pressed3 = pygame.mouse.get_pressed()
if Rectplace.collidepoint(pos) and pressed1:
marriage = linecache.getline("Responses.txt", 7)
print("To the question, "Do you plan on getting married someday?"n 1 = Definitely not n 2 = Probably not n 3 = Maybe/Unsure n 4 = Probably n 5 = Definitely,n your partner responded:  ")
print(marriage)
input("How important to you is your partner's response to this question?: ")
if Rect2.collidepoint(pos) and pressed1:
religion = linecache.getline("Responses.txt", 10)
print("To the question, "What is your religious affiliation" n Buddhist n Catholic n Hindu n Muslim n Protestant n Latter-day Saint n Not Religious/Atheist/Agnostic n Other n, your partner responded:  ")
print(religion)
if Rect3.collidepoint(pos) and pressed1:
print("To the question, "On a scale from 1 (Very Conservative) to 7 (Very Liberal),what is your political orientation?", your parter responded:  ")
politics = linecache.getline("Responses.txt", 11)
print(politics)
if Rect4.collidepoint(pos) and pressed1:
children = linecache.getline("Responses.txt", 8)
print(children)
if Rect5.collidepoint(pos) and pressed1:
move = linecache.getline("Responses.txt", 9)
print(move)

通过对整个循环使用"if"函数,这很容易解决。此外,您应该自动执行设置变量和调用输入的部分

会是这样的

for n in range(0,s):
if returned_value != '0':
input value
rendered[n] = sys_font.render('text', 0, (80, 200, 80))
screen.blit(rendered, (x, y))

相关内容

  • 没有找到相关文章

最新更新