extraa

How to make dynamic button with Game

– (void)viewDidLoad

{

[super viewDidLoad];

xaxis = 20,yaxis=100,index=1;

for (int y = 0; y<4; y++)

{

for (int x=0; x<4; x++)

{

btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];

btn1.frame=CGRectMake(xaxis, yaxis, 50, 50);

btn1.backgroundColor=[UIColor redColor];

[btn1 addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];

xaxis = xaxis + 70;

btn1.tag=index;

index++;

[self.view addSubview:btn1];

}

yaxis=yaxis+70;

xaxis=20;

}

randm = (arc4random()%16+1);

btn1 =(UIButton *)[self.view viewWithTag:randm];

btn1.backgroundColor=[UIColor blueColor];

}

-(IBAction)btnclick:(UIButton *)sender

{

if (sender.tag == randm)

{

count++;

sender.backgroundColor=[UIColor brownColor];

sender.enabled=false;

if (count == 16)

{

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@”Game Overr” message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@”ok”, nil];

[alert show];

}

else

{

BOOL flag=true;

while (flag)

{

randm = (arc4random()%16+1);

btn1 = (UIButton *)[self.view viewWithTag:randm];

if (btn1.enabled) {

btn1.backgroundColor=[UIColor blueColor];

flag=false;

}

}

}

}

}

How to make dynamic button with Game

– (void)viewDidLoad

{

[super viewDidLoad];

xaxis = 20,yaxis=100,index=1;

for (int y = 0; y<4; y++)

{

for (int x=0; x<4; x++)

{

btn1 =[UIButton buttonWithType:UIButtonTypeRoundedRect];

btn1.frame=CGRectMake(xaxis, yaxis, 50, 50);

btn1.backgroundColor=[UIColor redColor];

[btn1 addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];

xaxis = xaxis + 70;

btn1.tag=index;

index++;

[self.view addSubview:btn1];

}

yaxis=yaxis+70;

xaxis=20;

}

randm = (arc4random()%16+1);

btn1 =(UIButton *)[self.view viewWithTag:randm];

btn1.backgroundColor=[UIColor blueColor];

}

-(IBAction)btnclick:(UIButton *)sender

{

if (sender.tag == randm)

{

count++;

sender.backgroundColor=[UIColor brownColor];

sender.enabled=false;

if (count == 16)

{

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@”Game Overr” message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@”ok”, nil];

[alert show];

}

else

{

BOOL flag=true;

while (flag)

{

randm = (arc4random()%16+1);

btn1 = (UIButton *)[self.view viewWithTag:randm];

if (btn1.enabled) {

btn1.backgroundColor=[UIColor blueColor];

flag=false;

}

}

}

}

How to make timer

– (IBAction)Start:(id)sender

{

[time1 invalidate];

time1 = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(onTick) userInfo:Nil repeats:YES];

}

– (void)onTick

{

count++;

NSString *ts = [[NSString alloc]initWithFormat:@”%d”,count ];

_lbl1.text= ts;

}

– (IBAction)stop:(id)sender

{

if ([time1 isValid])

{

[time1 invalidate];

//count=0; // using this two line direct set 0 & satrt with 0

// _lbl1.text=@”0″;

NSString *ts = [[NSString alloc]initWithFormat:@”%d”,count ];

_lbl1.text= ts;

}

// time1 = nil;

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s