본문 바로가기
KDT/C# 프로그래밍

23/07/21 스타크래프트(플레이어,몬스터,무기)

by 잰쟁 2023. 7. 21.
728x90

(과제 내용)

무기(AXE)가 생성되었습니다.
플레이어(홍길동)가 생성되었습니다.
몬스터(고블린)가 생성되었습니다.
홍길동이 AXE를 착용했습니다.
홍길동이 고블린를 공격했습니다.
몬스터가 피해를 입었습니다. (-3)
체력: 7/10

 

using System;
using System.Diagnostics.Eventing.Reader;
using System.Diagnostics.Tracing;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters;
using System.Security.Permissions;

namespace LearnDotnet
{
    internal class Program
    {

        static void Main(string[] args)
        {
           new App(); //new: 클래스의 instance를 생성하고 생성자를 호출
        }         
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearnDotnet
{
    internal class App
    {
      
        //생성자 메서드
        public App()
        {
            Weapon weapon = new Weapon(Weapon.eWeaponType.AXE);
            Player player = new Player("홍길동");
            Monster monster = new Monster("고블린");
            player.Equip(weapon);  
            player.Attack(monster);

        }

       
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearnDotnet
{
    internal class Player
    {
        public string playerName;
        private Weapon weapon;
        private int damage = 3;

        //생성자 메서드
        public Player(string playerName)
        {
            this.playerName = playerName;
            Console.WriteLine("플레이어({0})가 생성되었습니다.",playerName);

        }

        public void Attack(Monster target)
        {
            Console.WriteLine("{0}이 {1}를 공격했습니다.", this.playerName, target.monsterName);

            target.HitDamage(this.damage);
        }

        public void Equip(Weapon weapon)
        {
            this.weapon = weapon;
            Console.WriteLine("{0}이 {1}를 착용했습니다.",this.playerName, weapon.weaponType);
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;

namespace LearnDotnet
{
    internal class Weapon
    {
        public enum eWeaponType 
        { 
           AXE,
           KNIFE
        }

        int damage = 10;
        int price = 100;

        public eWeaponType weaponType;
        //생성자 메서드
        public Weapon(eWeaponType weaponType)
        {
            this.weaponType = weaponType;
            Console.WriteLine("무기({0})가 생성되었습니다.", this.weaponType);
        }

    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearnDotnet
{
    internal class Monster
    {
        public string monsterName;
        private int hp;
        private int maxHp = 10;

        //생성자 메서드
        public Monster(string monsterName)
        {
            this.hp = this.maxHp;
            this.monsterName = monsterName; 
            Console.WriteLine("몬스터({0})가 생성되었습니다.",this.monsterName);
        }

        public void HitDamage(int damage)
        {
            this.hp -= damage;
            Console.WriteLine("몬스터가 피해를 입었습니다. (-{0})", damage);

            Console.WriteLine("체력: {0}/{1}", this.hp, this.maxHp);
        }
    }

'KDT > C# 프로그래밍' 카테고리의 다른 글

23/07/24 배열  (0) 2023.07.24
23/07/24 메딕 마린 힐  (0) 2023.07.24
23/07/21 스타크래프트(플레이어, 몬스터, 무기 - 실패본)  (0) 2023.07.21
23/07/21 스타크래프트2  (0) 2023.07.21
23/07/21 스타크래프트 1  (0) 2023.07.21