//
// Game.m
// UIGame
//
// Created by Ibokan on12-8-21.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "Game.h"
@implementation Game
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have asuperview.
[superdidReceiveMemoryWarning];
// Release any cached data, images, etcthat aren't in use.
}
#pragma mark - View lifecycle
- (void)dealloc
{
[super dealloc];
}
// Implement viewDidLoad to do additional setup afterloading the view, typically from a nib.
- (void)viewDidLoad
{
[superviewDidLoad];
self.view.backgroundColor=[UIColorblackColor];
UIView * viewa=[[UIViewalloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
viewa.backgroundColor=[UIColor blackColor];
//===================================================================================
//
// 利用for 循环 生成28个按钮 并为每个按钮的tag 赋值(100-127)
//
//===================================================================================
int x=100; //为了给每个tag 赋值
for (int i=0; i<4; i++){
for(int j=0;j<7; j++) {
UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(20+77*i, 20+55*j, 48, 48);
[button setImage:[UIImage imageNamed:@"g.png"]forState:UIControlStateNormal];
button.tag= x++;
button.titleLabel.tag=1;
[viewa addSubview:button];
if(button.tag==106)
{
[button addTarget:self action:@selector(urClick:) forControlEvents:UIControlEventTouchUpInside];
}
else if(button.tag==113||button.tag==120)
{
[button addTarget:self action:@selector(ulrClick:) forControlEvents:UIControlEventTouchUpInside];
}
else if(button.tag==107||button.tag==114)
{
[button addTarget:self action:@selector(dlrClick:) forControlEvents:UIControlEventTouchUpInside];
}
else if(button.tag==121)
{
[buttonaddTarget:self action:@selector(dlClick:)forControlEvents:UIControlEventTouchUpInside];
}else
{
[buttonaddTarget:self action:@selector(udlrClick:)forControlEvents:UIControlEventTouchUpInside];
}
}
}
[self.view addSubview:viewa];
[viewarelease];
}
//===================================================================================
//
// 这是tag值为中间的10个按钮响应
//
//===================================================================================
#pragma mark - 点击事件一
- (void)udlrClick:(id)sender
{
UIButton *button = sender; //点击事件
UIButton * up; //上边
UIButton *down; //下边
UIButton *left; //左边
UIButton *right; //右边
[buttonsetImage:[UIImage imageNamed:@"h.png"]forState:UIButtonTypeCustom];
if (button.titleLabel.tag == 1){
[button setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
button.titleLabel.tag =0;
} else {
[button setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
button.titleLabel.tag =1;
}
up = (UIButton*)[self.view viewWithTag:button.tag-1];
if (up.titleLabel.tag == 1){
[up setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
up.titleLabel.tag =0;
} else {
[up setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
up.titleLabel.tag =1;
}
down =(UIButton *)[self.viewviewWithTag:button.tag+1];
if (down.titleLabel.tag == 1){
[down setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
down.titleLabel.tag =0;
} else {
[down setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
down.titleLabel.tag =1;
}
left =(UIButton *)[self.viewviewWithTag:button.tag-7];
if (left.titleLabel.tag == 1){
[left setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
left.titleLabel.tag =0;
} else {
[left setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
left.titleLabel.tag =1;
}
right =(UIButton *)[self.viewviewWithTag:button.tag+7];
if (right.titleLabel.tag == 1){
[right setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
right.titleLabel.tag =0;
} else {
[right setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
right.titleLabel.tag =1;
}
}
//===================================================================================
//
// 这是tag值为106个按钮响应 也就是左下角的
//
//===================================================================================
#pragma mark - 点击事件二
- (void)urClick:(id)sender
{
UIButton *button = sender; //点击的按钮
UIButton *up; //上边
UIButton *right; //右边
[buttonsetImage:[UIImage imageNamed:@"g.png"]forState:UIButtonTypeCustom];
if (button.titleLabel.tag == 1){
[button setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
button.titleLabel.tag =0;
} else {
[button setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
button.titleLabel.tag =1;
}
up = (UIButton*)[self.viewviewWithTag:button.tag-1];
if (up.titleLabel.tag == 1){
[up setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
up.titleLabel.tag =0;
} else {
[up setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
up.titleLabel.tag =1;
}
right =(UIButton *)[self.viewviewWithTag:button.tag+7];
if (right.titleLabel.tag == 1){
[right setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
right.titleLabel.tag =0;
} else {
[right setImage:[UIImageimageNamed:@"g.png"]forState:UIButtonTypeCustom];
right.titleLabel.tag =1;
}
}
//===================================================================================
//
// 这是按钮最下一排 第2第3个 的事件
//
//===================================================================================
#pragma mark - 点击事件三
- (void)ulrClick:(id)sender
{
UIButton *button = sender; //点击的按钮
UIButton *up; //上边
UIButton *left; //左边
UIButton *right; //右边
[buttonsetImage:[UIImage imageNamed:@"h.png"]forState:UIButtonTypeCustom];
if (button.titleLabel.tag == 1){
[button setImage:[UIImageimageNamed:@"h.png"]forState:UIButtonTypeCustom];
button.titleLabel.tag =0;
} else {
[button setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
button.titleLabel.tag = 1;
}
up =(UIButton *)[self.view viewWithTag:button.tag-1];
if (up.titleLabel.tag == 1) {
[upsetImage:[UIImageimageNamed:@"h.png"] forState:UIButtonTypeCustom];
up.titleLabel.tag = 0;
} else {
[upsetImage:[UIImageimageNamed:@"g.png"] forState:UIButtonTypeCustom];
up.titleLabel.tag = 1;
}
left =(UIButton *)[self.view viewWithTag:button.tag-7];
if (left.titleLabel.tag == 1) {
[left setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
left.titleLabel.tag = 0;
} else {
[left setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
left.titleLabel.tag = 1;
}
right =(UIButton *)[self.view viewWithTag:button.tag+7];
if (right.titleLabel.tag == 1) {
[right setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
right.titleLabel.tag = 0;
} else {
[right setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
right.titleLabel.tag = 1;
}
}
//===================================================================================
//
// 这是按钮最上一排 第2第3个 的事件
//
//===================================================================================
#pragma mark - 点击事件四
- (void)dlrClick:(id)sender
{
UIButton * button = sender;//点击事件
UIButton * down; //下边
UIButton * left; //左边
UIButton * ringht; //右边
[button setImage:[UIImageimageNamed:@"g.png"] forState:UIButtonTypeCustom];
if (button.titleLabel.tag == 1) {
[button setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
button.titleLabel.tag = 0;
} else {
[button setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
button.titleLabel.tag = 1;
}
down =(UIButton *)[self.view viewWithTag:button.tag+1];
if (down.titleLabel.tag == 1) {
[down setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
down.titleLabel.tag = 0;
} else {
[down setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
down.titleLabel.tag = 1;
}
left =(UIButton *)[self.view viewWithTag:button.tag-7];
if (left.titleLabel.tag == 1) {
[left setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
left.titleLabel.tag = 0;
} else {
[left setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
left.titleLabel.tag = 1;
}
ringht =(UIButton *)[self.view viewWithTag:button.tag+7];
if (ringht.titleLabel.tag == 1) {
[ringht setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
ringht.titleLabel.tag = 0;
} else {
[ringht setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
ringht.titleLabel.tag = 1;
}
}
//===================================================================================
//
// 这是按钮 右上角
//
//===================================================================================
#pragma mark - 点击事件五
- (void)dlClick:(id)sender
{
UIButton * button = sender; //点击的按钮
UIButton * down; //下边
UIButton * left; //左边
[button setImage:[UIImageimageNamed:@"g.png"] forState:UIButtonTypeCustom];
if (button.titleLabel.tag == 1) {
[button setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
button.titleLabel.tag = 0;
} else {
[button setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
button.titleLabel.tag = 1;
}
down =(UIButton *)[self.view viewWithTag:button.tag+1];
if (down.titleLabel.tag == 1) {
[down setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
down.titleLabel.tag = 0;
} else {
[down setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
down.titleLabel.tag = 1;
}
left =(UIButton *)[self.view viewWithTag:button.tag-7];
if (left.titleLabel.tag == 1) {
[left setImage:[UIImage imageNamed:@"h.png"] forState:UIButtonTypeCustom];
left.titleLabel.tag = 0;
} else {
[left setImage:[UIImage imageNamed:@"g.png"] forState:UIButtonTypeCustom];
left.titleLabel.tag = 1;
}
}
- (void)viewDidUnload
{
[superviewDidUnload];
// Release any retained subviews of themain view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supportedorientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end