-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
127 lines (106 loc) · 3.5 KB
/
Program.cs
File metadata and controls
127 lines (106 loc) · 3.5 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
namespace Interfaces
{
internal class Program
{
static void Main(string[] args)
{
Player player = new Player("R2D2", 100);
List<IInteractable> interactObjects = new List<IInteractable>
{
new FuelTank(),
new SupplyCrate(),
new EnemyDrone()
};
GameLoop(player, interactObjects);
}
static void GameLoop(Player player, List<IInteractable> interactObjects)
{
foreach (var interactable in interactObjects)
{
interactable.Interact(player);
Console.WriteLine();
}
player.ShowStats();
}
}
public interface IInteractable
{
void Interact(Player player);
}
public class Player
{
private string _name;
private int _health;
private int _xp;
private int _damage = 12;
public Player(string name, int health)
{
_name = name;
_health = Math.Max(health, 1);
_xp = 0;
}
public string Name { get { return _name; } }
public int Health { get { return _health; } }
public int XP { get { return _xp; } }
public int Damage { get { return _damage; } }
public void TakeDamage(int damage)
{
_health = Math.Min(_health - damage, _health);
_health = Math.Max(_health, 0);
Console.WriteLine($"Игрок {_name} получил урон: {damage}. Здоровье: {_health}.");
}
public void AddXP(int amount)
{
if (amount <= 0) return;
_xp += amount;
Console.WriteLine($"Игрок {_name} получил {amount} опыта!");
}
public void ShowStats()
{
Console.WriteLine($"Игрок: {_name}. Здоровье: {_health}. Опыт: {_xp}.");
}
}
public class FuelTank : IInteractable
{
private int _damage = 20;
public void Interact(Player player)
{
Console.WriteLine("Бздыщ! Цистерна взорвалась!");
player.TakeDamage(_damage);
}
}
public class SupplyCrate : IInteractable
{
private int _xpReward = 50;
public void Interact(Player player)
{
Console.WriteLine($"*Вы нашли припасы! +{_xpReward} XP*");
player.AddXP(_xpReward);
}
}
public class EnemyDrone : IInteractable
{
private int _health = 30;
private int _damage = 10;
public void Interact(Player player)
{
Console.WriteLine($"Игрок {player.Name} атакует дрон!");
TakeDamage(player.Damage);
if (_health <= 0)
Console.WriteLine("Дрон уничтожен");
else
{
Console.WriteLine("Дрон контратакует!");
player.TakeDamage(_damage);
}
}
public void TakeDamage(int damage)
{
_health = Math.Min(_health - damage, _health);
_health = Math.Max(_health, 0);
Console.WriteLine($"Дрон получил урон: {damage}. Здоровье: {_health}.");
}
}
}