본문 바로가기

C# 언어/C# 기초 문법12

[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#] 함수 ✳ 함수 → 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.
[C#] 조건문 ✳ 분기문(조건문) ◾ if, else if, else → 자주 사용 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void Main(string[] args) { // 분기문(조건문) // 죽었을 때 알림 int hp = 10; bool isDead = (hp 2024. 3. 19.
[C#] 산술 연산 / 비교 연산자 / 논리 연산자 ✳ 산술 연산 +, -, *, /, % hp 수치가 커질수도 줄수도 1) 할당 : int hp 2) write : hp = 100; 3) read : hp using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void Main(string[] args) { int hp = 100; int value = 5; hp = hp - value; Console.WriteLine(hp); } } ✳ 비교 연산자 ◾ , =, ==, != using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static .. 2024. 3. 18.
[C#] 스트링 포맷 ✳ 스트링 포맷 ◾ 문자열에 있는 서식 지정 항목을 지정된 개체의 문자열 표현으로 바꿉니다. ◾ Format 을 많이 사용했지만, 지금은 앞에 $(달러)를 붙입니다. 1. Format 사용 using System.Security.Cryptography.X509Certificates; namespace CShop { class Program { static void Main(string[] args) { // int -> string int hp = 100; int maxHp = 100; // string message = "당신의 HP는 ?? 입니다."; string message = string.Format("당신의 Hp는 {0} / {1}입니다.", hp, maxHp); Console.WriteLin.. 2024. 3. 18.