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] 웅, 메네 #160

Merged
merged 15 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
9d3d884
feat: Hand 타입의 enum 설정(가위, 바위, 보)
JaeKimdev Aug 23, 2022
304be4f
feat: 게임을 시작하는 gameStart 함수 구현
JaeKimdev Aug 23, 2022
c2881d6
feat: 사용자 핸드를 생성하는 makeUserHand 함수 구현
iOS-Woong Aug 23, 2022
7714db1
feat: 랜덤 컴퓨터 핸드와 유저 핸드를 비교하는 함수 checkResult 구현
JaeKimdev Aug 23, 2022
338d82f
fix: 유저 입력이 0일 경우, 종료 로직 추가
iOS-Woong Aug 23, 2022
71b6df0
refactor: Hand Enum에서 불필요한 Int 타입 삭제
JaeKimdev Aug 23, 2022
25bd02f
style: enum파일 분리
iOS-Woong Aug 23, 2022
f5e7b75
feat: 전역변수 제거하고 Result enum 생성
JaeKimdev Aug 23, 2022
92e87d4
refactor: 사용자 Hand와 컴퓨터Hand를 비교하여 Result타입을 반환하는 compareHand 함수 리팩토링
iOS-Woong Aug 23, 2022
0bf720c
refactor: compareHand 함수에서 반환된 Result타입의 rawValue를 출력하는 displayResult 구현
JaeKimdev Aug 23, 2022
193f2ef
refactor: 함수'makeUserHand' 리팩토링
iOS-Woong Aug 23, 2022
f276819
refactor: 'startGame' 함수에서 재귀함수 이용하여 반복구현하도록 리팩토링
iOS-Woong Aug 23, 2022
357fac1
refactor: compareHand 함수 파라미터 수정 및 튜플로 승패 처리하도록 리팩토링
JaeKimdev Aug 24, 2022
13bfedd
refactor: makeUserHand 함수 삭제 후, startGame 함수에서 그역할을 동시에 수행하도록 수정
iOS-Woong Aug 24, 2022
4320b5d
refactor: compareHand 함수 case:draw조건 삭제 및 함수명 변경
iOS-Woong Aug 24, 2022
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
12 changes: 12 additions & 0 deletions RockPaperScissors/RockPaperScissors.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
868EE1F428B3BE50001F389E /* RockPaperScissors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 868EE1F328B3BE50001F389E /* RockPaperScissors.swift */; };
868EE1F628B506A1001F389E /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 868EE1F528B506A1001F389E /* Result.swift */; };
C7ABA0E1254EA63000B2367D /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7ABA0E0254EA63000B2367D /* main.swift */; };
D2CB093F28B504CF00D0DD7E /* Hand.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2CB093E28B504CF00D0DD7E /* Hand.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -23,8 +26,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
868EE1F328B3BE50001F389E /* RockPaperScissors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RockPaperScissors.swift; sourceTree = "<group>"; };
868EE1F528B506A1001F389E /* Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = "<group>"; };
C7ABA0DD254EA63000B2367D /* RockPaperScissors */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = RockPaperScissors; sourceTree = BUILT_PRODUCTS_DIR; };
C7ABA0E0254EA63000B2367D /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
D2CB093E28B504CF00D0DD7E /* Hand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hand.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -58,6 +64,9 @@
isa = PBXGroup;
children = (
C7ABA0E0254EA63000B2367D /* main.swift */,
868EE1F328B3BE50001F389E /* RockPaperScissors.swift */,
D2CB093E28B504CF00D0DD7E /* Hand.swift */,
868EE1F528B506A1001F389E /* Result.swift */,
);
path = RockPaperScissors;
sourceTree = "<group>";
Expand Down Expand Up @@ -119,7 +128,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
868EE1F428B3BE50001F389E /* RockPaperScissors.swift in Sources */,
C7ABA0E1254EA63000B2367D /* main.swift in Sources */,
868EE1F628B506A1001F389E /* Result.swift in Sources */,
D2CB093F28B504CF00D0DD7E /* Hand.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
15 changes: 15 additions & 0 deletions RockPaperScissors/RockPaperScissors/Hand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Hand.swift
// RockPaperScissors
//
// Created by woong, mene on 23/8/2022.
//

import Foundation

enum Hand: Int, CaseIterable {
case none = 0
case scissor = 1
case rock = 2
case paper = 3
}
14 changes: 14 additions & 0 deletions RockPaperScissors/RockPaperScissors/Result.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Result.swift
// RockPaperScissors
//
// Created by woong, mene on 23/8/2022.
//

import Foundation

enum Result: String {
case win = "이겼습니다!"
case lose = "졌습니다!"
case draw = "비겼습니다!"
}
52 changes: 52 additions & 0 deletions RockPaperScissors/RockPaperScissors/RockPaperScissors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// RockPaperScissors.swift
// RockPaperScissors
//
// Created by woong, mene on 22/8/2022.
//

import Foundation

func compareHand(with computer: Hand, and user: Hand) -> Result {
switch (computer, user) {
case (.rock, .paper), (.paper, .scissor), (.scissor, .rock):
return .win
case (.rock, .scissor), (.paper, .rock), (.scissor, .paper):
return .lose
default:
return .draw
}
}

func display(of result: Result) {
print(result.rawValue)
}

func startGame() {
let randomComputerHand: Hand = Hand(rawValue: Int.random(in: 1...3)).unsafelyUnwrapped

print("computerHand : \(randomComputerHand)")
print("가위(1), 바위(2), 보(3)! <종료 : 0> :", terminator: " ")

guard let inputNumberString = readLine(),
let inputNumber = Int(inputNumberString),
let result = Hand(rawValue: inputNumber) else {

print("잘못된 입력입니다. 다시 시도해주세요.")
return startGame()
}

switch result {
case .none:
print("게임종료")
case .rock, .scissor, .paper:
let gameResult: Result = compareHand(with: randomComputerHand, and: result)
display(of: gameResult)

if gameResult == Result.draw {
startGame()
}
}
}


3 changes: 1 addition & 2 deletions RockPaperScissors/RockPaperScissors/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

import Foundation

print("Hello, World!")

startGame()