You have a basic understanding of arrays, state, views, images, text, and more, so let’s put them together: your challenge is to make a brain training game that challenges players to win or lose at rock, paper, scissors.
So, very roughly:
So, if the app chose “Rock” and “Win” the player would need to choose “Paper”, but if the app chose “Rock” and “Lose” the player would need to choose “Scissors”.
To solve this challenge you’ll need to draw on skills you learned in tutorials 1 and 2:
["Rock", "Paper", "Scissors"].
@Stateproperties to store the app’s current choice and whether the player should win or lose.
Int.random(in:)to select a random move. You can use it for whether the player should win too if you want, but there’s an even easier choice:
Bool.random()is randomly true or false.
VStackshowing the player’s score, the app’s move, and whether the player should win or lose. You can use
if shouldWinto return one of two different text views.
I’m going to provide some hints below, but I suggest you try to complete as much of the challenge as you can before reading them.
This should be a fun exercise: there’s a little bit of Swift, a little bit of SwiftUI, and a little bit of logic, all wrapped up in a game where you can really go to town on theming you want to.
SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.
Link copied to your pasteboard.