iphone - UIImageView comparing images in game -


i working on rock paper scissor shoe game, , have no idea on how this. have 2 uiimageview(s), , within each 1 image. want able compare 2 images. have looked online, , cannot find anything. want able say

 if([imageview1.image == rock] && [imageview2.image == scissor]) {     textlabel.text = @"you won!";  } 

i know syntax wrong of course, trying show english part of looking for. appreciated.

i not have kind of source code show not know doing this. not looking pixel pixel comparison, or complex, looking way determine if image same or not.

ok, here how solve problem using enums. firstly, declare enum. can call whatever like, cam calling rps_state

enum rps_state {     rps_rock,     rps_scissor,     rps_paper,     rps_undefined }; 

it's useful include undefined state init purposes. now, these things defined in enum integers 0-3.

so can use following when setting images.

 -(void) settorock:(uiimageview *) view {       view.image = rockimage;       view.tag = rps_rock;  }   -(void) settoscissor:(uiimageview *) view  {       view.image = scissorimage;       view.tag = rps_scissor;  }   -(void) settopaper:(uiimageview *) view  {       view.image = paperimage;       view.tag = rps_paper;  } 

then can set , compare them nice , easy.

 [self settopaper:imageview1];  [self settopaper:imageview2];   if(imageview1.tag == imageview2.tag){   }   

and on. can use enums type. eg

 enum rps_state variableholdingonlyrpsstate;  

hope helps :)


Comments