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

가위바위보 게임 [STEP 1] oliver #12

Open
wants to merge 4 commits into
base: rft_2_oliver
Choose a base branch
from
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
153 changes: 152 additions & 1 deletion RockPaperScissors/RockPaperScissors.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
objects = {

/* Begin PBXBuildFile section */
18BCCBB22BADB34A000ADA5D /* RPSStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCCBB12BADB34A000ADA5D /* RPSStrategy.swift */; };
18BCCBB32BADB34A000ADA5D /* RPSStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCCBB12BADB34A000ADA5D /* RPSStrategy.swift */; };
18BCCBB52BADB608000ADA5D /* GameCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCCBB42BADB608000ADA5D /* GameCalculator.swift */; };
18BCCBB62BADB608000ADA5D /* GameCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCCBB42BADB608000ADA5D /* GameCalculator.swift */; };
18BCCBB82BADBC72000ADA5D /* GameProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCCBB72BADBC72000ADA5D /* GameProcessor.swift */; };
18BCCBB92BADBC72000ADA5D /* GameProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BCCBB72BADBC72000ADA5D /* GameProcessor.swift */; };
A7A432AD2BA9628300CD85B9 /* Hand.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7A432AC2BA9628300CD85B9 /* Hand.swift */; };
A7A432B52BA963F100CD85B9 /* RPSCalculatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7A432B42BA963F100CD85B9 /* RPSCalculatorTests.swift */; };
A7A432BB2BA9642300CD85B9 /* Hand.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7A432AC2BA9628300CD85B9 /* Hand.swift */; };
A7A432BC2BA9647F00CD85B9 /* GameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C78484632B6A32E500FBF8B4 /* GameView.swift */; };
C784841D2B5E48E300FBF8B4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C784841C2B5E48E300FBF8B4 /* AppDelegate.swift */; };
C784841F2B5E48E300FBF8B4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C784841E2B5E48E300FBF8B4 /* SceneDelegate.swift */; };
C78484212B5E48E300FBF8B4 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C78484202B5E48E300FBF8B4 /* GameViewController.swift */; };
Expand All @@ -16,7 +26,23 @@
C78484642B6A32E500FBF8B4 /* GameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C78484632B6A32E500FBF8B4 /* GameView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
A7A432B62BA963F100CD85B9 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C78484112B5E48E300FBF8B4 /* Project object */;
proxyType = 1;
remoteGlobalIDString = C78484182B5E48E300FBF8B4;
remoteInfo = RockPaperScissors;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
18BCCBB12BADB34A000ADA5D /* RPSStrategy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RPSStrategy.swift; sourceTree = "<group>"; };
18BCCBB42BADB608000ADA5D /* GameCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCalculator.swift; sourceTree = "<group>"; };
18BCCBB72BADBC72000ADA5D /* GameProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameProcessor.swift; sourceTree = "<group>"; };
A7A432AC2BA9628300CD85B9 /* Hand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hand.swift; sourceTree = "<group>"; };
A7A432B22BA963F100CD85B9 /* RockPaperScissorsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RockPaperScissorsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A7A432B42BA963F100CD85B9 /* RPSCalculatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RPSCalculatorTests.swift; sourceTree = "<group>"; };
C78484192B5E48E300FBF8B4 /* RockPaperScissors.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RockPaperScissors.app; sourceTree = BUILT_PRODUCTS_DIR; };
C784841C2B5E48E300FBF8B4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C784841E2B5E48E300FBF8B4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -29,6 +55,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
A7A432AF2BA963F100CD85B9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
C78484162B5E48E300FBF8B4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -39,10 +72,19 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
A7A432B32BA963F100CD85B9 /* RockPaperScissorsTests */ = {
isa = PBXGroup;
children = (
A7A432B42BA963F100CD85B9 /* RPSCalculatorTests.swift */,
);
path = RockPaperScissorsTests;
sourceTree = "<group>";
};
C78484102B5E48E300FBF8B4 = {
isa = PBXGroup;
children = (
C784841B2B5E48E300FBF8B4 /* RockPaperScissors */,
A7A432B32BA963F100CD85B9 /* RockPaperScissorsTests */,
C784841A2B5E48E300FBF8B4 /* Products */,
);
sourceTree = "<group>";
Expand All @@ -51,6 +93,7 @@
isa = PBXGroup;
children = (
C78484192B5E48E300FBF8B4 /* RockPaperScissors.app */,
A7A432B22BA963F100CD85B9 /* RockPaperScissorsTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -66,13 +109,35 @@
C78484252B5E48E400FBF8B4 /* Assets.xcassets */,
C78484272B5E48E400FBF8B4 /* LaunchScreen.storyboard */,
C784842A2B5E48E400FBF8B4 /* Info.plist */,
A7A432AC2BA9628300CD85B9 /* Hand.swift */,
18BCCBB12BADB34A000ADA5D /* RPSStrategy.swift */,
18BCCBB42BADB608000ADA5D /* GameCalculator.swift */,
18BCCBB72BADBC72000ADA5D /* GameProcessor.swift */,
);
path = RockPaperScissors;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
A7A432B12BA963F100CD85B9 /* RockPaperScissorsTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = A7A432B82BA963F100CD85B9 /* Build configuration list for PBXNativeTarget "RockPaperScissorsTests" */;
buildPhases = (
A7A432AE2BA963F100CD85B9 /* Sources */,
A7A432AF2BA963F100CD85B9 /* Frameworks */,
A7A432B02BA963F100CD85B9 /* Resources */,
);
buildRules = (
);
dependencies = (
A7A432B72BA963F100CD85B9 /* PBXTargetDependency */,
);
name = RockPaperScissorsTests;
productName = RockPaperScissorsTests;
productReference = A7A432B22BA963F100CD85B9 /* RockPaperScissorsTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
C78484182B5E48E300FBF8B4 /* RockPaperScissors */ = {
isa = PBXNativeTarget;
buildConfigurationList = C784842D2B5E48E400FBF8B4 /* Build configuration list for PBXNativeTarget "RockPaperScissors" */;
Expand All @@ -97,9 +162,13 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1500;
LastSwiftUpdateCheck = 1520;
LastUpgradeCheck = 1500;
TargetAttributes = {
A7A432B12BA963F100CD85B9 = {
CreatedOnToolsVersion = 15.2;
TestTargetID = C78484182B5E48E300FBF8B4;
};
C78484182B5E48E300FBF8B4 = {
CreatedOnToolsVersion = 15.0.1;
};
Expand All @@ -119,11 +188,19 @@
projectRoot = "";
targets = (
C78484182B5E48E300FBF8B4 /* RockPaperScissors */,
A7A432B12BA963F100CD85B9 /* RockPaperScissorsTests */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
A7A432B02BA963F100CD85B9 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
C78484172B5E48E300FBF8B4 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -137,19 +214,44 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
A7A432AE2BA963F100CD85B9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
18BCCBB92BADBC72000ADA5D /* GameProcessor.swift in Sources */,
18BCCBB62BADB608000ADA5D /* GameCalculator.swift in Sources */,
A7A432B52BA963F100CD85B9 /* RPSCalculatorTests.swift in Sources */,
A7A432BC2BA9647F00CD85B9 /* GameView.swift in Sources */,
18BCCBB32BADB34A000ADA5D /* RPSStrategy.swift in Sources */,
A7A432BB2BA9642300CD85B9 /* Hand.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
C78484152B5E48E300FBF8B4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
18BCCBB82BADBC72000ADA5D /* GameProcessor.swift in Sources */,
C78484212B5E48E300FBF8B4 /* GameViewController.swift in Sources */,
C784841D2B5E48E300FBF8B4 /* AppDelegate.swift in Sources */,
18BCCBB52BADB608000ADA5D /* GameCalculator.swift in Sources */,
18BCCBB22BADB34A000ADA5D /* RPSStrategy.swift in Sources */,
A7A432AD2BA9628300CD85B9 /* Hand.swift in Sources */,
C78484642B6A32E500FBF8B4 /* GameView.swift in Sources */,
C784841F2B5E48E300FBF8B4 /* SceneDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
A7A432B72BA963F100CD85B9 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C78484182B5E48E300FBF8B4 /* RockPaperScissors */;
targetProxy = A7A432B62BA963F100CD85B9 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
C78484222B5E48E300FBF8B4 /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand All @@ -170,6 +272,44 @@
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
A7A432B92BA963F100CD85B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5K3W33ZZ68;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.2;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = kr.co.oliver.RockPaperScissorsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RockPaperScissors.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/RockPaperScissors";
};
name = Debug;
};
A7A432BA2BA963F100CD85B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5K3W33ZZ68;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.2;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = kr.co.oliver.RockPaperScissorsTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RockPaperScissors.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/RockPaperScissors";
};
name = Release;
};
C784842B2B5E48E400FBF8B4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -296,6 +436,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5K3W33ZZ68;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = RockPaperScissors/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -322,6 +463,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5K3W33ZZ68;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = RockPaperScissors/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -344,6 +486,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
A7A432B82BA963F100CD85B9 /* Build configuration list for PBXNativeTarget "RockPaperScissorsTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
A7A432B92BA963F100CD85B9 /* Debug */,
A7A432BA2BA963F100CD85B9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C78484142B5E48E300FBF8B4 /* Build configuration list for PBXProject "RockPaperScissors" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
64 changes: 64 additions & 0 deletions RockPaperScissors/RockPaperScissors/GameCalculator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// GameCalculator.swift
// RockPaperScissors
//
// Created by MacBook on 2024/03/22.
//

import Foundation

enum GameState: Equatable {
case beforeStart
case playing
case finished(isWin: Bool)
}

enum SetResult: String {
case win
case draw
case lose
}

protocol GameCalculator {
var gameState: GameState { get }

func play(myHand: Hand, opponentHand: Hand)
func reset()
}

final class RPSGameCalculator: GameCalculator {
private var winCount: Int
private var gameCount: Int
private let maxGameCount: Int
private let winCondition: Int
private(set) var gameState: GameState

init(maxGameCount: Int, winCondition: Int) {
self.maxGameCount = maxGameCount
self.winCondition = winCondition
self.winCount = 0
self.gameCount = 0
self.gameState = .beforeStart
}

func play(myHand: Hand, opponentHand: Hand) {
gameState = .playing
gameCount += 1
let setResult: SetResult = myHand.singleSetPlay(opponentHand: opponentHand)

if setResult == .win {
winCount += 1
}

if gameCount == maxGameCount {
let isWin: Bool = winCount >= winCondition
gameState = .finished(isWin: isWin)
}
}

func reset() {
winCount = 0
gameCount = 0
gameState = .beforeStart
}
}
36 changes: 36 additions & 0 deletions RockPaperScissors/RockPaperScissors/GameProcessor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// GameProcessor.swift
// RockPaperScissors
//
// Created by MacBook on 2024/03/22.
//

import Foundation

protocol GameProcessor {
func play()
}

struct RPSGameProcessor: GameProcessor {
private let gameCalculator: GameCalculator

init(gameCalculator: GameCalculator) {
self.gameCalculator = gameCalculator
}

func play() {

switch gameCalculator.gameState {
case .beforeStart, .playing:
guard let myHand: Hand = Hand.randomHand(),
let opponentHand: Hand = Hand.randomHand()
else {
return
}

gameCalculator.play(myHand: myHand, opponentHand: opponentHand)
case .finished:
return
}
}
}
Loading