0

I am working on a rock paper scissor shoe game, and I have no idea on how to do this. I have two UIImageView(s), and within each one is an image. I want to be able to compare the two images. I have looked up online, and cannot find anything. I want to be able to say

 if([imageView1.image == rock] && [imageView2.image == scissor]) { textLabel.text = @"You won!"; } 

I know that this syntax is wrong of course, but I am trying to show the english part of what I am looking for. Any help is appreciated.

I do not have any kind of source code to show you as I do not know what I am doing with this. I am not looking for pixel to pixel comparison, or anything complex, I am only looking for a way to determine if the image is the same or not.

3
  • 2
    Can you not tag the UIImageView with an integer depending on what image it has. so when you set imageView1 to rock, set imageView1.tag = 1; 2 for scissor, 3 for paper. then just compare the tag on the image view to know what it is. Better yet, create an enum for your types :) Commented May 5, 2013 at 23:07
  • Honestly, I have not even thought of that. That is SO much simpler, I have read to use a 3rd party API consisting of surveillance image comparisons and stuff like that. One more thing; I have never used enum much, just in Java, and haven't gotten to it yet, could you show me an example? Commented May 5, 2013 at 23:09
  • Of course, i'll leave it in an answer below. Commented May 5, 2013 at 23:24

1 Answer 1

3

OK, Here is how I would solve this problem using enums. Firstly, declare your enum. You can call it whatever you like, i cam calling it RPS_STATE

enum RPS_STATE { RPS_ROCK, RPS_SCISSOR, RPS_PAPER, RPS_UNDEFINED }; 

it's always useful to include an undefined state for init purposes. Now, these things defined in the enum are actually just integers from 0-3.

So you can use the following when you are setting your 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 you can set and compare them nice and easy.

 [self setToPaper:imageView1]; [self setToPaper:imageView2]; if(imageView1.tag == imageView2.tag){ } 

and so on. You can also use enums as a type. eg

 enum RPS_STATE variableHoldingOnlyRPSState; 

Hope that helps :)

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I cannot believe it is that simple! :) Thanks a lot! I'll edit the stuff I have, and see how it turns out. thanks again! GOd bless you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.