Learn Courses My Dashboard

Simple App Ideas to Practice

Hello everyone. I just finished Chris’s 14-Day Challenge. I was hoping I could get a few simple app ideas that I could attempt using the knowledge from the challenge to help solidify what I’ve learned and to practice and hopefully get better. Thanks in advance for any suggestions provided!

1 Like

Welcome to the community!

Based on only the 14 day challenge as your experience:

  • adding another computer player
  • showing win/lose and tie
  • hit a certain threshold and then show a winner (at 10 points who wins)
  • restart game button (scores back to 0)

Good luck!

Thanks! These would be some cool mods to the War game! I’ll give these a try. And by try I mean I’ll probably work tirelessly until I figure them out :slight_smile:

2 Likes
  • I’ve added a 3rd player
  • I’ve added a 10 point threshold
  • I managed to create an alert that asks if the user wants to start a new game or not. If they click Yes the cards flip to show the backs and all the scores reset and game play can continue and if they click No, the game will terminate

Where I am currently stuck is adding a secondary alert that displays the winner and when the user clicks OK, then the game will exit. That code just won’t execute. A nudge in the right direction would be great. I tried nesting this second alert inside the the .cancel portion of the code block but still nothing. I’ve tried other placements as well with no success.

Great work on the first 3 :clap::clap::clap:
When I first started I couldn’t figure out how to even make the users tie :joy:

When you hit the threshold for the win

You can show an alert, you can actions for ok/cancel with custom code in each action

Ok button would reset scores and you could flip the cards to the backs again

Cancel would dismiss the alert but leave it in its current state

You can also paste your code here for what you’re doing for the alert and I can maybe see what’s going wrong
Paste your code in as text, rather than providing a screenshot.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key). You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.

Here’s the code for the alert that DOES work and it pops up as soon as someone reaches 10:

Button("Play Again?) {
}
.alert(isPresented: $presentAlert1) {
    Alert(
        title: Text("Game Over"),
        message: Text("\(gameWinner) wins!\nPlay again?"),
        primaryButton: .destructive(Text("Yes")) {
            restart()
        },
        secondaryButton: .cancel(Text("No")) {
            exit(0)
        })}

So, what I was initially trying to do above was instead of having “exit(0)” on the secondary button, I wanted it to pop another alert displaying the winner with just an OK button. Once the user had a chance to see it, besides the fact the scores show it, they click OK and THEN the game exits. This next block of code is for that additional alert. It would never fire AND the game would let me proceed passed 10.

Button("Results") {
}
.alert(isPresented: $presentAlert2) {
    Alert(
        title: Text("Results"),
        message: Text("\(gameWinner) wins!"),
        dismissButton: .default(Text("OK")) {
            exit(0)
        }
)}

I would not show two alerts back to back, it’s an odd flow overall

But what you would need to do is instead of exit(0) change the Boolean for presentAlert2 to be true this is in your first alert code

Yeah, I agree. I’m going to scrap the second alert :slight_smile: I did try commenting out exit(0) and setting the presentAlert2 to true instead but it still didn’t fire the alert and allows the user to keep playing passed 10. It still shows the winner on the first alert anyway so I think I’m gonna call this one good. I really appreciate your assistance and feedback on this. Any ideas for apps from scratch I could try? Every time I try to think of something, I get a mental block, LOL.

I would look further in on some of Chris’ videos before trying your own apps, because at this point you’ve only really gone through 3-5 concepts and adding a few more can give you a broader range of ideas of apps you can make

Understood and will do. Thanks again for all your help!

1 Like