> 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;
}
}
}
'c# 강의 > 과제' 카테고리의 다른 글
20200415 - 아이템 생성, 검색, 꺼내기, 출력 과제 (0) | 2020.04.16 |
---|---|
20200414 - 테란~아카데미까지 (0) | 2020.04.14 |
20200413 - 팩토리 시즈모드 (0) | 2020.04.13 |
20200410 - 주말 과제 (0) | 2020.04.12 |
20200409 - Enum 활용(강화 기능) (0) | 2020.04.10 |