import\u0020random\nimport\u0020turtle\nimport\u0020pgzrun\u0020as\u0020pr\nimport\u0020datetime\nimport\u0020time\nimport\u0020copy\n\nTILE_SIZE\u0020=\u002050\nWIDTH\u0020=\u0020(10\u0020*\u0020TILE_SIZE)\nHEIGHT\u0020=\u0020(10\u0020*\u0020TILE_SIZE)\nTITLE\u0020=\u0020'消灭星星'\n\nstars\u0020=\u0020[]\nfor\u0020i\u0020in\u0020range(10):\n\u0020\u0020row\u0020=\u0020[]\n\u0020\u0020for\u0020j\u0020in\u0020range(10):\n\u0020\u0020\u0020\u0020x\u0020=\u0020random.randint(1,\u00206)\n\u0020\u0020\u0020\u0020row.append(x)\n\u0020\u0020stars.append(row)\n\nTiles\u0020=\u0020[]\n\n\ndef\u0020updateTiles():\n\u0020\u0020Tiles.clear()\n\u0020\u0020for\u0020i\u0020in\u0020range(10):\n\u0020\u0020\u0020\u0020for\u0020j\u0020in\u0020range(10):\n\u0020\u0020\u0020\u0020\u0020\u0020tile\u0020=\u0020Actor('star'+str(stars[i][j]))\n\u0020\u0020\u0020\u0020\u0020\u0020tile.left\u0020=\u0020j\u0020*\u0020TILE_SIZE\n\u0020\u0020\u0020\u0020\u0020\u0020tile.top\u0020=\u0020i\u0020*\u0020TILE_SIZE\n\u0020\u0020\u0020\u0020\u0020\u0020Tiles.append(tile)\n\nupdateTiles()\n\ndef\u0020draw():\n\u0020\u0020screen.clear()\n\u0020\u0020for\u0020tile\u0020in\u0020Tiles:\n\u0020\u0020\u0020\u0020tile.draw()\n\u0020\u0020for\u0020i\u0020in\u0020range(10):\n\u0020\u0020\u0020\u0020for\u0020j\u0020in\u0020range(10):\n\u0020\u0020\u0020\u0020\u0020\u0020screen.draw.text(\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020str(stars[i][j]),\u0020(jTILE_SIZE,\u0020iTILE_SIZE),\u0020fontsize=35,\u0020color='white')\n\ndef\u0020on_mouse_down(pos,\u0020button):\n\u0020\u0020ic\u0020=\u0020int(pos[1]/TILE_SIZE)\n\u0020\u0020jc\u0020=\u0020int(pos[0]/TILE_SIZE)\n\u0020\u0020con\u0020=\u0020{(ic,\u0020jc)}\n\u0020\u0020for\u0020k\u0020in\u0020range(20):\n\u0020\u0020\u0020\u0020tempSet\u0020=\u0020copy.deepcopy(con)\n\u0020\u0020\u0020\u0020for\u0020each\u0020in\u0020tempSet:\n\u0020\u0020\u0020\u0020\u0020\u0020i\u0020=\u0020each[0]\n\u0020\u0020\u0020\u0020\u0020\u0020j\u0020=\u0020each[1]\n\u0020\u0020\u0020\u0020\u0020\u0020clid\u0020=\u0020stars[i][j]\n\u0020\u0020\u0020\u0020\u0020\u0020if\u0020i\u0020>\u00200\u0020and\u0020stars[i-1][j]\u0020==\u0020clid:\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020con.add((i-1,\u0020j))\n\u0020\u0020\u0020\u0020\u0020\u0020if\u0020i\u0020<\u00209\u0020and\u0020stars[i+1][j]\u0020==\u0020clid:\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020con.add((i+1,\u0020j))\n\u0020\u0020\u0020\u0020\u0020\u0020if\u0020j\u0020>\u00200\u0020and\u0020stars[i][j-1]\u0020==\u0020clid:\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020con.add((i,\u0020j-1))\n\u0020\u0020\u0020\u0020\u0020\u0020if\u0020j\u0020<\u00209\u0020and\u0020stars[i][j+1]\u0020==\u0020clid:\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020con.add((i,\u0020j+1))\n\u0020\u0020\u0020\u0020\u0020\u0020tempSet.clear()\n\u0020\u0020\u0020\u0020for\u0020each\u0020in\u0020con:\n\u0020\u0020\u0020\u0020\u0020\u0020\u0020\u0020stars[each[0]][each[1]]\u0020=\u00200\n\u0020\u0020\u0020\u0020updateTiles()\n\u0020\u0020\u0020\u0020draw()\n\npr.run(draw)\n

消灭星星游戏:使用Python和Pygame Zero打造简单消除游戏

原文地址: https://www.cveoy.top/t/topic/pPyj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录