using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using HumanLikeBattleRobots.Logic;
using HumanLikeBattleRobots.Data;

namespace HumanLikeBattleRobots.Control
{
    static class Keyboard
    {
        static Dictionary<Keys, bool> keysDown = new Dictionary<Keys, bool>();
        public delegate void OnKeyHandler();
        public static OnKeyHandler OnKey;

        public static void Initialize()
        {
            keysDown.Clear();
            // добавляем в словарь коды клавиш клавиатуры
            foreach (Keys key in Enum.GetValues(typeof(Keys)))
                if (!keysDown.ContainsKey(key))
                    keysDown.Add(key, false);
        }

        public static void SetKeyDown(Keys key)
        {
            if (key == Keys.R && !GameManager.NeedToRestart)
                GameManager.NeedToRestart = true;

            if (key == Keys.M)
            {
                GameManager.Mute = !GameManager.Mute;
                if (GameManager.Mute)
                    Bass.Bass.BASS_Stop();
                else
                {
                    Bass.Bass.BASS_Start();
                    Bass.Bass.BASS_StreamPlay(SoundResources.Music, false, (UInt16)4);
                }
            }

            keysDown[key] = true;
            if (OnKey != null)
                OnKey();
        }

        public static void SetKeyUp(Keys key)
        {
            keysDown[key] = false;
            if (OnKey != null)
                OnKey();
        }

        public static bool KeyIsDown(Keys key)
        {
            return keysDown[key];
        }
    }
}
