資源簡介
需要安裝 curses ,詳見 這里 https://blog.csdn.net/celina0321/article/details/83047612
代碼片段和文件信息
#-*-?coding:utf-8?-*-
import?curses
from?random?import?randrange?choice?#?generate?and?place?new?tile
from?collections?import?defaultdict
letter_codes?=?[ord(ch)?for?ch?in?‘WASDRQwasdrq‘]
actions?=?[‘Up‘?‘Left‘?‘Down‘?‘Right‘?‘Restart‘?‘Exit‘]
actions_dict?=?dict(zip(letter_codes?actions?*?2))
def?get_user_action(keyboard):????
????char?=?“N“
????while?char?not?in?actions_dict:????
????????char?=?keyboard.getch()
????return?actions_dict[char]
def?transpose(field):
????return?[list(row)?for?row?in?zip(*field)]
def?invert(field):
????return?[row[::-1]?for?row?in?field]
class?GameField(object):
????def?__init__(self?height=4?width=4?win=2048):
????????self.height?=?height
????????self.width?=?width
????????self.win_value?=?win
????????self.score?=?0
- 上一篇:python 串口調試工具源碼
- 下一篇:Python實現百度文庫
評論
共有 條評論