mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
37 lines
932 B
C#
37 lines
932 B
C#
namespace Basketball;
|
|
|
|
public class Shot
|
|
{
|
|
private readonly string _name;
|
|
|
|
public Shot(string name)
|
|
{
|
|
_name = name;
|
|
}
|
|
|
|
public static bool TryGet(int shotNumber, out Shot? shot)
|
|
{
|
|
shot = shotNumber switch
|
|
{
|
|
// Although the game instructions reference two different jump shots,
|
|
// the original game code treats them both the same and just prints "Jump shot"
|
|
<= 2 => new JumpShot(),
|
|
3 => new Shot("Lay up"),
|
|
4 => new Shot("Set shot"),
|
|
_ => null
|
|
};
|
|
return shot is not null;
|
|
}
|
|
|
|
public static Shot Get(float shotNumber) =>
|
|
shotNumber switch
|
|
{
|
|
<= 2 => new JumpShot(),
|
|
> 3 => new Shot("Set shot"),
|
|
> 2 => new Shot("Lay up"),
|
|
_ => throw new Exception("Unexpected value")
|
|
};
|
|
|
|
public override string ToString() => _name;
|
|
}
|