31: WorldScramble, part 3

그루두·2024년 5월 16일
0

100 days of SwiftUI

목록 보기
40/108

100 days of swiftui: 31
https://www.hackingwithswift.com/100/swiftui/31

challenge

  1. Disallow answers that are shorter than three letters or are just our start word.
  2. Add a toolbar button that calls startGame(), so users can restart with a new word whenever they want to.
  3. Put a text view somewhere so you can track and show the player’s score for a given root word. How you calculate score is down to you, but something involving number of words and their letter count would be reasonable.

solution

  1. 입력된 단어가 3글자 초과이고 rootword와 겹치지 않는지 확인하기
        guard isNotRootWord(word: word) else {
            wordError(title: "Root word is not possible", message: "Use another word")
            return
        }
        guard isLonggerThan3(word: word) else {
            wordError(title: "Word is too short", message: "Input the word longer than 3")
            return
        }
    func isNotRootWord(word: String) -> Bool {
        !(rootWord == word)
    }
    func isLonggerThan3(word: String) -> Bool {
        word.count > 3
    }

코드 파일
https://github.com/treesofgroo/Ios-WordScramble/commit/701e3dbf35584bbc39bfc291a306e9521089c1f2

  1. 새로운 게임을 시작할 수 있는 toolbar 만들기
            .toolbar {
                Button(action: {
                    startGame()
                }, label: {
                    Text("New Word")
                })
            }

코드 파일
https://github.com/treesofgroo/Ios-WordScramble/commit/e1b8f998b6331fca982f5f181efce28edf3af893

  1. score를 만들어 적용시키기
  • score를 만들어서, 유효한 단어를 입력하면 글자 수만큼 점수를 증가시켰다.
  • 새로운 게임이 시작되면 0점으로 초기화했다.
  • usedWords가 새로운 게임이 시작되어도 값이 남아있는 걸 확인해서, 새로운 게임이 시작될 때 모든 요소를 지워 초기화했다.

코드 파일
https://github.com/treesofgroo/Ios-WordScramble/commit/d109245b66de8ef054a63ff7c3d33cdd543508a6

profile
계속 해보자

0개의 댓글

관련 채용 정보