> App.cs

더보기
                PlayerPlane playerPlane = new PlayerPlane("비행기", 0, -6);

                Monster monster = new Monster("악당",0, 9, 1);

                Bullet bullet = playerPlane.Shoot(1, monster);

                Console.WriteLine("총알소멸");
                //총알 객체 삭제
                bullet = null;

 

> PlayerPlane.cs

더보기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20200413
{
    class PlayerPlane
    {
        public string name;
        public int damage;
        public int x;
        public int y;
        public Bullet bullet;

        public PlayerPlane() { }

        public PlayerPlane(string name, int x, int y) {
            this.name = name;
            this.x = x;
            this.y = y;
            Console.WriteLine($"{this.name}이 생성되었습니다.({this.x}/{this.y})");
        }
        
        public Bullet Shoot( int damage, Monster monster) {
            bullet = new Bullet(this.x, this.y, damage);
            bullet.Move(monster);
            return bullet; 
        }
    }
}

 

> Bullet.cs

더보기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20200413
{
    class Bullet
    {
        public string name;
        public int damage;
        public int x;
        public int y; 

        public Bullet() { }

        public Bullet(int x, int y, int damage) {
            this.damage = damage;
            this.x = x;
            this.y = y;
            Console.WriteLine($"총알이 생성되었습니다.[damage: {this.damage} ({this.x}/{this.y})]");
        }

        public string Move(Monster monster)
        {
            string check = "";
            
            for (int i = this.y; i <= 10; i++)
            {
                Console.WriteLine($"총알위치: ({this.x}/{i})");
                if (this.x == monster.x && i == monster.y)
                {
                    Console.WriteLine($"몬스터 격추 ({this.x}/{i})");
                    check = "격추";
                    break;
                }
                check = "통과";
            }
            return check;
        }
    }
}

+ Recent posts