|
I'm currently working through Day 35 for the edutainment app. To me this app feels like it could be really similar to GuessTheFlag when it comes down to the game logic, so I'm working in that direction. However, I'm having a hard time translating some of the logic from GuessTheFlag to this project for a number of reasons. So far, this is what I'm trying to accomplish:
My goal is to generate three random answers for a user to choose from (they each appear in a blue box), while only one of them is the correct answer. Again this is super similar to GuessTheFlag but I'm stuck on implementing it. How do I generate both the random answers and the correct answer for a user to select? |
|
@swiftdoc is mixing what the program does with what the program shows....
Take your big problem and break it down into several, smaller solvable problems. To make it easier, put each problem in a separate room in your house, and only solve the problem in that room. Don't try to solve two problems at once. Problem #1You have two numbers, Rather than having a bunch of logic polluting your Game LogicYour game logic can all be neatly packaged into a convenient
Problem #2Now that you've created a
Problem #3Now that you have a Possibly you'll want to show a success message when the player selects the correct answer. Maybe the New Problem What did you learn?First, pull your logic into Second remember that SwiftUI is declarative. Re-read that statement. It's declarative. Declare what you WANT TO SEE. I want to see three options from this array of Don't multiply the two operands in your Full Example
Keep Coding |
|
HomeworkThere's a bug in the How can you solve it?? Please return here with your solution. |
|
Homework #2The But in the sample code above, I created a computed variable in the This violates one of the lessons from above namely, keep your game logic in a separate struct. Can you think of a way to move the Keep CodingPlease return here and let us know how you solved this. |
|
|
|
The solution for the picker bug was using an Further, the |
|
To get the Another step was to cut out the To have this reflect in the UI, I added I may have missed something here, but your responses were very helpful and I now have a much better development process :) |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.