The application does the following:
• When the user the user clicks the Spin button three colors are randomly selected and displayed.
• If all three colors are the same the user wins and a message is displayed otherwise the user loses and a corresponding message is displayed.
• A count of the wins is displayed.
• A count of the losses is displayed.
See the screenshot at the bottom.
• Use labels and set the background color for the color blocks.
• Define and use a method that takes two parameters, a label object and a color. The method sets the label's background color to the specified color.
• Create instance variables for the GUI items in the interface file.
• Create properties for the instance variables in the interface file.
• Synthesize the properties for the instance variables in the implementation file.
• In Interface Builder drag the GUI items you will use into the UIWindow instance window.
• Compile and run. Don't forget to save in Interface Builder.
• Declare the action method for the button.
• Define the action method for the button. Put a console output message in the method.
• Make connections from the Connections tab in the Inspector, or right click on the AppDelegate in the "Doc" window, to the correspoding GUI item.
• Make the target/action connection for the button.
• Compile and run. Make sure the button presses call the button method.
• Add the remaining functionality.
• Do initialization in the method provided when the project was created:
• - (BOOL) application:(UIApplication *)application
• didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Remember inheritance, if a method or property isn't defined in an object's class it might come from a parent class.
If a label is never modified it does not need an instance variable.
What would cause the following error message?
Error: Cannot use object as a parameter.
Some code that might be useful:
// Console output
NSLog(@"Message %@", nsString);
// Create colors
[UIColor colorWithRed: 0.9 green: 0.9 blue: 0.6 alpha: 1.0]
// Create a string from an int
[NSString stringWithFormat:@"%d", int_num]
// Include for random functions: #include <stdlib.h>
// Set the random number generator seed from the system clock.
time_t seed = time(0);
// Get a random value
int num = rand() % 3