|
Hello everyone, I'm a graphic designer learning Swift UI, so I don't have much prior programming knowledge. I've been on the course up to day 25 and am having a hard time in the "Rock - Paper - Scissors" challenge. First, I'm looking for a way so that when the alert shows a "Restart" button (when the player has reached 10 rounds), the action changes to gameOver to reset the game. Currently, when I've played 10 rounds, the "Restart" button appears but the gameOver action has not been assigned. Second, I want to convert those integers to a String, because currently I'm using integers to represent "Rock"[0], "Paper"[1] and "Scissors"[2]. Here's the code I'm working on, I know it's a bit messy and any advice is welcome. Thanks!
|
|
First one I would do it like this:
Second , did you try to cast them in a String? |
|
Thank you @ioannisfa, I solved the first problem, didn't expect such a piece of code to solve the problem so quickly. But I'm still stuck on the second problem, can you give me some suggestions? |
|
Ok now I think I got what you meant on your second question before. Although how you did it works, you could just make your myCurrentChoice into an array same to the first array you have
and use these array in your func. Now I would suggest to have a look on how Genie solved it which is the way Paul suggested and it's much quicker and cleaner. https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-25-rock-paper-scissors/14854/15694 P.S. You will see that I almost did a similar solution to yours in the beginning. |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.