Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions week2/2022-iOS-2week.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
D4265FCA289C0EED007B9AD9 /* CardListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4265FC1289C0EED007B9AD9 /* CardListView.swift */; };
D4265FCB289C0EED007B9AD9 /* BottomButtonListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4265FC2289C0EED007B9AD9 /* BottomButtonListView.swift */; };
D4265FCD289C0EED007B9AD9 /* MainGameBoardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4265FC4289C0EED007B9AD9 /* MainGameBoardView.swift */; };
D4AFE63A28A7A58600814689 /* ConstantEmojiContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AFE63928A7A58600814689 /* ConstantEmojiContent.swift */; };
D4AFE63A28A7A58600814689 /* Emoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4AFE63928A7A58600814689 /* Emoji.swift */; };
D4E4D29D289805D400432365 /* ChanggyoAssignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E4D29C289805D400432365 /* ChanggyoAssignment.swift */; };
D4E4D2A1289805D500432365 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D4E4D2A0289805D500432365 /* Assets.xcassets */; };
D4E4D2A4289805D500432365 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D4E4D2A3289805D500432365 /* Preview Assets.xcassets */; };
Expand All @@ -28,7 +28,7 @@
D4265FC1289C0EED007B9AD9 /* CardListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardListView.swift; sourceTree = "<group>"; };
D4265FC2289C0EED007B9AD9 /* BottomButtonListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomButtonListView.swift; sourceTree = "<group>"; };
D4265FC4289C0EED007B9AD9 /* MainGameBoardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainGameBoardView.swift; sourceTree = "<group>"; };
D4AFE63928A7A58600814689 /* ConstantEmojiContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantEmojiContent.swift; sourceTree = "<group>"; };
D4AFE63928A7A58600814689 /* Emoji.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Emoji.swift; sourceTree = "<group>"; };
D4E4D299289805D400432365 /* 2022-iOS-2week.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "2022-iOS-2week.app"; sourceTree = BUILT_PRODUCTS_DIR; };
D4E4D29C289805D400432365 /* ChanggyoAssignment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChanggyoAssignment.swift; sourceTree = "<group>"; };
D4E4D2A0289805D500432365 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -99,7 +99,7 @@
D4E4D2A0289805D500432365 /* Assets.xcassets */,
D4E4D29C289805D400432365 /* ChanggyoAssignment.swift */,
D4265FC4289C0EED007B9AD9 /* MainGameBoardView.swift */,
D4AFE63928A7A58600814689 /* ConstantEmojiContent.swift */,
D4AFE63928A7A58600814689 /* Emoji.swift */,
D4265FCE289C1120007B9AD9 /* Model */,
D4265FD0289C1136007B9AD9 /* Viewmodel */,
D4265FBF289C0EED007B9AD9 /* View */,
Expand Down Expand Up @@ -185,7 +185,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D4AFE63A28A7A58600814689 /* ConstantEmojiContent.swift in Sources */,
D4AFE63A28A7A58600814689 /* Emoji.swift in Sources */,
D4265FCD289C0EED007B9AD9 /* MainGameBoardView.swift in Sources */,
D4265FCB289C0EED007B9AD9 /* BottomButtonListView.swift in Sources */,
D4265FC5289C0EED007B9AD9 /* CardView.swift in Sources */,
Expand Down
134 changes: 134 additions & 0 deletions week2/2022-iOS-2week/Model/ImojiGame.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

struct EmojiGame {
var leftCardSetCount: Int { cards.count - cards.filter {$0.state == .isMatched}.count }

private(set) var cards: [Card]
private(set) var point: Int

private var isFaceUpCard = false

// MARK: mutating Func
mutating func changeGameTheme(cardEmojis: [String], displayCardCount: Int) {
let startIndex = Int.random(in: 1...1000) % cardEmojis.count
let endIndex = startIndex + displayCardCount
var newCards = [Card]()

for i in startIndex ... endIndex {
let index = i % cardEmojis.count
newCards.append(Card(imoji: cardEmojis[index], id: index * 2 + 1))
newCards.append(Card(imoji: cardEmojis[index], id: index * 2 ))
}

point = 0
cards = newCards.shuffled()
}

mutating func changeStateCard(cardId: Int) {
guard let chosenIndex = cards.firstIndex(where: {cardId == $0.id}) else { return }
if cards[chosenIndex].state == .isMatched { return }

if isFaceUpCard {
cards[chosenIndex].state.changeCardState()
calculatePoint()
isFaceUpCard = false
}
else {
for index in 0 ..< cards.count {
if cards[index].state != .isFaceDown {
cards[index].state.changeCardState()
}
}
isFaceUpCard = true
cards[chosenIndex].state.changeCardState()
}
}

mutating private func calculatePoint() {
guard let firstCardIndex = cards.firstIndex(where: { $0.state == .isFaceUp }),
let secondCardIndex = cards.lastIndex(where: { $0.state == .isFaceUp }) else { return }

if cards[firstCardIndex].imoji == cards[secondCardIndex].imoji {
point += 3
if leftCardSetCount == 2 {
cards[firstCardIndex].state = .isMatched
cards[secondCardIndex].state = .isMatched
print(leftCardSetCount)
}
else {
cards[firstCardIndex].state = .waitForMatched
cards[secondCardIndex].state = .waitForMatched
}
}
else if !cards[firstCardIndex].didSelected && !cards[secondCardIndex].didSelected {
point += 0
}
else if cards[firstCardIndex].didSelected && cards[secondCardIndex].didSelected {
point -= 2
}
else {
point -= 1
}

cards[firstCardIndex].didSelected = true
cards[secondCardIndex].didSelected = true
}
}

// MARK: - extension Nested Struct
extension EmojiGame {
struct Card: Identifiable, Hashable {
var didSelected = false
var state: CardState = .isFaceDown
var imoji: String
var id: Int
}

enum CardState {
case isFaceUp
case isFaceDown
case isMatched
case waitForMatched

mutating func changeCardState() {
switch self {
case .waitForMatched:
self = .isMatched
case .isFaceUp:
self = .isFaceDown
case .isFaceDown:
self = .isFaceUp
case .isMatched:
self = .isMatched
}
}
}
}

extension EmojiGame {
struct ConstantContent {
static let face = ["😀","😍","🤪","🤑","😔","😰","🤯","🤕","🤐","🤩","🤡","🤠","😶","👿","😶‍🌫️","🥶"]
static let animal = ["🐶","🐭","🐻","🐯","🐨","🐸","🦧","🦊","🦍","🐷","🦁","🦥","🦒"]
static let sports = ["🏉","🏈","⚽","🏀","⚾","🥎","🎾","🏐","🎱","🥏","🏓","🥅","🪃","🏒","🥍","🥊"]
static let heart = ["🧡","💔","💙","💜","💛","💚","🤎","🤍","🖤","❤️‍🔥","💝","💗"]
static let vehicle = ["🚗","🚑","🚙","🚓","🚒","🚕","🛺","🚐","🚌","🛻","🚎","🚚","🏎","🚛","🏍","🛵","🚁"]
static let outfit = ["👚","🥼","🦺","🧥","👙","🩱","👞","🥿","🥾","🧢","👡","👠","🧦","👘","👗","🧤","🧣","👓"]

static func emit(willChangeTheme theme: Theme.Kind) -> [String] {
switch theme {
case .face:
return face
case .animal:
return animal
case .sports:
return sports
case .vehicle:
return vehicle
case .heart:
return heart
case .outfit:
return outfit
}
}
}

}
4 changes: 2 additions & 2 deletions week3/Calculator/Calculator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
D460BBA128A93C4800FACD16 /* Preview Content */,
D49F037928AE1B9500E3D308 /* View */,
D49F037A28AE1B9F00E3D308 /* Model */,
D4156BA428B23BA200F51371 /* DoubleExtension.swift */,
D4156BA628B23BAA00F51371 /* StringExtension.swift */,
D49F037828AE1B7300E3D308 /* ViewModel */,
);
path = Calculator;
Expand All @@ -89,8 +91,6 @@
isa = PBXGroup;
children = (
D460BBAD28A952A700FACD16 /* Calculator.swift */,
D4156BA428B23BA200F51371 /* DoubleExtension.swift */,
D4156BA628B23BAA00F51371 /* StringExtension.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand Down
121 changes: 0 additions & 121 deletions week3/Calculator/Calculator/Model/CalculatorButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,124 +5,3 @@
// Created by changgyo seo on 2022/08/21.
//

enum CalculatorButton: Identifiable, Equatable {
case equal
case add(Bool)
case subtract(Bool)
case multiply(Bool)
case divide(Bool)
case percent
case sign
case clear(clearType)
case numberOrDot(String)
case none

var id: String { return content }

var content: String {
switch self {
case .equal:
return "="
case .add:
return "+"
case .subtract:
return "-"
case .multiply:
return "*"
case .divide:
return "/"
case .percent:
return "%"
case .sign:
return "±"
case .clear(.displayresult):
return "C"
case .clear(.alldata):
return "AC"
case .numberOrDot(let value):
return value
default:
return ""
}
}

var backgroundColor: (red: Double, green: Double, blue: Double, opacity: Double) {
switch self {
case .clear, .percent, .sign:
return (160 / 255, 160 / 255, 160 / 255 , 1)
case .numberOrDot:
return (50 / 255, 50 / 255, 50 / 255, 1)
case .add, .divide, .multiply, .subtract:
if isActive {
return (1, 1, 1, 1)
}
else {
return (233 / 255, 157 / 255, 57 / 255, 1)
}
default:
return (233 / 255, 157 / 255, 57 / 255, 1)
}
}

var textColorColor: (red: Double, green: Double, blue: Double, opacity: Double) {
switch self {
case .clear, .percent, .sign:
return (0, 0, 0, 1)
case .add, .divide, .multiply, .subtract:
if isActive {
return (233 / 255, 157 / 255, 57 / 255, 1)
}
else {
return (1, 1, 1, 1)
}
default:
return (1, 1, 1, 1)
}
}

var buttonSize: Int {
switch self {
case .numberOrDot("0"):
return 2
default:
return 1
}
}

var isActive: Bool {
switch self {
case .add(let isActive):
return isActive
case .subtract(let isActive):
return isActive
case .multiply(let isActive):
return isActive
case .divide(let isActive):
return isActive
default:
return false
}
}

mutating func activeButton(active: Bool) {
switch self {
case .divide:
self = .divide(active)
case .multiply:
self = .multiply(active)
case .subtract:
self = .subtract(active)
case .add:
self = .add(active)
default:
break
}
}
}

extension CalculatorButton {
enum clearType {
case alldata
case displayresult
}
}
Loading