C#/수업내용

2020.04.03. 수업내용 - for문, 글자색 변경

dev_sr 2020. 4. 3. 13:03
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_002
{
    class App
    {
        public App()
        {
            Console.WriteLine("2020-04-03");
 
            //아이언맨의 체력은 10입니다.
            //타노스의 공격력은 3입니다.
            //아이언맨이 타노스에게 3만큼 공격을 받았습니다.
            //아이언맨의 체력은 n입니다.
 
            string heroName = "아이언맨";
            int heroHp = 10;
            string monsterName = "타노스";
            int monsterAttack = 3;
 
            Console.WriteLine(heroName + "의 체력은" + " " + heroHp + "입니다.");
            Console.WriteLine(monsterName + "의 공격력은" + " " + monsterAttack + "입니다.\n");
 
            for(int i=0; i<4; i++)
            {
                heroHp -= monsterAttack;
                Console.WriteLine(heroName+"이"+" "+monsterName+"에게"+" "+monsterAttack+"의 공격을 받았습니다.");
                Console.WriteLine(heroName + "의 체력은" + " " + heroHp + "입니다.\n");
            }
 
            //빵의 갯수는 5개입니다.
            //홍길동님이 빵을 먹었습니다.
            //n개의 빵이 남았습니다.
 
            Console.WriteLine("빵의 갯수는 5개 입니다.\n");
 
            for(int i=4; i>-1; i-- )
            {
                Console.WriteLine("홍길동님이 빵을 먹었습니다.");
                Console.WriteLine(i + "개의 빵이 남았습니다.\n");
            }
 
            //2xn
 
            for (int i = 1; i < 10; i++
            {
                Console.WriteLine(2 + " x " + i);
            }
 
            //2xn=2n
 
            for (int i = 1; i < 10; i++)
            {
                Console.WriteLine(2 + " x " + i + " = " + 2 * i);
            }
 
            //1~12월
            for(int i=1; i<13; i++)
            {
                Console.WriteLine(i + "월");
            }
 
            //2018~2024년
 
            for(int i=2018; i<2025; i++)
            {
                Console.WriteLine(i + "년");
            }
 
 
            //캐릭터 이름 : 홍길동
            //최대 체력 : 10
            //현재 체력 : 10
            //홍길동이 공격을 받았습니다
            //물약을 먹고 체력을 회복했습니다
 
            string Name = "홍길동";
            int maxHp = 10;
            int nowHp = 10;
            int damage = 3;
            int portion = 1;
 
            Console.WriteLine("캐릭터 이름 : " + Name);
            Console.WriteLine("최대 체력 : " + maxHp);
            Console.WriteLine("현재 체력 : " + nowHp+"\n");
 
            for(int i=0; i<3; i++)
            {
                nowHp -= damage;
                Console.Write("공격을 받았습니다 ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("(-" + damage + ") ");
                Console.ResetColor();
                Console.WriteLine(nowHp + "/" + maxHp);
 
                nowHp += portion;
                Console.Write("물약을 먹고 체력을 회복했습니다 ");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("(+" + portion + ") ");
                Console.ResetColor();
                Console.WriteLine(nowHp + "/" + maxHp);
              
 
            }
            
        }
    }
}
 
 
 

 

 

 

결과값

 

색상 변경까지 적용했습니다.