在我的井字游戏代码中,按重置按钮后动画选项不起作用

时间:2019-09-23 17:38:58

标签: java android android-studio jquery-animate

在android studio中,井字游戏重置按钮未显示任何类型的动画,请在我单击重置按钮应用程序时工作正常,但O和X的动画未显示,当我启动应用程序但按重置后显示动画按钮360图像(O和X)的动画不显示。

public class MainActivity extends AppCompatActivity {

int turn = 0;
//0 for cross and 1 for circle;

int[] arr = {2,2,2,2,2,2,2,2,2};


public void click (View view){

    ImageView imageView = (ImageView) view;

    int tagg = Integer.parseInt(imageView.getTag().toString());


    if (arr[tagg-1]==2)
    {
        arr[tagg-1]= turn;

        if(turn == 0)
        {
            imageView.setImageResource(R.drawable.x_image);
            imageView.animate().rotation(360).setDuration(1000);
            turn = 1;

            if (arr[0]==0&&arr[1]==0&&arr[2]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[3]==0&&arr[4]==0&&arr[5]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }

            if (arr[6]==0&&arr[7]==0&&arr[8]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[0]==0&&arr[3]==0&&arr[6]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[1]==0&&arr[4]==0&&arr[7]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[2]==0&&arr[5]==0&&arr[8]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[0]==0&&arr[4]==0&&arr[8]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[2]==0&&arr[4]==0&&arr[6]==0)
            {
                Toast.makeText(MainActivity.this,"cross wins",Toast.LENGTH_SHORT).show();

            }

        }
        else
        {
            imageView.setImageResource(R.drawable.o_image);
            imageView.animate().rotation(360).setDuration(1000);
            turn = 0;

            if (arr[0]==1&&arr[1]==1&&arr[2]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[3]==1&&arr[4]==1&&arr[5]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }

            if (arr[6]==1&&arr[7]==1&&arr[8]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[0]==1&&arr[3]==1&&arr[6]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[1]==1&&arr[4]==1&&arr[7]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[2]==1&&arr[5]==1&&arr[8]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[0]==1&&arr[4]==1&&arr[8]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }
            if (arr[2]==1&&arr[4]==1&&arr[6]==1)
            {
                Toast.makeText(MainActivity.this,"circle wins",Toast.LENGTH_SHORT).show();

            }

        }

    }
    else
        Toast.makeText(MainActivity.this,"this place is filled already..",Toast.LENGTH_SHORT).show();



}

public void btnclick (View view)
{
    turn = 0;
    for (int i=0;i<9;i++)
    {
        arr[i] = 2;
    }
    ImageView imageView1 = (ImageView) findViewById(R.id.img1);
    imageView1.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView2 = (ImageView) findViewById(R.id.img2);
    imageView2.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView3 = (ImageView) findViewById(R.id.img3);
    imageView3.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView4 = (ImageView) findViewById(R.id.img4);
    imageView4.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView5 = (ImageView) findViewById(R.id.img5);
    imageView5.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView6 = (ImageView) findViewById(R.id.img6);
    imageView6.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView7 = (ImageView) findViewById(R.id.img7);
    imageView7.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView8 = (ImageView) findViewById(R.id.img8);
    imageView8.setImageResource(R.mipmap.ic_launcher);
    ImageView imageView9 = (ImageView) findViewById(R.id.img9);
    imageView9.setImageResource(R.mipmap.ic_launcher);

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }
}

在我的井字游戏代码动画选项中,按重置按钮后不起作用。

1 个答案:

答案 0 :(得分:0)

在您的onCreate方法中,您什么都没有调用,这可能会导致一些问题,请注意,该方法应该是您的主要方法。

但是请与我们共享xml文件,以便我们进一步为您提供帮助。