在我的井字游戏代码中,动画选项在按下重置按钮后不起作用
In my tic tac toe game code animate option not working after press reset button
在android工作室中,井字游戏重置按钮不显示任何类型的动画请帮助当我点击重置按钮应用程序工作正常但O和X的动画不显示,动画显示当我启动应用程序,但在按下重置按钮后,图像(O 和 X)的 360 度动画不显示。
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);
}
}
在我的井字游戏代码中,动画选项在按下重置按钮后不起作用。
在你的 onCreate 方法中你没有调用任何东西,这可能会导致一些问题,b/c这个方法应该是你的主要方法。
但请与我们分享 xml 文件,以便我们进一步帮助您。
在android工作室中,井字游戏重置按钮不显示任何类型的动画请帮助当我点击重置按钮应用程序工作正常但O和X的动画不显示,动画显示当我启动应用程序,但在按下重置按钮后,图像(O 和 X)的 360 度动画不显示。
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);
}
}
在我的井字游戏代码中,动画选项在按下重置按钮后不起作用。
在你的 onCreate 方法中你没有调用任何东西,这可能会导致一些问题,b/c这个方法应该是你的主要方法。
但请与我们分享 xml 文件,以便我们进一步帮助您。