using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
public class Solution
{
static void Main(string[] args)
{
List<int> list = Enumerable.Range(0, 10).ToList();
int[] targetNumber = new int[3];
Random rand = new Random();
HashSet<int> checkList = new HashSet<int>();
// 중복되지 않는 숫자로 targetNumber의 갯수만큼 추출
for (int i =0; i< targetNumber.Length; i++)
{
int selectNum = list[rand.Next(0, list.Count)];
targetNumber[i] = selectNum;
checkList.Add(selectNum);
list.Remove(selectNum);
}
bool guessedCorrectly = false;
int attempts = 0;
while (!guessedCorrectly)
{
int ball = 0;
int strike = 0;
Console.Write($"Enter your guess (3 digits): ");
string input = Console.ReadLine();
// 입력이 예외 상황인지 확인
if (input.Length != targetNumber.Length || !input.All(char.IsDigit))
{
Console.WriteLine("Invalid input. Please enter 3 digits.");
continue;
}
int[] userGuess = input.Select(x => x -'0').ToArray();
attempts++;
for(int i =0; i < targetNumber.Length; i++)
{
if (targetNumber[i] == userGuess[i])
strike++;
else if (checkList.Contains(userGuess[i]))
ball++;
}
if(strike == targetNumber.Length)
{
Console.WriteLine($"Congratulations! You've guessed the number in {attempts} attempts.");
guessedCorrectly = true;
}
else
Console.WriteLine($"{strike} Strike(s), {ball} Ball(s)");
}
}
}
또한 길이와, 입력받는 문자열의 형태를 확인하여 정상적인 입력이 아니라면 재입력을 받도록 예외처리도 추가해 주었습니다.
linq를 사용하게 되면 훨씬 더 간결하게 코드를 작성할 수 있었습니다.
기본적인 유니티 엔진 사용법에 대해서 배우는 프로젝트 입니다.

큰 문제 없이 기존에 알고 있던 내용으로 프로젝트를 진행할 수 있었고, 추가적으로 알게 된 내용은 아래와 같이 ToString을 할때 소숫점 출력 갯수를 지정해 줄 수 있다는 부분이었습니다.
timeTxt.text = totalTime.ToString("N2");
앞선 프로젝트의 복습으로 볼수 있는 프로젝트 입니다.

다른 것은 이전과 크게 달라질것이 없는 복습 형태의 프로젝트입니다.
특기할만한 내용은
Playerprefs 였습니다. 프로젝트를 여러번 진행했음에도 확인하지 못했던 방식이었는데 관련된 내용을 좀 더 조사해보니 몇몇 부분에서는 쉽게 사용하기 좋을것으로 생각됩니다.
간단하게 정리하자면 아래와 같이 결론내릴 수 있습니다.
PlayerPrefs는 간단한 설정 값이나 작은 데이터 저장에는 유용하지만,
보안이 취약하고, 대량 데이터 저장에는 부적절허다.
PlayerPrefs를 사용해야 하는 경우
게임 설정 값 저장 (볼륨, 해상도, 키 설정)
간단한 유저 진행도 저장 (레벨, 최고 점수)
빠른 로컬 데이터 저장이 필요할 때
⚠️ PlayerPrefs를 사용하지 말아야 하는 경우
보안이 중요한 정보 (예: 로그인 정보, 인앱 구매 데이터)
대량 데이터 저장 (예: 퀘스트 진행, 인벤토리 데이터)
빠른 접근이 필요한 경우 (JSON, 데이터베이스가 더 적합)
장기적으로는 JSON 파일 저장, SQLite, Firebase 등의 대체 방법을 고려하는 것이 좋습니다.