猫史档案馆


【Python作品分享】文字游戏【作品秀】

用户:62123776212377查看:0 回复:1 评论:0 创建时间:2022-08-31T21:07:49


【作品展示】

center_image

 

【作品介绍】

真.文字游戏

 

【作品源代码】

import random

xl = 10
yyy = []
xxx = []
p = 0
jnj = 5
jnx = 0
jny = 0
c = 0
xx = random.randint((-50), 50)
yy = random.randint((-50), 50)
x = random.randint((-50), 50)
y = random.randint((-50), 50)
print('接下来开始游戏,请阅读说明:')
print('1  2  3  4  分别对应上  下  左  右。及控制发方向。输入均为方向。每次行走一个单位。需要玩家控制点到达终点。')
print('本游戏为纯文字。')
print('技能:瞬移(输入 jn)但是不能直接传送到目的地否则……')
print('随机轰炸(轰炸前会提醒)')

def function1():

    print('当前坐标:')
    print(xx)
    print(yy)
    print('__________________________')
    if (xx == x and yy == y):
        print('已到达终点')
        p = 1


while (p == 0):
    print('目标坐标')
    print(x, y) 
    h = input('')
    if (h == '1'):
        yy += 1
        if (yy <= 50 and yy >= -50):
            function1()
            if (p == 1):
                break
        elif (yy > 50):
            yy -= 1
            print('超出边界!')
    elif (h == '2'):
        yy -= 1
        if (yy >= -50 and yy <= 50):
            function1()
            if (p == 1):
                break
        else:
            yy += 1
            print('超出边界')
    elif (h == '3'):
        xx -= 1
        if (xx <= 50 and xx >= -50):
            function1()
            if (p == 1):   
                break
        else:
            xx += 1
            print('超出边界!')
    elif (h == '4'):
        xx += 1
        if (xx <= 50 and xx >= -50):
            function1()
            if (p == 1):
                break
        else:
            xx -= 1
            print('超出边界!')
    elif (h == 'jn'):
        jnx = int(input('输入坐标(x)'))
        jny = int(input('输入坐标(y)'))
        if (jnx <= 50 and jnx >= -50 and jny <= 50 and jny >= -50):
            if (jnx == x or jny == y):
                print('接受惩罚')
                for count in range(50):
                    xxxx = random.randint((-50), 50)
                    yyyy = random.randint((-50), 50)
                    f = ((xxxx - xx) + (yyyy - yy))
                    if (abs(f) > 18 and xxxx != x and yyyy != y):
                        xx = xxxx
                        yy = yyyy
            else:
                xx = jnx
                yy = jny
        else:
            print('超出边界')
    else:
        print('输入错误!!!')




if(sj == 2):
    hy = random.randint(-50,50)
    hx = random.randint(-50,50)
    print('下一轮将开始轰炸!')
    ld = (hy - yy)*(hy - yy) + (hy - yy)*(hy - yy)
elif(sj > 1):
    sj -= 1
elif(sj == 1):
    if(abs(ld) <= 10):
        xl -= 3
        sj = 5    

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
62123776212377

下面那一段是将要加入的东西。可以先猜一猜

点赞0


评论