|
Heya, i just started with the rock-paper-scissors project on Day 25. I looked back at the GuessTheFlag Project i created earlier on. But this time i have no idea where to start. At first i did this: @State private var RPS = ["Scissors", "Rock", "Paper"] @State private var GameMove = Int.random(in: 0...2) I have no idea how to continue and what to do. Can you guys maybe give me some advice how to set this up. It would be super nice if you wouldn't give me like the whole code, so i have to think for myself. Thank you very much! |
|
Here is a minimal version of the game code. Some of the button logic is missing. See if you can first finish the logic to correctly calculate the score and perhaps later improve the game layout. Good luck.
|
|
If you want some ideas here my code on github |
|
Answering @NigelGee... I looked at your code on GitHub, but I think you have not completely understand the app's purpose. The challenge asks to create not a standard app of "Rock, Scissor Sister" but a brain training game where the app asks users to guess if they're gonna lose or win. Every time, for 10 loops, the game have to ask the player if he's gonna lose or win and, only then, will ask for "rock, scissor, paper". For example: First Loop: The Game randomly pick-up TRUE and ROCK, and then ask player: "You think you're gonna WIN or LOSE"? If the player select WIN, then he have to select Paper to get a +1 score. But, if he select LOSE, he have to select SCISSOR to get a +1 score. Second Loop: The Game randomly pick-up TRUE and SCISSOR, and then ask player: "You think you're gonna WIN or LOSE"? If the player select WIN, then he have to select Rock to get a +1 score. But, if he select LOSE, he have to select Paper to get a +1 score. Three, Four, and so on.. This is the difficulty :\ |
|
Thanks to @wieniek for the starting point. I adjusted the code to take care of situations where the random choice is the same as your pick. Also, the func should run before the button is tapped. Now, the time is to count the ten games and than stop. Plus create somw UI. Feel free to play around and good luck. Example:
|
|
Guys, here is my full code. I know isn't perfect, but might help to somebody. Any feedback is much appreciated. Thanks.
|
SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!
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.