-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
59 lines (51 loc) · 1.46 KB
/
Copy pathPlayer.cs
File metadata and controls
59 lines (51 loc) · 1.46 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
using System;
using System.Collections.Generic;
using System.Linq;
public class Player : Creature
{
public List<Item> Inventory { get; private set; } = new List<Item>();
public bool HasWon { get; set; }
public Player(string name) : base(name, 100) { }
public override void Attack(Creature target)
{
int damage = 15;
Console.WriteLine($"{Name} swings at {target.Name} and hits for {damage} damage.");
target.TakeHit(damage);
}
public void UseItem()
{
if (!Inventory.Any())
{
Console.WriteLine("You have no items to use.");
return;
}
Console.WriteLine("What would you like to use?");
for (int i = 0; i < Inventory.Count; i++)
{
Console.WriteLine($"{i + 1}. {Inventory[i].Name}");
}
Console.Write(">> ");
if (int.TryParse(Console.ReadLine(), out int choice) && choice >= 1 && choice <= Inventory.Count)
{
Inventory[choice - 1].OnPickUp(this);
Inventory.RemoveAt(choice - 1);
}
else
{
Console.WriteLine("Invalid choice.");
}
}
public void ShowInventory()
{
if (!Inventory.Any())
{
Console.WriteLine("Your bag is empty.");
return;
}
Console.WriteLine("In your bag:");
foreach (var item in Inventory)
{
Console.WriteLine($"- {item.Name}");
}
}
}