網(wǎng)上有很多關(guān)于pos機(jī)游戲測(cè)試,python 打地鼠小游戲的知識(shí),也有很多人為大家解答關(guān)于pos機(jī)游戲測(cè)試的問(wèn)題,今天pos機(jī)之家(www.shineka.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來(lái)看下吧!
本文目錄一覽:
pos機(jī)游戲測(cè)試
給大家分享一段AI自動(dòng)生成的代碼(在這個(gè)游戲中,玩家需要在有限時(shí)間內(nèi)打中盡可能多的出現(xiàn)在地圖上的地鼠),有興趣的朋友可以跑一下試試。
注意,在代碼的第20,21行,需要先準(zhǔn)備兩個(gè)png格式的圖片,分別對(duì)應(yīng)地鼠和地洞,并將圖片路徑完整準(zhǔn)確復(fù)制到代碼中。
我測(cè)試的結(jié)果在最下面,確實(shí)可以跑起來(lái)。學(xué)習(xí)代碼還是從案例中學(xué)習(xí)比較快
import pygameimport random# 定義顏色WHITE = (255, 255, 255)BLACK = (0, 0, 0)RED = (255, 0, 0)GREEN = (0, 255, 0)BLUE = (0, 0, 255)# 初始化pygamepygame.init()# 設(shè)置游戲窗口size = (700, 500)screen = pygame.display.set_mode(size)pygame.display.set_caption("打地鼠")# 加載圖片hole_img = pygame.image.load(r"C:\\Users\\gong\\Desktop\\3322.png")#地鼠hammer_img = pygame.image.load(r"C:\\Users\\gong\\Desktop\\2233.png")#地洞# 設(shè)置字體font = pygame.font.SysFont(None, 25)# 設(shè)置時(shí)間clock = pygame.time.Clock()FPS = 60# 定義地鼠class Mole(pygame.sprite.Sprite): def __init__(self, pos): super().__init__() self.image = hole_img self.rect = self.image.get_rect() self.rect.x, self.rect.y = pos self.show_mole = False self.hide_time = 0 self.points = 0 def update(self): if not self.show_mole and pygame.time.get_ticks() - self.hide_time > random.randint(1000, 5000): self.show_mole = True self.image = pygame.transform.scale(hammer_img, (70, 70)) self.image.set_colorkey(WHITE) self.show_time = pygame.time.get_ticks() elif self.show_mole and pygame.time.get_ticks() - self.show_time > 500: self.show_mole = False self.image = hole_img self.hide_time = pygame.time.get_ticks() def hit(self): if self.show_mole: self.show_mole = False self.image = hole_img self.hide_time = pygame.time.get_ticks() self.points += 1# 定義地鼠群all_moles = pygame.sprite.Group()for i in range(10): mole = Mole((random.randint(0, 630), random.randint(0, 430))) all_moles.add(mole)# 游戲循環(huán)done = Falsewhile not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True elif event.type == pygame.MOUSEBUTTONDOWN: for mole in all_moles: if mole.rect.collidepoint(event.pos): mole.hit() screen.fill(GREEN) # 更新地鼠 all_moles.update() # 繪制地鼠 all_moles.draw(screen) # 繪制得分 text = font.render("得分: " + str(sum([mole.points for mole in all_moles])), True, BLACK) screen.blit(text, (10, 10)) # 刷新屏幕 pygame.display.flip() # 控制幀率 clock.tick(FPS)# 退出pygamepygame.quit()
實(shí)際運(yùn)行起來(lái)的效果,供參考
以上就是關(guān)于pos機(jī)游戲測(cè)試,python 打地鼠小游戲的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于pos機(jī)游戲測(cè)試的知識(shí),希望能夠幫助到大家!
