这是一个没什么用的小游戏
因为抖音很火的萝卜猫太刷屏了,于是灵机一动整了个赛博基米
import os
import time
import msvcrt
def clear_screen():
print('\033[2J\033[H', end='', flush=True)
def get_key():
if msvcrt.kbhit():
return msvcrt.getch()
return None
def main():
os.system('')
print('\033[?25l', end='')
cat_art_normal = [
" /\\_/\\ ",
" ( o.o ) ",
" > ^ < "
]
cat_art_happy = [
" /\\_/\\ ",
" ( ^w^ ) ",
" > ~ < "
]
# ___
# ( )
# [~T~ ]
# [____]
# Carrot:
# ///
# \ \
# \ \
# V
player = "~~~~~~"
step_size = 3
width = 40
player_x = width // 2
happy_end_time = 0
time.sleep(2)
print('\033[2J', end='')
try:
while True:
output_buffer = "\033[H"
output_buffer += "\n"
current_art = cat_art_happy if time.time() < happy_end_time else cat_art_normal
for line in current_art:
output_buffer += line.center(width) + "\n"
output_buffer += "\n"
line1 = " ___ /// "
line2 = " ( ) \\ \\ "
line3 = " [~T~ ] \\ \\ "
line4 = " [____] V "
label_line = " 纸巾 萝卜 "
output_buffer += line1.center(width) + "\n"
output_buffer += line2.center(width) + "\n"
output_buffer += line3.center(width) + "\n"
output_buffer += line4.center(width) + "\n"
output_buffer += label_line.center(width) + "\n"
output_buffer += "\n" * 2
padding = " " * player_x
line_content = padding + player
output_buffer += line_content.ljust(width) + "\n"
output_buffer += "\n按q结束训练"
output_buffer += "\033[J"
print(output_buffer, end='', flush=True)
key = get_key()
if key:
if key == b'q':
break
elif key == b' ':
happy_end_time = time.time() + 1.0
elif key == b'\xe0':
special = msvcrt.getch()
if special == b'K':
player_x = max(0, player_x - step_size)
elif special == b'M':
player_x = min(width - len(player), player_x + step_size)
time.sleep(0.016)
except KeyboardInterrupt:
pass
finally:
print('\033[?25h')
print("\n哈基米驯化完成")
if __name__ == "__main__":
main()链接:
左右键可以控制下面横线移动,空格就是奖励哈基米
