C# 루프가 이상해요 반복이 2번씩 되네요
-
게시물 수정 , 삭제는 로그인 필요
클래스 3개로 주사위 게임을 만드는데...
여기 case 10같은경우 반복이 이상하게 되는데 제가 뭔가 잘못한게 있나요?
Your dice roll totalled {0}
Press any key to roll dice again to obtain your {0} points
하고 한번씩 딱딱 끊겨야되는데 안멈추고 그냥 2번씩 반복을 해버려요. 거기다 다른y/n 같은것도 스킵해버릴때가 있구요. 뭐가 잘못된건가요?
public void Play() {
do{
int a = die1.Roll();
int b = die2.Roll();
int sum = a+b;
//declare int sum and roll dice
die1.Roll();
die2.Roll();
Console.WriteLine("\n Your dice roll totalled {0}", sum);
switch(sum)
......
...
...
...
case 10:
//declare second sum
int sum2 = 0;
do{
Console.WriteLine("Press any key to roll dice again to obtain your {0} points.", sum);
Console.Read();
//// show the first sum
sum2 = die1.Roll()+ die2.Roll();
// calculate second sum
Console.WriteLine("Your dice roll totalled" + sum2);
// show the second sum
if (sum2 == 7)
{
Console.WriteLine("\n You lose - I got two points", sum2);
cPoint = cPoint + 2;// add computer's points
}
else if (sum2 == sum)
{
Console.WriteLine("You've obtained {0} points", sum);
mPoint = mPoint + sum;// add my points
}
} while ((sum2 != 7)&&(sum!=sum2)) ;// if sum2 is same with sum or sum2 is 7 end while statement
//end do..while
break;
클래스 3개로 주사위 게임을 만드는데...
여기 case 10같은경우 반복이 이상하게 되는데 제가 뭔가 잘못한게 있나요?
Your dice roll totalled {0}
Press any key to roll dice again to obtain your {0} points
하고 한번씩 딱딱 끊겨야되는데 안멈추고 그냥 2번씩 반복을 해버려요. 거기다 다른y/n 같은것도 스킵해버릴때가 있구요. 뭐가 잘못된건가요?
public void Play() {
do{
int a = die1.Roll();
int b = die2.Roll();
int sum = a+b;
//declare int sum and roll dice
die1.Roll();
die2.Roll();
Console.WriteLine("\n Your dice roll totalled {0}", sum);
switch(sum)
......
...
...
...
case 10:
//declare second sum
int sum2 = 0;
do{
Console.WriteLine("Press any key to roll dice again to obtain your {0} points.", sum);
Console.Read();
//// show the first sum
sum2 = die1.Roll()+ die2.Roll();
// calculate second sum
Console.WriteLine("Your dice roll totalled" + sum2);
// show the second sum
if (sum2 == 7)
{
Console.WriteLine("\n You lose - I got two points", sum2);
cPoint = cPoint + 2;// add computer's points
}
else if (sum2 == sum)
{
Console.WriteLine("You've obtained {0} points", sum);
mPoint = mPoint + sum;// add my points
}
} while ((sum2 != 7)&&(sum!=sum2)) ;// if sum2 is same with sum or sum2 is 7 end while statement
//end do..while
break;