C#

스타크래프트 시즈탱크 만들기

s0002 2023. 1. 5. 13:00
using System;

namespace Study04
{
    class Program
    {
        static void Main(string[] args)
        {
            new App();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study04
{
    class App
    {
        public App()
        {
            SiegeTank tank = new SiegeTank(150,30,1);
            tank.Move();

            tank.ChangeMode();
            Console.WriteLine("공격력:{0}",tank.damage);
            tank.Move();

            tank.ChangeMode();
            Console.WriteLine("공격력:{0}",tank.damage);
            tank.Move();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Study04
{
    
    class SiegeTank
    {
        public enum ModeType
        {
             TANK, //탱크
             SIEGE //공성
        }
        //멤버 변수
        public ModeType modeType;
        public int damage; 
        int hp;
        int armor;

        //생성자
        public SiegeTank(int hp, int damage, int armor)
        {
            this.modeType = ModeType.TANK;
            this.damage = damage;
            this.hp = hp;
            this.armor = armor;
            Console.WriteLine("탱크가 생성되었습니다");
            Console.WriteLine("체력:{0}, 공격력:{1}, 방어력:{2}",this.hp,this.damage,this.armor);
        }

        //멤버 메서드
        public void ChangeMode()
        {
            if (this.modeType == ModeType.TANK)
            {
                Console.WriteLine("{0}모드에서 {1}모드로 전환합니다", this.modeType, ModeType.SIEGE);
                this.modeType = ModeType.SIEGE;
                this.damage = 70;
            }
            else
            {
                Console.WriteLine("{0}모드에서 {1}모드로 전환합니다", this.modeType, ModeType.TANK);
                this.modeType = ModeType.TANK;
                this.damage = 30;
            }
        }
        public void Move()
        {
            if (this.modeType == ModeType.TANK)
            {
                Console.WriteLine("이동했습니다");
            }
            else
            {
                Console.WriteLine("이동할 수 없습니다");
            }
        }
    }
}

'C#' 카테고리의 다른 글

스타듀밸리 캐릭터 클래스  (0) 2023.01.05
레이스  (0) 2023.01.05
스타크래프트 마린, 메딕 만들기  (0) 2023.01.05
클래스 연습5  (0) 2023.01.04
클래스 연습4  (0) 2023.01.04