有什么好的编程软件?
以下是我写的内容
import randomimport curses
# 初始化窗口stdscr = curses.initscr()curses.curs_set(0)sh, sw = stdscr.getmaxyx()w = stdscr.subwin(sh, sw, 0, 0)
w.keypad(1)w.timeout(100)
# 初始化贪吃蛇和食物的位置snk_x = sw//4snk_y = sh//2snake = [lbk] [lbk]snk_y, snk_x[rbk], [lbk]snk_y, snk_x-1[rbk], [lbk]snk_y, snk_x-2[rbk][rbk]
food = [lbk]sh//2, sw//2[rbk]w.addch(int(food[lbk]0[rbk]), int(food[lbk]1[rbk]), curses.ACS_PI)
key = curses.KEY_RIGHT
# 游戏循环while True: next_key = w.getch() key = key if next_key == -1 else next_key
# 判断是否输了 if ( snake[lbk]0[rbk][lbk]0[rbk] in [lbk]0, sh[rbk] or snake[lbk]0[rbk][lbk]1[rbk] in [lbk]0, sw[rbk] or snake[lbk]0[rbk] in snake[lbk]1:[rbk] ): curses.endwin() quit()
new_head = [lbk]snake[lbk]0[rbk][lbk]0[rbk], snake[lbk]0[rbk][lbk]1[rbk][rbk]
# 根据按键更新蛇头位置 if key == curses.KEY_DOWN: new_head[lbk]0[rbk] += 1 if key == curses.KEY_UP: new_head[lbk]0[rbk] -= 1 if key == curses.KEY_LEFT: new_head[lbk]1[rbk] -= 1 if key == curses.KEY_RIGHT: new_head[lbk]1[rbk] += 1
# 插入新的蛇头 snake.insert(0, new_head)
# 检查是否吃到食物 if snake[lbk]0[rbk] == food: food = None while food is None: nf = [lbk] random.randint(1, sh-1), random.randint(1, sw-1) [rbk] food = nf if nf not in snake else None w.addch(food[lbk]0[rbk], food[lbk]1[rbk], curses.ACS_PI) else: # 移除尾部 tail = snake.pop() w.addch(int(tail[lbk]0[rbk]), int(tail[lbk]1[rbk]), ' ')
# 绘制蛇 w.addch(int(snake[lbk]0[rbk][lbk]0[rbk]), int(snake[lbk]0[rbk][lbk]1[rbk]), curses.ACS_CKBOARD)
以下是我写的内容
import randomimport curses
# 初始化窗口stdscr = curses.initscr()curses.curs_set(0)sh, sw = stdscr.getmaxyx()w = stdscr.subwin(sh, sw, 0, 0)
w.keypad(1)w.timeout(100)
# 初始化贪吃蛇和食物的位置snk_x = sw//4snk_y = sh//2snake = [lbk] [lbk]snk_y, snk_x[rbk], [lbk]snk_y, snk_x-1[rbk], [lbk]snk_y, snk_x-2[rbk][rbk]
food = [lbk]sh//2, sw//2[rbk]w.addch(int(food[lbk]0[rbk]), int(food[lbk]1[rbk]), curses.ACS_PI)
key = curses.KEY_RIGHT
# 游戏循环while True: next_key = w.getch() key = key if next_key == -1 else next_key
# 判断是否输了 if ( snake[lbk]0[rbk][lbk]0[rbk] in [lbk]0, sh[rbk] or snake[lbk]0[rbk][lbk]1[rbk] in [lbk]0, sw[rbk] or snake[lbk]0[rbk] in snake[lbk]1:[rbk] ): curses.endwin() quit()
new_head = [lbk]snake[lbk]0[rbk][lbk]0[rbk], snake[lbk]0[rbk][lbk]1[rbk][rbk]
# 根据按键更新蛇头位置 if key == curses.KEY_DOWN: new_head[lbk]0[rbk] += 1 if key == curses.KEY_UP: new_head[lbk]0[rbk] -= 1 if key == curses.KEY_LEFT: new_head[lbk]1[rbk] -= 1 if key == curses.KEY_RIGHT: new_head[lbk]1[rbk] += 1
# 插入新的蛇头 snake.insert(0, new_head)
# 检查是否吃到食物 if snake[lbk]0[rbk] == food: food = None while food is None: nf = [lbk] random.randint(1, sh-1), random.randint(1, sw-1) [rbk] food = nf if nf not in snake else None w.addch(food[lbk]0[rbk], food[lbk]1[rbk], curses.ACS_PI) else: # 移除尾部 tail = snake.pop() w.addch(int(tail[lbk]0[rbk]), int(tail[lbk]1[rbk]), ' ')
# 绘制蛇 w.addch(int(snake[lbk]0[rbk][lbk]0[rbk]), int(snake[lbk]0[rbk][lbk]1[rbk]), curses.ACS_CKBOARD)