示例#1
0
        void Jiggle(SpriteBatch spriteBatch, Texture2D tile, Vector2 tilePosition, Texture2D letter)
        {
            if (jiggleDirection == JiggleDirection.Stop)
            {
                Rectangle rect = new Rectangle((int)tilePosition.X, (int)tilePosition.Y, ((int)(0.18 * ViewPortWidth)), ((int)(0.3 * ViewPortHeight)));
                spriteBatch.Draw(tile, rect, Color.White);
                spriteBatch.Draw(letter, rect, Color.White);
            }
            else
            {
                switch (jiggleState)
                {
                    case JiggleState.Center:

                        switch (jiggleDirection)
                        {
                            case JiggleDirection.Left:
                                jiggleState = JiggleState.Left;
                                tilePosition.X -= JiggleAmount;
                                tilePosition.Y -= JiggleAmount;
                                break;

                            case JiggleDirection.Right:
                                jiggleState = JiggleState.Right;
                                tilePosition.X += JiggleAmount;
                                tilePosition.Y += JiggleAmount;
                                break;
                        }
                        break;

                    case JiggleState.Left:

                        switch (jiggleDirection)
                        {
                            case JiggleDirection.Left:
                                jiggleDirection = JiggleDirection.Right;
                                break;

                            case JiggleDirection.Right:
                                jiggleState = JiggleState.Center;
                                tilePosition.X += JiggleAmount;
                                tilePosition.Y += JiggleAmount;
                                break;
                        }
                        break;

                    case JiggleState.Right:

                        switch (jiggleDirection)
                        {
                            case JiggleDirection.Left:
                                jiggleState = JiggleState.Center;
                                tilePosition.X -= JiggleAmount;
                                tilePosition.Y -= JiggleAmount;
                                break;

                            case JiggleDirection.Right:
                                jiggleDirection = JiggleDirection.Left;
                                break;
                        }
                        break;
                }

                Rectangle rect = new Rectangle((int)tilePosition.X, (int)tilePosition.Y, ((int)(0.18 * ViewPortWidth)), ((int)(0.3 * ViewPortHeight)));
                spriteBatch.Draw(tile, rect, Color.White);
                spriteBatch.Draw(letter, rect, Color.White);
            }
        }
示例#2
0
        public void Initialize( ContentManager content, 
                                float X, 
                                float Y, 
                                int viewPortWidth, 
                                int viewPortHeight, 
                                string assetName)
        {
            _state = TileState.Blank;

            _position.X = X;
            _position.Y = Y; 
            _viewPortWidth = viewPortWidth;
            _viewPortHeight = viewPortHeight;

            _tileGraphic = content.Load<Texture2D>(assetName);

            _X = content.Load<Texture2D>("BoardX");
            _O = content.Load<Texture2D>("BoardO");

            _XMoveClip = content.Load<SoundEffect>("XMove");
            _OMoveClip = content.Load<SoundEffect>("OMove");

            jiggleState = JiggleState.Center;
            jiggleDirection = JiggleDirection.Left;
        }
示例#3
0
        async public void Draw(SpriteBatch spriteBatch)
        {
            // tile not yet clicked, just draw the tile
            if (_state == TileState.Blank)
            {
                Rectangle rect = new Rectangle((int) _position.X, (int) _position.Y, ((int) (0.18 * ViewPortWidth)), ((int)(0.3 * ViewPortHeight)));
                spriteBatch.Draw(_tileGraphic, rect, Color.White);
            }

            // tile clicked and is currently blank, so set the proper state
            if ((_tileClicked) && (_state == TileState.Blank) && (GameState._gameOver == false))
            {
                _tileClicked = false;

                if (GameState._whosTurn == PlayerTurn.X)
                {
                    _state = TileState.X;
                    GameState._whosTurn = PlayerTurn.O;
                    GameState._moves++;
                    _OMoveClip.Play();
                }
                else
                {
                    _state = TileState.O;
                    GameState._whosTurn = PlayerTurn.X;
                    GameState._moves++;
                    _XMoveClip.Play();
                }
            }

            // if the tile state is set to O or X, then draw the appropriate letter

            if (_state == TileState.O)
            {
                // jiggle the tile
                for (int i = 0; i < JiggleAmount; i++)
                {
                    Jiggle(spriteBatch, _tileGraphic, _position, _O);
                    await Task.Delay(100);
                }
                jiggleDirection = JiggleDirection.Stop;
            }

            if (_state == TileState.X)
            {
                // jiggle the tile
                for (int i = 0; i < JiggleAmount; i++)
                {
                    Jiggle(spriteBatch, _tileGraphic, _position, _X);
                    await Task.Delay(100);
                }
                jiggleDirection = JiggleDirection.Stop;
            }
         }