↑ 맞춘 화면
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Roulette
{
class Program
{
static void Main(string[] args)
{
int count = 0; // 입력 저장을 위한 카운트
int[,] Num = new int[5,9];
Random rand = new Random();
int[] SaveNum = new int[45];
int ComNum;
int ReadNum;
char conti;
bool overlap = false;
Console.WriteLine("########################################################################");
Console.WriteLine("######################## !! 재미나는 룰렛게임 !! #######################");
Console.WriteLine();
while (true)
{
ComNum = rand.Next(100, 99999)%45+1;
Console.WriteLine(" << 컴퓨터가 룰렛 번호를 선택했습니다 >> ");
Console.WriteLine("########################################################################");
do
{
if (!overlap)
{
Console.WriteLine();
RandomArray(ref Num); // 랜덤 배열 표시 함수
Print(Num, SaveNum, count);
}
Console.Write(" >> 번호를 선택하세요 : ");
ReadNum = int.Parse(Console.ReadLine());
overlap = false;
for (int k = 0; k < count; k++)
if (ReadNum == SaveNum[k])
{
overlap = true;
break;
}
if (overlap)
{
Console.WriteLine();
Console.WriteLine(" << !!! 중복 입력하셨습니다 !!! 다른 번호를 입력하세요 !!! >> ");
Print(Num, SaveNum, count);
Console.WriteLine();
}
else
{
SaveNum[count] = ReadNum;
count++;
Console.WriteLine();
Console.WriteLine(" >> {0} 번을 선택하셨습니다~ 당첨됐을까요? ", ReadNum);
if (ComNum != ReadNum)
{
Console.WriteLine(" >> 아쉽지만 {0}번은 아니네요~ 다시 시도하세요~ ", ReadNum);
}
}
} while (ComNum != ReadNum);
Console.WriteLine("####### [ 추카추카~ 당첨 되셨습니다~ ] #######");
Console.WriteLine(" >> 닭이라도 쏘세요~~ㅋㅋㅋ");
Console.WriteLine(" >> {0}번 만에 성공하셨네요~ 대단하심~", count);
Console.WriteLine();
Console.Write(" >> 계속 하시겠습니까? (Y/N) : ");
conti = char.ToUpper(char.Parse(Console.ReadLine()));
if (conti == 'Y')
{
count = 0;
continue;
}
else
break;
}
Console.WriteLine();
}
static void RandomArray(ref int[,] Num)
{
Random rand = new Random();
bool overlap;
int RandNum;
int i, j, k, l;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 9; j++)
{
Num[i, j] = 0;
}
}
for (i = 0; i < 5; i++)
{
for (j = 0; j < 9; j++)
{
while (true)
{
overlap = false;
RandNum = rand.Next(1, 46);
for (k = 0; k < i + 1; k++)
{
for (l = 0; l < 9; l++)
{
if (RandNum == Num[k, l])
{
overlap = true;
break;
}
}
if (overlap)
break;
}
if (!overlap)
{
Num[i, j] = RandNum;
break;
}
}
}
}
}
static void Print(int[,] Num, int[] SaveNum, int count)
{
int i, j, k;
bool overlap;
Console.WriteLine();
for (i = 0; i < 5; i++)
{
for (j = 0; j < 9; j++)
{
overlap = false;
for (k = 0; k < count; k++)
if (Num[i, j] == SaveNum[k])
{
Console.Write("------\t");
overlap = true;
break;
}
if (!overlap)
if (Num[i, j] < 10)
Console.Write("[ 0{0} ]\t", Num[i, j]);
else
Console.Write("[ {0} ]\t", Num[i, j]);
}
Console.WriteLine();
Console.WriteLine();
}
}
}
}
나름 힘든 작업이었음..ㅋㅋ
맨날 랜덤과 배열, 출력... 그게 다인듯..
새로운걸 찾아야하는데.. ㅡㅡ 뭐가 좋을까나~~