{"id":694899,"student_id":10,"content":"from game import *\nfrom random import randint\n\nset_backdrop('black')\n\nwalls = [\n '1111111111111111111111111111',\n '1000000000000110000000000001',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1000000000000000000000000001',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1000000000000110000000000001',\n '1111111111110110111111111111',\n '1111111111110110111111111111',\n '1000000000000110000000000001',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1000000000000000000000000001',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1011110111110110111101111101',\n '1000000000000110000000000001',\n '1111111111111111111111111111',\n]\n\ngrid = []\nfood = []\n\nfor x in range(28):\n grid.append([])\n for y in range(22):\n w = create_sprite('w.png')\n w.x = x * 30 + 15\n w.y = y * 30 + 15\n w.hidden = walls[y][x] == '0'\n grid[x].append(w)\n if walls[y][x] == '0':\n n = create_sprite('player.png')\n n.x = x * 30 + 15\n n.y = y * 30 + 15\n n.scale = 0.2\n if randint(0, 1) \u003c 0.01:\n n.scale = 0.4\n food.append(n)\n \n\nplayer = create_sprite('player.png')\nplayer.moveTo(grid[1][1])\nplayer.target = grid[2][1]\n\npinky = create_sprite('r.png')\npinky.moveTo(grid[26][1])\npinky.target = grid[25][1]\n\ndef loop():\n move_player() \n move(pinky)\n for f in food:\n if f.touched(player):\n f.hidden = True\n\ndef move_player():\n player.toward(player.target)\n if player.distance_to(player.target) \u003e 1:\n player.step_forward(1)\n else:\n player.move_to(player.target)\n \n x = player.x // 30\n y = player.y // 30\n \n if key.up and grid[x][y - 1].hidden:\n player.target = grid[x][y - 1]\n if key.down and grid[x][y + 1].hidden:\n player.target = grid[x][y + 1]\n if key.left and grid[x - 1][y].hidden:\n player.target = grid[x - 1][y]\n if key.right and grid[x + 1][y].hidden:\n player.target = grid[x + 1][y]\n\ndef move(sprite):\n sprite.toward(sprite.target)\n if sprite.distance_to(sprite.target) \u003e 1:\n sprite.step_forward(1)\n else:\n sprite.move_to(sprite.target)\n \n x = sprite.x // 30\n y = sprite.y // 30\n \n arr = []\n if grid[x][y - 1].hidden and sprite.direction != 180:\n arr.append(grid[x][y - 1])\n if grid[x][y + 1].hidden and sprite.direction != 0:\n arr.append(grid[x][y + 1])\n if grid[x - 1][y].hidden and sprite.direction != 90:\n arr.append(grid[x - 1][y])\n if grid[x + 1][y].hidden and sprite.direction != 270:\n arr.append(grid[x + 1][y])\n \n rand = randint(0, len(arr) - 1)\n sprite.target = arr[rand]\n \n print(arr[0].x,arr[0].y)\n \n\nforever(loop)","created_at":"2024-02-15T17:12:36.304+08:00","updated_at":"2024-02-15T18:07:45.103+08:00","name":"小精靈","language":"python","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/694899/43ec580d143b3c56d8ea867c956e6a8a.jpg"},"parent_id":4,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":61,"hashid":"meys9e4jy","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":15565800,"file_name":"o.png","project_id":694899,"asset_id":721108,"created_at":"2024-02-15T17:12:46.081+08:00","updated_at":"2024-02-15T17:12:46.081+08:00"},{"id":15565801,"file_name":"g.png","project_id":694899,"asset_id":721109,"created_at":"2024-02-15T17:12:46.083+08:00","updated_at":"2024-02-15T17:12:46.083+08:00"},{"id":15565802,"file_name":"r.png","project_id":694899,"asset_id":721110,"created_at":"2024-02-15T17:12:46.237+08:00","updated_at":"2024-02-15T17:12:46.237+08:00"},{"id":15565803,"file_name":"b.png","project_id":694899,"asset_id":721111,"created_at":"2024-02-15T17:12:46.239+08:00","updated_at":"2024-02-15T17:12:46.239+08:00"},{"id":15565798,"file_name":"w.png","project_id":694899,"asset_id":721106,"created_at":"2024-02-15T17:12:45.925+08:00","updated_at":"2024-02-15T17:12:45.925+08:00"},{"id":15565799,"file_name":"player.png","project_id":694899,"asset_id":721107,"created_at":"2024-02-15T17:12:45.927+08:00","updated_at":"2024-02-15T17:12:45.927+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
截圖
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦