Skip to content

Instantly share code, notes, and snippets.

View verborghs's full-sized avatar

Steven Verborgh verborghs

View GitHub Profile
public interface IVendingMachineView
{
event EventHandler CoinInserted;
event EventHandler Cancel;
event EventHandler Select;
event EventHandler<NumberEnteredArgs> NumberEntered;
void ShowMessage(string message);
void AddProduct(string code, Product p);
}
public class VendingMachine
{
private Dictionary<string, Product> _products = new Dictionary<string, Product>()
{
{ "01", new Product("Product 01", 3, 5)},
{ "02", new Product("Product 02", 2, 1)},
{ "03", new Product("Product 03", 1, 0)},
{ "11", new Product("Product 04", 4, 0)},
{ "12", new Product("Product 05", 1, 5)},
{ "13", new Product("Product 06", 1, 5)},
public class VendingMachine
{
private Dictionary<string, Product> _products = new Dictionary<string, Product>()
{
{ "01", new Product("Product 01", 3, 5)},
{ "02", new Product("Product 02", 2, 1)},
{ "03", new Product("Product 03", 1, 0)},
{ "11", new Product("Product 04", 4, 0)},
{ "12", new Product("Product 05", 1, 5)},
{ "13", new Product("Product 06", 1, 5)},
public class AvailabilityChangedArgs : EventArgs
{
public bool SoldOut { get; }
public AvailabilityChangedArgs(bool soldOut)
{
SoldOut = soldOut;
}
}
public class Product
{
private int _available;
public event EventHandler AvailabilityChanged;
public Product(string name, int coins, int available)
{
Name = name;
Coins = coins;
Available = available;
public class ProductView : MonoBehaviour
{
[SerializeField]
private Text _code;
[SerializeField]
private Text _name;
[SerializeField]
@verborghs
verborghs / VendingMachineBehaviour.cs
Last active October 30, 2019 08:14
Using TimedQueue
namespace VendingMachines
{
public class VendingMachineBehaviour : MonoBehaviour
{
#region Serialized Fields
[SerializeField]
private Text _message;
[SerializeField]
namespace VendingMachines
{
public class Product
{
public Product(string name, int coins, int available)
{
Name = name;
Coins = coins;
Available = available;
namespace Utils
{
public class ShowMessages : MonoBehaviour
{
[SerializeField]
private Text _message;
private TimedQueue<string> queue;
@verborghs
verborghs / ShowMessages.cs
Created October 29, 2019 14:04
TimedQueue using delegates
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Utils
{
public class ShowMessages : MonoBehaviour
{
[SerializeField]