generated from admin/template
lab-06
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System.Globalization;
|
||||
|
||||
var pokemon = new Pokemon();
|
||||
|
||||
pokemon.ShowInfo();
|
||||
// Console.WriteLine($@"{pokemon.PokemonLevel}
|
||||
// {pokemon.PokemonHp}
|
||||
// {pokemon.PokemonName}");
|
||||
|
||||
class Pokemon
|
||||
{
|
||||
// FIELDS
|
||||
private string pokemonName;
|
||||
private byte pokemonLevel;
|
||||
private short pokemonHp;
|
||||
|
||||
private const byte
|
||||
MAX_NAME_LENGTH = 25,
|
||||
MIN_LEVEL = 1,
|
||||
MAX_LEVEL = 100;
|
||||
private const short
|
||||
MIN_HP = 0,
|
||||
MAX_HP = 2500;
|
||||
private const string DEFAULT_NAME = "Unknown";
|
||||
|
||||
// PROPS
|
||||
public string PokemonName
|
||||
{
|
||||
get => pokemonName;
|
||||
set
|
||||
{
|
||||
if(value != String.Empty)
|
||||
{
|
||||
if(value.Length > MAX_NAME_LENGTH)
|
||||
{
|
||||
pokemonName = value; // Cut method
|
||||
return;
|
||||
}
|
||||
|
||||
pokemonName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte PokemonLevel
|
||||
{
|
||||
get => pokemonLevel;
|
||||
set
|
||||
{
|
||||
if (value < MIN_LEVEL) pokemonLevel = 1;
|
||||
else if (value > MAX_LEVEL) pokemonLevel = 100;
|
||||
else pokemonLevel = value;
|
||||
}
|
||||
}
|
||||
|
||||
public short PokemonHp
|
||||
{
|
||||
get => pokemonHp;
|
||||
set
|
||||
{
|
||||
if (value < MIN_HP) pokemonHp = 0;
|
||||
else if (value > MAX_HP) pokemonHp = 2500;
|
||||
else pokemonHp = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTORS
|
||||
public Pokemon(string pokemonName = DEFAULT_NAME)
|
||||
{
|
||||
this.pokemonName = pokemonName;
|
||||
}
|
||||
|
||||
public Pokemon(string pokemonName, short pokemonHp = 100) : this(pokemonName)
|
||||
{
|
||||
this.pokemonHp = pokemonHp;
|
||||
}
|
||||
|
||||
public Pokemon(string pokemonName, short pokemonHp = 100, byte pokemonLevel = MIN_LEVEL) : this(pokemonName, pokemonHp)
|
||||
{
|
||||
this.pokemonLevel = pokemonLevel;
|
||||
}
|
||||
|
||||
|
||||
// METHODS
|
||||
public override string ToString() => $"Name: {pokemonName} Level: {pokemonLevel} HP: {pokemonHp}";
|
||||
public void ShowInfo() => Console.WriteLine($"=== Information ===\n{ToString()}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user