본문 바로가기

C# 언어15

[C#] 객체지향 직업선택 1. 파일 분리 , Player 작업 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _240330 { // 똑같이 열거형 enum PlayerType { None = 0, Warrial = 1, Archer = 2, Magition = 3, } internal class Player { protected PlayerType type; protected int hp = 0; protected int attack = 0; protected Player(PlayerType type) // 아무것도 인자가 없으면 사용 불가 { this.. 2024. 3. 30.
[C#] 객체지향 using System.Numerics; using System.Security.Cryptography.X509Certificates; namespace CShop { class Player // 상속해주는 부모 / 기반 { // static 오로지 1개만 존재 static public int counter = 1; // public : 공공 없으면 안에서만 사용 가능 public int id; public int hp; public int attack; public Player() { Console.WriteLine("플레이어 호출"); } } class Archer : Player { } class Knight : Player // 자식 혹은 파생 클래스 { Knight() { Console.Writ.. 2024. 3. 22.
직업 선택 1) 직업 선택 및 열거형 using System.Numerics; using System.Security.Cryptography.X509Certificates; namespace CShop { enum ClassType { None = 0, Warrial = 1, Archer = 2, Magition = 3, } class Program { static void Main(string[] args) { ClassType choice = ClassType.None; while (true) { Console.WriteLine("******************"); Console.WriteLine("직업을 골라주세요 !"); Console.WriteLine("[1] 전사"); Console.WriteLine.. 2024. 3. 19.
[C#] 팩토리얼 / 재귀함수 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { // 팩토리얼 5! = 5 + 4 + 3 + 2 + 1 static int Factorial(int n) { int ret = 1; for (int num = 1; num 2024. 3. 19.
[C#] 피라미드 ✳ 피라미드 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void Main(string[] args) { // 피라미드 별모양 for (int i = 0; i < 6; i++) { for (int q = 0; q 2024. 3. 19.
[C#] 구구단 ✳ 구구단 2 ~ 9단 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void Main(string[] args) { // 구구단 for (int i = 2; i < 10; i++) { for (int q = 1; q < 10; q++) { Console.WriteLine($"{i} * {q} = {i * q}"); } } } } } 2024. 3. 19.
[C#] 함수 ✳ 함수 → 50만줄 수준 (상용 게임) → Method Function : 메소드 = 함수 → C++ = Function 대부분 함수라고해서 통용함 → 사용법 : 한정자 반환형식 이름(매개변수목록) → void(빈값)을 사용하면 return(반환)값이 없어도 가능 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void HelloWorld() // void 이므로 return(반환) 할 필요없음 { Console.WriteLine("함수 작동"); } static void Main(string[] args) { HelloWorld(); } } } using System.Security.. 2024. 3. 19.
[C#] 열거형 ✳ enum 열거형 : 우리만의 타입을 만들겠다. → 기본적으로 열거형 멤버의 연결된 상수 값은 int 형식입니다. → 즉, 0으로 시작하고 정의 텍스트 순서에 따라 1씩 증가합니다. → 다른 정수 숫자 형식을 열거형 형식의 기본 형식으로 명시적으로 지정할 수 있습니다. // enum 열거형 : 우리만의 타입을 만듬 enum Choice { None = 0, Rcok = 1, Paper = 2, Scissors = 0 } 2024. 3. 19.
[C#] 반복문 / break / continue ✳ 반복문은 for / while , do while이 있다. 1) while → ~ 동안 → 무조건 == 무한루프 → while(1 or ture) // 조건식이 true 인 동안 무한반복 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void Main(string[] args) { // while, do while 반복문 int count = 5; while (count > 0) // 0보다 크면 실행 { Console.WriteLine("반복문 while"); count--; // count 5 부터 1씩 작아지기 } } } } using System.Security.Crypto.. 2024. 3. 19.