其中运用到得都是iOS中的基础知识,并非很难。
一些基本的button设置,label设置不展示了,只是写一下方法:
- (void)PshearView:(ImageView *)PshearView
{
ImageView *image2 = (ImageView *)[self.view viewWithTag:4];
NSInteger num = arc4random()%(3 - 1 + 1) + 1;
if (num == 1) {
NSLog(@"%ld", num);
ImageView *image = (ImageView *)[self.view viewWithTag:1];
image2.backgroundColor = [UIColor orangeColor];
image.backgroundColor = [UIColor orangeColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"平局!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
else if (num == 2)
{
ImageView *image = (ImageView *)[self.view viewWithTag:2];
NSLog(@"%ld",num);
image.backgroundColor = [UIColor greenColor];
image2.backgroundColor = [UIColor redColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"你输了!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
else if (num == 3)
{
ImageView *image = (ImageView *)[self.view viewWithTag:3];
NSLog(@"%ld", num);
image.backgroundColor = [UIColor redColor];
image2.backgroundColor = [UIColor greenColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"你赢了!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
}
- (void)Pstone:(ImageView *)Pstgone
{
ImageView *image2 = (ImageView *)[self.view viewWithTag:5];
NSInteger num = arc4random()%(3 - 1 + 1) + 1;
if (num == 1) {
NSLog(@"%ld", num);
ImageView *image = (ImageView *)[self.view viewWithTag:1];
image2.backgroundColor = [UIColor greenColor];
image.backgroundColor = [UIColor redColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"你赢了!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
else if (num == 2)
{
NSLog(@"%ld",num);
ImageView *image = (ImageView *)[self.view viewWithTag:2];
image.backgroundColor = [UIColor orangeColor];
image2.backgroundColor = [UIColor orangeColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"平局!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
else if (num == 3)
{
NSLog(@"%ld", num);
ImageView *image = (ImageView *)[self.view viewWithTag:3];
image.backgroundColor = [UIColor greenColor];
image2.backgroundColor = [UIColor redColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"你输了!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
}
- (void)Pcloth:(ImageView *)Pcloth
{
ImageView *image2 = (ImageView *)[self.view viewWithTag:6];
NSInteger num = arc4random()%(3 - 1 + 1) + 1;
if (num == 1) {
NSLog(@"%ld", num);
ImageView *image = (ImageView *)[self.view viewWithTag:1];
image2.backgroundColor = [UIColor redColor];
image.backgroundColor = [UIColor greenColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"你输了!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
else if (num == 2)
{
NSLog(@"%ld",num);
ImageView *image = (ImageView *)[self.view viewWithTag:2];
image.backgroundColor = [UIColor redColor];
image2.backgroundColor = [UIColor greenColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"你赢了!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
else if (num == 3)
{
NSLog(@"%ld", num);
ImageView *image = (ImageView *)[self.view viewWithTag:3];
image.backgroundColor = [UIColor orangeColor];
image2.backgroundColor = [UIColor orangeColor];
image2.alpha = 0.7;
image.alpha = 0.7;
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示!" message:@"平局!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"继续", nil];
[alertView show];
[alertView release];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
ImageView *image1 = (ImageView *)[self.view viewWithTag:1];
ImageView *image2 = (ImageView *)[self.view viewWithTag:2];
ImageView *image3 = (ImageView *)[self.view viewWithTag:3];
ImageView *image4 = (ImageView *)[self.view viewWithTag:4];
ImageView *image5 = (ImageView *)[self.view viewWithTag:5];
ImageView *image6 = (ImageView *)[self.view viewWithTag:6];
switch (buttonIndex) {
case 1:
image1.backgroundColor = [UIColor clearColor];
image2.backgroundColor = [UIColor clearColor];
image3.backgroundColor = [UIColor clearColor];
image4.backgroundColor = [UIColor clearColor];
image5.backgroundColor = [UIColor clearColor];
image6.backgroundColor = [UIColor clearColor];
break;
case 0:
image1.backgroundColor = [UIColor clearColor];
image2.backgroundColor = [UIColor clearColor];
image3.backgroundColor = [UIColor clearColor];
image4.backgroundColor = [UIColor clearColor];
image5.backgroundColor = [UIColor clearColor];
image6.backgroundColor = [UIColor clearColor];
break;
default:
break;
}
}