コード例 #1
0
        /// <summary>
        /// Palauttaa annetun näppäimen tilan (ks. <c>ButtonState</c>).
        /// </summary>
        /// <param name="key">Näppäin.</param>
        /// <returns>Näppäimen tila</returns>
        public ButtonState GetKeyState(Key key)
        {
            bool down     = CurrentState.IsKeyDown(key);
            bool lastdown = PrevState.IsKeyDown(key);

            if (lastdown && down)
            {
                return(ButtonState.Down);
            }
            if (!lastdown && down)
            {
                return(ButtonState.Pressed);
            }
            if (lastdown && !down)
            {
                return(ButtonState.Released);
            }

            return(ButtonState.Up);
        }
コード例 #2
0
 //methods
 public bool IsPressed(GraphicObject buttonpressed)
 {
     if (Key != Keys.None)
     {
         if (!IsSlow)
         {
             return(CurrState.IsKeyDown(Key));// && PrevState.IsKeyUp(Key);
         }
         else
         {
             return(CurrState.IsKeyDown(Key) && !PrevState.IsKeyDown(Key));
         }
     }
     else if (Name != "")
     {
         if (buttonpressed == null)
         {
             return(false);
         }
         return(buttonpressed.IsCalled(Name));
     }
     return(false);
 }
コード例 #3
0
        private void ProcessKeyboardInput(GameTime gameTime, Bot bot)
        {
            KeyboardState state = Keyboard.GetState();

            if (state.IsKeyDown(Keys.Right) & !PrevState.IsKeyDown(Keys.Right))
            {
                FocusID     += 1;
                UpgradeFocus = false;
            }
            if (state.IsKeyDown(Keys.Left) & !PrevState.IsKeyDown(Keys.Left))
            {
                FocusID     -= 1;
                UpgradeFocus = false;
            }
            if (state.IsKeyDown(Keys.Down) & !PrevState.IsKeyDown(Keys.Down))
            {
                UpgradeFocus = !UpgradeFocus;
            }
            if (state.IsKeyDown(Keys.Up) & !PrevState.IsKeyDown(Keys.Up))
            {
                UpgradeFocus = !UpgradeFocus;
            }

            if (FocusID < 0)
            {
                FocusID = NumberOfButtons - 1;
            }
            else if (FocusID >= NumberOfButtons)
            {
                FocusID = 0;
            }

            if (state.IsKeyDown(Keys.Enter) & !PrevState.IsKeyDown(Keys.Enter))
            {
                bot.IsStarted = true;
                if (!UpgradeFocus)
                {
                    switch ((ButtonID)FocusID)
                    {
                    case ButtonID.explosiveForceButton:
                    {
                        Player1.AddForces(new ExplosiveForce(gameTime), Player2, gameTime);
                        break;
                    }

                    case ButtonID.rifleForceButton:
                    {
                        Player1.AddForces(new RifleForce(gameTime), Player2, gameTime);
                        break;
                    }

                    case ButtonID.rocketForceButton:
                    {
                        Player1.AddForces(new RocketForce(gameTime), Player2, gameTime);
                        break;
                    }

                    case ButtonID.droneCarrierForceButton:
                    {
                        Player1.AddForces(new DroneCarrierForce(gameTime), Player2, gameTime);
                        break;
                    }

                    case ButtonID.cannonForceButton:
                    {
                        Player1.AddForces(new CannonForce(gameTime), Player2, gameTime);
                        break;
                    }

                    default:
                        break;
                    }
                }
                else
                {
                    LearnInputOutput learning = new LearnInputOutput(Player2.ListOfForces, Player1.ListOfForces, Player1.Upgrades, Player1.Cash, (int)((int)((ForcesType)FocusID) + 6));
                    Data.WriteToFile(learning);
                    Player1.DidSomething(gameTime);
                    Player1.Upgrade((ForcesType)FocusID);
                }
            }
            //TEMP ADDING ENEMY

            /*
             * if (state.IsKeyDown(Keys.NumPad1) & !PrevState.IsKeyDown(Keys.NumPad1))
             * {
             *  Player2.AddForces(new ExplosiveForce(gameTime), Player1, gameTime);
             * }
             * if (state.IsKeyDown(Keys.NumPad2) & !PrevState.IsKeyDown(Keys.NumPad2))
             * {
             *  Player2.AddForces(new RifleForce(gameTime), Player1, gameTime);
             * }
             * if (state.IsKeyDown(Keys.NumPad3) & !PrevState.IsKeyDown(Keys.NumPad3))
             * {
             *  Player2.AddForces(new RocketForce(gameTime), Player1, gameTime);
             * }
             * if (state.IsKeyDown(Keys.NumPad4) & !PrevState.IsKeyDown(Keys.NumPad4))
             * {
             *  Player2.AddForces(new DroneCarrierForce(gameTime), Player1, gameTime);
             * }
             * if (state.IsKeyDown(Keys.NumPad5) & !PrevState.IsKeyDown(Keys.NumPad5))
             * {
             *
             *  Player2.AddForces(new CannonForce(gameTime), Player1, gameTime);
             * }
             * //TEMP UPGRADING ENEMY
             * if (state.IsKeyDown(Keys.NumPad0) & !PrevState.IsKeyDown(Keys.NumPad0))
             * {
             *  Player2.Upgrade((ForcesType)0);
             * }
             * if (state.IsKeyDown(Keys.NumPad6) & !PrevState.IsKeyDown(Keys.NumPad6))
             * {
             *  Player2.Upgrade((ForcesType)1);
             * }
             * if (state.IsKeyDown(Keys.NumPad7) & !PrevState.IsKeyDown(Keys.NumPad7))
             * {
             *  Player2.Upgrade((ForcesType)2);
             * }
             * if (state.IsKeyDown(Keys.NumPad8) & !PrevState.IsKeyDown(Keys.NumPad8))
             * {
             *  Player2.Upgrade((ForcesType)3);
             * }
             * if (state.IsKeyDown(Keys.NumPad9) & !PrevState.IsKeyDown(Keys.NumPad9))
             * {
             *  Player2.Upgrade((ForcesType)4);
             * }
             * //testing engine
             * if (state.IsKeyDown(Keys.Space) & !PrevState.IsKeyDown(Keys.Space))
             * {
             *  //GameEventEngine.Add(new GameEventDelayed(() => { tmpColor = Color.Red; },1.0f));
             *  //GameEventEngine.Add(new GameEventDelayed(() => { tmpColor = Color.Green; }, 2.0f));
             *  //GameEventEngine.Add(new GameEventDelayed(() => { tmpColor = Color.Black; }, 3.0f));
             *  //GameEventEngine.Add(new GameEventCyclic(() => { tmpColor = Color.Red; }, 2, 5));
             * }
             */

            PrevState = state;
        }