Esempio n. 1
0
        /// <summary>
        /// Triggered when a token is added to the board.
        /// </summary>
        public void OnTokenAdded(
            object sender,
            TokenArgs args)
        {
            // Create a new token
            TokenSprite     ts = new TokenSprite(this, args.Token);
            ContainerSprite ms = new ContainerSprite(ts);

            sprites.Add(ms);

            // Move the sprite over
            ms.RateX = 100;
            ms.RateY = 100;
            ms.X     = ms.DesiredX = TileSize * args.Token.Column;
            ms.Y     = ms.DesiredY = TileSize * args.Token.Row;
            ms.Y    -= TileSize;

            // Check the state
            if (Game.State == GameState.InProgress &&
                args.Token.Type == TokenType.Flooded && args.Token.Value == ' ')
            {
                // Flooded tokens show up in place, but with a special
                // animation
                ms.Y = ms.DesiredY;
                ms.X = ms.DesiredX;
                ts.DrawableState.Frame = TokenSprite.FloodedStart;
            }

            // We need to sort the list again
            sortNext = true;
            QueueDraw();
            log.Debug(
                "TokenAdded: {0} sprits {1} state {2}", ts, sprites.Count, Game.State);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the first token sprite in the point.
        /// </summary.
        private TokenSprite GetTokenSprite(
            double dx,
            double dy)
        {
            // Adjust for our offset
            int x = (int)dx;              //(int) dx - pixmapX;
            int y = (int)dy;              //(int) dy - pixmapY;

            // Go through it
            foreach (ISprite sprite in sprites)
            {
                // Don't bother if we aren't a moving one
                ContainerSprite ms = sprite as ContainerSprite;
                if (ms == null)
                {
                    continue;
                }

                TokenSprite ts = ms.TokenSprite;

                // Check it
                if (ts.Rectangle.Contains(x, y))
                {
                    return(ts);
                }
            }

            // Can't find it
            //log.Debug("GetTokenSprite: {0}x{1}", x, y);
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Triggered when a token is changed on the board.
        /// </summary>
        public void OnTokenChanged(
            object sender,
            TokenArgs args)
        {
            // Remove the old one
            TokenSprite ts = GetTokenSprite(args.Token);

            ts.UpdateDrawable();
        }
Esempio n. 4
0
        /// <summary>
        /// Triggered when the button is pressed.
        /// </summary>
        private void OnButtonPress(
            object sender,
            ButtonPressEventArgs args)
        {
            // Ignore if we are in the wrong state
            if (Game.State != GameState.InProgress || IsMoving)
            {
                return;
            }

            // Force a redraw
            QueueDraw();

            // Get the token at that point
            EventButton ev = args.Event;
            TokenSprite ts = GetTokenSprite(ev.X, ev.Y);

            if (ts == null)
            {
                //log.Debug("OnButtonPress: No sprites at {0}x{1}",
                //ev.X, ev.Y);
                return;
            }

            // If we are in a space, we can't select
            if (!ts.CanSelect)
            {
                //log.Debug("OnButtonPress: Cannot selected {0}", ts);
                return;
            }

            // Check for valid connect
            if (Game.Board.IsFinalToken(ts.Token))
            {
                // We need to remove the pieces from our board
                Game.Board.ScoreChain();

                // Update the display
                QueueDraw();
                return;
            }

            // Add to the chain
            Game.Board.AddToChain(ts.Token);

            // We handled it
            args.RetVal = true;
            log.Debug("OnButtonPress(): {0}", ts);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a token sprite for a given token, or returns null if
        /// there is one.
        /// </summary>
        public ContainerSprite GetContainerSprite(Token token)
        {
            // Go through the sprites, unwrap the moving sprites, and
            // check for the token.
            foreach (ISprite sprite in sprites)
            {
                if (sprite is ContainerSprite)
                {
                    ContainerSprite ms = (ContainerSprite)sprite;
                    TokenSprite     ts = ms.TokenSprite;

                    if (ts != null && ts.Token == token)
                    {
                        return(ms);
                    }
                }
            }

            // Can't find it
            return(null);
        }
Esempio n. 6
0
        /// <summary>
        /// Triggered when a token is added to the board.
        /// </summary>
        public void OnTokenAdded(
			object sender,
			TokenArgs args)
        {
            // Create a new token
            TokenSprite ts = new TokenSprite(this, args.Token);
            ContainerSprite ms = new ContainerSprite(ts);
            sprites.Add(ms);

            // Move the sprite over
            ms.RateX = 100;
            ms.RateY = 100;
            ms.X = ms.DesiredX = TileSize * args.Token.Column;
            ms.Y = ms.DesiredY = TileSize * args.Token.Row;
            ms.Y -= TileSize;

            // Check the state
            if (Game.State == GameState.InProgress &&
                args.Token.Type == TokenType.Flooded && args.Token.Value == ' ')
            {
                // Flooded tokens show up in place, but with a special
                // animation
                ms.Y = ms.DesiredY;
                ms.X = ms.DesiredX;
                ts.DrawableState.Frame = TokenSprite.FloodedStart;
            }

            // We need to sort the list again
            sortNext = true;
            QueueDraw();
            log.Debug(
                "TokenAdded: {0} sprits {1} state {2}", ts, sprites.Count, Game.State);
        }
Esempio n. 7
0
 /// <summary>
 /// Constructs the container sprite.
 /// </summary>
 public ContainerSprite(TokenSprite sprite)
     : base(sprite)
 {
 }
Esempio n. 8
0
 /// <summary>
 /// Constructs the container sprite.
 /// </summary>
 public ContainerSprite(TokenSprite sprite)
     : base(sprite)
 {
 }