0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NCCAdvent Calendar 2021

Day 7

お料理.cs

Posted at
main.cs
using System;
using System.Collections.Generic;


class Program
{
	static Osaihu osaihu = new(100);
	static Dictionary<string, Guzai> supermarket = loadSuper();
	static Dictionary<string, List<string>> recipe = loadRecipes();
	static Nabe Main(string[] args)
	{
		Console.WriteLine("お料理開始!");
		if (args.Length == 0) return null;
		if (recipe.TryGetValue(args[0], out var list))
		{
			var bag = shopping(list, osaihu);
			Nabe nabe = new();
			nabe.AddAll(bag);
			nabe.Nikomu(100);
			return nabe;
		}
		return null;
	}
	static List<Guzai> shopping(List<string> list, Osaihu osaihu)
	{
		List<Guzai> cart = new();
		foreach (var item in list)
		{
			if (supermarket.TryGetValue(item, out var guzai))
			{
				cart.Add(guzai);
			}
			else
			{
				cart.Add(null);
			}
		}
		List<Guzai> bag = new();
		int sum = 0;
		foreach (var item in cart)
		{
			sum += item.price;
			bag.Add(item);
		}
		osaihu.Withdraw(sum);
		return bag;
	}
}
osaihu.cs
class Osaihu
{
	int money;
	public Osaihu(int m)
	{
		money = m;
	}
	public void Add(int m)
	{
		money += m;
	}
	public void Withdraw(int m)
	{
		money -= m;
	}
}
guzai.cs
enum GuzaiState
{
	packed,
	unpacked,
	cutted,
}
class Guzai
{
	public string name { get; }
	public int price { get; }
	public double tempreture { get; set; }
	const double DEFAULT_TEMPRETURE = 10;
	GuzaiState state = GuzaiState.packed;
	public Guzai(string name, int price, double tempreture = DEFAULT_TEMPRETURE)
	{
		this.name = name;
		this.price = price;
		this.tempreture = tempreture;
	}
}

nabe.cs
class Nabe
{
	List<Guzai> contents = new();
	public void Add(Guzai guzai)
	{
		contents.Add(guzai);
	}
	public void AddAll(List<Guzai> guzais)
	{
		contents = guzais;
	}
	public void Nikomu(double min)
	{
		foreach (var item in contents)
		{
			item.tempreture += min * 1.5;
		}
	}
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?