ProjetPatate/Assets/Scripts/Consumable.cs

45 lines
1 KiB
C#
Raw Normal View History

2020-12-04 21:49:58 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2020-12-05 20:28:33 +01:00
using System; //Exceptions
2020-12-04 21:49:58 +01:00
//Represents consumable : sprite and informations
public class Consumable //: MonoBehaviour
{
private HashSet<string> allowed_types = new HashSet<string>(new [] {"beer", "pression", "vodka"});
2020-12-05 15:22:00 +01:00
private string _type; //Type from allowed_types
2020-12-04 21:49:58 +01:00
private int _value;
2020-12-05 15:22:00 +01:00
private Sprite _sprite; //Display details
2020-12-04 21:49:58 +01:00
//Read-only accessors
public string Type
{
get{ return _type;}
// set{}
}
public int Value
{
get{ return _value;}
// set{}
}
public Sprite Sprite
{
get{ return _sprite;}
// set{}
}
2020-12-05 15:22:00 +01:00
//Constructor
2020-12-04 21:49:58 +01:00
//TODO : Handle sprite = null
public Consumable(string type, int value, Sprite sprite)
{
2020-12-05 15:22:00 +01:00
//Test if type is an allowed type
2020-12-04 21:49:58 +01:00
if(!allowed_types.Contains(type))
{
throw new Exception("Invalid consumable type :"+type);
}
_type=type;
_value=value;
_sprite=sprite;
}
}