1 Star 0 Fork 0

dttolch/tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mud_main.py 9.56 KB
一键复制 编辑 原始数据 按行查看 历史
dttolch 提交于 2022-11-05 13:28 . update mud_main.py.
import pygame as pg
import random
import time
pg.init()
screen = pg.display.set_mode((640, 480))
GRAY = pg.Color('gray15')
BLUE = pg.Color('dodgerblue1')
GREEN = pg.Color('Green')
RED = pg.Color('Red')
YELLOW = pg.Color('Yellow')
CYAN = pg.Color('Cyan')
position = ["一个山洞","一处悬崖","海边","办公大楼","学校","医院","早市","澡堂子","月球基地","天宫空间站",
"天安门","长白山","青海湖","洱海","香格里拉","西湖","黄鹤楼","长江","渤海湾","西安",
"葫芦岛","大连","青岛","北京","天津","上海","广州","深圳"]
treasure = ["个宝箱","个钱包","个钻石","元人民币","个铠甲","本武功秘籍","个油条","个羊肉串","个CPU","个内存条","个鼠标","个键盘",
"个显示器","个自行车","个小汽车"]
attribute = ["攻击力","防御力","闪避能力","内力","生命","暴击率","暴击效果","攻速","韧性"]
attribute_val = {"攻击力":1,"防御力":1,"闪避能力":1,"内力":1,"生命":1,"暴击率":1,"暴击效果":1,"攻速":1,"韧性":1}
hidden_attribute = ["幸运值"]
hidden_attribute_val = {"幸运值":1}
enemy = ["野猪","间谍","外星人","老虎","狮子","大象","山羊","野狼","小猫咪","流浪狗","蚯蚓","巨龙","蝙蝠","苍蝇","蚊子","吞噬兽"]
enemy_special =["你妈妈","你爸爸"]
enemy_class = ["普通的","狡猾的","强壮的","年老的","年幼的","变异的","受辐射的","聪明的","笨拙的","灵敏的","有学问的","暴躁的"]
food = ["肉夹馍","凉皮","饺子","咖喱饭","炸酱面","打卤面","盖浇饭","米线","面包",
"冰激凌","蓝莓圣代","苹果","香蕉","橙子","柚子","冬枣","蓝莓","炸花生米",
"爆米花","手抓羊肉","葫芦鸡","粘豆包","猪肉炖粉条","小鸡炖蘑菇","凉拌西红柿",
"蚝油生菜","糖醋里脊","油焖大虾","灌汤包子","水煮肉片","烤鱼","油条豆浆",
"西红柿炒鸡蛋","肉馅包子","葡萄"]
def main():
clock = pg.time.Clock()
#font = pg.font.Font(None, 30)
font = pg.font.Font("c:/windows/fonts/STFANGSO.ttf", 30)
font_attr = pg.font.Font("c:/windows/fonts/STFANGSO.ttf", 16)
button_rect = pg.Rect(200, 200, 50, 30)
#x,y ,width,height,
button_rect_clean_position = pg.Rect(200, 400, 400, 40)
button_rect_clean_money = pg.Rect(260, 206, 200, 40)
button_rect_clean_info = pg.Rect(0, 400, 640, 40)
width = 140
height = 30
#info_start_x = 480
button_rect_clean_money_dig = pg.Rect(480, 10, width, height)
button_rect_clean_attack_dig = pg.Rect(480, 10+height, width, height)
button_rect_clean_defence_dig = pg.Rect(480, 10+height*2, width, height)
button_rect_clean_life_dig = pg.Rect(480, 10+height*3, width, height)
score = 0
#money = 0
done = False
screen.fill(GRAY)
pg.draw.rect(screen, BLUE, button_rect)
txt = font.render("Money:"+str(score), True, BLUE)
screen.blit(txt, (260, 206))
event_index = 0
attribute_num = 0
attribute_index = 0
while not done:
for event in pg.event.get():
if event.type == pg.QUIT:
done = True
# event.type == pg.KEYDOWN
if event.type == pg.MOUSEBUTTONDOWN:
if button_rect.collidepoint(event.pos):
if event.button == 1: # Left button.
print('Increment.')
score += 1
elif event.button == 3: # Right button.
print('Decrement.')
score -= 1
txt = font.render("Money:"+str(score), True, BLUE)
pg.draw.rect(screen, GRAY, button_rect_clean_money)
screen.blit(txt, (260, 206))
event_index += 1
#step_num += 1
if event_index == 1:
pg.draw.rect(screen, GRAY, button_rect_clean_info)
#position
txt = font.render("你来到了", True, GREEN)
screen.blit(txt, (10, 400))
pg.draw.rect(screen, GRAY, button_rect_clean_position)
this_position = position[random.randint(0,len(position)-1)]
txt = font.render(this_position, True, BLUE)
screen.blit(txt, (200, 400))
if event_index == 2:
pg.draw.rect(screen, GRAY, button_rect_clean_info)
#treasure
treasure_num = random.randint(1,1000000)
score += treasure_num
txt = font.render("你捡到了"+str(treasure_num), True, GREEN)
screen.blit(txt, (10, 400))
pg.draw.rect(screen, GRAY, button_rect_clean_position)
this_treasure = treasure[random.randint(0,len(treasure)-1)]
txt = font.render(this_treasure, True, BLUE)
screen.blit(txt, (200, 400))
if event_index == 3:
pg.draw.rect(screen, GRAY, button_rect_clean_info)
#enemy
enemy_index = random.randint(0,len(enemy)-1)
enemy_class_index = random.randint(0,len(enemy_class)-1)
enemy_name = enemy_class[enemy_class_index]+enemy[enemy_index]
txt = font.render("你遇到了"+enemy_name, True, GREEN)
screen.blit(txt, (10, 400))
if event_index == 4:
#battle
pg.draw.rect(screen, GRAY, button_rect_clean_info)
txt = font.render("你和"+enemy_name+"发生了激烈的战斗", True, GREEN)
screen.blit(txt, (10, 400))
#battle_flag = 2
if event_index == 5: #battle result
battle_result = random.randint(0,100)
if battle_result>50:#fail
pg.draw.rect(screen, GRAY, button_rect_clean_info)
txt = font.render("你被"+enemy_name+"打败了", True, BLUE)
screen.blit(txt, (10, 400))
elif battle_result<50:#success
pg.draw.rect(screen, GRAY, button_rect_clean_info)
txt = font.render("你打败了"+enemy_name, True, RED)
screen.blit(txt, (10, 400))
else:
pg.draw.rect(screen, GRAY, button_rect_clean_info)
txt = font.render("你和"+enemy_name+"打成了平手", True, YELLOW)
screen.blit(txt, (10, 400))
if event_index == 6:# random.randint(2,10):
pg.draw.rect(screen, GRAY, button_rect_clean_info)
#treasure
attribute_num = random.randint(1,1000)
attribute_index = random.randint(0,len(attribute)-1)
attribute_val[attribute[attribute_index]] += attribute_num
txt = font.render("这一日你忽有所感"+attribute[attribute_index]+"增加了"+str(attribute_num), True, GREEN)
screen.blit(txt, (10, 400))
#pg.draw.rect(screen, GRAY, button_rect_clean_position)
#this_treasure = treasure[random.randint(0,len(treasure)-1)]
#txt = font.render(this_treasure, True, BLUE)
#screen.blit(txt, (200, 400))
if event_index == 7:
step_num = 0
pg.draw.rect(screen, GRAY, button_rect_clean_info)
attribute_index = random.randint(0,len(attribute)-1)
attribute_num = attribute_val[attribute[attribute_index]]
txt = font.render("这一日你内视发现"+attribute[attribute_index]+"已经到了"+str(attribute_num), True, GREEN)
screen.blit(txt, (10, 400))
if event_index == 8:
step_num = 0
pg.draw.rect(screen, GRAY, button_rect_clean_info)
enemy_special_index = random.randint(0,len(enemy_special)-1)
food_index = random.randint(0,len(food)-1)
txt = font.render("这一日你回家发现"+enemy_special[enemy_special_index]+"给你准备了"+food[food_index], True, CYAN)
screen.blit(txt, (10, 400))
event_index = 0
#dig refresh
#screen.fill(GRAY)
pg.draw.rect(screen, GRAY, button_rect_clean_money_dig)
txt = font_attr.render("Money:"+str(score), True, BLUE)
screen.blit(txt, (480, 10))
pg.draw.rect(screen, GRAY, button_rect_clean_attack_dig)
txt = font_attr.render("Attack:"+str(attribute_val["攻击力"]), True, BLUE)
screen.blit(txt, (480, 10+height))
pg.draw.rect(screen, GRAY, button_rect_clean_defence_dig)
txt = font_attr.render("Defence:"+str(attribute_val["防御力"]), True, BLUE)
screen.blit(txt, (480, 10+height*2))
pg.draw.rect(screen, GRAY, button_rect_clean_life_dig)
txt = font_attr.render("Life:"+str(attribute_val["生命"]), True, BLUE)
screen.blit(txt, (480, 10+height*3))
pg.display.flip()
clock.tick(30)
if __name__ == '__main__':
main()
pg.quit()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dttolch/tools.git
git@gitee.com:dttolch/tools.git
dttolch
tools
tools
master

搜索帮助