我有 2 个图像,我有 4 个图像视图我想在 2-2 个图像视图上随机设置 2 个图像。
就像纸牌游戏一样。在该用户选择 1 张卡时,如果图像相同,则用户还有 3 个选项可以打开相同的图像,然后用户在再次单击后赢得游戏。请帮帮我...
int r =arc4random()%4;
int z=arc4random()%4;
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:r];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
if(r!=z)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}else{
if(r==3)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z-2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}
if(r==0)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z+2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}if(r==1)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z+2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}
if(r==2)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z-2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}
}