예제 #1
0
        public void KeyUpHandled(KeyboardState ks)
        {
            int direction = -1;

            Keys[] keys = ks.GetPressedKeys();

            if (keys.Contains(Keys.Up))
            {
                direction = SnakeGameModel.MOVE_UP;
            }
            else if (keys.Contains(Keys.Down))
            {
                direction = SnakeGameModel.MOVE_DOWN;
            }
            else if (keys.Contains(Keys.Left))
            {
                direction = SnakeGameModel.MOVE_LEFT;
            }
            else if (keys.Contains(Keys.Right))
            {
                direction = SnakeGameModel.MOVE_RIGHT;
            }
            // Find all snakeboard model we know
            if (direction == -1)
            {
                return;
            }
            SnakeGameModel sbm = (SnakeGameModel)model;

            sbm.SetDirection(direction);
        }
        public void KeyUpHandled(KeyboardState ks)
        {
            int direction = -1;

            Keys[] keys = ks.GetPressedKeys();
            if (keys.Contains(Keys.Space))
            {
                Stop();
                //System.Threading.Thread.Sleep(1000);
            }
            else if (keys.Contains(Keys.Up))
            {
                Start();
                direction = SnakeGameModel.MOVE_UP;
            }
            else if (keys.Contains(Keys.Down))
            {
                Start();
                direction = SnakeGameModel.MOVE_DOWN;
            }
            else if (keys.Contains(Keys.Left))
            {
                Start();
                direction = SnakeGameModel.MOVE_LEFT;
            }
            else if (keys.Contains(Keys.Right))
            {
                Start();
                direction = SnakeGameModel.MOVE_RIGHT;
            }

            // Find all snakeboard model we know


            /*  if (direction == -5 && pause==false) {
             * // memtime = timer;
             *  Stop();
             *  pause = true;
             * }
             * else if (direction == -5 && pause == true)
             * {
             * // timer = memtime;
             *  Start();
             *  pause = false;
             * }*/
            if (direction == -1)
            {
                return;
            }
            foreach (Model m in mList)
            {
                if (m is SnakeGameModel)
                {
                    // Tell the model to update
                    SnakeGameModel sbm = (SnakeGameModel)m;
                    sbm.SetDirection(direction);
                }
            }
        }
예제 #3
0
        public void KeyUpHandled(KeyboardState ks)
        {
            int direction = -1;

            Keys[] keys = ks.GetPressedKeys();

            if (keys.Contains(Keys.Up))
            {
                direction = SnakeGameModel.MOVE_UP;
            }
            else if (keys.Contains(Keys.Down))
            {
                direction = SnakeGameModel.MOVE_DOWN;
            }
            else if (keys.Contains(Keys.Left))
            {
                direction = SnakeGameModel.MOVE_LEFT;
            }
            else if (keys.Contains(Keys.Right))
            {
                direction = SnakeGameModel.MOVE_RIGHT;
            }
            else if (keys.Contains(Keys.Space))
            {
                if (!ispause)
                {
                    Stop();
                    ispause = true;
                    System.Threading.Thread.Sleep((int)System.TimeSpan.FromSeconds(0.25).TotalMilliseconds);
                }
                else
                {
                    Start();
                    ispause = false;
                    System.Threading.Thread.Sleep((int)System.TimeSpan.FromSeconds(0.25).TotalMilliseconds);
                }
            }
            // Find all snakeboard model we know
            if (direction == -1)
            {
                return;
            }
            foreach (Model m in mList)
            {
                if (m is SnakeGameModel)
                {
                    // Tell the model to update
                    SnakeGameModel sbm = (SnakeGameModel)m;
                    sbm.SetDirection(direction);
                }
            }
        }
        public void KeyUpHandled(KeyboardState ks)
        {
            int direction = -1;

            Keys[] keys = ks.GetPressedKeys();

            if (keys.Contains(Keys.Up))
            {
                direction = SnakeGameModel.MOVE_UP;
            }
            else if (keys.Contains(Keys.Down))
            {
                direction = SnakeGameModel.MOVE_DOWN;
            }
            else if (keys.Contains(Keys.Left))
            {
                direction = SnakeGameModel.MOVE_LEFT;
            }
            else if (keys.Contains(Keys.Right))
            {
                direction = SnakeGameModel.MOVE_RIGHT;
            }
            else if (keys.Contains(Keys.Space))
            {
                if (!TimeSpace)
                {
                    Stop();
                    TimeSpace = true;
                }
                else
                {
                    Start();
                    TimeSpace = false;
                }
            }

            // Find all snakeboard model we know
            if (direction == -1)
            {
                return;
            }
            foreach (Model m in mList)
            {
                if (m is SnakeGameModel)
                {
                    // Tell the model to update
                    SnakeGameModel sbm = (SnakeGameModel)m;
                    sbm.SetDirection(direction);
                }
            }
        }