2048的移动功能有问题

时间:2019-05-24 12:13:25

标签: c++ codeblocks

正在为我的编码类工作一个项目,但是我对如何进行2048的移动感到非常困惑。某些部分可以工作,而另一些部分会使右上角的方块变成一个很大的数字串。 / p>

正如我所说,这是针对c ++编码类的。我从事井字游戏和石头,纸,剪刀之类的简单项目。所有这些都像魅力一样。 下面是该函数上移的代码。我想起了上升运动,就可以将其转换为其他方向。以及用于设置网格的代码以及用于设置板的0和2的功能。

 void moveyBois(int a[4][4], char b)
        {
            if(b == 'w' || b == 'W') //Up, and I'm gonna be honest, I've tried this over and over again, but whenever I do a single edit to it, it just breaks on me.
            {
                for(int i = 0; i < 4;)
                {
                        if(a[0][0] != 0 && a[0][1] == 0 && a[0][2] == 0 && a[0][3] == 0)
                        {
                            a[0][0] = a[0][0];
                        }

                        else if(a[0][0] == 0 && a[0][1] != 0 && a[0][2] == 0 && a[0][3] == 0)
                            {
                                a[0][0] = a[0][1];
                                a[0][1] = 0;
                            }
                        else if(a[0][0] == 0 && a[0][1] == 0 && a[0][2] != 0 && a[0][3] == 0)
                        {
                            a[0][0] = a[0][2];
                            a[0][2] = 0;
                        }
                        else if(a[0][0] == 0 && a[0][1] == 0 && a[0][2] == 0 && a[0][3] != 0)
                        {
                            a[0][0] = a[0][3];
                            a[0][3] = 0;
                        }


                    else if(a[0][i] == a[0][i+1])
                    {
                        if(a[0][i] == a[0][i+2] && a[0][i+1] != a[0][i+3])
                        {
                            a[0][i] = (a[0][i] + a[0][i+1]);
                            a[0][i+1] = a[0][i+2];
                            a[0][i+2] = a[0][i+3];
                            a[0][i+3] = 0;
                        }
                        else if(a[0][i+1] == a[0][i+2] && a[0][i+1] == a[0][i+3])
                        {
                            a[0][i] = (a[0][i] + a[0][i+1]);
                            a[0][i+1] = (a[0][i+1] + a[0][i+1]);
                            a[0][i+2] = 0;
                            a[0][i+3] = 0;
                        }
                        else
                        {
                            a[0][i] = (a[0][i] + a[0][i+1]);
                            a[0][i+1] = 0;
                        }
                    }
                    else if(a[0][i+1] == 0 && a[0][i] == a[0][i+2])
                        {
                            a[0][i] = (a[0][i] + a[0][i+2]);
                            a[0][i+2] = 0;
                        }

                    else if(a[0][i+1] == 0 && a[0][i+2] == 0 && a[0][i] == a[0][i+3])
                        {
                            a[0][i] = (a[0][i] + a[0][i+3]);
                            a[0][i+3] = 0;
                        }

                        if(a[1][0] != 0 && a[1][1] == 0 && a[1][2] == 0 && a[1][3] == 0)
                        {
                            a[1][0] = a[1][0];
                        }

                        else if(a[1][0] == 0 && a[1][1] != 0 && a[1][2] == 0 && a[1][3] == 0)
                            {
                                a[1][0] = a[1][1];
                                a[1][1] = 0;
                            }
                        else if(a[1][0] == 0 && a[1][1] == 0 && a[1][2] != 0 && a[1][3] == 0)
                        {
                            a[1][0] = a[1][2];
                            a[1][2] = 0;
                        }
                        else if(a[1][0] == 0 && a[1][1] == 0 && a[1][2] == 0 && a[1][3] != 0)
                        {
                            a[1][0] = a[1][3];
                            a[1][3] = 0;
                        }


                    else if(a[1][i] == a[1][i+1])
                    {
                        if(a[1][i] == a[1][i+2] && a[1][i+1] != a[1][i+3])
                        {
                            a[1][i] = (a[1][i] + a[1][i+1]);
                            a[1][i+1] = a[1][i+2];
                            a[1][i+2] = a[1][i+3];
                            a[1][i+3] = 0;
                        }
                        else if(a[1][i+1] == a[1][i+2] && a[1][i+1] == a[1][i+3])
                        {
                            a[1][i] = (a[1][i] + a[1][i+1]);
                            a[1][i+1] = (a[1][i+1] + a[1][i+1]);
                            a[1][i+2] = 0;
                            a[1][i+3] = 0;
                        }
                        else
                        {
                            a[1][i] = (a[1][i] + a[1][i+1]);
                            a[1][i+1] = 0;
                        }
                    }
                    else if(a[1][i+1] == 0 && a[1][i] == a[1][i+2])
                        {
                            a[1][i] = (a[1][i] + a[1][i+2]);
                            a[1][i+2] = 0;
                        }

                    else if(a[1][i+1] == 0 && a[1][i+2] == 0 && a[1][i] == a[1][i+3])
                        {
                            a[1][i] = (a[1][i] + a[1][i+3]);
                            a[1][i+3] = 0;
                        }

                        if(a[2][0] != 0 && a[2][1] == 0 && a[2][2] == 0 && a[2][3] == 0)
                        {
                            a[2][0] = a[2][0];
                        }

                        else if(a[2][0] == 0 && a[2][1] != 0 && a[2][2] == 0 && a[2][3] == 0)
                            {
                                a[2][0] = a[2][1];
                                a[2][1] = 0;
                            }
                        else if(a[2][0] == 0 && a[2][1] == 0 && a[2][2] != 0 && a[2][3] == 0)
                        {
                            a[2][0] = a[2][2];
                            a[2][2] = 0;
                        }
                        else if(a[2][0] == 0 && a[2][1] == 0 && a[2][2] == 0 && a[2][3] != 0)
                        {
                            a[2][0] = a[2][3];
                            a[2][3] = 0;
                        }


                    else if(a[2][i] == a[2][i+1])
                    {
                        if(a[2][i] == a[2][i+2] && a[2][i+1] != a[2][i+3])
                        {
                            a[2][i] = (a[2][i] + a[2][i+1]);
                            a[2][i+1] = a[2][i+2];
                            a[2][i+2] = a[2][i+3];
                            a[2][i+3] = 0;
                        }
                        else if(a[2][i+1] == a[2][i+2] && a[2][i+1] == a[2][i+3])
                        {
                            a[2][i] = (a[2][i] + a[2][i+1]);
                            a[2][i+1] = (a[2][i+1] + a[2][i+1]);
                            a[2][i+2] = 0;
                            a[2][i+3] = 0;
                        }
                        else
                        {
                            a[2][i] = (a[2][i] + a[2][i+1]);
                            a[2][i+1] = 0;
                        }
                    }
                    else if(a[2][i+1] == 0 && a[2][i] == a[2][i+2])
                        {
                            a[2][i] = (a[2][i] + a[2][i+2]);
                            a[2][i+2] = 0;
                        }

                    else if(a[2][i+1] == 0 && a[2][i+2] == 0 && a[2][i] == a[2][i+3])
                        {
                            a[2][i] = (a[2][i] + a[2][i+3]);
                            a[2][i+3] = 0;
                        }

                        if(a[3][0] != 0 && a[3][1] == 0 && a[3][2] == 0 && a[3][3] == 0)
                        {
                            a[3][0] = a[3][0];
                        }

                        else if(a[3][0] == 0 && a[3][1] != 0 && a[3][2] == 0 && a[3][3] == 0)
                            {
                                a[3][0] = a[3][1];
                                a[3][1] = 0;
                            }
                        else if(a[3][0] == 0 && a[3][1] == 0 && a[3][2] != 0 && a[3][3] == 0)
                        {
                            a[3][0] = a[3][2];
                            a[3][2] = 0;
                        }
                        else if(a[3][0] == 0 && a[3][1] == 0 && a[3][2] == 0 && a[3][3] != 0)
                        {
                            a[3][0] = a[3][3];
                            a[3][3] = 0;
                        }


                    else if(a[3][i] == a[3][i+1])
                    {
                        if(a[3][i] == a[3][i+2] && a[3][i+1] != a[3][i+3])
                        {
                            a[3][i] = (a[3][i] + a[3][i+1]);
                            a[3][i+1] = a[3][i+2];
                            a[3][i+2] = a[3][i+3];
                            a[3][i+3] = 0;
                        }
                        else if(a[3][i+1] == a[3][i+2] && a[3][i+1] == a[3][i+3])
                        {
                            a[3][i] = (a[3][i] + a[3][i+1]);
                            a[3][i+1] = (a[3][i+1] + a[3][i+1]);
                            a[3][i+2] = 0;
                            a[3][i+3] = 0;
                        }
                        else
                        {
                            a[3][i] = (a[3][i] + a[3][i+1]);
                            a[3][i+1] = 0;
                        }
                    }
                    else if(a[3][i+1] == 0 && a[3][i] == a[3][i+2])
                        {
                            a[3][i] = (a[3][i] + a[3][i+2]);
                            a[3][i+2] = 0;
                        }

                    else if(a[3][i+1] == 0 && a[3][i+2] == 0 && a[3][i] == a[3][i+3])
                        {
                            a[3][i] = (a[3][i] + a[3][i+3]);
                            a[3][i+3] = 0;
                        }


                    i++;
                }

            }
            else if(b == 'a' || b == 'A') //Left
            {

            }
            else if(b == 's' || b == 'S') //Down
            {

            }
            else if(b == 'd' || b == 'D') //Right
            {

            }
            else
            {

            }
        }

void stupidStarters(int a[4][4])
        {
          for(int i = 0; i < 4;)
            {
                a[i][0] = 0;
                i++;
            }
            for(int i = 0; i < 4;)
            {
                a[i][1] = 0;
                i++;
            }
            for(int i = 0; i < 4;)
            {
                a[i][2] = 0;
                i++;
            }
            for(int i = 0; i < 4;)
            {
                a[i][3] = 0;
                i++;
            }
void griddyBois(int a[4][4])
        {
             cout << "+------+------+------+------+" << endl;
            cout << "| " << setw(4) << a[0][0] << " | " << setw(4) << a[1][0] << " | " << setw(4) << a[2][0] << " | " << setw(4) << a[3][0] << " |" << endl;
             cout << "+------+------+------+------+";
            cout << "\n| " << setw(4) << a[0][1] << " | " << setw(4) << a[1][1] << " | " << setw(4) << a[2][1] << " | " << setw(4) << a[3][1] << " |" << endl;
             cout << "+------+------+------+------+";
            cout << "\n| " << setw(4) << a[0][2] << " | " << setw(4) << a[1][2] << " | " << setw(4) << a[2][2] << " | " << setw(4) << a[3][2] << " |" << endl;
             cout << "+------+------+------+------+";
            cout << "\n| " << setw(4) << a[0][3] << " | " << setw(4) << a[1][3] << " | " << setw(4) << a[2][3] << " | " << setw(4) << a[3][3] << " |" << endl;
             cout << "+------+------+------+------+" << endl;
        }

我希望游戏板将瓷砖向上移动,但也要合并相邻的瓷砖,以使其在给定方向上发生碰撞。它可以进行约2个动作,然后在右上角的框中给我一个相当大的数字,约40万。

0 个答案:

没有答案