じゃんけん [Janken]
Date: 26 Feb 2023
Category: blog Project Reflection
Tags: Swift, SwiftUI, iOS Development, Hacking with Swift
Repo: https://github.com/SeikaHirori/janken_RockPaperScissors
Abstract: Using the specifications from Hacking with Swift, recreate the classic game: Rock, Paper, Scissors. In additional, add an extra win condition to score points. On a personally touch, support to switch to from English to the Japanese version (じゃんけん [janken]) was added. This was to see how multi-language support could be implemented. One limitation is that the current implementation of multiple languages might not scale well. Another limitation is due to current personal limited knowledge of SwiftUI, the SwiftUI toolkit has not been used to its fullest potential. Addition limitation is that tests were not written as the focus is learning the tool kit first. Lastly, the look of the UI could be improved.
Highlights and Experience
-
The prompt from Hacking with Swift (HwS) was fairly straight forward!
-
It’s implementing the classic game: Rock, Paper, Scissors (RPS)!
-
The game is knownじゃんけん (janken) in Japanese!
-
The prompt also stated another condition to gain points: purposely win or lose against the opponent based on the given visibly displayed prompt.
-
Applied a lot of tools from this lesson as they allow deeper customization: https://www.hackingwithswift.com/100/swiftui/23
-
-
I wanted to add my own twist: Switching between the Japanese and English language! Personally, I am learning Japanese at the moment AND I remembered about Japan’s じゃんけん, and I wanted to see how I could implement switching between じゃんけん and RPS.
- For language switching, I used an Array to store the strings. I originally planned to use enums, but I wasn’t sure how to implement it when switching between English and Japanese language. A future implementation is discussed in the limitations section.
Limitations:
-
Language switching wise
- For how I implemented the information being display, you have to be ATTENTIVE to make sure that those respective information are being updated whenever you toggle between English and Japanese.
-
UI
-
From my subjective take, the UI’s look could be drastically improved. I am still new to Swift UI’s toolset, so there are still endless amount of things I have not learned and used yet! I will go beyond Capsule() soon!
-
Ideally, I would like to switch to a different page when you get your final score.
-
-
Code design
- Placement of code is all over the place in my opinion. I think some of the logic (i.e. functions/ methods) could be placed in a separate file, but I will gain more insight as I gain more exposure to SwiftUI code designs.
Future improvements:
-
Improve look of UI
-
Change design of switching between multiple languages by using combination of enum and dictionary/HashMap.
-
Idea suggested by: https://stackoverflow.com/a/43431251
-
If I implement more than two languages, I will need change implementation of switching between languages. Currently, it switches between languages when a certain Bool variable is changed, so this can be changed to an enum, string, or int. Additional, the UI toggle could change to a dropdown menu.
-
------
Conclusion: It was a lovely experience overall for working on this second challenge project! It accumulated all the SwiftUI materials used in HwS’s Projects 1 to 3. It was a bit tough trying to find clear information on how SwiftUI’s tools worked since Apple’s official documentation (doc) only explains them on an abstract level. When compared to the doc for Rust, Apple’s lacks visual and example codes. As a result, I had to search through various websites for additional information. The project has multiple areas that could improved. As I am following HwS’s SwiftUI syllabus, I might be coming back to this project in the future to make improvements? If that doesn’t happen, I do want to comeback and implement some other features, such as a two-player Person vs Person (PvP) mode. This task will definitely require in-depth knowledge, but I do want to see how it is implemented! For now, I will proceed to the next lessons for HwS’s SwiftUI syllabus :D