// 1) 가위 => 0
// 2) 바위 => 1
// 3) 보 => 2
var computerChoice = Int.random(in: 0...2)
var myChoice = 2
// 그냥 출력한번 해보기
switch computerChoice {
case 0:
print("컴퓨터의 선택은 가위 입니다.")
case 1:
print("컴퓨터의 선택은 바위 입니다.")
case 2:
print("컴퓨터의 선택은 보 입니다.")
default:
break
}
switch myChoice {
case 0:
print("당신의 선택은 가위 입니다.")
case 1:
print("당신의 선택은 바위 입니다.")
case 2:
print("당신의 선택은 보 입니다.")
default:
break
}
// 로직을 짜기 전에 고민
if myChoice == 0 { // 각 케이스 별로 다 고려
if computerChoice == 0 {
print("무승부 입니다.")
} else if computerChoice == 1 {
print("당신은 졌습니다.")
} else { //computerChoice == 2
print("당신이 이겼습니다.")
}
} else if myChoice == 1 {
if computerChoice == 0 {
print("당신이 이겼습니다.")
} else if computerChoice == 1 {
print("무승부 입니다.")
} else { //computerChoice == 2
print("당신은 졌습니다.")
}
} else { //myChoice == 2
if computerChoice == 0 {
print("당신은 졌습니다.")
} else if computerChoice == 1 {
print("당신이 이겼습니다.")
} else { //computerChoice == 2
print("무승부 입니다.")
}
}
if myChoice == computerChoice { // 무승부의 경우를 먼저 정의 ===> 이긴 경우 ===> 나머지
print("무승부 입니다.")
} else if myChoice == 0 && computerChoice == 2 {
print("당신이 이겼습니다.")
} else if myChoice == 1 && computerChoice == 0 {
print("당신이 이겼습니다.")
} else if myChoice == 2 && computerChoice == 1 {
print("당신이 이겼습니다.")
} else {
print("당신은 졌습니다.")
}
코드를 입력하세요