import SwiftUI
struct ContentView: View {@State private var emojiCards = ["🍎", "🍌", "🍇", "🍉", "🍓", "🍒", "🍑", "🍍"].doubled().shuffled()
@State private var flippedCards = Set<Int>()
@State private var matchedCards = Set<Int>()
Here I was, a week of spring vacation ahead of me, and absolutely zero motivation to fill out another summer internship application. So, naturally, I did what any self-respecting, mildly procrastinating tech enthusiast would do: I decided to build an iOS app. Because, honestly, why not?
Chapter 1: “It Begins with an Emoji…”
Armed with SwiftUI, a penchant for whimsy, and an inexplicable fondness for fruit emojis, I embarked on creating “ololi,” the emoji matching game no one knew they needed until now. Here’s the gist: you’ve got a bunch of fruit emojis, and your mission, should you choose to accept it, is to match ’em up before time runs out. Sounds simple, right? Oh, sweet summer child…
First off, doubling and shuffling an array of emojis? Check. It’s like making a smoothie but forgetting to put the lid on the blender.
Chapter 2: “The Flippening”
Keeping track of which cards have been flipped and which have found their soulmate was a bit like trying to remember where I left my keys. In a fit of what I can only describe as “coding grace,” I managed to wrangle some state variables into submission.
@State private var gameTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
@State private var timeRemaining = 90
@State private var isGameOver = false
@State private var showingTitleScreen = true // Control the display of the title screen
@State private var selectedTime = 90 // Default to easy mode
Introducing a ticking time bomb into the mix because, hey, life’s not exciting enough as it is.
Chapter 3: “A Wild UI Appears”
Building the UI was like deciding on an outfit. You start simple, then before you know it, you’re layering like it’s Fashion Week. GeometryReader? Check. VStacks within VStacks? Check. A sense of existential dread as you wonder if anyone will actually play this game? Double-check.
var body: some View {in
GeometryReader { geometry
VStack {if showingTitleScreen {
TitleScreenView(startGame: {self.showingTitleScreen = false
self.timeRemaining = self.selectedTime
}, selectedTime: $selectedTime)else {
} // Display the game title
GameTitleView() if isGameOver {
in
GeometryReader { geo
gameOverView
.frame(width: geo.size.width, height: geo.size.height)
}else {
}
gameView
}
} }
I crafted a title screen with the same care and attention a cat gives to knocking things off a table. Effortlessly, obviously.
Chapter 4: “Game Over, Man. Game Over!”
The game had to end somehow, and not just with me questioning my life choices. So, a game-over screen was born, popping up with all the gentleness of a jack-in-the-box set to a timer.
private var gameOverView: some View {
VStack {"Game Over")
Text(
.font(.largeTitle)"You matched all the cards with \(timeRemaining) seconds remaining!")
Text(
.font(.headline)"Play Again") {
Button(
resetGame()
}
.padding()
.background(Color.blue)
.foregroundColor(.white)10)
.cornerRadius(
} }
And, like any good gamer, I included a “Play Again” button because, let’s face it, we’re all gluttons for punishment.
Epilogue: “Reflections and Regrets”
Looking back, creating “ololi” was a journey of self-discovery, frustration, and an absurd amount of Googling. Would I do it again? In a heartbeat. After all, there’s something magical about bringing a bunch of pixels to life and watching as they frustrate and delight people in equal measure.
So, there you have it. My spring break, encapsulated in a game about matching fruit emojis. Who needs internships when you have SwiftUI and a stubborn refusal to do anything remotely productive?
Well me… I need an internship. And hopefully, despite my frustration with how Xcode differs from literally every other development platform I have used, this experience has taught me something about software development. I hope to keep working on this app, as it is far from perfect.
It’s almost human in that way… Too human…
In all seriousness this project has taught me some useful skills I hope to use in future schemes, hopefully incorporating my earlier Russian Verb ML Classifier model. Of course I would likely have to tackle Apple’s CreateML tool, which will be a tale for another day…