猫史档案馆


【Python作品分享】minecraft1.6.7【作品秀】

用户:杜达小川川OuO杜达小川川OuO查看:5 回复:2 评论:5 创建时间:2021-08-01T13:55:14


【作品展示】

center_image

 

【作品介绍】

minecraft

操作:

w : 前

a : 后

s :左

d :右

r :摧毁(前方)方块

 

【作品源代码】

import os
import time
import random
import keyboard
#这是(`=O.O=)彩蛋!!!!!!
wordlist = [["  ", "  ", "  ", "  ", "  ", "叶", "  ", "  ","  ", "  ", "  ", " |"],
            ["  ", "  ", "  ", "  ", "叶", "叶", "叶", "  ", "  ", "  ", "  ", " |"],
            ["  ", "  ", "  ", "叶", "叶", "叶", "叶", "叶", "  ", "  ", "  ", " |"],
            ["  ", "  ", "  ", "  ", "  ", "树", "  ", "  ", "  ", "  ", "  ", " |"],
            ["  ", "  ", "  ", "我", "  ", "树", "  ", "  ", "  ", "  ", "  ", " |"],
            ["  ", "  ", "  ", "  ", "  ", "树", "  ", "  ", "  ", "  ", "  ", " |"],
            ["  ", "  ", "  ", "  ", "  ", "  ", "  ", "  ","  ", "牛", "  ", " |"],
            ["__", "__", "__", "__", "__", "__", "__", "__","__", "__", "__", "_|"]
            ]
def W():
    wo_de_list = " "
    mu_biao_list = []
    list_suo_yin = 0
    wo_de_zuo_biao = 0
    for i in wordlist:
        for j in i:
            if j == "我":
                wo_de_list = i
                list_suo_yin = wordlist.index(i)
                if list_suo_yin == 0:
                    break
                else:
                    mu_biao_list = wordlist[list_suo_yin-1]
                    wo_de_zuo_biao = i.index(j)
                    if mu_biao_list[wo_de_zuo_biao] != "  ":
                        break
                    wo_de_list.remove(j)
                    mu_biao_list.pop(wo_de_zuo_biao)
                    mu_biao_list.insert(wo_de_zuo_biao, "我")
                    i.insert(wo_de_zuo_biao, "  ")
    os.system("cls")
    c = 0
    for i in wordlist:
        for j in i:
            if c == 11:
                print(j)
                c = 0
            else:
                print(j,end="")
                c += 1
def S():
    wo_de_list = " "
    mu_biao_list = []
    list_suo_yin = 0
    wo_de_zuo_biao = 0
    for i in range(len(wordlist), 0, -1):
        for j in wordlist[i-1]:
            if j == "我":
                s_fan = wordlist[i-1]
                wo_de_list = s_fan
                list_suo_yin = wordlist.index(s_fan)
                if list_suo_yin == 6:
                    break
                else:
                    mu_biao_list = wordlist[list_suo_yin+1]
                    wo_de_zuo_biao = s_fan.index(j)
                    if mu_biao_list[wo_de_zuo_biao] != "  ":
                        break
                    wo_de_list.remove(j)
                    mu_biao_list.pop(wo_de_zuo_biao)
                    mu_biao_list.insert(wo_de_zuo_biao, "我")
                    s_fan.insert(wo_de_zuo_biao, "  ")
    os.system("cls")
    c = 0
    for i in wordlist:
        for j in i:
            if c == 11:
                print(j)
                c = 0
            else:
                print(j,end="")
                c += 1
def A():
    wo_de_list = []
    mu_biao_di = " "
    list_suo_yin = 0
    wo_de_zuo_biao = 0
    for i in wordlist:
        for j in i:
            if j == "我":
                wo_de_list = i
                wo_de_zuo_biao = i.index(j)
                if wo_de_zuo_biao == 0:
                    break
                else:
                    mu_biao_di = wo_de_zuo_biao-1
                    if wo_de_list[mu_biao_di] != "  ":
                        break
                    wo_de_list.remove(j)
                    wo_de_list.pop(int(mu_biao_di))
                    wo_de_list.insert(mu_biao_di, "我")
                    wo_de_list.insert(wo_de_zuo_biao, "  ")
    os.system("cls")
    c = 0
    for i in wordlist:
        for j in i:
            if c == 11:
                print(j)
                c = 0
            else:
                print(j,end="")
                c += 1
def D():
    wo_de_list = []
    mu_biao_di = " "
    j_de_zhi = " "
    wo_de_zuo_biao = " "
    i_de_zhi = []
    for i in range(len(wordlist),0,-1):
        for j in range(len(wordlist[i-1]),0,-1):
            j_de_zhi = wordlist[i-1][j-1]
            if j_de_zhi == "我":
                i_de_zhi = wordlist[i-1]
                wo_de_list = i_de_zhi
                wo_de_zuo_biao = wo_de_list.index(j_de_zhi)
                if wo_de_zuo_biao == 10:
                    break
                else:
                    mu_biao_di = wo_de_zuo_biao
                    if wo_de_list[mu_biao_di+1] != "  ":
                        break
                    wo_de_list.remove(j_de_zhi)
                    wo_de_list.pop(mu_biao_di)
                    wo_de_list.insert(mu_biao_di, "我")
                    wo_de_list.insert(wo_de_zuo_biao, "  ")
    os.system("cls")
    c = 0
    for i in wordlist:
        for j in i:
            if c == 11:
                print(j)
                c = 0
            else:
                print(j,end="")
                c += 1
def R():
    cui_hui_wu_de_zuo_biao = 0
    wo_de_zuo_biao = 0
    cui_hui_wu_de_list = []
    cui_hui_wu_de_zhong_lei = [
                               "树",
                               "叶",
                               "牛"
                              ]
    i_de_zuo_biao = []
    for i in wordlist:
        for j in i:
            if j == "我":
                i_de_zuo_biao = wordlist.index(i)
                wo_de_zuo_biao = i.index(j)
                cui_hui_wu_de_list = wordlist[i_de_zuo_biao-1]
                cui_hui_wu_de_zuo_biao = cui_hui_wu_de_list[wo_de_zuo_biao]
                if cui_hui_wu_de_zuo_biao == "  ":
                    break
                else:
                    if cui_hui_wu_de_zuo_biao in cui_hui_wu_de_zhong_lei:
                        if cui_hui_wu_de_zuo_biao == "树":
                            time.sleep(3)
                            cui_hui_wu_de_list.remove(cui_hui_wu_de_zuo_biao)
                            cui_hui_wu_de_list.insert(wo_de_zuo_biao,"  ")
                        if cui_hui_wu_de_zuo_biao == "叶":
                            time.sleep(1)
                            cui_hui_wu_de_list.remove(cui_hui_wu_de_zuo_biao)
                            cui_hui_wu_de_list.insert(wo_de_zuo_biao, "  ")
                        if cui_hui_wu_de_zuo_biao == "牛":
                            cui_hui_wu_de_list.remove(cui_hui_wu_de_zuo_biao)
                            cui_hui_wu_de_list.insert(wo_de_zuo_biao, "  ")
    os.system("cls")
    c = 0
    for i in wordlist:
        for j in i:
            if c == 11:
                print(j)
                c = 0
            else:
                print(j,end="")
                c += 1
def niu(x):
    fang_xiang = random.randint(1,10)
    if fang_xiang == 1:
        wo_de_list = " "
        mu_biao_list = []
        list_suo_yin = 0
        wo_de_zuo_biao = 0
        for i in wordlist:
            for j in i:
                if j == "牛":
                    wo_de_list = i
                    list_suo_yin = wordlist.index(i)
                    if list_suo_yin == 0:
                        break
                    else:
                        mu_biao_list = wordlist[list_suo_yin-1]
                        wo_de_zuo_biao = i.index(j)
                        if mu_biao_list[wo_de_zuo_biao] != "  ":
                            break
                        wo_de_list.remove(j)
                        mu_biao_list.pop(wo_de_zuo_biao)
                        mu_biao_list.insert(wo_de_zuo_biao, "牛")
                        i.insert(wo_de_zuo_biao, "  ")
                        os.system("cls")
                        c = 0
                        for i in wordlist:
                            for j in i:
                                if c == 11:
                                    print(j)
                                    c = 0
                                else:
                                    print(j,end="")
                                    c += 1
                        
    if fang_xiang == 2:
        wo_de_list = " "
        mu_biao_list = []
        list_suo_yin = 0
        wo_de_zuo_biao = 0
        for i in range(len(wordlist), 0, -1):
            for j in wordlist[i-1]:
                if j == "牛":
                    s_fan = wordlist[i-1]
                    wo_de_list = s_fan
                    list_suo_yin = wordlist.index(s_fan)
                    if list_suo_yin == 6:
                        break
                    else:
                        mu_biao_list = wordlist[list_suo_yin+1]
                        wo_de_zuo_biao = s_fan.index(j)
                        if mu_biao_list[wo_de_zuo_biao] != "  ":
                            break
                        wo_de_list.remove(j)
                        mu_biao_list.pop(wo_de_zuo_biao)
                        mu_biao_list.insert(wo_de_zuo_biao, "牛")
                        s_fan.insert(wo_de_zuo_biao, "  ")
                        os.system("cls")
                        c = 0
                        for i in wordlist:
                            for j in i:
                                if c == 11:
                                    print(j)
                                    c = 0
                                else:
                                    print(j,end="")
                                    c += 1
    if fang_xiang == 3:
        wo_de_list = []
        mu_biao_di = " "
        list_suo_yin = 0
        wo_de_zuo_biao = 0
        for i in wordlist:
            for j in i:
                if j == "牛":
                    wo_de_list = i
                    wo_de_zuo_biao = i.index(j)
                    if wo_de_zuo_biao == 0:
                        break
                    else:
                        mu_biao_di = wo_de_zuo_biao-1
                        if wo_de_list[mu_biao_di] != "  ":
                            break
                        wo_de_list.remove(j)
                        wo_de_list.pop(int(mu_biao_di))
                        wo_de_list.insert(mu_biao_di, "牛")
                        wo_de_list.insert(wo_de_zuo_biao, "  ")
                        os.system("cls")
                        c = 0
                        for i in wordlist:
                            for j in i:
                                if c == 11:
                                    print(j)
                                    c = 0
                                else:
                                    print(j,end="")
                                    c += 1
    if fang_xiang == 4:
        wo_de_list = []
        mu_biao_di = " "
        j_de_zhi = " "
        wo_de_zuo_biao = " "
        i_de_zhi = []
        for i in range(len(wordlist),0,-1):
            for j in range(len(wordlist[i-1]),0,-1):
                j_de_zhi = wordlist[i-1][j-1]
                if j_de_zhi == "牛":
                    i_de_zhi = wordlist[i-1]
                    wo_de_list = i_de_zhi
                    wo_de_zuo_biao = wo_de_list.index(j_de_zhi)
                    if wo_de_zuo_biao == 10:
                        break
                    else:
                        mu_biao_di = wo_de_zuo_biao
                        if wo_de_list[mu_biao_di+1] != "  ":
                            break
                        wo_de_list.remove(j_de_zhi)
                        wo_de_list.pop(mu_biao_di)
                        wo_de_list.insert(mu_biao_di, "牛")
                        wo_de_list.insert(wo_de_zuo_biao, "  ")
                        os.system("cls")
                        c = 0
                        for i in wordlist:
                            for j in i:
                                if c == 11:
                                    print(j)
                                    c = 0
                                else:
                                    print(j,end="")
                                    c += 1
c = 0
for i in wordlist:
    for j in i:
        if c == 11:
            print(j)
            c = 0
        else:
            print(j, end="")
            c += 1
if __name__ == '__main__':
    keyboard.add_hotkey('w', W)
    keyboard.add_hotkey('s', S)
    keyboard.add_hotkey('a', A)
    keyboard.add_hotkey('d', D)
    keyboard.add_hotkey('r', R)
    keyboard.hook(niu)
    keyboard.wait()
"""
************************更新日志************************
1.0更新
更新了上下键
************************
1.5更新
更新了左右键
************************
1.5.2更新
更新了树和叶
将世界扩大
更新了摧毁键(r键)
************************
1.6更新
不用回车就可以操控
更新了牛
************************
1.6.7更新
按r可以喵掉牛😎
########################
作者:杜达小川川OuO
作品:#minecraft1.6.7
     表情包生成器2.5

     额( -﹏-)...没了
"""

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
KIHIOKIHIO

其实你的程序有严重BUG,来看看我无BUG的2048(先上代码后效果):

import random

h=[]
i=0
while i<16:
    h.append(0)
    i+=1
l=random.randint(0,15)
l2=random.randint(0,15)
while l2==l:
    l2=random.randint(0,15)
h[l]=2
h[l2]=2
win=0
while True:
    i=0
    pzf=' '
    while i<16:
        if (i+1)%4==1:
            pzf=str(h[i])
        else:
            pzf=pzf+str(h[i])
        if (i+1)%4==0:
            print(pzf)
        else:
            j=0
            while j<5-(len(str(h[i]))):
                pzf=pzf+' '
                j+=1
        i+=1
    i=0
    while i<16:
        if h[i]==2048:
            print("你组合出了2048!!!你赢了!!!")
            win=1
            break
        i+=1
    if win==1:
        break
    i=0
    xh=1
    while i<16:
        if h[i]==0:
            xh=0
            break
        i+=1
    if xh==1:
        js=0
        i=0
        while i<16:
            if i%4!=3:
                if h[i]==h[i+1]:
                    js+=1
            i+=1
        i=0
        while i<4:
            j=0
            while j<=8:
                if h[i+j]==h[i+j+4]:
                    js+=1
                j+=4
            i=i+1
        if js==0:
            print("没法拼接了,你输了……")
            break
    try:
        x=float(input("你要做什么决策?(1上2下3左4右):"))
    except ValueError:
        print("ERROR:你的输入为字符串")
        break
    if x-(float(int(x)))>0:
        print("ERROR:你的输入为小数")
        break
    x=int(x)
    if x==1:
        i=4
        while i<16:
            f=i
            if h[i]!=0:
                while f>=0:
                    if h[f]!=0 and f!=i:
                        if h[f]==h[i]:
                            h[f]+=h[i]
                            h[i]=0
                        else:
                            if f!=i-4:
                                h[f+4]=h[i]
                                h[i]=0
                        break
                    f-=4
                if h[f+4]==0 and f<0:
                    h[f+4]=h[i]
                    h[i]=0
            i+=1
        i=0
        g=0
        while i<16:
            if h[i]==0:
                g=1
                break
            i+=1
        if g==1:
            l=random.randint(0,15)
            while h[l]!=0:
                l=random.randint(0,15)
            js=random.randint(1,2)
            h[l]=js*2
    elif x==2:
        i=11
        while i>=0:
            f=i
            if h[i]!=0:
                while f<=15:
                    if h[f]!=0 and f!=i:
                        if h[f]==h[i]:
                            h[f]+=h[i]
                            h[i]=0
                        else:
                            if f!=i+4:
                                h[f-4]=h[i]
                                h[i]=0
                        break
                    f+=4
                if h[f-4]==0 and f>15:
                    h[f-4]=h[i]
                    h[i]=0
            i-=1
        i=0
        g=0
        while i<16:
            if h[i]==0:
                g=1
                break
            i+=1
        if g==1:
            l=random.randint(0,15)
            while h[l]!=0:
                l=random.randint(0,15)
            js=random.randint(1,2)
            h[l]=js*2
    elif x==4:
        i=15
        while i>=0:
            if i%4!=3:
                f=i
                if h[i]!=0:
                    while f<=((int(i/4))*4+3):
                        if h[f]!=0 and f!=i:
                            if h[f]==h[i]:
                                h[f]+=h[i]
                                h[i]=0
                            else:
                                if f!=i+1:
                                    h[f-1]=h[i]
                                    h[i]=0
                            break
                        f+=1
                    if h[f-1]==0 and f>((int(i/4))*4+3):
                        h[f-1]=h[i]
                        h[i]=0
            i-=1
        i=0
        g=0
        while i<16:
            if h[i]==0:
                g=1
                break
            i-=1
        if g==1:
            l=random.randint(0,15)
            while h[l]!=0:
                l=random.randint(0,15)
            js=random.randint(1,2)
            h[l]=js*2
    elif x==3:
        i=1
        while i<16:
            if i%4!=0:
                f=i
                if h[i]!=0:
                    while f>=((int(i/4))*4):
                        if h[f]!=0 and f!=i:
                            if h[f]==h[i]:
                                h[f]+=h[i]
                                h[i]=0
                            else:
                                if f!=i-1:
                                    h[f+1]=h[i]
                                    h[i]=0
                            break
                        f-=1
                    if h[f+1]==0 and f<((int(i/4))*4):
                        h[f+1]=h[i]
                        h[i]=0
            i+=1
        i=0
        g=0
        while i<16:
            if h[i]==0:
                g=1
                break
            i+=1
        if g==1:
            l=random.randint(0,15)
            while h[l]!=0:
                l=random.randint(0,15)
            js=random.randint(1,2)
            h[l]=js*2
    else:
        print("ERROR:你输入的整数不合理")
        break

center_image

点赞0


评论


杜达小川川OuO杜达小川川OuO

下面那位🙃
center_image

点赞0


评论