C#
Public
Guest class managing prizes in a game
Defines a Guest class that tracks a guest's name and the prizes (gifts) they have won, allowing addition of prizes and calculating the total value of prizes for a specific target.
C#
using System;
using System.Collections.Generic;
namespace HF10
{
internal class Guest
{
private string name;
private List<Gift> prizes;
public string Name
{
get { return name; }
}
public Guest(string n)
{
name = n;
prizes = new List<Gift>();
}
public void Wins(Gift a)
{
if (prizes.Contains(a))
{
throw new Exception();
}
if (a.Target == null || !a.Target.Gifts.Contains(a))
{
throw new Exception();
}
a.Target.Gifts.Remove(a);
prizes.Add(a);
}
public int Result(TargetShot c)
{
int sum = 0;
foreach (Gift gift in prizes)
{
if (gift.Target == c)
{
sum += gift.Value();
}
}
return sum;
}
}
}