WordScramble is a SwiftUI-based word game where players create new words from a given root word. The game enforces various rules to ensure the words are valid and calculates a score based on the length of the words.
- Dynamic Word Input: Users can enter new words via a text field.
- Word Validation: The app checks if the entered word:
- Is not empty
- Has not been used before
- Is not the root word itself
- Is longer than three characters
- Can be constructed from the letters of the root word
- Is a real English word
- Score Calculation: The score is updated based on the length of the valid words entered.
- New Game: Users can start a new game, which will load a new root word and reset the score and used words.
These instructions will help you set up and run the project on your local machine for development and testing purposes.
- Xcode 12 or later
- Swift 5.3 or later
- Clone the repository:
git clone https://github.com/OmPreetham/WordScramble.git
- Open the project in Xcode:
cd WordScramble open WordScramble.xcodeproj
- Run the project on the simulator or a physical device.
This is the main view of the app, where the game logic is implemented.
-
State Variables:
usedWords
: An array of words used by the player.rootWord
: The current root word from which new words are derived.newWord
: The word currently being entered by the player.errorTitle
anderrorMessage
: For displaying error alerts.showingError
: Boolean to control the display of error alerts.score
: The player's current score.
-
Main UI Components:
NavigationStack
: The main container for the view.TextField
: Allows the user to input new words.List
: Displays the list of used words with their lengths.Toolbar
: Contains the score display and a button to start a new game.
-
Game Functions:
startGame()
: Loads a new root word and resets the game state.addNewWord()
: Validates the new word and updates the game state.isOriginal(word:)
: Checks if the word has been used before.isRootWord(word:)
: Ensures the word is not the root word itself.isShorter(word:)
: Checks if the word is at least four characters long.isPossible(word:)
: Validates if the word can be made from the root word.isReal(word:)
: UsesUITextChecker
to ensure the word is valid.calculateScore(for:)
: Updates the score based on the word length.wordError(title:message:)
: Displays an error alert.
This project is licensed under the MIT License - see the LICENSE file for details.
- The app is inspired by the word game featured in the 100 Days of SwiftUI course by Paul Hudson.
- Thanks to Apple for providing the development tools and frameworks.