示例#1
0
        static string SelectString(string prompt)
        {
            string value = string.Empty;

            bool again = true;

            while (again)
            {
                try
                {
                    value = InputHandlers.GetString(prompt);
                    if (value != "planet" && value != "drink")
                    {
                        throw new FormatException();
                    }

                    again = false;
                }
                catch (FormatException)
                {
                    Console.WriteLine("That data does not exist. Please try again.");
                }
            }

            return(value);
        }
示例#2
0
 public void InitialStartup(ref int progress)
 {
     InputHistory.Initialize();
     progress++;
     InputHandlers.Initialize();
     progress++;
 }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Pig Latin translator!");

            bool again = true;

            while (again)
            {
                string input = InputHandlers.GetString("Enter the text to be translated: ");

                Console.WriteLine(ToPigLatin(input));

                Console.WriteLine();

                again = InputHandlers.Continue("Translate another line? (y/n): ");

                Console.Clear();
            }

            Console.WriteLine();

            Console.WriteLine("Goodbye!");

            Console.ReadLine();
        }
示例#4
0
 protected List <HandlerResponse> ProcessInputHandlers()
 {
     /* var fi = new FileInfo(ProjectFilePath).Directory?.FullName;
      * var list = new List<HandlerResponse>();
      * if (string.IsNullOrWhiteSpace(fi))
      * {
      *  return null;
      * }
      * foreach (var handler in InputHandlers)
      * {
      *  try
      *  {
      *      var result = handler.Process(fi);
      *      if (result.Result == HandlerResult.NotRun)
      *      {
      *          result.Result = HandlerResult.OK;
      *      }
      *      list.Add(result);
      *      Log($"Handler {handler.Name} returned {result.Result}: {result.ResultMessage}");
      *  }
      *  catch (Exception ex)
      *  {
      *      list.Add(new HandlerResponse(handler, false, ex.Message));
      *      Log($"Handler {handler.Name} encountered {ex.GetType().Name}: {ex.Message}");
      *  }
      * }
      * return list; */
     return(InputHandlers.ProcessHandlers(new FileInfo(ProjectFilePath).Directory?.FullName, s => Log(s)));
 }
示例#5
0
        static int SelectNumber(string prompt)
        {
            int value = 0;

            bool again = true;

            while (again)
            {
                try
                {
                    value = InputHandlers.GetInteger(prompt);
                    if (value < 1 || value > 20)
                    {
                        throw new IndexOutOfRangeException();
                    }

                    again = false;
                }
                catch (FormatException)
                {
                    Console.WriteLine("Say what? Try again.");
                    Console.WriteLine();
                }
                catch (IndexOutOfRangeException)
                {
                    Console.WriteLine("That student does not exist. Please try again.");
                    Console.WriteLine();
                }
            }

            return(value - 1);            // Realign for array index.
        }
示例#6
0
 public void Begin(IInputHandler handler)
 {
     if (handler != null)
     {
         InputHandlers.Push(handler);
     }
 }
示例#7
0
 public void InitialStartup()
 {
     InputHistory.Initialize();
     InputHandlers.Initialize();
     SettingsManager.Initialize();
     MusicPlayer.Init();
     EffectPlayer.Init();
 }
示例#8
0
        protected override void OnProcessEntities(GameTime gameTime, IEnumerable <int> entityIdCollection)
        {
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);

            // REVIEW: We invoke the handlers as we're enumerating through components.
            // This will be a problem if the components are added/remove during the enumeration in response
            // to a handler.
            float ellapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            foreach (int liveId in entityIdCollection)
            {
                statesWorker.Clear();
                actionsWorker.Clear();
                InputMap inputMap = inputMapComponents.GetComponentFor(liveId);

                foreach (KeyValuePair <Keys, int> pair in inputMap.KeyToAction)
                {
                    if (!previousKeyboardState.IsKeyDown(pair.Key) && currentKeyboardState.IsKeyDown(pair.Key))
                    {
                        actionsWorker.Add(pair.Value);
                    }
                }
                foreach (KeyValuePair <Keys, int> pair in inputMap.KeyToState)
                {
                    if (currentKeyboardState.IsKeyDown(pair.Key))
                    {
                        statesWorker.Add(pair.Value);
                    }
                }

                foreach (KeyValuePair <Buttons, int> pair in inputMap.ButtonToAction)
                {
                    if (!previousGamePadState.IsButtonDown(pair.Key) && currentGamePadState.IsButtonDown(pair.Key))
                    {
                        actionsWorker.Add(pair.Value);
                    }
                }
                foreach (KeyValuePair <Buttons, int> pair in inputMap.ButtonToState)
                {
                    if (currentGamePadState.IsButtonDown(pair.Key))
                    {
                        statesWorker.Add(pair.Value);
                    }
                }

                InputHandlers inputHandlers = inputHandlersComponents.GetComponentFor(liveId);
                foreach (int callbackId in inputHandlers.InputHandlerIds)
                {
                    Callbacks.GetCallback(callbackId)(EntityManager, liveId, actionsWorker, statesWorker);
                }
            }

            previousKeyboardState = currentKeyboardState;
            previousGamePadState  = currentGamePadState;
        }
        public void InitialStartup()
        {
            if (MagicalLifeSettings.Storage.Player.Default.PlayerID == Guid.Empty)
            {
                MagicalLifeSettings.Storage.Player.Default.PlayerID = Guid.NewGuid();
            }

            InputHistory.Initialize();
            InputHandlers.Initialize();
            SettingsManager.Initialize();
            MusicPlayer.Init();
        }
示例#10
0
        static void Main(string[] args)
        {
            bool again = true;

            while (again)
            {
                int student = SelectNumber("Which alien C# student would you like to know more about? (Enter a number between 1-20.): ");
                Console.Write($"Student {student + 1} is {aliens[student]}. ");

                bool more = true;

                string prompt = $"What would you like to know about {aliens[student]}? (Enter planet or drink.): ";

                while (more)
                {
                    string know = SelectString(prompt);

                    ShowInfo(know, student);

                    more = InputHandlers.Continue("Would you like to know more? (Enter 'y' or 'n'.): ");

                    if (more)
                    {
                        if (know == "planet")
                        {
                            know = "drink";
                        }
                        else
                        {
                            know = "planet";
                        }

                        ShowInfo(know, student);

                        more = false;                           // no more info exists, end loop.
                    }
                }
                Console.WriteLine();

                again = InputHandlers.Continue("Would you like to know about another student? (Enter 'y' or 'n'.): ");

                Console.WriteLine();
            }

            Console.WriteLine();

            Console.WriteLine("Thanks and have a stellar eon!");

            Console.ReadLine();
        }
示例#11
0
        public void InitialStartup()
        {
            SettingsManager.Initialize();

            if (SettingsManager.PlayerSettings.Settings.PlayerID == Guid.Empty)
            {
                SettingsManager.PlayerSettings.Settings.PlayerID = Guid.NewGuid();
            }

            InputHistory.Initialize();
            InputHandlers.Initialize();
            MusicPlayer.Init();
            this.SaveSettings();
        }
示例#12
0
        /// <summary>
        /// Starts the engine so it is capturing input from the console
        /// </summary>
        /// <returns></returns>
        public static Guid Capture(ConsoleKeyPressHandler KeyHandler)
        {
            Guid id = Guid.NewGuid();

            var Handlers = new InputHandlers()
            {
                KeyHandler = KeyHandler
            };

            Observers.Add(id, Handlers);
            Register_Handlers(Handlers);

            Start();
            return(id);
        }
示例#13
0
        public ClickTwicePackSettings WithHandler(IHandler handler)
        {
            var input  = handler as IInputHandler;
            var output = handler as IOutputHandler;

            if (input != null)
            {
                InputHandlers.Add(input);
            }
            if (output != null)
            {
                OutputHandlers.Add(output);
            }
            return(this);
        }
示例#14
0
        //private Player.Roshambo SelectRPS()
        private string SelectRPS()
        {
            string selection = InputHandlers.GetString(
                "Rock, paper or scissors? (Enter r,p or s.): ");

            if (selection == "r")
            {
                //return Player.Roshambo.Rock;
                return("Rock");
            }
            else if (selection == "p")
            {
                //return Player.Roshambo.Paper;
                return("Paper");
            }
            else
            {
                //return Player.Roshambo.Scissors;
                return("Scissors");
            }
        }
示例#15
0
        protected override void OnProcessEntities(GameTime gameTime, IEnumerable <int> entityIdCollection)
        {
            float ellapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            foreach (int liveId in entityIdCollection)
            {
                GameState gameState = gameStateComponents.GetComponentFor(liveId);
                entityGrid.Bounds       = gameState.Bounds;
                gameState.TimeRemaining = Math.Max(0, gameState.TimeRemaining - ellapsed);;

                if (cachedBounds != gameState.Bounds)
                {
                    cachedBounds = gameState.Bounds;
                    Util.Helpers.CalculateDeathSpiralPoints(cachedBounds, deathBlockSpiralPoints);
                }

                MaybeSendDeathBlock(gameState);

                // Let's do some other tasks.
                if (!gameState.IsGameOver)
                {
                    MessageData data = new MessageData();
                    EntityManager.SendMessage(Messages.QueryWinningPlayer, ref data, null);
                    if (data.Handled)
                    {
                        gameState.WinningPlayerUniqueId = data.Int32;
                        // The game is over. This is the uniqueId of the player that won.
                        if (gameState.WinningPlayerUniqueId != EntityManager.InvalidEntityUniqueId)
                        {
                            gameState.IsGameOver = true;
                            bool          allocatedNew;
                            InputHandlers ih = (InputHandlers)EntityManager.AddComponentToEntity(EntityManager.GetEntityByLiveId(liveId), ComponentTypeIds.InputHandlers, out allocatedNew);
                            ih.InputHandlerIds.Add("RestartGame".CRC32Hash());
                        }
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// Publishes the app to the given folder
        /// </summary>
        /// <param name="targetPath">Folder to publsh the project too</param>
        /// <param name="behaviour">Preferred treatment of previous builds</param>
        /// <returns>The collection of results from the output handlers</returns>
        public List <HandlerResponse> PublishApp(string targetPath,
                                                 PublishBehaviour behaviour = PublishBehaviour.CleanFirst)
        {
            var results = InputHandlers.ProcessHandlers(
                new FilePath(ProjectFilePath).GetDirectory().MakeAbsolute(Environment).FullPath, s => Log(s));

            Log(
                $"Completed processing input handlers: {results.Count(r => r.Result == HandlerResult.OK)} OK, {results.Count(r => r.Result == HandlerResult.Error)} errors, {results.Count(r => r.Result == HandlerResult.NotRun)} not run");
            if (results.Any(r => r.Result == HandlerResult.Error))
            {
                throw new HandlerProcessingException(InputHandlers, results);
            }
            string outputPath;

            if (behaviour == PublishBehaviour.DoNotBuild)
            {
                outputPath  = Path.Combine(new FileInfo(ProjectFilePath).Directory.FullName, "bin", Configuration);
                BuildAction = null;
            }
            else
            {
                outputPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString("N"));
                if (!FileSystem.Exist((DirectoryPath)outputPath))
                {
                    FileSystem.GetDirectory(outputPath).Create();
                }
            }
            var props = new Dictionary <string, string>
            {
                { "Configuration", Configuration },
                { "Platform", Platform },
                { "OutputPath", outputPath },
                { "PublishDir", Path.Combine(outputPath, "app.publish") + "\\" }
            };

            BuildSettings = new MSBuildSettings
            {
                Configuration   = Configuration,
                MSBuildPlatform = GetMSBuildPlatform(Platform),
                Verbosity       = Verbosity.Quiet
            };
            BuildSettings.AddTargets(behaviour);
            BuildSettings.AddProperties(props, AdditionalProperties);
            BuildAction?.Invoke(this);
            var publishDir =
                new DirectoryPath(
                    new DirectoryInfo(props["OutputPath"]).GetDirectories()
                    .FirstOrDefault(d => d.Name == "app.publish")
                    .FullName);

            if (GenerateManifest)
            {
                PrepareManifestManager(publishDir, InformationSource.Both);
                ManifestManager.DeployManifest(ManifestManager.CreateAppManifest());
            }
            Log("Processing output handlers");
            var output = OutputHandlers.ProcessHandlers(publishDir.FullPath, s => Log(s));

            Log(
                $"Completed processing output handlers: {output.Count(r => r.Result == HandlerResult.OK)} OK, {output.Count(r => r.Result == HandlerResult.Error)} errors, {output.Count(r => r.Result == HandlerResult.NotRun)} not run");
            if (output.Any(o => o.Result == HandlerResult.Error) && ErrorAction != null)
            {
                Log("Error encountered while processing output handlers. Aborting!");
                ErrorAction?.Invoke(output);
                //throw new HandlerProcessingException(OutputHandlers, output); // in case something goes real wrong
            }
            if (string.IsNullOrWhiteSpace(targetPath))
            {
                return(output);
            }
            Log("Copying publish results to target directory");
            new DirectoryInfo(publishDir.MakeAbsolute(Environment).FullPath).Copy(destDirPath: targetPath,
                                                                                  copySubDirs: true);
            return(output);
        }
示例#17
0
 private static void Unregister_Handlers(InputHandlers Handlers)
 {
     onKeyPress -= Handlers.KeyHandler;
 }
示例#18
0
        public void DoWork()
        {
            int playerWins = 0;
            int vvWins     = 0;
            int ccWins     = 0;

            bool again = true;

            CallousCarnivores cc = null;
            ValiantVegans     vv = null;

            RoshamboPlayer rp = new RoshamboPlayer();

            rp.name = string.Empty;

            Console.WriteLine("Welcome to Rock Paper Scissors!\n");

            string name = InputHandlers.GetString("Enter your name: ");

            while (again)
            {
                try
                {
                    rp.name = name;

                    string str = "Would you like to play against the ";
                    str += "Valiant Vegans or the Callous Carnivores? (vv/cc): ";
                    string team = InputHandlers.GetString(str);
                    team = team.ToLower();

                    if (team != "vv" && team != "cc")
                    {
                        Console.WriteLine("");
                        continue;
                    }

                    Console.WriteLine();

                    rp.value = SelectRPS();

                    if (team == "vv")
                    {
                        vv      = new ValiantVegans();
                        vv.name = "Valiant Vegans";
                        vv.GenerateRoshambo();

                        int i = GetWinner(rp.value, vv.value, rp.name, vv.name);
                        if (i > 0)
                        {
                            playerWins++;
                        }
                        else if (i < 0)
                        {
                            vvWins++;
                        }
                    }
                    else
                    {
                        cc      = new CallousCarnivores();
                        cc.name = "Callous Carnivores";
                        cc.GenerateRoshambo();

                        int i = GetWinner(rp.value, cc.value, rp.name, cc.name);
                        if (i > 0)
                        {
                            playerWins++;
                        }
                        else if (i < 0)
                        {
                            ccWins++;
                        }
                    }

                    Console.WriteLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                again = InputHandlers.Continue("Play again? (y/n): ");
            }

            Console.WriteLine($"\nWins - {rp.name}: {playerWins}\tCallous Carnivores: {ccWins}\tValiant Vegans: {vvWins}\n");

            Console.WriteLine("Goodbye!");
        }
示例#19
0
        private void PickUpPowerUp(int entityLiveIdPlayer, PlayerInfo player, PowerUp powerUp)
        {
            Entity playerEntity = EntityManager.GetEntityByLiveId(entityLiveIdPlayer);

            //EntityManager.SendMessage(playerEntity, Messages.PlaySound, "PowerUp".CRC32Hash(), 1f, null);
            EntityManager.SendMessage(playerEntity, Messages.PlaySound, powerUp.SoundId, 1f, 0.3f, null);

            switch (powerUp.Type)
            {
            case PowerUpType.BombDown:
                player.PermittedSimultaneousBombs = Math.Max(1, player.PermittedSimultaneousBombs - 1);
                break;

            case PowerUpType.BombUp:
                player.PermittedSimultaneousBombs++;
                break;

            case PowerUpType.FireUp:
                player.BombState.Range++;
                break;

            case PowerUpType.FireDown:
                player.BombState.Range = Math.Max(1, player.BombState.Range - 1);
                break;

            case PowerUpType.SpeedUp:
                player.MaxSpeed *= GameConstants.PlayerSpeedUp;
                break;

            case PowerUpType.SpeedDown:
                player.MaxSpeed = Math.Max(GameConstants.PlayerMinSpeed, player.MaxSpeed / GameConstants.PlayerSpeedUp);
                break;

            case PowerUpType.FullFire:
                player.BombState.Range = GameConstants.InfiniteRange;
                break;

            case PowerUpType.PowerBomb:
                player.FirstBombInfinite = true;
                break;

            case PowerUpType.DangerousBomb:
                player.BombState.PropagationDirection = PropagationDirection.All;
                player.BombState.IsHardPassThrough    = true;
                break;

            case PowerUpType.PassThroughBomb:
                player.BombState.IsPassThrough = true;
                break;

            case PowerUpType.LandMineBomb:
                player.FirstBombLandMine = true;
                break;

            case PowerUpType.RemoteBomb:
                if (!player.RemoteTrigger)
                {
                    player.RemoteTrigger = true;     // This is necessary so that we don't add countdowns to bombs.
                    // Also add remote trigger input handling to this guy.
                    InputHandlers inputHandlers = (InputHandlers)EntityManager.GetComponent(entityLiveIdPlayer, ComponentTypeIds.InputHandlers);
                    if (inputHandlers != null)
                    {
                        inputHandlers.InputHandlerIds.Add("RemoteTrigger".CRC32Hash());
                    }
                }
                break;
            }
        }