Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            //var sequence = ArchimedesSpiral.GenerateSpiral(0.5, 512);

            //foreach (var point in sequence)
            //    Console.WriteLine(point);

            var engine = new KeyboardReader();

            engine.OnKeyPress += (_, keyArgs) => Console.WriteLine($"Key: {keyArgs.Key}, Alt: {keyArgs.IsAlt}, Ctrl: {keyArgs.IsCtrl}");

            int count = 0;
            var done  = false;

            do
            {
                try
                {
                    engine.ReadKeys('e');
                    done = true;
                }
                catch (InvalidOperationException e) when(count < 5)
                {
                    Console.WriteLine("You went backwards in the alphabet");
                    count++;
                }
            } while (!done);

            Console.WriteLine($"The last key was: {engine.PreviousKey}");
            Console.WriteLine("writing keys");
            foreach (var c in engine.AllKeys)
            {
                Console.WriteLine(c);
            }
        }
Exemplo n.º 2
0
    }      // End constructor

    /* PUBLIC METHODS */

    // This loads a JSON file (.stack) from the hard drive that contains only one CloudCoin and turns it into an object.
    //   This uses Newton soft but causes a enrror System.IO.FileNotFoundException. Could not load file 'Newtonsoft.Json'
    public FoundersCloudCoin loadOneCloudCoinFromJsonFile(String loadFilePath)
    {
        FoundersCloudCoin returnCC = new FoundersCloudCoin();

        //Load file as JSON
        String incomeJson = this.importJSON(loadFilePath);
        //STRIP UNESSARY test
        int secondCurlyBracket     = ordinalIndexOf(incomeJson, "{", 2) - 1;
        int firstCloseCurlyBracket = ordinalIndexOf(incomeJson, "}", 0) - secondCurlyBracket;

        // incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket);
        incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket + 1);
        // Console.Out.WriteLine(incomeJson);
        //Deserial JSON

        try
        {
            returnCC = JsonConvert.DeserializeObject <FoundersCloudCoin>(incomeJson);
        }
        catch (JsonReaderException)
        {
            Console.WriteLine("There was an error reading files in your bank.");
            CoreLogger.Log("There was an error reading files in your bank.");
            Console.WriteLine("You may have the aoid memo bug that uses too many double quote marks.");
            Console.WriteLine("Your bank files are stored using and older version that did not use properly formed JSON.");
            Console.WriteLine("Would you like to upgrade these files to the newer standard?");
            Console.WriteLine("Your files will be edited.");
            Console.WriteLine("1 for yes, 2 for no.");
            KeyboardReader reader = new KeyboardReader();
            int            answer = reader.readInt(1, 2);
            if (answer == 1)
            {
                //Get rid of ed and aoid
                //Get file names in bank folder
                String[] fileNames = new DirectoryInfo(bankFolder).GetFiles().Select(o => o.Name).ToArray();
                for (int i = 0; i < fileNames.Length; i++)
                {
                    Console.WriteLine("Fixing " + bankFolder + "\\" + fileNames[i]);
                    CoreLogger.Log("Fixing " + bankFolder + "\\" + fileNames[i]);
                    string text = File.ReadAllText(bankFolder + "\\" + fileNames[i]);
                    text = text.Replace("\"aoid\": [\"memo\"=\"\"]", "");
                    File.WriteAllText(bankFolder + "\\" + fileNames[i], text);
                }    //End for all files in bank
                CoreLogger.Log("Done Fixing. The program will now exit. Please restart. Press any key.");
                Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key.");
                Console.Read();
                Environment.Exit(0);
            }
            else
            {
                CoreLogger.Log("Leaving files as is. You maybe able to fix the manually by editing the files.");
                Console.WriteLine("Leaving files as is. You maybe able to fix the manually by editing the files.");
                Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key.");
                Console.Read();
                Environment.Exit(0);
            }
        }

        return(returnCC);
    }    //end load one CloudCoin from JSON
Exemplo n.º 3
0
        private void UpdateCamera()
        {
            foreach (Keys key in KeyboardReader.GetPressedKeys())
            {
                switch (key)
                {
                case Keys.Down:
                    Camera.Move(new Vector2(0, 5));
                    break;

                case Keys.Left:
                    Camera.Move(new Vector2(-5, 0));
                    break;

                case Keys.Right:
                    Camera.Move(new Vector2(5, 0));
                    break;

                case Keys.Up:
                    Camera.Move(new Vector2(0, -5));
                    break;

                default:
                    break;
                }
            }
        }
 private void Start()
 {
     errorWindow = GameObject.Find("Popup Windows").
                   GetComponentInChildren <ErrorWindow>(true).gameObject;
     errorText         = errorWindow.GetComponentInChildren <TextMeshProUGUI>();
     uiButtons         = GameObject.Find("Main UI Buttons");
     theKeyboardReader = FindObjectOfType <KeyboardReader>();
     theGamepadReader  = FindObjectOfType <GamepadReader>();
 }
 private void Start()
 {
     theInputIndexController  = FindObjectOfType <InputIndexController>();
     theErrorController       = FindObjectOfType <ErrorController>();
     theInputReaderController =
         FindObjectOfType <InputReaderController>();
     theGamepadReader  = FindObjectOfType <GamepadReader>();
     theKeyboardReader = FindObjectOfType <KeyboardReader>();
     buttonColors      = GetComponentInParent <Button>().colors;
 }
Exemplo n.º 6
0
 private void UpdateDndLayer()
 {
     if (KeyboardReader.GetClickedKeys().Contains(Keys.L))
     {
         DndItem.LayerDepth = Enum.GetValues(typeof(LayerDepth))
                              .Cast <LayerDepth>()
                              .Where(l => l != LayerDepth.None)
                              .ElementAt((int)DndItem.LayerDepth % 3);
     }
 }
Exemplo n.º 7
0
        public void Update(GameObject gameObject, GameTime gameTime)
        {
            Keys[] keys = KeyboardReader.GetClickedKeys();

            if (keys.Contains(Keys.W))
            {
                foreach (GameObject collisionObject in _collisionObjects)
                {
                    if (collisionObject.Bounds.Contains(gameObject.Bounds))
                    {
                        _gameplayManager.NextLevel();
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (IsActive)
            {
                KeyboardReader.Update();
                MouseReader.Update();
            }

            base.Update(gameTime);
        }
Exemplo n.º 9
0
        private void FindSnapPosition(Vector2 mousePosition)
        {
            _snapPosition = null;

            if (!KeyboardReader.GetPressedKeys().Any(k => k == Keys.LeftControl || k == Keys.RightControl))
            {
                List <Rectangle> destinations = Items.Where(o => Camera.ObjectIsVisible(o))
                                                .Select(o => Camera.WorldToScreen(o.Bounds))
                                                .ToList();

                Rectangle source = DndItem.Bounds;
                source.X = (int)mousePosition.X;
                source.Y = (int)mousePosition.Y;

                _snapPosition = Snap.FindContainerBounds(_snapPosition, source, Bounds);
                _snapPosition = Snap.FindCornerPosition(_snapPosition, source, destinations.ToArray());
            }
        }
Exemplo n.º 10
0
        public void Update(GameObject gameObject, GameTime gameTime)
        {
            Keys[] keys = KeyboardReader.GetClickedKeys();

            if (keys.Contains(Keys.W))
            {
                foreach (GameObject teleporterObject in _teleporterObjects)
                {
                    if (teleporterObject.Bounds.Contains(gameObject.Bounds))
                    {
                        GameObject[] teleporters = _teleporterObjects.Where(t => t != teleporterObject).ToArray();

                        if (teleporters.Length > 0)
                        {
                            GameObject teleporter = teleporters[Game1.Random.Next(0, teleporters.Length)];
                            gameObject.Position = teleporter.Position + (gameObject.Position - teleporterObject.Position);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
 public override IEnumerable<Barebones.Dependencies.IDependency> GetDependencies()
 {
     yield return new Dependency<KeyboardReader>( item => m_Keyboard = item );
     yield return new Dependency<PhysicsComponent>(item => m_Physics = item);
 }
Exemplo n.º 12
0
 public override IEnumerable<Barebones.Dependencies.IDependency> GetDependencies()
 {
     yield return new Dependency<ConstraintComponent<CharacterController>>(item => m_Controller = item);
     yield return new Dependency<KeyboardReader>(item => m_Reader = item);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WindowsInputManager"/> class.
 /// </summary>
 public WindowsInputManager()
 {
     this.keyboardReader = new KeyboardReader();
 }
Exemplo n.º 14
0
 public override IEnumerable<Barebones.Dependencies.IDependency> GetDependencies()
 {
     yield return new Dependency<KeyboardReader>(item => m_Reader = item);
 }