1 游戏说明:
死亡条件:碰壁、吃自己!
状态:只有吃了食物才会随机生成其中一种状态,分别是:稳如老狗、幸运光滑、衰神附体之一 状态:稳如老狗:相对于上一次速度不变!
状态:幸运光滑:相对于上一次速度变慢!
状态:衰神附体:相对于上一次速度变快!
总体速率对比刚开始是快还是慢,如果是正直代表慢,如果是负值代表快! 该说的就这么多了! 加油,快来开启你的欧皇人生吧~
2 代码
import tkinter
import time
import random
from threading import Thread, Event
from tkinter import Canvas# 游戏数值统计类
class MyScore(object):str_score = "Score:"str_buff = '状态:'str_random = '总Buff:'def __init__(self):self.game_window = Canvas(root, width=width, height=23, bg='Snow') # 'Snow'self.game_window.place(x=2, y=2)self.font_format = ('宋体', 12)self.score = -10self.buff = 0self.var_random = 0self.var_buff = '稳如老狗'self.sum = 0# 绘制矩形框def show_frame(self):self.game_window.create_rectangle(2, 2, 301, 24, tag=("frame",))self.game_window.create_rectangle(82, 2, 192, 24, tag=("frame",))# 增加积分提示def show_game_score(self):self.score += 10self.game_window.create_text(10, 13, text=MyScore.str_score + str(self.score), font=self.font_format, anchor=tkinter.W, tag=('score',))# 随机值显示def show_game_random(self):self.sum += self.buffself.game_window.create_text(195, 13, text=MyScore.str_random + '%.3f' % self.sum, font=self.font_format, anchor=tkinter.W,tag=('random',))# 增加状态显示def show_game_buff(self):if self.buff > 0:self.var_buff = '幸运光环'elif self.buff < 0:self.var_buff = '衰神附体'else:self.var_buff = '稳如老狗'self.game_window.create_text(138, 13, text=MyScore.str_buff + self.var_buff, font=self.font_format, tag=('buff',))# 游戏界面类
class MyCanvas(object):msg_1 = "游戏说明"msg_2 = "1.开始\暂停\继续:Enter\Space"msg_3 = "2.移动方向:按wasd键"msg_end = "GAME OVER"msg_stop = " Press Enter\Space\nto continue the game"def __init__(self):self.game_window = Canvas(root, width=width, height=height, bg='Tan') # Tanself.game_window.place(x=2, y=27)self.font_format = ('宋体', 12)self.flag = True