Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【REFACTOR】コードを整理 #92

Merged
merged 22 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
90c53fa
[feat] quizButton のincorrectを適用
mrs1669 May 30, 2024
d6459ac
[refactor] 不要になったalertの削除
mrs1669 May 30, 2024
e95ad7c
[refactor] quizIndexの重複を削除
mrs1669 May 30, 2024
b40ce47
[refactor] rename QuizEntity
mrs1669 May 30, 2024
386f2c5
[refactor] QuizViewでGeometryReaderを利用するように
mrs1669 May 30, 2024
1f93ee8
[refactor] make QuizContentView
mrs1669 May 30, 2024
e977461
[refactor] QuizTimeLimitView を QuizContentViewに移行
mrs1669 May 30, 2024
e1486c2
[refactor] QuizContentにまとめ
mrs1669 May 30, 2024
18435e4
[refactor] QuizContentViewに変数を渡す
mrs1669 May 30, 2024
06fb843
[refactor] QuizNumberViewを QuizContentViewに移行
mrs1669 May 30, 2024
ac7b971
[refactor] fix preview quizNumber
mrs1669 May 30, 2024
1868b6e
[refactor] QuizIndexViewを QuizContentViewに移行
mrs1669 May 30, 2024
6847097
[refactor] 階層を変更
mrs1669 May 31, 2024
a9e415c
[refactor] 背景色を共通化
mrs1669 May 31, 2024
dca3934
[refactor] QuizNumberView の背景を消す
mrs1669 May 31, 2024
0306c1f
[refactor] コメントの削除
mrs1669 May 31, 2024
4f6bb74
[refactor] インデントの修正
mrs1669 May 31, 2024
6d8a8d2
[refactor] quizNumberBackgroundView を easyだけ移行
mrs1669 May 31, 2024
63aeaad
[refactor] quizNumberBackgroundViewに移行
mrs1669 May 31, 2024
ead1bf8
[refactor] 重複したswitch文を削除
mrs1669 May 31, 2024
c0a7a76
[refactor] if式を適用
mrs1669 May 31, 2024
f01b669
[refactor] quizNumberTextの作成
mrs1669 May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions PrimePickApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4F02A57D2BF62F61003DF310 /* PrimeQuizEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F02A57C2BF62F61003DF310 /* PrimeQuizEntity.swift */; };
4F02A57D2BF62F61003DF310 /* QuizEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F02A57C2BF62F61003DF310 /* QuizEntity.swift */; };
4F02A57F2BF63A43003DF310 /* QuizDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F02A57E2BF63A43003DF310 /* QuizDataManager.swift */; };
4F0C82822BC8247500E1480E /* PrimePickApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0C82812BC8247500E1480E /* PrimePickApp.swift */; };
4F0C82842BC8247500E1480E /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0C82832BC8247500E1480E /* MainView.swift */; };
Expand All @@ -22,12 +22,13 @@
4F8BE16C2BF4FFB000D7CF0E /* PrimeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8BE16B2BF4FFB000D7CF0E /* PrimeData.swift */; };
4F8BE16E2BF504BB00D7CF0E /* QuizView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8BE16D2BF504BB00D7CF0E /* QuizView.swift */; };
4F8DC1842C08D66200247F62 /* QuizResultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8DC1832C08D66200247F62 /* QuizResultView.swift */; };
4F8DC1872C08F56000247F62 /* QuizContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8DC1862C08F56000247F62 /* QuizContentView.swift */; };
4FEC65B12C01164800A8B731 /* SelectDifficultyButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEC65B02C01164800A8B731 /* SelectDifficultyButtonView.swift */; };
4FEC65B42C01184E00A8B731 /* Text+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEC65B32C01184E00A8B731 /* Text+Extension.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4F02A57C2BF62F61003DF310 /* PrimeQuizEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimeQuizEntity.swift; sourceTree = "<group>"; };
4F02A57C2BF62F61003DF310 /* QuizEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizEntity.swift; sourceTree = "<group>"; };
4F02A57E2BF63A43003DF310 /* QuizDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizDataManager.swift; sourceTree = "<group>"; };
4F0C827E2BC8247500E1480E /* PrimePickApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PrimePickApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
4F0C82812BC8247500E1480E /* PrimePickApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimePickApp.swift; sourceTree = "<group>"; };
Expand All @@ -44,6 +45,7 @@
4F8BE16B2BF4FFB000D7CF0E /* PrimeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimeData.swift; sourceTree = "<group>"; };
4F8BE16D2BF504BB00D7CF0E /* QuizView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizView.swift; sourceTree = "<group>"; };
4F8DC1832C08D66200247F62 /* QuizResultView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizResultView.swift; sourceTree = "<group>"; };
4F8DC1862C08F56000247F62 /* QuizContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuizContentView.swift; sourceTree = "<group>"; };
4FC177B82BEEAB2C00447A06 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
4FEC65B02C01164800A8B731 /* SelectDifficultyButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectDifficultyButtonView.swift; sourceTree = "<group>"; };
4FEC65B32C01184E00A8B731 /* Text+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Text+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -82,8 +84,8 @@
4F65A3972C0100FD00065A53 /* Enum */,
4FEC65B22C0117FC00A8B731 /* Extension */,
4FEC65B52C01234C00A8B731 /* View */,
4F0C82812BC8247500E1480E /* PrimePickApp.swift */,
4F8BE1682BF4FB8E00D7CF0E /* QuizData */,
4F0C82812BC8247500E1480E /* PrimePickApp.swift */,
4F0C82852BC8247600E1480E /* Assets.xcassets */,
4F42C7A52BF7756200F92FBB /* ColorAssets.xcassets */,
4FC177B82BEEAB2C00447A06 /* Info.plist */,
Expand Down Expand Up @@ -114,11 +116,22 @@
children = (
4F8BE16B2BF4FFB000D7CF0E /* PrimeData.swift */,
4F02A57E2BF63A43003DF310 /* QuizDataManager.swift */,
4F02A57C2BF62F61003DF310 /* PrimeQuizEntity.swift */,
4F02A57C2BF62F61003DF310 /* QuizEntity.swift */,
);
path = QuizData;
sourceTree = "<group>";
};
4F8DC1852C08F53D00247F62 /* QuizContent */ = {
isa = PBXGroup;
children = (
4F8DC1862C08F56000247F62 /* QuizContentView.swift */,
4F2239252BFD0873004C71A6 /* QuizIndexView.swift */,
4F42C7A32BF76E7700F92FBB /* QuizNumberView.swift */,
4F2239212BFC9DEB004C71A6 /* QuizTimeLimitView.swift */,
);
path = QuizContent;
sourceTree = "<group>";
};
4FEC65B22C0117FC00A8B731 /* Extension */ = {
isa = PBXGroup;
children = (
Expand All @@ -141,9 +154,7 @@
isa = PBXGroup;
children = (
4F8BE16D2BF504BB00D7CF0E /* QuizView.swift */,
4F2239252BFD0873004C71A6 /* QuizIndexView.swift */,
4F42C7A32BF76E7700F92FBB /* QuizNumberView.swift */,
4F2239212BFC9DEB004C71A6 /* QuizTimeLimitView.swift */,
4F8DC1852C08F53D00247F62 /* QuizContent */,
4F2239232BFCEEF0004C71A6 /* QuizButtonView.swift */,
4F8DC1832C08D66200247F62 /* QuizResultView.swift */,
);
Expand Down Expand Up @@ -225,11 +236,12 @@
4F2239242BFCEEF0004C71A6 /* QuizButtonView.swift in Sources */,
4F8DC1842C08D66200247F62 /* QuizResultView.swift in Sources */,
4F2239262BFD0873004C71A6 /* QuizIndexView.swift in Sources */,
4F02A57D2BF62F61003DF310 /* PrimeQuizEntity.swift in Sources */,
4F02A57D2BF62F61003DF310 /* QuizEntity.swift in Sources */,
4F65A3992C01019000065A53 /* Difficulty.swift in Sources */,
4F0C82842BC8247500E1480E /* MainView.swift in Sources */,
4FEC65B12C01164800A8B731 /* SelectDifficultyButtonView.swift in Sources */,
4F8BE16E2BF504BB00D7CF0E /* QuizView.swift in Sources */,
4F8DC1872C08F56000247F62 /* QuizContentView.swift in Sources */,
4F2239222BFC9DEB004C71A6 /* QuizTimeLimitView.swift in Sources */,
4F0C82822BC8247500E1480E /* PrimePickApp.swift in Sources */,
4F02A57F2BF63A43003DF310 /* QuizDataManager.swift in Sources */,
Expand Down
6 changes: 3 additions & 3 deletions PrimePickApp/QuizData/QuizDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation
import GameplayKit

class QuizDataManager {
func makeQuizData(difficulty: Difficulty) -> [PrimeQuizEntity] {
func makeQuizData(difficulty: Difficulty) -> [QuizEntity] {
let primeData = PrimeData()
var quizData: [PrimeQuizEntity] = []
var quizData: [QuizEntity] = []
let timestamp = UInt64(Date().timeIntervalSince1970 * 1000)
var generator = SeededGenerator(seed: timestamp)

Expand All @@ -34,7 +34,7 @@ class QuizDataManager {
let primeNumbers = primeData.generateThreeDigitPrimes()
isCorrect = primeNumbers.contains(randomInt)
}
let primeQuizEntity = PrimeQuizEntity(quizId: i, number: randomInt, isCorrect: isCorrect)
let primeQuizEntity = QuizEntity(quizId: i, number: randomInt, isCorrect: isCorrect)
quizData.append(primeQuizEntity)
}
return quizData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// PrimeQuizEntity.swift
// QuizEntity.swift
// PrimePickApp
//
// Created by 村石 拓海 on 2024/05/16.
//

import Foundation

struct PrimeQuizEntity {
struct QuizEntity {
var quizId: Int
var number: Int
var isCorrect: Bool
Expand Down
32 changes: 4 additions & 28 deletions PrimePickApp/View/Quiz/QuizButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,18 @@
import SwiftUI

struct QuizButtonView: View {
var quizData: [PrimeQuizEntity]
var quizData: [QuizEntity]
@Binding var correctQuizNumber: Int
@Binding var quizIndex: Int
@Binding var isPresentedResult: Bool
@State private var showAlert = false
@Environment(\.dismiss) private var dismiss

var body: some View {
ZStack {
HStack {
Spacer()

ZStack {
RoundedRectangle(cornerRadius: 25)
.stroke(Color.quizIncorrectButton, lineWidth: 5)
.background(RoundedRectangle(cornerRadius: 25).fill(Color.quizIncorrectButton.opacity(0.1)))
.frame(width: UIScreen.main.bounds.width * 2 / 5, height: UIScreen.main.bounds.height / 4)
.shadow(radius: 10)

Text("❌")
.font(.custom("ArialRoundedMTBold", size: 80))
}
quizButton(option: "Incorrect")
.onTapGesture {
print("❌")
if !quizData[quizIndex].isCorrect {
Expand All @@ -39,11 +29,8 @@ struct QuizButtonView: View {
print("不正解")
}
if quizIndex < 9 {
if quizIndex < 9 {
quizIndex += 1
}
quizIndex += 1
} else {
// showAlert = true
isPresentedResult = true
}
}
Expand All @@ -60,26 +47,15 @@ struct QuizButtonView: View {
print("不正解")
}
if quizIndex < 9 {
if quizIndex < 9 {
quizIndex += 1
}
quizIndex += 1
} else {
// showAlert = true
isPresentedResult = true
}
}

Spacer()
}
}
.alert(isPresented: $showAlert) {
Alert(
title: Text("You Score is \(correctQuizNumber) points!"),
dismissButton: .default(Text("OK!")) {
dismiss()
}
)
}
}
}

Expand Down
62 changes: 62 additions & 0 deletions PrimePickApp/View/Quiz/QuizContent/QuizContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// QuizContentView.swift
// PrimePickApp
//
// Created by 村石 拓海 on 2024/05/31.
//

import SwiftUI

struct QuizContentView: View {
@Binding var quizNumber: Int
let difficulty: Difficulty
let quizData: [QuizEntity]

var body: some View {
GeometryReader { geometry in
ZStack(alignment: .leading) {
switch difficulty {
case .easy:
Color("appGreen")
.opacity(0.5)
.edgesIgnoringSafeArea(.all)
case .normal:
Color.blue
.opacity(0.5)
.edgesIgnoringSafeArea(.all)
case .hard:
Color.red
.opacity(0.5)
.edgesIgnoringSafeArea(.all)
}

VStack(spacing: .zero) {
QuizIndexView(difficulty: difficulty, quizNumber: $quizNumber)
.frame(height: geometry.size.height / 6)

QuizNumberView(
quizNumber: $quizNumber,
difficulty: difficulty,
quizData: quizData
)
.frame(height: geometry.size.height * 2 / 3)

QuizTimeLimitView(difficulty: difficulty)
.frame(height: geometry.size.height / 6)
}
}
}
}
}

struct QuizContentView_Previews: PreviewProvider {
@State static var quizNumber = 0

static var previews: some View {
QuizContentView(
quizNumber: $quizNumber,
difficulty: .easy,
quizData: [QuizEntity(quizId: 0, number: 3, isCorrect: true)]
)
}
}
21 changes: 21 additions & 0 deletions PrimePickApp/View/Quiz/QuizContent/QuizIndexView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// QuizIndexView.swift
// PrimePickApp
//
// Created by 村石 拓海 on 2024/05/22.
//

import SwiftUI

struct QuizIndexView: View {
let difficulty: Difficulty
@Binding var quizNumber: Int

var body: some View {
Text("No.\(quizNumber + 1)")
.font(.custom("ArialRoundedMTBold", size: 45))
.foregroundStyle(Color.gray)
.padding(.horizontal, 16)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
68 changes: 68 additions & 0 deletions PrimePickApp/View/Quiz/QuizContent/QuizNumberView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// QuizNumberView.swift
// PrimePickApp
//
// Created by 村石 拓海 on 2024/05/17.
//

import SwiftUI

struct QuizNumberView: View {
@Binding var quizNumber: Int
let difficulty: Difficulty
let quizData: [QuizEntity]

var body: some View {
ZStack {
quizNumberBackgroundView(difficulty: difficulty)

quizNumberText(
quizNumber: quizNumber,
difficulty: difficulty,
quizData: quizData
)
}
}
}

private func quizNumberBackgroundView(difficulty: Difficulty) -> some View {
let color = if difficulty == .easy {
Color.appGreen
} else if difficulty == .normal {
Color.blue
} else {
Color.red
}

return RoundedRectangle(cornerRadius: 25)
.stroke(color, lineWidth: 5)
.frame(width: 300, height: 200)
.shadow(radius: 10)
.background(
RoundedRectangle(cornerRadius: 25).fill(Color.white)
)
}

private func quizNumberText(quizNumber: Int, difficulty: Difficulty, quizData: [QuizEntity]) -> some View {
let size: CGFloat = if difficulty == .easy {
180
} else {
120
}

return Text(quizData[quizNumber].number.description)
.font(.custom("ArialRoundedMTBold", size: size))
.foregroundStyle(Color.gray)
}

struct QuizNumberView_Previews: PreviewProvider {
@State static var quizNumber = 3

static var previews: some View {
QuizNumberView(
quizNumber: $quizNumber,
difficulty: .easy,
quizData: [QuizEntity(quizId: 0, number: 3, isCorrect: true)]
)
}
}
37 changes: 0 additions & 37 deletions PrimePickApp/View/Quiz/QuizIndexView.swift

This file was deleted.

Loading