Sign-in / Sign-up
Your question

Objective-C Student Project: Calculating 8x6 Connect4 wins?

Tags:
  • Programming
  • Apps
Last response: in Apps General Discussion
January 11, 2013 4:10:12 PM

I am looking for a way to check if there is a win in my objective-c IOS application. Everything works, but I don't have a function to calculate the win possibilities. The positions are stored in a multidimensional array of array[x][y]. If there is no chip, it is valued at =0, red =1, and yellow=2. Does anyone know how to use some sort of method to calculate and check if there are 4 of the same colour in a row either horizontally vertically or diagonally. Skip to line 160 of ViewController.m :hello: 

Thanks for any help! :p 



Complete code:

ViewController.h
  1. //
  2. // ViewController.h
  3. // Connect4
  4. //
  5. // Created by Matthew Cooke on 12-12-18.
  6. // Copyright (c) 2012 Programming 12. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10.  
  11. @interface ViewController : UIViewController {
  12.  
  13.  
  14.  
  15.  
  16.  
  17. IBOutlet UIButton * button1;
  18. IBOutlet UIButton * button2;
  19. IBOutlet UIButton * button3;
  20. IBOutlet UIButton * button4;
  21. IBOutlet UIButton * button5;
  22. IBOutlet UIButton * button6;
  23. IBOutlet UIButton * button7;
  24. IBOutlet UIButton * button8;
  25.  
  26.  
  27.  
  28. UIImageView *image1;//had to use separate images as an array wouldn't work.
  29. UIImageView *image2;
  30. UIImageView *image3;
  31. UIImageView *image4;
  32. UIImageView *image5;
  33. UIImageView *image6;
  34. UIImageView *image7;
  35. UIImageView *image8;
  36. UIImageView *image9;
  37. UIImageView *image10;
  38. UIImageView *image11;
  39. UIImageView *image12;
  40. UIImageView *image13;
  41. UIImageView *image14;
  42. UIImageView *image15;
  43. UIImageView *image16;
  44. UIImageView *image17;
  45. UIImageView *image18;
  46. UIImageView *image19;
  47. UIImageView *image20;
  48. UIImageView *image21;
  49. UIImageView *image22;
  50. UIImageView *image23;
  51. UIImageView *image24;
  52. UIImageView *image25;
  53. UIImageView *image26;
  54. UIImageView *image27;
  55. UIImageView *image28;
  56. UIImageView *image29;
  57. UIImageView *image30;
  58. UIImageView *image31;
  59. UIImageView *image32;
  60. UIImageView *image33;
  61. UIImageView *image34;
  62. UIImageView *image35;
  63. UIImageView *image36;
  64. UIImageView *image37;
  65. UIImageView *image38;
  66. UIImageView *image39;
  67. UIImageView *image40;
  68. UIImageView *image41;
  69. UIImageView *image42;
  70. UIImageView *image43;
  71. UIImageView *image44;
  72. UIImageView *image45;
  73. UIImageView *image46;
  74. UIImageView *image47;
  75. UIImageView *image48;
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83.  
  84. //@property (nonatomic, retain) IBOutlet UIImageView* imageView;
  85. @property (nonatomic) IBOutlet UIButton * button1;
  86. @property (nonatomic) IBOutlet UIButton * button2;
  87. @property (nonatomic) IBOutlet UIButton * button3;
  88. @property (nonatomic) IBOutlet UIButton * button4;
  89. @property (nonatomic) IBOutlet UIButton * button5;
  90. @property (nonatomic) IBOutlet UIButton * button6;
  91. @property (nonatomic) IBOutlet UIButton * button7;
  92. @property (nonatomic) IBOutlet UIButton * button8;
  93. @property (nonatomic) IBOutlet UIImageView *image1;
  94. @property (nonatomic) IBOutlet UIImageView *image2;
  95. @property (nonatomic) IBOutlet UIImageView *image3;
  96. @property (nonatomic) IBOutlet UIImageView *image4;
  97. @property (nonatomic) IBOutlet UIImageView *image5;
  98. @property (nonatomic) IBOutlet UIImageView *image6;
  99. @property (nonatomic) IBOutlet UIImageView *image7;
  100. @property (nonatomic) IBOutlet UIImageView *image8;
  101. @property (nonatomic) IBOutlet UIImageView *image9;
  102. @property (nonatomic) IBOutlet UIImageView *image10;
  103. @property (nonatomic) IBOutlet UIImageView *image11;
  104. @property (nonatomic) IBOutlet UIImageView *image12;
  105. @property (nonatomic) IBOutlet UIImageView *image13;
  106. @property (nonatomic) IBOutlet UIImageView *image14;
  107. @property (nonatomic) IBOutlet UIImageView *image15;
  108. @property (nonatomic) IBOutlet UIImageView *image16;
  109. @property (nonatomic) IBOutlet UIImageView *image17;
  110. @property (nonatomic) IBOutlet UIImageView *image18;
  111. @property (nonatomic) IBOutlet UIImageView *image19;
  112. @property (nonatomic) IBOutlet UIImageView *image20;
  113. @property (nonatomic) IBOutlet UIImageView *image21;
  114. @property (nonatomic) IBOutlet UIImageView *image22;
  115. @property (nonatomic) IBOutlet UIImageView *image23;
  116. @property (nonatomic) IBOutlet UIImageView *image24;
  117. @property (nonatomic) IBOutlet UIImageView *image25;
  118. @property (nonatomic) IBOutlet UIImageView *image26;
  119. @property (nonatomic) IBOutlet UIImageView *image27;
  120. @property (nonatomic) IBOutlet UIImageView *image28;
  121. @property (nonatomic) IBOutlet UIImageView *image29;
  122. @property (nonatomic) IBOutlet UIImageView *image30;
  123. @property (nonatomic) IBOutlet UIImageView *image31;
  124. @property (nonatomic) IBOutlet UIImageView *image32;
  125. @property (nonatomic) IBOutlet UIImageView *image33;
  126. @property (nonatomic) IBOutlet UIImageView *image34;
  127. @property (nonatomic) IBOutlet UIImageView *image35;
  128. @property (nonatomic) IBOutlet UIImageView *image36;
  129. @property (nonatomic) IBOutlet UIImageView *image37;
  130. @property (nonatomic) IBOutlet UIImageView *image38;
  131. @property (nonatomic) IBOutlet UIImageView *image39;
  132. @property (nonatomic) IBOutlet UIImageView *image40;
  133. @property (nonatomic) IBOutlet UIImageView *image41;
  134. @property (nonatomic) IBOutlet UIImageView *image42;
  135. @property (nonatomic) IBOutlet UIImageView *image43;
  136. @property (nonatomic) IBOutlet UIImageView *image44;
  137. @property (nonatomic) IBOutlet UIImageView *image45;
  138. @property (nonatomic) IBOutlet UIImageView *image46;
  139. @property (nonatomic) IBOutlet UIImageView *image47;
  140. @property (nonatomic) IBOutlet UIImageView *image48;
  141.  
  142.  
  143.  
  144. - (IBAction)contentModeChanged:(UISegmentedControl*)segmentedControl;
  145.  
  146. @end


ViewController.m
  1. //
  2. // ViewController.m
  3. // Connect4
  4. //
  5. // Created by Block B-F on 12-12-18.
  6. // Copyright (c) 2012 Programming 12. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController ()
  12.  
  13. @end
  14.  
  15. @implementation ViewController;
  16.  
  17. @synthesize image1;
  18. @synthesize image2;
  19. @synthesize image3;
  20. @synthesize image4;
  21. @synthesize image5;
  22. @synthesize image6;
  23. @synthesize image7;
  24. @synthesize image8;
  25. @synthesize image9;
  26. @synthesize image10;
  27. @synthesize image11;
  28. @synthesize image12;
  29. @synthesize image13;
  30. @synthesize image14;
  31. @synthesize image15;
  32. @synthesize image16;
  33. @synthesize image17;
  34. @synthesize image18;
  35. @synthesize image19;
  36. @synthesize image20;
  37. @synthesize image21;
  38. @synthesize image22;
  39. @synthesize image23;
  40. @synthesize image24;
  41. @synthesize image25;
  42. @synthesize image26;
  43. @synthesize image27;
  44. @synthesize image28;
  45. @synthesize image29;
  46. @synthesize image30;
  47. @synthesize image31;
  48. @synthesize image32;
  49. @synthesize image33;
  50. @synthesize image34;
  51. @synthesize image35;
  52. @synthesize image36;
  53. @synthesize image37;
  54. @synthesize image38;
  55. @synthesize image39;
  56. @synthesize image40;
  57. @synthesize image41;
  58. @synthesize image42;
  59. @synthesize image43;
  60. @synthesize image44;
  61. @synthesize image45;
  62. @synthesize image46;
  63. @synthesize image47;
  64. @synthesize image48;
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. //@synthesize imageView;
  72.  
  73. @synthesize button1, button2, button3, button4, button5, button6, button7, button8;
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. int x1 = 0; //unactivated
  82. int x2 = 0;
  83. int x3 = 0;
  84. int x4 = 0;
  85. int x5 = 0;
  86. int x6 = 0;
  87. int x7 = 0;
  88. int x8 = 0;
  89. int x9 = 0;
  90. int x10 = 0;
  91. int x11 = 0;
  92. int x12 = 0;
  93. int x13 = 0;
  94. int x14 = 0;
  95. int x15 = 0;
  96. int x16 = 0;
  97. int x17 = 0;
  98. int x18 = 0;
  99. int x19 = 0;
  100. int x20 = 0;
  101. int x21 = 0;
  102. int x22 = 0;
  103. int x23 = 0;
  104. int x24 = 0;
  105. int x25 = 0;
  106. int x26 = 0;
  107. int x27 = 0;
  108. int x28 = 0;
  109. int x29 = 0;
  110. int x30 = 0;
  111. int x31 = 0;
  112. int x32 = 0;
  113. int x33 = 0;
  114. int x34 = 0;
  115. int x35 = 0;
  116. int x36 = 0;
  117. int x37 = 0;
  118. int x38 = 0;
  119. int x39 = 0;
  120. int x40 = 0;
  121. int x41 = 0;
  122. int x42 = 0;
  123. int x43 = 0;
  124. int x44 = 0;
  125. int x45 = 0;
  126. int x46 = 0;
  127. int x47 = 0;
  128. int x48 = 0;
  129.  
  130.  
  131.  
  132.  
  133.  
  134. int i = -1;
  135. int row1 = 0;
  136. int row2 = 0;
  137. int row3 = 0;
  138. int row4 = 0;
  139. int row5 = 0;
  140. int row6 = 0;
  141. int row7 = 0;
  142. int row8 = 0;
  143. int x = 0;
  144. int winArray[9][7];
  145. bool win = 0;
  146.  
  147. UIImage * red;
  148. UIImage * yellow;
  149.  
  150.  
  151.  
  152.  
  153.  
  154. -(int)checkWin{
  155.  
  156. for (int c=1; c<=8; c++){
  157.  
  158. for (int r=1; r<=6; r++){
  159.  
  160. //....*******HELP*******HELP*******HELP*******HELP********HELP********HELP********HELP********HELP********HELP********HELP
  161.  
  162. }
  163.  
  164. }
  165.  
  166.  
  167.  
  168.  
  169. return win;
  170. }
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. -(int)whatImage{
  182. i++;
  183.  
  184.  
  185. if(x==1){// skip to the ------ line.
  186. if (i%2==1){
  187. [image1 setImage:[UIImage imageNamed: @"red.png"]];
  188. [image1 setHidden: NO];
  189. ////[self.view addSubview: image1];
  190. ////[self.view bringSubviewToFront: image1];
  191. x1=1;//red's
  192.  
  193. }
  194. else if (i%2==0){
  195. [image1 setImage:[UIImage imageNamed: @"yellow.png"]];
  196. [image1 setHidden: NO];
  197. // //[self.view addSubview: image1];
  198. // //[self.view bringSubviewToFront: image1];
  199. x1=2;//yellow's
  200.  
  201. }
  202. else{
  203. NSLog(@"Error");
  204. [super didReceiveMemoryWarning];
  205. }
  206. winArray[1][1] = x1;
  207. }
  208.  
  209. else if(x==2){
  210. if (i%2==1){
  211. [image2 setImage:[UIImage imageNamed: @"red.png"]];
  212. [image2 setHidden: NO];
  213. ////[self.view addSubview: image2];
  214. //[self.view bringSubviewToFront: image2];
  215. x2=1;
  216.  
  217. }
  218. else if (i%2==0){
  219. [image2 setImage:[UIImage imageNamed: @"yellow.png"]];
  220. [image2 setHidden: NO];
  221. ////[self.view addSubview: image2];
  222. //[self.view bringSubviewToFront: image2];
  223. x2=2;
  224.  
  225. }
  226. else{
  227. NSLog(@"Error");
  228. [super didReceiveMemoryWarning];
  229. }
  230. winArray[2][1] = x2;
  231. }
  232. else if(x==3){
  233. if (i%2==1){
  234. [image3 setImage:[UIImage imageNamed: @"red.png"]];
  235. [image3 setHidden: NO];
  236. ////[self.view addSubview: image3];
  237. //[self.view bringSubviewToFront: image3];
  238. x3=1;
  239.  
  240. }
  241. else if (i%2==0){
  242. [image3 setImage:[UIImage imageNamed: @"yellow.png"]];
  243. [image3 setHidden: NO];
  244. ////[self.view addSubview: image3];
  245. //[self.view bringSubviewToFront: image3];
  246. x3=2;
  247.  
  248. }
  249. else{
  250. NSLog(@"Error");
  251. [super didReceiveMemoryWarning];
  252. }
  253. winArray[3][1] = x3;
  254. }
  255. else if(x==4){
  256. if (i%2==1){
  257. [image4 setImage:[UIImage imageNamed: @"red.png"]];
  258. [image4 setHidden: NO];
  259. ////[self.view addSubview: image4];
  260. //[self.view bringSubviewToFront: image4];
  261. x4=1;
  262.  
  263. }
  264. else if (i%2==0){
  265. [image4 setImage:[UIImage imageNamed: @"yellow.png"]];
  266. [image4 setHidden: NO];
  267. ////[self.view addSubview: image4];
  268. //[self.view bringSubviewToFront: image4];
  269. x4=2;
  270.  
  271. }
  272. else{
  273. NSLog(@"Error");
  274. [super didReceiveMemoryWarning];
  275. }
  276. winArray[4][1] = x4;
  277. }
  278.  
  279. else if(x==5){
  280. if (i%2==1){
  281. [image5 setImage:[UIImage imageNamed: @"red.png"]];
  282. [image5 setHidden: NO];
  283. ////[self.view addSubview: image5];
  284. //[self.view bringSubviewToFront: image5];
  285. x5=1;
  286. winArray[5][1] = 1;
  287. }
  288. else if (i%2==0){
  289. [image5 setImage:[UIImage imageNamed: @"yellow.png"]];
  290. [image5 setHidden: NO];
  291. ////[self.view addSubview: image5];
  292. //[self.view bringSubviewToFront: image5];
  293. x5=2;
  294. winArray[5][1] = 2;
  295. }
  296. else{
  297. NSLog(@"Error");
  298. [super didReceiveMemoryWarning];
  299. }
  300. winArray[5][1] = x5;
  301. }
  302. else if(x==6){
  303. if (i%2==1){
  304. [image6 setImage:[UIImage imageNamed: @"red.png"]];
  305. [image6 setHidden: NO];
  306. ////[self.view addSubview: image6];
  307. //[self.view bringSubviewToFront: image6];
  308. x6=1;
  309.  
  310. }
  311. else if (i%2==0){
  312. [image6 setImage:[UIImage imageNamed: @"yellow.png"]];
  313. [image6 setHidden: NO];
  314. ////[self.view addSubview: image6];
  315. //[self.view bringSubviewToFront: image6];
  316. x6=2;
  317. ;
  318. }
  319. else{
  320. NSLog(@"Error");
  321. [super didReceiveMemoryWarning];
  322. }
  323. winArray[6][1] = x6;
  324. }
  325.  
  326. else if(x==7){
  327. if (i%2==1){
  328. [image7 setImage:[UIImage imageNamed: @"red.png"]];
  329. [image7 setHidden: NO];
  330. ////[self.view addSubview: image7];
  331. //[self.view bringSubviewToFront: image7];
  332. x7=1;
  333. winArray[7][1] = 1;
  334. }
  335. else if (i%2==0){
  336. [image7 setImage:[UIImage imageNamed: @"yellow.png"]];
  337. [image7 setHidden: NO];
  338. ////[self.view addSubview: image7];
  339. //[self.view bringSubviewToFront: image7];
  340. x7=2;
  341. winArray[7][1] = 1;
  342. }
  343. else{
  344. NSLog(@"Error");
  345. [super didReceiveMemoryWarning];
  346.  
  347. }
  348. winArray[7][1] = x7;
  349. }
  350. else if(x==8){
  351. if (i%2==1){
  352. [image8 setImage:[UIImage imageNamed: @"red.png"]];
  353. [image8 setHidden: NO];
  354. ////[self.view addSubview: image8];
  355. //[self.view bringSubviewToFront: image8];
  356. x8=1;
  357. }
  358. else if (i%2==0){
  359. [image8 setImage:[UIImage imageNamed: @"yellow.png"]];
  360. [image8 setHidden: NO];
  361. ////[self.view addSubview: image8];
  362. //[self.view bringSubviewToFront: image8];
  363. x8=2;
  364. }
  365. else{
  366. NSLog(@"Error");
  367. [super didReceiveMemoryWarning];
  368. }
  369. winArray[8][1] = x8;
  370. }
  371.  
  372.  
  373. else if(x==9){
  374. if (i%2==1){
  375. [image9 setImage:[UIImage imageNamed: @"red.png"]];
  376. [image9 setHidden: NO];
  377. ////[self.view addSubview: image9];
  378. //[self.view bringSubviewToFront: image9];
  379. x9=1;
  380. }
  381. else if (i%2==0){
  382. [image9 setImage:[UIImage imageNamed: @"yellow.png"]];
  383. [image9 setHidden: NO];
  384. ////[self.view addSubview: image9];
  385. //[self.view bringSubviewToFront: image9];
  386. x9=2;
  387. }
  388. else{
  389. NSLog(@"Error");
  390. [super didReceiveMemoryWarning];
  391. }
  392. winArray[1][2] = x9;
  393. }
  394.  
  395. else if(x==10){
  396. if (i%2==1){
  397. [image10 setImage:[UIImage imageNamed: @"red.png"]];
  398. [image10 setHidden: NO];
  399. ////[self.view addSubview: image10];
  400. //[self.view bringSubviewToFront: image10];
  401. x10=1;
  402. }
  403. else if (i%2==0){
  404. [image10 setImage:[UIImage imageNamed: @"yellow.png"]];
  405. [image10 setHidden: NO];
  406. ////[self.view addSubview: image10];
  407. //[self.view bringSubviewToFront: image10];
  408. x10=2;
  409. }
  410. else{
  411. NSLog(@"Error");
  412. [super didReceiveMemoryWarning];
  413. }
  414. winArray[2][2] = x10;
  415. }
  416.  
  417. else if(x==11){
  418. if (i%2==1){
  419. [image11 setImage:[UIImage imageNamed: @"red.png"]];
  420. [image11 setHidden: NO];
  421. ////[self.view addSubview: image11];
  422. //[self.view bringSubviewToFront: image11];
  423. x11=1;
  424. }
  425. else if (i%2==0){
  426. [image11 setImage:[UIImage imageNamed: @"yellow.png"]];
  427. [image11 setHidden: NO];
  428. ////[self.view addSubview: image11];
  429. //[self.view bringSubviewToFront: image11];
  430. x11=2;
  431. }
  432. else{
  433. NSLog(@"Error");
  434. [super didReceiveMemoryWarning];
  435. }
  436. winArray[3][2] = x11;
  437. }
  438.  
  439. else if(x==12){
  440. if (i%2==1){
  441. [image12 setImage:[UIImage imageNamed: @"red.png"]];
  442. [image12 setHidden: NO];
  443. ////[self.view addSubview: image12];
  444. //[self.view bringSubviewToFront: image12];
  445. x12=1;
  446. }
  447. else if (i%2==0){
  448. [image12 setImage:[UIImage imageNamed: @"yellow.png"]];
  449. [image12 setHidden: NO];
  450. ////[self.view addSubview: image12];
  451. //[self.view bringSubviewToFront: image12];
  452. x12=2;
  453. }
  454. else{
  455. NSLog(@"Error");
  456. [super didReceiveMemoryWarning];
  457. }
  458. winArray[4][2] = x12;
  459. }
  460.  
  461. else if(x==13){
  462. if (i%2==1){
  463. [image13 setImage:[UIImage imageNamed: @"red.png"]];
  464. [image13 setHidden: NO];
  465. ////[self.view addSubview: image13];
  466. //[self.view bringSubviewToFront: image13];
  467. x13=1;
  468. }
  469. else if (i%2==0){
  470. [image13 setImage:[UIImage imageNamed: @"yellow.png"]];
  471. [image13 setHidden: NO];
  472. ////[self.view addSubview: image13];
  473. //[self.view bringSubviewToFront: image13];
  474. x13=2;
  475. }
  476. else{
  477. NSLog(@"Error");
  478. [super didReceiveMemoryWarning];
  479. }
  480. winArray[5][2] = x13;
  481. }
  482.  
  483. else if(x==14){
  484. if (i%2==1){
  485. [image14 setImage:[UIImage imageNamed: @"red.png"]];
  486. [image14 setHidden: NO];
  487. ////[self.view addSubview: image14];
  488. //[self.view bringSubviewToFront: image14];
  489. x14=1;
  490. }
  491. else if (i%2==0){
  492. [image14 setImage:[UIImage imageNamed: @"yellow.png"]];
  493. [image14 setHidden: NO];
  494. ////[self.view addSubview: image14];
  495. //[self.view bringSubviewToFront: image14];
  496. x14=2;
  497. }
  498. else{
  499. NSLog(@"Error");
  500. [super didReceiveMemoryWarning];
  501. }
  502. winArray[6][2] = x14;
  503. }
  504.  
  505. else if(x==15){
  506. if (i%2==1){
  507. [image15 setImage:[UIImage imageNamed: @"red.png"]];
  508. [image15 setHidden: NO];
  509. ////[self.view addSubview: image15];
  510. //[self.view bringSubviewToFront: image15];
  511. x15=1;
  512. }
  513. else if (i%2==0){
  514. [image15 setImage:[UIImage imageNamed: @"yellow.png"]];
  515. [image15 setHidden: NO];
  516. ////[self.view addSubview: image15];
  517. //[self.view bringSubviewToFront: image15];
  518. x15=2;
  519. }
  520. else{
  521. NSLog(@"Error");
  522. [super didReceiveMemoryWarning];
  523. }
  524. winArray[7][2] = x15;
  525. }
  526.  
  527. else if(x==16){
  528. if (i%2==1){
  529. [image16 setImage:[UIImage imageNamed: @"red.png"]];
  530. [image16 setHidden: NO];
  531. ////[self.view addSubview: image16];
  532. //[self.view bringSubviewToFront: image16];
  533. x16=1;
  534. }
  535. else if (i%2==0){
  536. [image16 setImage:[UIImage imageNamed: @"yellow.png"]];
  537. [image16 setHidden: NO];
  538. ////[self.view addSubview: image16];
  539. //[self.view bringSubviewToFront: image16];
  540. x16=2;
  541. }
  542. else{
  543. NSLog(@"Error");
  544. [super didReceiveMemoryWarning];
  545. }
  546. winArray[8][2] = x16;
  547. }
  548.  
  549. else if(x==17){
  550. if (i%2==1){
  551. [image17 setImage:[UIImage imageNamed: @"red.png"]];
  552. [image17 setHidden: NO];
  553. ////[self.view addSubview: image17];
  554. //[self.view bringSubviewToFront: image17];
  555. x17=1;
  556. }
  557. else if (i%2==0){
  558. [image17 setImage:[UIImage imageNamed: @"yellow.png"]];
  559. [image17 setHidden: NO];
  560. ////[self.view addSubview: image17];
  561. //[self.view bringSubviewToFront: image17];
  562. x17=2;
  563. }
  564. else{
  565. NSLog(@"Error");
  566. [super didReceiveMemoryWarning];
  567. }
  568. winArray[1][3] = x17;
  569. }
  570.  
  571. else if(x==18){
  572. if (i%2==1){
  573. [image18 setImage:[UIImage imageNamed: @"red.png"]];
  574. [image18 setHidden: NO];
  575. ////[self.view addSubview: image18];
  576. //[self.view bringSubviewToFront: image18];
  577. x18=1;
  578. }
  579. else if (i%2==0){
  580. [image18 setImage:[UIImage imageNamed: @"yellow.png"]];
  581. [image18 setHidden: NO];
  582. ////[self.view addSubview: image18];
  583. //[self.view bringSubviewToFront: image18];
  584. x18=2;
  585. }
  586. else{
  587. NSLog(@"Error");
  588. [super didReceiveMemoryWarning];
  589. }
  590. winArray[2][3] = x18;
  591. }
  592.  
  593. else if(x==19){
  594. if (i%2==1){
  595. [image19 setImage:[UIImage imageNamed: @"red.png"]];
  596. [image19 setHidden: NO];
  597. ////[self.view addSubview: image19];
  598. //[self.view bringSubviewToFront: image19];
  599. x19=1;
  600. }
  601. else if (i%2==0){
  602. [image19 setImage:[UIImage imageNamed: @"yellow.png"]];
  603. [image19 setHidden: NO];
  604. ////[self.view addSubview: image19];
  605. //[self.view bringSubviewToFront: image19];
  606. x19=2;
  607. }
  608. else{
  609. NSLog(@"Error");
  610. [super didReceiveMemoryWarning];
  611. }
  612. winArray[3][3] = x19;
  613. }
  614.  
  615. else if(x==20){
  616. if (i%2==1){
  617. [image20 setImage:[UIImage imageNamed: @"red.png"]];
  618. [image20 setHidden: NO];
  619. ////[self.view addSubview: image20];
  620. //[self.view bringSubviewToFront: image20];
  621. x20 =1;
  622. }
  623. else if (i%2==0){
  624. [image20 setImage:[UIImage imageNamed: @"yellow.png"]];
  625. [image20 setHidden: NO];
  626. ////[self.view addSubview: image20];
  627. //[self.view bringSubviewToFront: image20];
  628. x20 =2;
  629. }
  630. else{
  631. NSLog(@"Error");
  632. [super didReceiveMemoryWarning];
  633. }
  634. winArray[4][3] = x20;
  635. }
  636.  
  637. else if(x==21){
  638. if (i%2==1){
  639. [image21 setImage:[UIImage imageNamed: @"red.png"]];
  640. [image21 setHidden: NO];
  641. ////[self.view addSubview: image21];
  642. //[self.view bringSubviewToFront: image21];
  643. x21 =1;
  644. }
  645. else if (i%2==0){
  646. [image21 setImage:[UIImage imageNamed: @"yellow.png"]];
  647. [image21 setHidden: NO];
  648. //[self.view addSubview: image21];
  649. //[self.view bringSubviewToFront: image21];
  650. x21=2;
  651. }
  652. else{
  653. NSLog(@"Error");
  654. [super didReceiveMemoryWarning];
  655. }
  656. winArray[5][3] = x21;
  657. }
  658.  
  659. else if(x==22){
  660. if (i%2==1){
  661. [image22 setImage:[UIImage imageNamed: @"red.png"]];
  662. [image22 setHidden: NO];
  663. //[self.view addSubview: image22];
  664. //[self.view bringSubviewToFront: image22];
  665. x22 =1;
  666. }
  667. else if (i%2==0){
  668. [image22 setImage:[UIImage imageNamed: @"yellow.png"]];
  669. [image22 setHidden: NO];
  670. //[self.view addSubview: image22];
  671. //[self.view bringSubviewToFront: image22];
  672. x22 =2;
  673. }
  674. else{
  675. NSLog(@"Error");
  676. [super didReceiveMemoryWarning];
  677. }
  678. winArray[6][3] = x22;
  679. }
  680.  
  681. else if(x==23){
  682. if (i%2==1){
  683. [image23 setImage:[UIImage imageNamed: @"red.png"]];
  684. [image23 setHidden: NO];
  685. //[self.view addSubview: image23];
  686. //[self.view bringSubviewToFront: image23];
  687. x23 =1;
  688. }
  689. else if (i%2==0){
  690. [image23 setImage:[UIImage imageNamed: @"yellow.png"]];
  691. [image23 setHidden: NO];
  692. //[self.view addSubview: image23];
  693. //[self.view bringSubviewToFront: image23];
  694. x23 =2;
  695. }
  696. else{
  697. NSLog(@"Error");
  698. [super didReceiveMemoryWarning];
  699. }
  700. winArray[7][3] = x23;
  701. }
  702.  
  703. else if(x==24){
  704. if (i%2==1){
  705. [image24 setImage:[UIImage imageNamed: @"red.png"]];
  706. [image24 setHidden: NO];
  707. //[self.view addSubview: image24];
  708. //[self.view bringSubviewToFront: image24];
  709. x24 =1;
  710. }
  711. else if (i%2==0){
  712. [image24 setImage:[UIImage imageNamed: @"yellow.png"]];
  713. [image24 setHidden: NO];
  714. //[self.view addSubview: image24];
  715. //[self.view bringSubviewToFront: image24];
  716. x24 =2;
  717. }
  718. else{
  719. NSLog(@"Error");
  720. [super didReceiveMemoryWarning];
  721. }
  722. winArray[8][3] = x24;
  723. }
  724.  
  725. else if(x==25){
  726. if (i%2==1){
  727. [image25 setImage:[UIImage imageNamed: @"red.png"]];
  728. [image25 setHidden: NO];
  729. //[self.view addSubview: image25];
  730. //[self.view bringSubviewToFront: image25];
  731. x25 =1;
  732. }
  733. else if (i%2==0){
  734. [image25 setImage:[UIImage imageNamed: @"yellow.png"]];
  735. [image25 setHidden: NO];
  736. //[self.view addSubview: image25];
  737. //[self.view bringSubviewToFront: image25];
  738. x25 =2;
  739. }
  740. else{
  741. NSLog(@"Error");
  742. [super didReceiveMemoryWarning];
  743. }
  744. winArray[1][4] = x25;
  745. }
  746.  
  747. else if(x==26){
  748. if (i%2==1){
  749. [image26 setImage:[UIImage imageNamed: @"red.png"]];
  750. [image26 setHidden: NO];
  751. //[self.view addSubview: image26];
  752. //[self.view bringSubviewToFront: image26];
  753. x26 =1;
  754. }
  755. else if (i%2==0){
  756. [image26 setImage:[UIImage imageNamed: @"yellow.png"]];
  757. [image26 setHidden: NO];
  758. //[self.view addSubview: image26];
  759. //[self.view bringSubviewToFront: image26];
  760. x26 =2;
  761. }
  762. else{
  763. NSLog(@"Error");
  764. [super didReceiveMemoryWarning];
  765. }
  766. winArray[2][4] = x26;
  767. }
  768.  
  769. else if(x==27){
  770. if (i%2==1){
  771. [image27 setImage:[UIImage imageNamed: @"red.png"]];
  772. [image27 setHidden: NO];
  773. //[self.view addSubview: image27];
  774. //[self.view bringSubviewToFront: image27];
  775. x27 =1;
  776. }
  777. else if (i%2==0){
  778. [image27 setImage:[UIImage imageNamed: @"yellow.png"]];
  779. [image27 setHidden: NO];
  780. //[self.view addSubview: image27];
  781. //[self.view bringSubviewToFront: image27];
  782. x27=2;
  783. }
  784. else{
  785. NSLog(@"Error");
  786. [super didReceiveMemoryWarning];
  787. }
  788. winArray[3][4] = x27;
  789. }
  790.  
  791. else if(x==28){
  792. if (i%2==1){
  793. [image28 setImage:[UIImage imageNamed: @"red.png"]];
  794. [image28 setHidden: NO];
  795. //[self.view addSubview: image28];
  796. //[self.view bringSubviewToFront: image28];
  797. x28 =1;
  798. }
  799. else if (i%2==0){
  800. [image28 setImage:[UIImage imageNamed: @"yellow.png"]];
  801. [image28 setHidden: NO];
  802. //[self.view addSubview: image28];
  803. //[self.view bringSubviewToFront: image28];
  804. x28 =2;
  805. }
  806. else{
  807. NSLog(@"Error");
  808. [super didReceiveMemoryWarning];
  809. }
  810. winArray[4][4] = x28;
  811. }
  812.  
  813. else if(x==29){
  814. if (i%2==1){
  815. [image29 setImage:[UIImage imageNamed: @"red.png"]];
  816. [image29 setHidden: NO];
  817. //[self.view addSubview: image29];
  818. //[self.view bringSubviewToFront: image29];
  819. x29 =1;
  820. }
  821. else if (i%2==0){
  822. [image29 setImage:[UIImage imageNamed: @"yellow.png"]];
  823. [image29 setHidden: NO];
  824. //[self.view addSubview: image29];
  825. //[self.view bringSubviewToFront: image29];
  826. x29 =2;
  827. }
  828. else{
  829. NSLog(@"Error");
  830. [super didReceiveMemoryWarning];
  831. }
  832. winArray[5][4] = x29;
  833. }
  834.  
  835. else if(x==30){
  836. if (i%2==1){
  837. [image30 setImage:[UIImage imageNamed: @"red.png"]];
  838. [image30 setHidden: NO];
  839. //[self.view addSubview: image30];
  840. //[self.view bringSubviewToFront: image30];
  841. x30 =1;
  842. }
  843. else if (i%2==0){
  844. [image30 setImage:[UIImage imageNamed: @"yellow.png"]];
  845. [image30 setHidden: NO];
  846. //[self.view addSubview: image30];
  847. //[self.view bringSubviewToFront: image30];
  848. x30 =2;
  849. }
  850. else{
  851. NSLog(@"Error");
  852. [super didReceiveMemoryWarning];
  853. }
  854. winArray[6][4] = x30;
  855. }
  856.  
  857. else if(x==31){
  858. if (i%2==1){
  859. [image31 setImage:[UIImage imageNamed: @"red.png"]];
  860. [image31 setHidden: NO];
  861. //[self.view addSubview: image31];
  862. //[self.view bringSubviewToFront: image31];
  863. x31 =1;
  864. }
  865. else if (i%2==0){
  866. [image31 setImage:[UIImage imageNamed: @"yellow.png"]];
  867. [image31 setHidden: NO];
  868. //[self.view addSubview: image31];
  869. //[self.view bringSubviewToFront: image31];
  870. x31 =2;
  871. }
  872. else{
  873. NSLog(@"Error");
  874. [super didReceiveMemoryWarning];
  875. }
  876. winArray[7][4] = x31;
  877. }
  878.  
  879. else if(x==32){
  880. if (i%2==1){
  881. [image32 setImage:[UIImage imageNamed: @"red.png"]];
  882. [image32 setHidden: NO];
  883. //[self.view addSubview: image32];
  884. //[self.view bringSubviewToFront: image32];
  885. x32 =1;
  886. }
  887. else if (i%2==0){
  888. [image32 setImage:[UIImage imageNamed: @"yellow.png"]];
  889. [image32 setHidden: NO];
  890. //[self.view addSubview: image32];
  891. //[self.view bringSubviewToFront: image32];
  892. x32 =2;
  893. }
  894. else{
  895. NSLog(@"Error");
  896. [super didReceiveMemoryWarning];
  897. }
  898. winArray[8][4] = x32;
  899. }
  900.  
  901. else if(x==33){
  902. if (i%2==1){
  903. [image33 setImage:[UIImage imageNamed: @"red.png"]];
  904. [image33 setHidden: NO];
  905. //[self.view addSubview: image33];
  906. //[self.view bringSubviewToFront: image33];
  907. x33 =1;
  908. }
  909. else if (i%2==0){
  910. [image33 setImage:[UIImage imageNamed: @"yellow.png"]];
  911. [image33 setHidden: NO];
  912. //[self.view addSubview: image33];
  913. //[self.view bringSubviewToFront: image33];
  914. x33 =2;
  915. }
  916. else{
  917. NSLog(@"Error");
  918. [super didReceiveMemoryWarning];
  919. }
  920. winArray[1][5] = x33;
  921. }
  922.  
  923. else if(x==34){
  924. if (i%2==1){
  925. [image34 setImage:[UIImage imageNamed: @"red.png"]];
  926. [image34 setHidden: NO];
  927. //[self.view addSubview: image34];
  928. //[self.view bringSubviewToFront: image34];
  929. x34 =1;
  930. }
  931. else if (i%2==0){
  932. [image34 setImage:[UIImage imageNamed: @"yellow.png"]];
  933. [image34 setHidden: NO];
  934. //[self.view addSubview: image34];
  935. //[self.view bringSubviewToFront: image34];
  936. x34 =2;
  937. }
  938. else{
  939. NSLog(@"Error");
  940. [super didReceiveMemoryWarning];
  941. }
  942. winArray[2][5] = x34;
  943. }
  944.  
  945. else if(x==35){
  946. if (i%2==1){
  947. [image35 setImage:[UIImage imageNamed: @"red.png"]];
  948. [image35 setHidden: NO];
  949. //[self.view addSubview: image35];
  950. //[self.view bringSubviewToFront: image35];
  951. x35 =1;
  952. }
  953. else if (i%2==0){
  954. [image35 setImage:[UIImage imageNamed: @"yellow.png"]];
  955. [image35 setHidden: NO];
  956. //[self.view addSubview: image35];
  957. //[self.view bringSubviewToFront: image35];
  958. x35 =2;
  959. }
  960. else{
  961. NSLog(@"Error");
  962. [super didReceiveMemoryWarning];
  963. }
  964. winArray[3][5] = x35;
  965. }
  966.  
  967.  
  968. else if(x==36){
  969. if (i%2==1){
  970. [image36 setImage:[UIImage imageNamed: @"red.png"]];
  971. [image36 setHidden: NO];
  972. //[self.view addSubview: image36];
  973. //[self.view bringSubviewToFront: image36];
  974. x36 =1;
  975. }
  976. else if (i%2==0){
  977. [image36 setImage:[UIImage imageNamed: @"yellow.png"]];
  978. [image36 setHidden: NO];
  979. //[self.view addSubview: image36];
  980. //[self.view bringSubviewToFront: image36];
  981. x36 =2;
  982. }
  983. else{
  984. NSLog(@"Error");
  985. [super didReceiveMemoryWarning];
  986. }
  987. winArray[4][5] = x37;
  988. }
  989.  
  990. else if(x==37){
  991. if (i%2==1){
  992. [image37 setImage:[UIImage imageNamed: @"red.png"]];
  993. [image37 setHidden: NO];
  994. //[self.view addSubview: image37];
  995. //[self.view bringSubviewToFront: image37];
  996. x37 =1;
  997. }
  998. else if (i%2==0){
  999. [image37 setImage:[UIImage imageNamed: @"yellow.png"]];
  1000. [image37 setHidden: NO];
  1001. //[self.view addSubview: image37];
  1002. //[self.view bringSubviewToFront: image37];
  1003. x37 =2;
  1004. }
  1005. else{
  1006. NSLog(@"Error");
  1007. [super didReceiveMemoryWarning];
  1008. }
  1009. winArray[5][5] = x37;
  1010. }
  1011.  
  1012. else if(x==38){
  1013. if (i%2==1){
  1014. [image38 setImage:[UIImage imageNamed: @"red.png"]];
  1015. [image38 setHidden: NO];
  1016. //[self.view addSubview: image38];
  1017. //[self.view bringSubviewToFront: image38];
  1018. x38 =1;
  1019. }
  1020. else if (i%2==0){
  1021. [image38 setImage:[UIImage imageNamed: @"yellow.png"]];
  1022. [image38 setHidden: NO];
  1023. //[self.view addSubview: image38];
  1024. //[self.view bringSubviewToFront: image38];
  1025. x38 =2;
  1026. }
  1027. else{
  1028. NSLog(@"Error");
  1029. [super didReceiveMemoryWarning];
  1030. }
  1031. winArray[6][5] = x38;
  1032. }
  1033.  
  1034. else if(x==39){
  1035. if (i%2==1){
  1036. [image39 setImage:[UIImage imageNamed: @"red.png"]];
  1037. [image39 setHidden: NO];
  1038. //[self.view addSubview: image39];
  1039. //[self.view bringSubviewToFront: image39];
  1040. x39 =1;
  1041. }
  1042. else if (i%2==0){
  1043. [image39 setImage:[UIImage imageNamed: @"yellow.png"]];
  1044. [image39 setHidden: NO];
  1045. //[self.view addSubview: image39];
  1046. //[self.view bringSubviewToFront: image39];
  1047. x39 =2;
  1048. }
  1049. else{
  1050. NSLog(@"Error");
  1051. [super didReceiveMemoryWarning];
  1052. }
  1053. winArray[7][5] = x39;
  1054. }
  1055.  
  1056. else if(x==40){
  1057. if (i%2==1){
  1058. [image40 setImage:[UIImage imageNamed: @"red.png"]];
  1059. [image40 setHidden: NO];
  1060. //[self.view addSubview: image40];
  1061. //[self.view bringSubviewToFront: image40];
  1062. x40 =1;
  1063. }
  1064. else if (i%2==0){
  1065. [image40 setImage:[UIImage imageNamed: @"yellow.png"]];
  1066. [image40 setHidden: NO];
  1067. //[self.view addSubview: image40];
  1068. //[self.view bringSubviewToFront: image40];
  1069. x40 =2;
  1070. }
  1071. else{
  1072. NSLog(@"Error");
  1073. [super didReceiveMemoryWarning];
  1074. }
  1075. winArray[8][5] = x40;
  1076. }
  1077.  
  1078. else if(x==41){
  1079. if (i%2==1){
  1080. [image41 setImage:[UIImage imageNamed: @"red.png"]];
  1081. [image41 setHidden: NO];
  1082. //[self.view addSubview: image41];
  1083. //[self.view bringSubviewToFront: image41];
  1084. x41 =1;
  1085. }
  1086. else if (i%2==0){
  1087. [image41 setImage:[UIImage imageNamed: @"yellow.png"]];
  1088. [image41 setHidden: NO];
  1089. //[self.view addSubview: image41];
  1090. //[self.view bringSubviewToFront: image41];
  1091. x41 =2;
  1092. }
  1093. else{
  1094. NSLog(@"Error");
  1095. [super didReceiveMemoryWarning];
  1096. }
  1097. winArray[1][6] = x41;
  1098. }
  1099.  
  1100. else if(x==42){
  1101. if (i%2==1){
  1102. [image42 setImage:[UIImage imageNamed: @"red.png"]];
  1103. [image42 setHidden: NO];
  1104. //[self.view addSubview: image42];
  1105. //[self.view bringSubviewToFront: image42];
  1106. x42 =1;
  1107. }
  1108. else if (i%2==0){
  1109. [image42 setImage:[UIImage imageNamed: @"yellow.png"]];
  1110. [image42 setHidden: NO];
  1111. //[self.view addSubview: image42];
  1112. //[self.view bringSubviewToFront: image42];
  1113. x42 =2;
  1114. }
  1115. else{
  1116. NSLog(@"Error");
  1117. [super didReceiveMemoryWarning];
  1118. }
  1119. winArray[2][6] = x42;
  1120. }
  1121.  
  1122. else if(x==43){
  1123. if (i%2==1){
  1124. [image43 setImage:[UIImage imageNamed: @"red.png"]];
  1125. [image43 setHidden: NO];
  1126. //[self.view addSubview: image43];
  1127. //[self.view bringSubviewToFront: image43];
  1128. x43 =1;
  1129. }
  1130. else if (i%2==0){
  1131. [image43 setImage:[UIImage imageNamed: @"yellow.png"]];
  1132. [image43 setHidden: NO];
  1133. //[self.view addSubview: image43];
  1134. //[self.view bringSubviewToFront: image43];
  1135. x43 =2;
  1136. }
  1137. else{
  1138. NSLog(@"Error");
  1139. [super didReceiveMemoryWarning];
  1140. }
  1141. winArray[3][6] = x43;
  1142. }
  1143.  
  1144. else if(x==44){
  1145. if (i%2==1){
  1146. [image44 setImage:[UIImage imageNamed: @"red.png"]];
  1147. [image44 setHidden: NO];
  1148. //[self.view addSubview: image44];
  1149. //[self.view bringSubviewToFront: image44];
  1150. x44 =1;
  1151. }
  1152. else if (i%2==0){
  1153. [image44 setImage:[UIImage imageNamed: @"yellow.png"]];
  1154. [image44 setHidden: NO];
  1155. //[self.view addSubview: image44];
  1156. //[self.view bringSubviewToFront: image44];
  1157. x44 =2;
  1158. }
  1159. else{
  1160. NSLog(@"Error");
  1161. [super didReceiveMemoryWarning];
  1162. }
  1163. winArray[4][6] = x44;
  1164. }
  1165.  
  1166. else if(x==45){
  1167. if (i%2==1){
  1168. [image45 setImage:[UIImage imageNamed: @"red.png"]];
  1169. [image45 setHidden: NO];
  1170. //[self.view addSubview: image45];
  1171. //[self.view bringSubviewToFront: image45];
  1172. x45 =1;
  1173. }
  1174. else if (i%2==0){
  1175. [image45 setImage:[UIImage imageNamed: @"yellow.png"]];
  1176. [image45 setHidden: NO];
  1177. //[self.view addSubview: image45];
  1178. //[self.view bringSubviewToFront: image45];
  1179. x45 =2;
  1180. }
  1181. else{
  1182. NSLog(@"Error");
  1183. [super didReceiveMemoryWarning];
  1184. }
  1185. winArray[5][6] = x45;
  1186. }
  1187.  
  1188. else if(x==46){
  1189. if (i%2==1){
  1190. [image46 setImage:[UIImage imageNamed: @"red.png"]];
  1191. [image46 setHidden: NO];
  1192. //[self.view addSubview: image46];
  1193. //[self.view bringSubviewToFront: image46];
  1194. x46 =1;
  1195. }
  1196. else if (i%2==0){
  1197. [image46 setImage:[UIImage imageNamed: @"yellow.png"]];
  1198. [image46 setHidden: NO];
  1199. //[self.view addSubview: image46];
  1200. //[self.view bringSubviewToFront: image46];
  1201. x46 =2;
  1202. }
  1203. else{
  1204. NSLog(@"Error");
  1205. [super didReceiveMemoryWarning];
  1206. }
  1207. winArray[6][6] = x46;
  1208. }
  1209.  
  1210. else if(x==47){
  1211. if (i%2==1){
  1212. [image47 setImage:[UIImage imageNamed: @"red.png"]];
  1213. [image47 setHidden: NO];
  1214. //[self.view addSubview: image47];
  1215. //[self.view bringSubviewToFront: image47];
  1216. x47 =1;
  1217. }
  1218. else if (i%2==0){
  1219. [image47 setImage:[UIImage imageNamed: @"yellow.png"]];
  1220. [image47 setHidden: NO];
  1221. //[self.view addSubview: image47];
  1222. //[self.view bringSubviewToFront: image47];
  1223. x47 =2;
  1224. }
  1225. else{
  1226. NSLog(@"Error");
  1227. [super didReceiveMemoryWarning];
  1228. }
  1229. winArray[7][6] = x47;
  1230. }
  1231.  
  1232.  
  1233.  
  1234. else if(x==48){
  1235. if (i%2==1){
  1236. [image48 setImage:[UIImage imageNamed: @"red.png"]];
  1237. [image48 setHidden: NO];
  1238. //[self.view addSubview: image48];
  1239. //[self.view bringSubviewToFront: image48];
  1240. x48 =1;
  1241. }
  1242. else if (i%2==0){
  1243. [image48 setImage:[UIImage imageNamed: @"yellow.png"]];
  1244. [image48 setHidden: NO];
  1245. //[self.view addSubview: image48];
  1246. //[self.view bringSubviewToFront: image48];
  1247. x48 =2;
  1248. }
  1249. else{
  1250. NSLog(@"Error");
  1251. [super didReceiveMemoryWarning];
  1252. }
  1253. winArray[8][6] = x48;
  1254. }
  1255.  
  1256.  
  1257.  
  1258.  
  1259. return x;
  1260. }// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1261.  
  1262. -(void)game{
  1263.  
  1264. }
  1265.  
  1266.  
  1267. - (IBAction) showImage1{
  1268.  
  1269. row1++;
  1270.  
  1271. x = (row1-1)*8+1;
  1272.  
  1273. if (row1 == 1&& i<49){
  1274. x=1;
  1275. [self whatImage];
  1276. }
  1277.  
  1278.  
  1279. else if (row1 >= 2&& i<49&&row1<7){
  1280.  
  1281.  
  1282. x = (row1-1)*8+1;
  1283.  
  1284. [self whatImage];
  1285. }
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292. }
  1293.  
  1294.  
  1295.  
  1296. - (IBAction) showImage2{
  1297. row2++;
  1298. if (row2 == 1&& i<49){
  1299. x=2;
  1300. [self whatImage];
  1301. }
  1302.  
  1303.  
  1304. else if (row2 >= 2&& i<49&&row2<7){
  1305.  
  1306.  
  1307. x = (row2-1)*8+2;
  1308.  
  1309. [self whatImage];
  1310. }
  1311.  
  1312. }
  1313.  
  1314. - (IBAction) showImage3{
  1315. row3++;
  1316. if (row3 == 1&& i<49){
  1317. x=3;
  1318. [self whatImage];
  1319. }
  1320.  
  1321.  
  1322. else if (row3 >= 2&& i<49&&row3<7){
  1323.  
  1324.  
  1325. x = (row3-1)*8+3;
  1326. [self whatImage];
  1327.  
  1328. }
  1329.  
  1330. }
  1331. - (IBAction) showImage4{
  1332. row4++;
  1333. if (row4 == 1&& i<49){
  1334. x=4;
  1335. [self whatImage];
  1336. }
  1337.  
  1338.  
  1339. else if (row4 >= 2&& i<49&&row4<7){
  1340.  
  1341.  
  1342. x = (row4-1)*8+4;
  1343. [self whatImage];
  1344.  
  1345. }
  1346.  
  1347. }
  1348.  
  1349. - (IBAction) showImage5{
  1350. row5++;
  1351. if (row5 == 1&& i<49){
  1352. x=5;
  1353. [self whatImage];
  1354. }
  1355.  
  1356.  
  1357. else if (row5 >= 2&& i<49&&row5<7){
  1358.  
  1359.  
  1360. x = (row5-1)*8+5;
  1361.  
  1362. [self whatImage];
  1363. }
  1364.  
  1365. }
  1366. - (IBAction) showImage6{
  1367. row6++;
  1368. if (row6 == 1&& i<49){
  1369. x=6;
  1370. [self whatImage];
  1371. }
  1372.  
  1373.  
  1374. else if (row6 >= 2&& i<49&&row6<7){
  1375.  
  1376.  
  1377. x = (row6-1)*8+6;
  1378. [self whatImage];
  1379.  
  1380. }
  1381.  
  1382. }
  1383. - (IBAction) showImage7{
  1384. row7++;
  1385. if (row7 == 1&& i<49){
  1386. x=7;
  1387. [self whatImage];
  1388. }
  1389.  
  1390.  
  1391. else if (row7 >= 2&& i<49&&row7<7){
  1392.  
  1393.  
  1394. x = (row7-1)*8+7;
  1395.  
  1396. [self whatImage];
  1397. }
  1398.  
  1399. }
  1400.  
  1401. - (IBAction) showImage8{
  1402. row8++;
  1403. if (row8 == 1&& i<49){
  1404. x=8;
  1405. [self whatImage];
  1406. }
  1407.  
  1408.  
  1409. else if (row8 >= 2&& i<49&&row8<7){
  1410.  
  1411.  
  1412. x = (row8-1)*8+8;
  1413. [self whatImage];
  1414.  
  1415. }
  1416.  
  1417. }
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434. - (void)viewDidLoad
  1435. {
  1436.  
  1437.  
  1438. i++;
  1439. [super viewDidLoad];
  1440. // Do any additional setup after loading the view, typically from a nib.
  1441.  
  1442.  
  1443. }
  1444.  
  1445.  
  1446. - (void)viewDidUnload
  1447. {
  1448.  
  1449. [super viewDidUnload];
  1450. }
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. - (void)didReceiveMemoryWarning
  1457. {
  1458. [super didReceiveMemoryWarning];
  1459. // Dispose of any resources that can be recreated.
  1460. }
  1461.  
  1462. @end

More about : objective student project calculating 8x6 connect4 wins

January 14, 2013 2:20:13 PM

Well, the way I would do it would be, after a move is made, check in every direction for chips of the same color, and if the colors match, continue in that direction until either four chips are the same color (Win), or a different color is seen (Not a Win). Repeat for each direction.
m
0
l
a b L Programming
January 16, 2013 9:05:02 AM

Please, please, please refactor this. There is more copy and paste here than I've seen in some job applicants' programming test submissions. Almost all of that code is identical. I suggest you look at why an array won't work and sort that out. You would be able to remove an enormous amount of code duplication if you can dump all of those image fields.

I know this doesn't in any way answer your question, but you are going to save yourself future headaches if you clean this up now. With that much code duplication you are making this application easy to break and hard to maintain.
m
0
l
Related resources
Can't find your answer ? Ask !
January 16, 2013 11:07:44 AM

Yeah, I was wondering why the OP didn't use arrays for the variables, and just use a FOR loop for control...
m
0
l
January 19, 2013 12:42:14 PM

It's funny because the variables could've been declared as:
int w8h6; to int w1h1; (all inclusive) but they are all x1 to x48 even though it's for a 2D array (at least interpretively).

It looks like the result of what happens when someone either sleeps through, or just doesn't pay enough attention during their programming classes.

If there is a university teaching people to do this Then
we have a reason to use our nuclear stockpile for good!
Else
maybe there is a God after all...
m
0
l
January 21, 2013 1:02:47 PM

^^ Because you can't teach a person program structure; they either know it, or they don't.

Still, having to do the same exact thing 48 times over is generally a hint its time to use some sort of array/collection.
m
0
l