1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| """ 一维游戏JumpGame 2020年5月27日 设计 2020年5月30日 增添第一关,本质上像是一个迷宫 by littlefean """ YOUR_PLACE_BLOCK = "你" AIR_BLOCK = "__" HOME_BLOCK = "初" WIN_BLOCK = "赢" GOTO_BLOCK = "跳" DEATH_BLOCK = "死" SWITCH_BLOCK = "阱" INDEX_ERROR_BLOCK = " " CAN_NOT_SEE_BLOCK = "__"
def level_1(): """ 生成关卡1 :return: 一个列表,是地图信息,和一个起始位置信息 """ INDEX = 36 START = 5 END = 33 g = [] for j in range(INDEX): g.append([0, 0]) g[START] = [1] g[END] = [2] g[0] = [4, 24] g[3] = [4, 11] g[4] = [4, 17] g[7] = [4, 2] g[9] = [4, 28] g[12] = [4, 6] g[14] = [4, 20] g[16] = [4, 11] g[18] = [4, 27] g[19] = [4, 30] g[22] = [4, 15] g[25] = [4, 28] g[26] = [4, 5] g[29] = [4, 17] g[31] = [4, 34] return g, START
def introduce(): print("Jump Game本质上是一个在一串格子上跳跃的游戏,游戏地图就是有限个方块排成一排") print("你出生在一个位置,每次只能向左或者向右移动一格,到了重点方块上,就过关了") print(f"你会看到很多格子,当你看到 {WIN_BLOCK} 的时候,那个方块就是终点方块") print(f"写着 /"{YOUR_PLACE_BLOCK}/"的方块是你现在的位置,输入4向左走,输入6向右走,输入0退出游戏")
def show(M, v, u): """ 展示玩家所能看到的当前地图情况 :param M: 地图 :param v: 视野 :param u: 玩家所处的位置 :return: """ for j in range(len(M)): if u - v <= j <= u + v: try: if j == u: print(f"{YOUR_PLACE_BLOCK}", end=" ") else: if M[j][0] == 0: print(f"{AIR_BLOCK}", end=" ") elif M[j][0] == 1: print(f"{HOME_BLOCK}", end=" ") elif M[j][0] == 2: print(f"{WIN_BLOCK}", end=" ") elif M[j][0] == 3: print(f"{DEATH_BLOCK}", end=" ") elif M[j][0] == 4: print(f"{GOTO_BLOCK}", end=" ") elif M[j][0] == 6: print(f"{SWITCH_BLOCK}", end=" ") except IndexError: print(f"{INDEX_ERROR_BLOCK}", end=" ") else: print(f"{CAN_NOT_SEE_BLOCK}", end=" ")
if __name__ == '__main__': view = 1 step = 0 (gameMap, place) = level_1()
introduce() show(gameMap, view, place)
while True: choice = 0 while True: try: choice = int(input("输入:")) break except ValueError: continue if (choice == 4) and (place > 0): place -= 1 step += 1 elif (choice == 6) and (place < len(gameMap) - 1): place += 1 step += 1 elif choice == 0: exit("您退出了游戏") else: print("错误指令")
if gameMap[place][0] == 2: print(f"你赢了,用了{step}步") break elif gameMap[place][0] == 3: print(f"你炸了,用了{step}步") break elif gameMap[place][0] == 4: place = gameMap[place][1] show(gameMap, view, place)
|