-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cs
More file actions
64 lines (54 loc) · 2.34 KB
/
Enemy.cs
File metadata and controls
64 lines (54 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Drawing;
using System.Windows.Forms;
namespace Spacewar
{
// Düşmanları temsil eden soyut sınıf (abstract class)
public abstract class Enemy
{
// Düşmanın görsel temsilcisi olan PictureBox
public PictureBox PictureBox { get; protected set; }
// Düşmanın sağlık değeri
public int Health { get; set; }
// Düşmanın yenildiğinde verdiği puan
public int Points { get; protected set; }
// Düşmanın hareket hızı
public int MoveSpeed { get; set; }
// Constructor: Yeni bir düşman oluşturur
protected Enemy(int x, int y, int width, int height, int health, int points, Control parent)
{
// Düşmanın görsel özelliklerini tanımlayan PictureBox
PictureBox = new PictureBox
{
Size = new Size(width, height), // Düşmanın boyutu
Location = new Point(x, y), // Düşmanın başlangıç konumu
BackColor = Color.Transparent, // Arka plan şeffaf
Image = Spacewar.Properties.Resources.ufo, // Varsayılan düşman görüntüsü
SizeMode = PictureBoxSizeMode.StretchImage, // Görüntü boyutlandırması
Parent = parent // Parent olarak sahne (genelde galaxy resmi) atanır
};
// Düşmanın özelliklerini ayarla
this.Health = health; // Sağlık puanı
this.Points = points; // Yenildiğinde verilen puan
this.MoveSpeed = 1; // Varsayılan hareket hızı
PictureBox.BringToFront(); // Düşmanı ön plana getir
}
// Düşmanın hareket mantığını tanımlayan soyut metot
public abstract void Move();
// Düşman hasar aldığında çağrılır
public void TakeDamage(int damage)
{
Health -= damage; // Sağlık değerini azalt
}
// Düşmanın yok olma durumunu kontrol eder
public bool IsDestroyed => Health <= 0;
// Düşmanı sahneden ve bellekten kaldırır
public void Destroy()
{
if (PictureBox?.Parent != null)
{
PictureBox.Parent.Controls.Remove(PictureBox); // Parent kontrolünden çıkar
}
PictureBox?.Dispose(); // Kaynağı serbest bırak
}
}
}