namespace CSbasic
{
internal class Program
{
static void Main(string[] args)
{
int[,] mapNumber = new int[3, 3] { { 0, 2, 1 }, { 0, 3, 1, }, { 0, 4, 0 } };
string[] map = { " l l ", "_____l_____l_____", " 1 l 2 l 3 ", " 4 l 5 l 6 ", " 7 l 8 l 9 " };
string[] marking = { "X", "O" };
int[,] victoryRecipe = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 1, 4, 7 }, { 2, 5, 8 }, { 3, 6, 9 }, { 3, 5, 7 }, { 1, 5, 9 } };
List<int> player1 = new List<int>();
List<int> player2 = new List<int>();
bool gameOver = false;
int i = 0;
int playerNum;
int uswerInput;
while (!gameOver)
{
playerNum = i % 2 + 1;
Console.WriteLine("플레이어 1:X와 플레이어 2: 0\n");
Console.WriteLine($"플레이어 {playerNum}의 차례\n");
DrawMap();
uswerInput = int.Parse(Console.ReadLine());
int mapNum = (uswerInput - 1) / 3 + 2;
map[mapNum] = map[mapNum].Replace(uswerInput.ToString(), marking[playerNum - 1]);
Console.Clear();
if (playerNum == 1)
{
player1.Add(uswerInput);
gameOver = Calculate(player1);
if(gameOver) Console.WriteLine("축하합니다 플레이어1님이 승리하셨습니다.");
}
else
{
player2.Add(uswerInput);
gameOver = Calculate(player2);
if(gameOver) Console.WriteLine("축하합니다 플레이어2님이 승리하셨습니다.");
}
i++;
if (i > 8) gameOver = true;
}
void DrawMap()
{
for (int i = 0; i < 3; i++)
{
for(int j=0; j <3; j++)
{
Console.WriteLine(map[mapNumber[i,j]]);
}
}
}
bool Calculate(List<int> player)
{
bool result=false;
for (int i = 0; i < 8; i++)
{
bool temp = player.Contains(victoryRecipe[i, 0]) &&
player.Contains(victoryRecipe[i, 1]) &&
player.Contains(victoryRecipe[i, 2]);
if(temp) result = true;
}
return result;
}
}
}
}
개선해야할 사항 player 1과 player2를 더 잘 구분했어야 함.
'내일배움캠프' 카테고리의 다른 글
| TextRPG의 필수기능 기본 구조 및 분석 (0) | 2025.02.06 |
|---|---|
| TIL 0205 TextRPG 의존성 주입 (0) | 2025.02.05 |
| Unity 7기 TIL (0) | 2025.01.24 |
| Unity 7기 TIL 5일차 Coroutine 주시 (2) | 2025.01.23 |
| 만들고 싶은 게임 (1) | 2025.01.15 |