CodShot
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;
        }
    }
}

Snippet actions

CodShot user
CodShot user
Updated: 2026-05-06 15:25
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support