0

PythonでコーディングしているTetrisの回転プログラムを作成しようとしています。回転部分は正常に機能しますが、ブロックが画面から回転したり、他のブロックに移動したりする問題があります。私が作成しようとしたのは、実際にブロックを回転させる前に回転が有効かどうかを確認するためにテスト回転を行う関数です。

関数はここで呼び出されます。

 if rotatecheck(curblock,rowheight,columnwidth):
        rotate(curblock,rowheight,columnwidth)

ここcurblockで、 は 4 つの rect オブジェクトと 1 つの色のリストであり、プレイスペースのサイズを定義する整数であり、次のcolumnwidthように定義されます。rowheightrotatecheck()

def rotatecheck(curc, ro, col):
    new=[]
    ct=len(blockonscreen)-1
    if ct==0:
        ct=1
    for z in range(len(curc)):
        new.append(curc[z])
    rotate(new, ro, col)
    for i in range(len(new)-1):
        if new[i].left<0 or new[i].left>=WINDOWWIDTH:
            return False
        for b in blockonscreen:
            if b !=curc:
                for x in range(len(block)-1):
                    if new[i] == block[x]:
                        return False
    return True

blockonscreenは、4 つの rect オブジェクトと 1 つの色を含むリストのリストであり、次のrotate()ように定義されます。

def rotate(curr,ro,col):
     if curr[4]==yellow:
         rotateo(curr,ro,col)
     elif curr[4]==cyan:
         rotatei(curr,ro,col)
     else:
         rotatea(curr,ro,col)

def rotatei(curr,ro,col):
    if curr[2].centerx>curr[0].centerx and curr[3].centerx>curr[0].centerx:
        horiz=True
        curr[0].centerx+=col
        bla=1
    elif curr[2].centerx<curr[0].centerx and curr[3].centerx<curr[0].centerx:
        horiz=True
        curr[0].centerx-=col
        bla=-1
    elif curr[2].centery>curr[0].centery and curr[3].centery>curr[0].centery:
        horiz=False
        curr[0].centery+=ro
        bla=-1
    elif curr[2].centery<curr[0].centery and curr[3].centery<curr[0].centery:
        horiz=False
        curr[0].centery-=ro
        bla=1
    for f in range (1,4):
        if horiz:
            curr[f].left=curr[0].left
            curr[f].top=curr[0].top+(blocks[0][f-1][0]*ro*bla)
        else:
            curr[f].top=curr[0].top
            curr[f].right=curr[0].right+(blocks[0][f-1][0]*col*bla)
def rotateo(curr,ro,col):
    pass
def rotatea(curr,ro,col):
    middlex=curr[0].centerx
    middley=curr[0].centery
    for r in range(1,4):
        if curr[r].centery==middley and curr[r].centerx>middlex:
            curr[r].centery+=ro
            curr[r].centerx-=col
        elif curr[r].centery==middley and curr[r].centerx<middlex:
            curr[r].centery-=ro
            curr[r].centerx+=col
        elif curr[r].centerx==middlex and curr[r].centery>middley:
            curr[r].centery-=ro
            curr[r].centerx-=col            
        elif curr[r].centerx==middlex and curr[r].centery<middley:
            curr[r].centery+=ro
            curr[r].centerx+=col            
        elif curr[r].centerx>middlex and curr[r].centery>middley:
            curr[r].centerx-=(2*col)
        elif curr[r].centery>middley and curr[r].centerx<middlex:
            curr[r].centery-=(2*ro)
        elif curr[r].centerx<middlex and curr[r].centery<middley:
            curr[r].centerx+=(2*col)
        elif curr[r].centerx>middlex and curr[r].centery<middley:
            curr[r].centery+=(2*ro)

現在の状態では、プログラムrotatecheck()は存在しないかのように動作します。コードを繰り返し精査しましたが、問題は見つかりません。

4

1 に答える 1