C#/수업내용

2020.04.07. 수업내용 - while 문 5 (애니메이션 3)

dev_sr 2020. 4. 7. 23:14

 

while문(조건, 무한)과 for문(무한) 사용해보기

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
            //6. while - 애니메이션 3
 
            //값을 입력 받고 출력하기
            Console.Write("공격 애니메이션 1 : ");
            string aniName1 = Console.ReadLine();
            Console.Write("공격 애니메이션 1 total 프레임 : ");
            var totalFrame1 = Int32.Parse(Console.ReadLine());
            Console.Write("공격 애니메이션 타격 프레임 : ");
            var attackFrame1 = Int32.Parse(Console.ReadLine());
            Console.Write("공격 애니메이션의 효과 : ");
            string aniEffect1 = Console.ReadLine();
 
            Console.Write("\n공격 애니메이션 2 :");
            string aniName2 = Console.ReadLine();
            Console.Write("공격 애니메이션 2 total 프레임 : ");
            var totalFrame2 = Int32.Parse(Console.ReadLine());
            Console.Write("공격 애니메이션 타격 프레임 : ");
            var attackFrame2 = Int32.Parse(Console.ReadLine());
            Console.Write("공격 애니메이션의 효과 : ");
            string aniEffect2 = Console.ReadLine();
 
            Console.Write("\n기본 애니메이션 : ");
            string basicName = Console.ReadLine();
            Console.Write("기본 애니메이션 total 프레임 : ");
            var basicTotalFrame = Convert.ToInt32(Console.ReadLine());
 
            Console.Write("\nPlay 입력: ");
            string playOrder = Console.ReadLine();
 
 
            //ani currentframe설정
            int currentFrame = 0;
 
            //ani1 반복 실행
            while (true)
            {
                //반복될때마다 currentFrame 증가
                currentFrame++;
 
 
                //currentFrame이 total Frame보다 커지면 종료
                if (currentFrame > totalFrame1)
                {
                    currentFrame = 0;
                    break;
                }
 
                //currentFrame이 타격 프레임이면 이펙트 실행
                if (currentFrame == attackFrame1)
                {
                    Console.WriteLine(aniEffect1);
                }
 
                //아니면 반복해서 실행
                else
                {
                    Console.WriteLine("{0} {1} frame", aniName1, currentFrame);
                }
 
            }
            Console.WriteLine();
 
            //ani2 반복 실행
            while (currentFrame < totalFrame2)
            {
                currentFrame++;
 
                if (currentFrame == attackFrame2)
                {
                    Console.WriteLine(aniEffect2);
                }
 
                else
                {
                    Console.WriteLine("{0} {1} frame", aniName2, currentFrame);
                }
            }
            currentFrame = 0;
            Console.WriteLine();
 
            //기본 애니메이션 반복 실행
            for (; ; )
            {
                currentFrame++;
 
                if (currentFrame > basicTotalFrame)
                {
                    Console.WriteLine("애니메이션 종료");
                    break;
                }
 
                else
                {
                    Console.WriteLine("{0} {1} frame", basicName, currentFrame);
                }
            }
 

 

결과 값