'C#'에 해당되는 글 38건

  1. 2019.03.27 <객체와 개체의 차이>
  2. 2019.03.26 <data type>var
  3. 2019.03.26 <공부할 거 모아두기>하루에 하나라도 찾아보려고 노력하기
  4. 2019.03.26 계속 수정됨
  5. 2019.03.26 <코드읽기>
  6. 2019.03.26 <진영, 종족, 직업 선택하기 1단계>ps비열한 얼라놈들, 호드를 위하여.
  7. 2019.03.26 <오버로딩과 오버라이드>메서드 오버라이드(상속)이해못함 내일 다시할 것
  8. 2019.03.25 <오우거잡이>수정본

<객체와 개체의 차이>

C#/과제 2019. 3. 27. 00:21

객체와 개체의 차이

객체(客體)(손 객, 몸 체)Object

객체 지향 프로그래밍의 방식(Object-Oriented Programming OOP)의

각각의 기능을 부분적으로 분담하고 필요한 부분을 객체로 하여 호출한다.

클래스의 생성된 개체(인스턴스)를 프로그램관점에서 볼때는 객체라고 해도 괜찮다.

클래스의 관점에서 볼때는 개체는 객체가 아닌 주체이다.


개체(個體)(따로 개, 몸 체)

전체나 집단에 상대하여 하나하나의 낱개를 이르는 말.

class를 통해 만들어진 인스턴스를 뜻함


클래스와 개체의 차이

클래스는 개체의 형식을 나타내는 청사진이고

실제로 메모리에 할당된 것은 개체(인스턴스)라고 부른다.


https://social.msdn.microsoft.com/Forums/ko-KR/c095ed0e-0f92-4c1b-8251-5950b4a1ca14/ctip-?forum=visualcsharpko

https://cerulean85.tistory.com/149

네이버 사전

Docs참조

:

<data type>var

C#/아는것 2019. 3. 26. 23:41

var타입은 c# 3.0부터 사용이 가능한 데이터 타입으로
들어가는 값을 보고 컴파일러가 알아서 데이터 타입을 정해주는 아주 유용한 녀석

1
2
int a=10;
var b=10;
cs


'C# > 아는것' 카테고리의 다른 글

Boxing Unboxing  (0) 2019.03.28
IndexOf와 static 한정자  (0) 2019.03.27
:

<공부할 거 모아두기>하루에 하나라도 찾아보려고 노력하기

C#/모르는것 2019. 3. 26. 23:11

익힌건 찾아서 지우고 아는것에 넣기

namespace 

using

static void main(string[] args)


3. 객체

4. double, float 연산
7. Class와 Struct
12. 암시적변환과 명시적변환
13. overriding, overloading

박싱(Boxing) 과 언박싱 (UnBoxing)

객체와 개체의 차이

왜 한글변수를 사용하지 않을 까


Fleg

IEnumerable Interface

IEnumerable<T> Interface


딕셔너리

retrun 값없이 리턴만 쓰는 경우

List<T> 리스트명
리스트명.Find(x=>x.name=="장검");

함수형언어

상속

Class Diagram

해시테이블


선택적 매개변수

params keywold

Binary Fomatter

'C# > 모르는것' 카테고리의 다른 글

partial class  (0) 2019.07.12
델리게이트  (0) 2019.03.28
:

계속 수정됨

C#/나만의 약속 2019. 3. 26. 23:01

1.변수선언시
int heroName;
//변수명은 처럼 시작은 무조건 소문자 언더바 없이 띄어쓰기 대신 대문자 사용하기.

2.메서드 선언시
class App
{

}
int Method();
//메서드 명의 맨 앞글자 대문자, 클래스도 대문자

3.줄바꿈 관리 잘하기
줄은 2줄이상 떼지 않기<<일단은 나중엔 바꾸고 싶음..

클래스의 맴버 선언, 정의시
종류별로 한번씩 띄어주기
ex)
맴버변수
맴버변수

생성자

맴버메서드
{

}

맴버메서드
{

}

4. enum타입 사용시 변수명 앞에 소문자 e 붙이기 eJob{ adqo, bwerog, bwrg }

:

<코드읽기>

C#/과제 2019. 3. 26. 22:55

1번은 A4에 한번
2~9번, 마지막에 일부러 에러내기 10번








:

<진영, 종족, 직업 선택하기 1단계>ps비열한 얼라놈들, 호드를 위하여.

C#/과제 2019. 3. 26. 19:24


App.cs

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace study_03
{
    class App
    {
        public App()
        {
            Character hero = new Character();
            int escapeLoof0 = 0;
            int escapeLoof1 = 0;
            int escapeLoof2 = 0;
            while (escapeLoof0 == 0)
            {
                //var heroCamp=영웅의 진영값
                hero.camp = hero.CharacterSelectCamp();
                while (escapeLoof1 == 0)
                {
                    //heroRace = 영웅의 종족값(진영값을 매개변수로 줌)
                    hero.race = hero.CharacterSelectRace(Convert.ToInt32(hero.camp));
                    if (Convert.ToInt32(hero.race) == 7)
                    {
                        escapeLoof0 = 0;
                        escapeLoof1 = 0;
                        escapeLoof2 = 0;
                        break;
                    }
                    else
                    {
                        escapeLoof0 = 1;
                        escapeLoof1 = 1;
                    }
                    while (escapeLoof2 == 0)
                    {
                        //heroJob = 영웅의 직업값(진영값과, 종족값을 매개변수로 줌)
                        hero.job = hero.CharacterSelectJob(Convert.ToInt32(hero.camp), Convert.ToInt32(hero.race));
                        if (Convert.ToInt32(hero.job) == 12)
                        {
                            escapeLoof0 = 0;
                            escapeLoof1 = 0;
                            escapeLoof2 = 0;
                            break;
                        }
                        else
                        {
                            escapeLoof0 = 1;
                            escapeLoof1 = 1;
                            escapeLoof2 = 1;
                        }
                    }
                }
            }
            //영웅의 이름 입력
            while (true)
            {
                Console.Write("당신의 이름을 입력하세요: ");
                hero.name = Console.ReadLine();
                if (hero.name == "")
                {
                    Console.WriteLine("잘못 입력하였습니다.");
                }
                else
                {
                    break;
                }
            }
            //최종출력
            Console.WriteLine("{0}진영의 {1} {2}({3})이 생성 되었습니다.", hero.camp, hero.race, hero.job, hero.name);
            Vector2 movePoint = new Vector2(3f,5f);
            Console.WriteLine("당신은 ({0},{1})로 이동했습니다.", movePoint.x, movePoint.y);
        }
    }
}
 
 
cs

GameEnums.cs

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace study_03
{
    public class GameEnums
    {
        public enum eCamp
        {
            None = -1,
            Horde,
            Alliance
        }
 
        public enum eHordeRace
        {
            None = -1,
            Orc,
            Undead,
            Tauren,
            Troll,
            BloodElf,
            Goblin,
            Pandaren,
            PreviousStage
        }
 
        public enum eAllianceRace
        {
            None = -1,
            Human,
            Dwarf,
            NightElf,
            Gnomes,
            Draenei,
            Werewolf,
            Pandaren,
            PreviousStage
        }
 
        public enum eJob
        {
            None = -1,
            Warrior,
            Priest,
            Rogue,
            Paladin,
            Hunter,
            Shaman,
            Mage,
            Warlock,
            Druid,
            DeathKnight,
            Monk,
            DemonHunter,
            PreviousStage
        }
    }
}
 
cs

Vector2.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace study_03
{
    public class Vector2
    {
        public float x, y;
 
        public Vector2()
        {
        }
 
        public Vector2(float x,float y)
        {
            this.x = x;
            this.y = y;
        }
    }
}
 
cs

Character.cs

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace study_03
{
    class Character
    {
        public string name;
        public float x, y;
        public Enum camp;
        public Enum race;
        public Enum job;
 
        public Character()
        {
 
        }
        public Character(float x,float y)
        {
            this.x = x;
            this.y = y;
        }
 
        public Character(string name)
        {
            this.name = name;
        }
 
        public void Move(Vector2 movePoint)
        {
            //현제 Character의 인스턴스가 좌표값으로 이동한다!
            Console.WriteLine("{0}이(가) ({1},{2})좌표로 이동했습니다."this.name, movePoint.x, movePoint.y);
        }
 
        public Enum CharacterSelectCamp()
        {
            while (true)
            {
                Console.Write("진영을 선택하세요.(호드/얼라이언스):");
                var input = Console.ReadLine();
                if (input == "호드")
                {
                    Console.WriteLine("호드를 선택하셨습니다.");
                    return GameEnums.eCamp.Horde;
                }
                else if (input == "얼라이언스")
                {
                    Console.WriteLine("얼라놈을 선택하셨습니다.");
                    return GameEnums.eCamp.Alliance;
                }
                else
                {
                    Console.WriteLine("잘못된 입력입니다.");
                }
            }
        }
 
        public Enum CharacterSelectRace(int heroCamp)
        {
            if (heroCamp == 0)
            {
                while (true)
                {
                    Console.Write("종족을 선택하세요.(0오크/1언데드/2타우렌/3트롤/4블러드엘프/5고블린/6판다렌/7진영다시선택)(숫자입력):");
                    var input = Console.ReadLine();
 
                    if (input == "0")
                    {
                        Console.WriteLine("오크를 선택하셨습니다.");
                        return GameEnums.eHordeRace.Orc;
                    }
                    else if (input == "1")
                    {
                        Console.WriteLine("언데드를 선택하셨습니다.");
                        return GameEnums.eHordeRace.Undead;
                    }
                    else if (input == "2")
                    {
                        Console.WriteLine("타우렌을 선택하셨습니다.");
                        return GameEnums.eHordeRace.Tauren;
                    }
                    else if (input == "3")
                    {
                        Console.WriteLine("트롤을 선택하셨습니다.");
                        return GameEnums.eHordeRace.Troll;
                    }
                    else if (input == "4")
                    {
                        Console.WriteLine("블러드엘프를 선택하셨습니다.");
                        return GameEnums.eHordeRace.BloodElf;
                    }
                    else if (input == "5")
                    {
                        Console.WriteLine("고블린을 선택하셨습니다.");
                        return GameEnums.eHordeRace.Goblin;
                    }
                    else if (input == "6")
                    {
                        Console.WriteLine("판다렌를 선택하셨습니다.");
                        return GameEnums.eHordeRace.Pandaren;
                    }
                    else if(input == "7")
                    {
                        Console.WriteLine("진영선택으로 되돌아갑니다.");
                        return GameEnums.eHordeRace.PreviousStage;
                    }
                    else
                    {
                        Console.WriteLine("잘못된 선택입니다.");
                    }
                }
            }
 
            else if (heroCamp == 1)
            {
                while (true)
                {
                    Console.Write("종족을 선택하세요.(0인간/1드워프/2나이트엘프/3노움/4드레나이/5늑대인간/6판다렌/7진영다시선택)(숫자입력):");
                    var input = Console.ReadLine();
 
                    if (input == "0")
                    {
                        Console.WriteLine("인간을 선택하셨습니다.");
                        return GameEnums.eAllianceRace.Human;
                    }
                    else if (input == "1")
                    {
                        Console.WriteLine("드워프를 선택하셨습니다.");
                        return GameEnums.eAllianceRace.Dwarf;
                    }
                    else if (input == "2")
                    {
                        Console.WriteLine("나이트엘프를 선택하셨습니다.");
                        return GameEnums.eAllianceRace.NightElf;
                    }
                    else if (input == "3")
                    {
                        Console.WriteLine("노움을 선택하셨습니다.");
                        return GameEnums.eAllianceRace.Gnomes;
                    }
                    else if (input == "4")
                    {
                        Console.WriteLine("드레나이를 선택하셨습니다.");
                        return GameEnums.eAllianceRace.Draenei;
                    }
                    else if (input == "5")
                    {
                        Console.WriteLine("늑대인간을 선택하셨습니다.");
                        return GameEnums.eAllianceRace.Werewolf;
                    }
                    else if (input == "6")
                    {
                        Console.WriteLine("판다렌을 선택하셨습니다.");
                        return GameEnums.eAllianceRace.Pandaren;
                    }
                    else if (input == "7")
                    {
                        Console.WriteLine("진영선택으로 되돌아갑니다.");
                        return GameEnums.eAllianceRace.PreviousStage;
                    }
                    else
                    {
                        Console.WriteLine("잘못된 선택입니다.");
                    }
                }
            }
            return GameEnums.eAllianceRace.None;
        }
 
        public Enum CharacterSelectJob(int heroCamp, int heroRace)
        {
            if (heroCamp == 0)
            {
                //종족이 호드일때
                if (heroRace == 0)
                {
                    //오크
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1사냥꾼/2도적/3주술사/4마법사/5흑마법사/6수도사/7죽음의기사/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
 
                }
                else if (heroRace == 1)
                {
                    //언데드
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1사냥꾼/2도적/3사제/4마법사/5흑마법사/6수도사/7죽음의기사/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 2)
                {
                    //타우렌
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1성기사/2사냥꾼/3사제/4주술사/5수도사/6드루이드/7죽음의기사/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("성기사를 선택하셨습니다.");
                            return GameEnums.eJob.Paladin;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("드루이드를 선택하셨습니다.");
                            return GameEnums.eJob.Druid;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 3)
                {
                    //트롤
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1사냥꾼/2도적/3사제/4주술사/5마법사/6흑마법사/7수도사/8드루이드/9죽음의기사/10종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("드루이드를 선택하셨습니다.");
                            return GameEnums.eJob.Druid;
                        }
                        else if (input == "9")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "10")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 4)
                {
                    //블러드엘프
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1성기사/2사냥꾼/3도적/4사제/5마법사/6흑마법사/7수도사/8죽음의기사/9악마사냥꾼/10종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("성기사를 선택하셨습니다.");
                            return GameEnums.eJob.Paladin;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "9")
                        {
                            Console.WriteLine("악마사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.DemonHunter;
                        }
                        else if (input == "10")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 5)
                {
                    //고블린
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1사냥꾼/2도적/3사제/4주술사/5마법사/6흑마법사/7죽음의기사/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 6)
                {
                    //판다렌
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1사냥꾼/2도적/3사제/4주술사/5마법사/6수도사/7종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                return GameEnums.eJob.None;
            }
            else if (heroCamp == 1)
            {
                //종족이 얼라일때
                if (heroRace == 0)
                {
                    //인간
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0성기사/1전사/2죽음의기사/3사냥꾼/4도적/5수도사/6마법사/7사제/8흑마법사/9종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("성기사를 선택하셨습니다.");
                            return GameEnums.eJob.Paladin;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "9")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 1)
                {
                    //드워프
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0성기사/1전사/2죽음의기사/3사냥꾼/4주술사/5도적/6수도사/7마법사/8사제/9흑마법사/10종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("성기사를 선택하셨습니다.");
                            return GameEnums.eJob.Paladin;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "9")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "10")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 2)
                {
                    //나이트엘프
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1죽음의기사/2사냥꾼/3도적/4드루이드/5수도사/6악마사냥꾼/7마법사/8사제/9종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("드루이드를 선택하셨습니다.");
                            return GameEnums.eJob.Druid;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("악마사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.DemonHunter;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "9")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 3)
                {
                    //노움
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1죽음의기사/2사냥꾼/3도적/4수도사/5마법사/6사제/7흑마법사/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 4)
                {
                    //드레나이
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0성기사/1전사/2죽음의기사/3사냥꾼/4주술사/5수도사/6마법사/7사제/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("성기사를 선택하셨습니다.");
                            return GameEnums.eJob.Paladin;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 5)
                {
                    //늑대인간
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1죽음의기사/2사냥꾼/3도적/4드루이드/5마법사/6사제/7흑마법사/8종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("죽음의기사를 선택하셨습니다.");
                            return GameEnums.eJob.DeathKnight;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("드루이드를 선택하셨습니다.");
                            return GameEnums.eJob.Druid;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("흑마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Warlock;
                        }
                        else if (input == "8")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else if (heroRace == 6)
                {
                    //판다렌
                    while (true)
                    {
                        Console.Write("직업을 선택하세요.(0전사/1사냥꾼/2도적/3사제/4주술사/5마법사/6수도사/7종족다시선택)(숫자입력):");
                        var input = Console.ReadLine();
 
                        if (input == "0")
                        {
                            Console.WriteLine("전사를 선택하셨습니다.");
                            return GameEnums.eJob.Warrior;
                        }
                        else if (input == "1")
                        {
                            Console.WriteLine("사냥꾼을 선택하셨습니다.");
                            return GameEnums.eJob.Hunter;
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("도적을 선택하셨습니다.");
                            return GameEnums.eJob.Rogue;
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("사제를 선택하셨습니다.");
                            return GameEnums.eJob.Priest;
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("주술사를 선택하셨습니다.");
                            return GameEnums.eJob.Shaman;
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("마법사를 선택하셨습니다.");
                            return GameEnums.eJob.Mage;
                        }
                        else if (input == "6")
                        {
                            Console.WriteLine("수도사를 선택하셨습니다.");
                            return GameEnums.eJob.Monk;
                        }
                        else if (input == "7")
                        {
                            Console.WriteLine("종족선택창으로 돌아갑니다.");
                            return GameEnums.eJob.PreviousStage;
                        }
                        else
                        {
                            Console.WriteLine("잘못된 선택입니다.");
                        }
                    }
                }
                else
                {
                    return GameEnums.eJob.None;
                }
            }
            else
            {
                return GameEnums.eCamp.None;
            }
        }
    }
}
 
cs


'C# > 과제' 카테고리의 다른 글

<객체와 개체의 차이>  (0) 2019.03.27
<코드읽기>  (0) 2019.03.26
<오버로딩과 오버라이드>메서드 오버라이드(상속)이해못함 내일 다시할 것  (0) 2019.03.26
<오우거잡이>수정본  (0) 2019.03.25
<stack과 heap>  (0) 2019.03.24
:

<오버로딩과 오버라이드>메서드 오버라이드(상속)이해못함 내일 다시할 것

C#/과제 2019. 3. 26. 00:13

c# override, overload

다형성



overloading

메서드의 이름을 중복하고 싶을때 받는 파라미터(개수, 타입)를 바꾸고 메서드의 이름을 같게하여, 사용하는 방법

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
namespace _20190322
{
    class Program
    {
        static void Main(string[] args)
        {
            //오버로딩 예제
            Test test = new Test();
            Console.WriteLine(test.sum(13));
            Console.WriteLine(test.sum(1.1f, 3.3f));
 
            Console.ReadKey();
        }
    }
}
 
cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _20190322
{
    class Test
    {
        public int sum(int a, int b)
        {
            return a + b;
        }
        public float sum(float a, float b)
        {
            return a + b;
        }
    }
}
 
cs



override

한정자는 상속된 메서드, 연산자의 기능을 확장하거나 수정하는 데 필요합니다.

사용하는 메서드or연산자는 같지만 그 기능이 다르고자 할때 사용한다!


메서드 오버라이드는 자식클래스에서 부모에게 상속받은 부모의 메서드를 재정의하여 사용하는 것이다.

부모클래스에서는 자식클래스가 오버라이드 할 수 있게 하기위해 앞에 virtual이라는 예약어를 메서드 앞에 붙인다.

자식클래스에서는 재정의 하여 사고싶으면 'override'라는 약어를 메서드 앞에 붙인다.//메서드 오버라이드는 너무 졸려서 맨정신일때 상속부터 다시 공부...........ㅠ
//연산자 오버라이드 예제(직접만든 벡터간의 합 연산자 +오버라이드)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
 
namespace _20190322
{
    class Program
    {
        static void Main(string[] args)
        {
            Vector2D Vector1 = new Vector2D(1f, 2f);
            Vector2D Vector2 = new Vector2D(2.2f, 3.3f);
 
            Console.WriteLine("({0}, {1})",(Vector1 + Vector2).x,(Vector1+Vector2).y);
 
            Console.ReadKey();
        }
    }
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _20190322
{
    class Vector2D
    {
        public float x, y;
        public Vector2D() { }
        public Vector2D(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
        public static Vector2D operator+(Vector2D a,Vector2D b)
        {
            return new Vector2D(a.x + b.x, a.y + b.y);
        }
    }
}
 
cs




//참고 사이트들

https://jshzizon.tistory.com/entry/C%EC%9D%98-%EA%B0%9D%EC%B2%B4%EC%A7%80%ED%96%A51-2-%EC%97%B0%EC%82%B0%EC%9E%90-%EC%98%A4%EB%B2%84%EB%A1%9C%EB%94%A9

https://salkuma.wordpress.com/2014/02/11/%EC%97%B0%EC%82%B0%EC%9E%90-%EC%98%A4%EB%B2%84%EB%A1%9C%EB%94%A9-vs-%EC%98%A4%EB%B2%84%EB%9D%BC%EC%9D%B4%EB%94%A9/

https://jshzizon.tistory.com/entry/C%EC%9D%98-%EA%B0%9D%EC%B2%B4%EC%A7%80%ED%96%A51-2-%EC%97%B0%EC%82%B0%EC%9E%90-%EC%98%A4%EB%B2%84%EB%A1%9C%EB%94%A9

:

<오우거잡이>수정본

C#/과제 2019. 3. 25. 23:01
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
 
using System.Collections.Generic;
 
using System.Linq;
 
using System.Text;
 
using System.Threading.Tasks;
 
 
 
namespace _20190322
 
{
 
    class Test
 
    {
 
        public Test()//c# Test 클래스의 생성자
 
        {
 
            Console.ForegroundColor = ConsoleColor.White;
 
            //몬스터 이름은 오우거입니다.
 
            string monsterName = "오우거";
 
            Console.WriteLine("몬스터의 이름은{0}입니다.", monsterName);
 
 
 
            //몬스터의 체력은 123 입니다.
 
            int monsterMaxHp = 123;
 
            int monsterHp = monsterMaxHp;
 
            Console.WriteLine("몬스터의 체력은 ({0}/{1})입니다.", monsterHp, monsterMaxHp);
 
 
 
            //몬스터는 사납고 무섭습니다.
 
            string monsterCharcter1 = "사나움";
 
            string monsterCharcter2 = "무서움";
 
            Console.WriteLine($"몬스터의 특성은 {monsterCharcter1}, {monsterCharcter2}입니다.\n");
 
            //용사의 이름은 홍길동 입니다.
 
            string heroName = "홍길동";
 
            Console.WriteLine("용사의 이름은 " + heroName + "입니다.");
 
            //용사의 체력은 80입니다.
 
            int heroMaxHp = 80;
 
            int heroHp = heroMaxHp;
 
            Console.WriteLine("용사의 체력은 ({0}/{1})입니다.", heroHp, heroMaxHp);
 
            //용사의 공격력은 4입니다.
 
            int heroAttackDamage = 4;
 
            Console.WriteLine($"용사의 공격력은 {heroAttackDamage}입니다.\n");
 
 
 
            //공격하시겠습니까?
 
            for (int i = 1true;)
 
            {
 
 
 
                
 
                Console.Write("공격하시겠습니까?(y/n):");
 
                var inputAgainAttack = Console.ReadKey();
 
                if (inputAgainAttack.Key == ConsoleKey.N)
 
                {
 
                    Console.WriteLine("몬스터가 도망갔습니다.");
 
                    Console.ReadKey();
 
                    break;
 
                }
 
                else if (inputAgainAttack.Key == ConsoleKey.Y)
 
                {
 
                    int multipleAttackChance;
 
                    Console.Write("몇회 공격하시겠습니까?:");
 
                    multipleAttackChance = int.Parse(Console.ReadLine());
 
 
 
                    for (int j = 1; j <= multipleAttackChance; j++, i++)
 
                    {
 
                        //용사가 몬스터를 공격했습니다.
 
                        Console.WriteLine("용사가 {0}을 공격했습니다.[{1}회]", monsterName,i);
 
                        //몬스터의 체력은 119입니다.(119/123형식으로 표시)
 
                        monsterHp = monsterHp - heroAttackDamage;
 
                        System.Threading.Thread.Sleep(1000);
 
 
 
                        Console.ForegroundColor = ConsoleColor.Red;
 
                        Console.WriteLine("{0}이(가) {1}의 피해를 받았습니다!!", monsterName, heroAttackDamage);
 
                        Console.ForegroundColor = ConsoleColor.White;
 
 
 
                        if (monsterHp <= 0)
 
                        {
 
                            Console.WriteLine("몬스터의 체력은 0/{0}입니다.\n",monsterMaxHp);
 
                            Console.WriteLine("몬스터가 죽었습니다.");
 
                            break;
 
                        }
 
                        else
 
                        {
 
                            Console.WriteLine("몬스터의 체력은 ({0}/{1})입니다.\n",monsterHp,monsterMaxHp);
 
                            System.Threading.Thread.Sleep(1000);
 
                        }
 
                    }
 
 
 
                }
 
                else
 
                {
 
                    Console.WriteLine("잘못된 입력 입니다.");
 
                }
 
                if (monsterHp <= 0)
 
                {
 
                    Console.ReadKey();
 
                    break;
 
                }
 
            }
 
        }
 
    }
 
}
 
 
cs


: