日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python 實(shí)現(xiàn)"神經(jīng)衰弱"翻牌游戲

瀏覽:277日期:2022-07-06 08:11:10

'神經(jīng)衰弱'翻牌游戲考察玩家的記憶力,游戲的開(kāi)頭會(huì)短時(shí)間給你看一小部分牌的圖案,當(dāng)玩家翻開(kāi)兩張相同圖案牌的時(shí)候,會(huì)消除,和你的小伙伴比一比誰(shuí)用時(shí)更短把。

源代碼

import random, pygame, sysfrom pygame.locals import *FPS = 30 # frames per second, the general speed of the programWINDOWWIDTH = 640 # size of window’s width in pixelsWINDOWHEIGHT = 480 # size of windows’ height in pixelsREVEALSPEED = 8 # speed boxes’ sliding reveals and coversBOXSIZE = 40 # size of box height & width in pixelsGAPSIZE = 10 # size of gap between boxes in pixelsBOARDWIDTH = 10 # number of columns of iconsBOARDHEIGHT = 7 # number of rows of iconsassert (BOARDWIDTH * BOARDHEIGHT) % 2 == 0, ’Board needs to have an even number of boxes for pairs of matches.’XMARGIN = int((WINDOWWIDTH - (BOARDWIDTH * (BOXSIZE + GAPSIZE))) / 2)YMARGIN = int((WINDOWHEIGHT - (BOARDHEIGHT * (BOXSIZE + GAPSIZE))) / 2)# R G BGRAY = (100, 100, 100)NAVYBLUE = ( 60, 60, 100)WHITE = (255, 255, 255)RED = (255, 0, 0)GREEN = ( 0, 255, 0)BLUE = ( 0, 0, 255)YELLOW = (255, 255, 0)ORANGE = (255, 128, 0)PURPLE = (255, 0, 255)CYAN = ( 0, 255, 255)BGCOLOR = NAVYBLUELIGHTBGCOLOR = GRAYBOXCOLOR = WHITEHIGHLIGHTCOLOR = BLUEDONUT = ’donut’SQUARE = ’square’DIAMOND = ’diamond’LINES = ’lines’OVAL = ’oval’ALLCOLORS = (RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, CYAN)ALLSHAPES = (DONUT, SQUARE, DIAMOND, LINES, OVAL)assert len(ALLCOLORS) * len(ALLSHAPES) * 2 >= BOARDWIDTH * BOARDHEIGHT, 'Board is too big for the number of shapes/colors defined.'def main(): global FPSCLOCK, DISPLAYSURF pygame.init() FPSCLOCK = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) mousex = 0 # used to store x coordinate of mouse event mousey = 0 # used to store y coordinate of mouse event pygame.display.set_caption(’Memory Game’) mainBoard = getRandomizedBoard() revealedBoxes = generateRevealedBoxesData(False) firstSelection = None # stores the (x, y) of the first box clicked. DISPLAYSURF.fill(BGCOLOR) startGameAnimation(mainBoard) while True: # main game loop mouseClicked = False DISPLAYSURF.fill(BGCOLOR) # drawing the window drawBoard(mainBoard, revealedBoxes) for event in pygame.event.get(): # event handling loop if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):pygame.quit()sys.exit() elif event.type == MOUSEMOTION:mousex, mousey = event.pos elif event.type == MOUSEBUTTONUP:mousex, mousey = event.posmouseClicked = True boxx, boxy = getBoxAtPixel(mousex, mousey) if boxx != None and boxy != None: # The mouse is currently over a box. if not revealedBoxes[boxx][boxy]:drawHighlightBox(boxx, boxy) if not revealedBoxes[boxx][boxy] and mouseClicked:revealBoxesAnimation(mainBoard, [(boxx, boxy)])revealedBoxes[boxx][boxy] = True # set the box as 'revealed'if firstSelection == None: # the current box was the first box clicked firstSelection = (boxx, boxy)else: # the current box was the second box clicked # Check if there is a match between the two icons. icon1shape, icon1color = getShapeAndColor(mainBoard, firstSelection[0], firstSelection[1]) icon2shape, icon2color = getShapeAndColor(mainBoard, boxx, boxy) if icon1shape != icon2shape or icon1color != icon2color: # Icons don’t match. Re-cover up both selections. pygame.time.wait(1000) # 1000 milliseconds = 1 sec coverBoxesAnimation(mainBoard, [(firstSelection[0], firstSelection[1]), (boxx, boxy)]) revealedBoxes[firstSelection[0]][firstSelection[1]] = False revealedBoxes[boxx][boxy] = False elif hasWon(revealedBoxes): # check if all pairs found gameWonAnimation(mainBoard) pygame.time.wait(2000) # Reset the board mainBoard = getRandomizedBoard() revealedBoxes = generateRevealedBoxesData(False) # Show the fully unrevealed board for a second. drawBoard(mainBoard, revealedBoxes) pygame.display.update() pygame.time.wait(1000) # Replay the start game animation. startGameAnimation(mainBoard) firstSelection = None # reset firstSelection variable # Redraw the screen and wait a clock tick. pygame.display.update() FPSCLOCK.tick(FPS)def generateRevealedBoxesData(val): revealedBoxes = [] for i in range(BOARDWIDTH): revealedBoxes.append([val] * BOARDHEIGHT) return revealedBoxesdef getRandomizedBoard(): # Get a list of every possible shape in every possible color. icons = [] for color in ALLCOLORS: for shape in ALLSHAPES: icons.append( (shape, color) ) random.shuffle(icons) # randomize the order of the icons list numIconsUsed = int(BOARDWIDTH * BOARDHEIGHT / 2) # calculate how many icons are needed icons = icons[:numIconsUsed] * 2 # make two of each random.shuffle(icons) # Create the board data structure, with randomly placed icons. board = [] for x in range(BOARDWIDTH): column = [] for y in range(BOARDHEIGHT): column.append(icons[0]) del icons[0] # remove the icons as we assign them board.append(column) return boarddef splitIntoGroupsOf(groupSize, theList): # splits a list into a list of lists, where the inner lists have at # most groupSize number of items. result = [] for i in range(0, len(theList), groupSize): result.append(theList[i:i + groupSize]) return resultdef leftTopCoordsOfBox(boxx, boxy): # Convert board coordinates to pixel coordinates left = boxx * (BOXSIZE + GAPSIZE) + XMARGIN top = boxy * (BOXSIZE + GAPSIZE) + YMARGIN return (left, top)def getBoxAtPixel(x, y): for boxx in range(BOARDWIDTH): for boxy in range(BOARDHEIGHT): left, top = leftTopCoordsOfBox(boxx, boxy) boxRect = pygame.Rect(left, top, BOXSIZE, BOXSIZE) if boxRect.collidepoint(x, y):return (boxx, boxy) return (None, None)def drawIcon(shape, color, boxx, boxy): quarter = int(BOXSIZE * 0.25) # syntactic sugar half = int(BOXSIZE * 0.5) # syntactic sugar left, top = leftTopCoordsOfBox(boxx, boxy) # get pixel coords from board coords # Draw the shapes if shape == DONUT: pygame.draw.circle(DISPLAYSURF, color, (left + half, top + half), half - 5) pygame.draw.circle(DISPLAYSURF, BGCOLOR, (left + half, top + half), quarter - 5) elif shape == SQUARE: pygame.draw.rect(DISPLAYSURF, color, (left + quarter, top + quarter, BOXSIZE - half, BOXSIZE - half)) elif shape == DIAMOND: pygame.draw.polygon(DISPLAYSURF, color, ((left + half, top), (left + BOXSIZE - 1, top + half), (left + half, top + BOXSIZE - 1), (left, top + half))) elif shape == LINES: for i in range(0, BOXSIZE, 4): pygame.draw.line(DISPLAYSURF, color, (left, top + i), (left + i, top)) pygame.draw.line(DISPLAYSURF, color, (left + i, top + BOXSIZE - 1), (left + BOXSIZE - 1, top + i)) elif shape == OVAL: pygame.draw.ellipse(DISPLAYSURF, color, (left, top + quarter, BOXSIZE, half))def getShapeAndColor(board, boxx, boxy): # shape value for x, y spot is stored in board[x][y][0] # color value for x, y spot is stored in board[x][y][1] return board[boxx][boxy][0], board[boxx][boxy][1]def drawBoxCovers(board, boxes, coverage): # Draws boxes being covered/revealed. 'boxes' is a list # of two-item lists, which have the x & y spot of the box. for box in boxes: left, top = leftTopCoordsOfBox(box[0], box[1]) pygame.draw.rect(DISPLAYSURF, BGCOLOR, (left, top, BOXSIZE, BOXSIZE)) shape, color = getShapeAndColor(board, box[0], box[1]) drawIcon(shape, color, box[0], box[1]) if coverage > 0: # only draw the cover if there is an coverage pygame.draw.rect(DISPLAYSURF, BOXCOLOR, (left, top, coverage, BOXSIZE)) pygame.display.update() FPSCLOCK.tick(FPS)def revealBoxesAnimation(board, boxesToReveal): # Do the 'box reveal' animation. for coverage in range(BOXSIZE, (-REVEALSPEED) - 1, -REVEALSPEED): drawBoxCovers(board, boxesToReveal, coverage)def coverBoxesAnimation(board, boxesToCover): # Do the 'box cover' animation. for coverage in range(0, BOXSIZE + REVEALSPEED, REVEALSPEED): drawBoxCovers(board, boxesToCover, coverage)def drawBoard(board, revealed): # Draws all of the boxes in their covered or revealed state. for boxx in range(BOARDWIDTH): for boxy in range(BOARDHEIGHT): left, top = leftTopCoordsOfBox(boxx, boxy) if not revealed[boxx][boxy]:# Draw a covered box.pygame.draw.rect(DISPLAYSURF, BOXCOLOR, (left, top, BOXSIZE, BOXSIZE)) else:# Draw the (revealed) icon.shape, color = getShapeAndColor(board, boxx, boxy)drawIcon(shape, color, boxx, boxy)def drawHighlightBox(boxx, boxy): left, top = leftTopCoordsOfBox(boxx, boxy) pygame.draw.rect(DISPLAYSURF, HIGHLIGHTCOLOR, (left - 5, top - 5, BOXSIZE + 10, BOXSIZE + 10), 4)def startGameAnimation(board): # Randomly reveal the boxes 8 at a time. coveredBoxes = generateRevealedBoxesData(False) boxes = [] for x in range(BOARDWIDTH): for y in range(BOARDHEIGHT): boxes.append( (x, y) ) random.shuffle(boxes) boxGroups = splitIntoGroupsOf(8, boxes) drawBoard(board, coveredBoxes) for boxGroup in boxGroups: revealBoxesAnimation(board, boxGroup) coverBoxesAnimation(board, boxGroup)def gameWonAnimation(board): # flash the background color when the player has won coveredBoxes = generateRevealedBoxesData(True) color1 = LIGHTBGCOLOR color2 = BGCOLOR for i in range(13): color1, color2 = color2, color1 # swap colors DISPLAYSURF.fill(color1) drawBoard(board, coveredBoxes) pygame.display.update() pygame.time.wait(300)def hasWon(revealedBoxes): # Returns True if all the boxes have been revealed, otherwise False for i in revealedBoxes: if False in i: return False # return False if any boxes are covered. return Trueif __name__ == ’__main__’: main()

運(yùn)行效果:

python 實(shí)現(xiàn)"神經(jīng)衰弱"翻牌游戲

以上就是python 實(shí)現(xiàn)'神經(jīng)衰弱'翻牌游戲的詳細(xì)內(nèi)容,更多關(guān)于python '神經(jīng)衰弱'翻牌游戲的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩av有码| 亚洲网址在线观看| 精品视频网站| 国内自拍视频一区二区三区| 国产+成+人+亚洲欧洲在线| 超碰在线99| 久久国产日本精品| 中文字幕av一区二区三区四区| 午夜欧美精品| 免费成人性网站| 久久国内精品自在自线400部| 精品亚洲a∨一区二区三区18| 日韩影院二区| 伊人久久大香伊蕉在人线观看热v| 国产日本亚洲| 日韩av二区| 欧美一级专区| 国产精品久久久亚洲一区| 天堂中文av在线资源库| 久久国产精品久久久久久电车 | 国产欧美一区二区精品久久久 | 成人在线超碰| 午夜国产精品视频| 国产一卡不卡| 亚洲特色特黄| 久久国产精品免费一区二区三区| 日韩电影二区| 日韩高清在线不卡| 波多野结衣久久精品| 免费黄网站欧美| 久久av免费| 亚洲女同一区| 久久久久观看| 另类av一区二区| 美女视频免费精品| 亚洲在线网站| 日韩欧美在线中字| 日韩国产在线观看一区| 99久久婷婷| 国产精品久久久亚洲一区| 欧洲毛片在线视频免费观看| 国产精品男女| 免费观看在线色综合| 日韩黄色大片| 国产精品美女在线观看直播| 国产美女精品| caoporn视频在线| 国产色噜噜噜91在线精品| 日韩视频一区| 国产精品字幕| 美女视频网站久久| 日本在线视频一区二区| 久久香蕉国产| 国产在线观看91一区二区三区| 亚洲资源网站| 天堂网在线观看国产精品| 美女国产精品久久久| 亚洲精品激情| 免费久久99精品国产自在现线| 亚洲天堂资源| 精品一区91| 四虎精品永久免费| av成人国产| 亚洲精品97| 日本少妇一区| 正在播放日韩精品| 久久精品国产99国产精品| 日本在线成人| 蜜桃视频一区二区三区| 激情久久中文字幕| 日韩中文在线电影| 国产成人精品999在线观看| 国产亚洲欧美日韩在线观看一区二区 | 中文字幕人成乱码在线观看| 欧美日韩国产一区二区在线观看| 中文字幕av一区二区三区四区| 99热免费精品| 日韩午夜av在线| 精品中文字幕一区二区三区 | 色综合五月天| 国产精品qvod| 国产乱码精品一区二区亚洲| 亚洲精品一二三**| 亚洲狼人精品一区二区三区| 午夜久久tv| 免费污视频在线一区| 久久久久久色| 亚洲日产国产精品| 亚洲一区二区小说| 香蕉久久久久久| 日韩不卡在线观看日韩不卡视频| 日本在线视频一区二区| 日韩av在线免费观看不卡| 日本精品久久| 国产亚洲高清在线观看| 国产日韩欧美中文在线| 日韩有吗在线观看| 视频一区二区三区在线| 亚洲深夜影院| 亚洲综合中文| 久久99伊人| 99视频在线精品国自产拍免费观看| av亚洲在线观看| 鲁大师成人一区二区三区| 久久午夜精品一区二区| 日韩欧美高清一区二区三区| 日韩高清二区| 免费日韩一区二区三区| 成人亚洲一区| 久久国产亚洲精品| 亚洲欧美激情诱惑| 日本亚洲欧美天堂免费| 91精品福利观看| 国产成人精品999在线观看| 成人羞羞视频播放网站| 91久久久久| 蜜臀精品久久久久久蜜臀| 天海翼精品一区二区三区| 久久精品72免费观看| 国产一区二区三区探花| 欧美一级精品| 日本成人手机在线| 福利视频一区| 国产精品呻吟| 欧美黑人做爰爽爽爽| 999精品色在线播放| 中文一区一区三区免费在线观 | 国产精品一区二区三区美女| 电影91久久久| 色天使综合视频| 视频一区二区三区在线| 国产精品永久| 99精品美女| 日韩国产欧美在线播放| 精品国产鲁一鲁****| 波多野结衣一区| 国产无遮挡裸体免费久久| av在线日韩| 色8久久久久| 久久精品高清| 日韩国产一二三区| 久久久水蜜桃av免费网站| 综合精品一区| 国产精品原创| 亚洲欧美激情诱惑| 国产精品伦理久久久久久| 蜜桃久久av| 国产精品久久久久久久免费观看 | 久久麻豆精品| 国产精品免费99久久久| 欧美日韩视频| 国内精品伊人| 亚洲精品在线国产| 久久麻豆精品| 国产精品高清一区二区| 在线精品小视频| 欧美激情视频一区二区三区免费| 激情五月综合| 毛片在线网站| 91伊人久久| 黄色日韩在线| 中文在线а√天堂| 欧美精品三级在线| 国产亚洲一区在线| 日韩中文欧美| 久久免费视频66| 中文久久精品| 国产日韩欧美在线播放不卡| 91精品久久久久久久久久不卡| 日韩福利视频导航| 91久久国产| 精品黄色一级片| 亚洲精品乱码久久久久久蜜桃麻豆| 日韩中文在线电影| 麻豆久久一区| 日韩av成人高清| 鲁大师影院一区二区三区| 电影亚洲精品噜噜在线观看| 国产精品久久久久久模特| 亚洲一区导航| 国产精品免费看| 午夜久久99| 99久精品视频在线观看视频| 日韩精品一区二区三区中文| 国产日韩中文在线中文字幕| 亚洲精品午夜av福利久久蜜桃| 久久不卡日韩美女| 狠狠色综合网| 免费av一区| 色综合www| 捆绑调教日本一区二区三区| 麻豆久久久久久| 国产日韩欧美三级| 91麻豆精品激情在线观看最新 | 亚洲精品麻豆| 视频一区国产视频| 视频一区在线播放| 美女久久一区| 国产视频一区免费看| 88xx成人免费观看视频库|