/// <summary>
        /// Compare all qualities on all ICrystallonEntities. Returns <c>true</c> if all-same or all-different.
        /// </summary>
        /// <param name='pEntities'>
        /// <c>ICrystallonEntity</c> Array to be analyzed.
        /// </param>
        /// <param name='pForScore'>
        /// Is this to score points, or just to test whether matches are still possible?
        /// </param>
        public virtual int Match( ICrystallonEntity[] pEntities, bool pForScore )
        {
            int numWild = 0;
            List<int>[] variants = QualityManager.Instance.qualityDict[_name];
            int[] results = {0,0,0};
            foreach ( ICrystallonEntity e in pEntities ) {
                var card = e as CardCrystallonEntity;

                if (card.Wild){
                    numWild++;
                    continue;
                }

                for (int i=0; i<variants.Length; i++) {
                    if ( variants[i].Contains( card.id ) ) {
                        results[i]++;
                        break;
                    }
                }
            }
            if (pForScore) {
                if ( Array.IndexOf(results, 2) != -1 ) { // ------- Successful match is 1 of each or 3 of one. Any 2s => FAIL
                    return numWild > 0 ? allSameScore : 0 ;
                } else if (    (results[0] == 1 || results[1] == 1)
                            && numWild < 2) { // --------------------- All Different
                    return allDifferentScore;
                } else { // ----------------------------------- All Same
                    return allSameScore;
                }
            }
            return -1;
        }
Example #2
0
        // OVERRIDES -------------------------------------------------------------
        public override void Apply( ICrystallonEntity pEntity, int pVariant)
        {
            SpriteTileCrystallonEntity e = pEntity as SpriteTileCrystallonEntity;

            string orient;
            switch(e.getOrientation()) {
            case(0):
            default:
                orient = "T";
                break;
            case(1):
                orient = "L";
                break;
            case(2):
                orient = "R";
                break;
            }

            //			string setName = LevelManager.Instance.PatternPath.Substring(0,4);

            e.setPattern(pVariant);
            e.getSprite().TextureInfo = Support.SpriteFromAtlas("gamePieces", LevelManager.Instance.PatternPath + "_v" + pVariant.ToString() + "_" + orient + ".png").TextureInfo;

            //			e.getSprite().TileIndex2D = new Vector2i( e.getOrientation(), e.getPattern() );
        }
Example #3
0
        // OVERRIDES --------------------------------------------------------------
        public override void Apply(ICrystallonEntity pEntity, int pVariant)
        {
            AbstractCrystallonEntity e = pEntity as AbstractCrystallonEntity;

            switch(pVariant)
            {
            case (0):
                e.setSound(LevelManager.Instance.SoundPrefix + "low.wav");
                break;
            case (1):
                e.setSound(LevelManager.Instance.SoundPrefix + "mid.wav");
                break;
            case (2):
                e.setSound(LevelManager.Instance.SoundPrefix + "high.wav");
                break;
            default:
                throw new NotImplementedException("QSound.Apply : pVariant must be 0,1,2");
                break;
            }

            if (LevelManager.Instance.SoundGlow == true) {
                QGlow.Instance.Apply(pEntity, pVariant);
            } else {
                QGlow.Instance.Apply(pEntity, -1);
            }
        }
        // OVERRIDES --------------------------------------------------------------
        public override void Apply( ICrystallonEntity pEntity, int pVariant )
        {
            SpriteTileCrystallonEntity e = pEntity as SpriteTileCrystallonEntity;
            var sprite = e.getSprite();
            e.setOrientation(pVariant);

            string orient;
            switch(pVariant) {
            case(0):
            default:
                orient = "T";
                break;
            case(1):
                orient = "L";
                break;
            case(2):
                orient = "R";
                break;
            }

            //			string setName = LevelManager.Instance.PatternPath.Substring(0,4);

            if (sprite != null ) {
                sprite.TextureInfo = Support.TextureInfoFromAtlas("gamePieces", LevelManager.Instance.PatternPath + "_v" + e.getPattern().ToString() + "_" + orient + ".png");
                sprite.Scale = e.getSprite().CalcSizeInPixels();
                sprite.Position = sprite.Scale/-2.0f;
            }
        }
        // OVERRIDES ------------------------------------------------------------
        public override void Apply( ICrystallonEntity pEntity, int pVariant)
        {
            SpriteTileCrystallonEntity e = pEntity as SpriteTileCrystallonEntity;

            e.setParticle(pVariant);

            //			(e.getNode() as SpriteTile).TileIndex2D = new Vector2i( e.getOrientation(), e.getPattern() );
        }
Example #6
0
 // OVERRIDES --------------------------------------------------------------------
 public override void Apply( ICrystallonEntity pEntity, int pVariant )
 {
     if ( pEntity is SpriteTileCrystallonEntity ) {
         var e = (pEntity as SpriteTileCrystallonEntity);
         e.getSprite().Color = palette[pVariant];
         e.setColor(pVariant);
     }
 }
Example #7
0
        // OVERRIDES -------------------------------------------------------------
        public override void Apply( ICrystallonEntity pEntity, int pVariant)
        {
            CardCrystallonEntity e = pEntity as CardCrystallonEntity;

            if ( QualityManager.Instance.scoringQualityList.Contains("QSymbol") ) {
                e.setSymbol( pVariant );
            } else {
                e.setSymbol( null );
            }
        }
Example #8
0
 // METHODS ----------------------------------------------------------------
 public override void Apply( ICrystallonEntity pEntity, int pVariant )
 {
     if (pEntity is CardCrystallonEntity == false) return;
     CardCrystallonEntity e = pEntity as CardCrystallonEntity;
     e.setGlow( pVariant );
     if (pVariant == -1) {
         return;
     }
     e.GlowSprite.RunAction( new TintTo(palette[pVariant], 0.0f) );
     //			pEntity.getNode().RunAction( new TintTo( palette[pVariant], 0.0f ) );
 }
        // METHODS ------------------------------------------------------------------------
        public void Tick( ICrystallonEntity pEntity )
        {
            //			CardCrystallonEntity e = pEntity as CardCrystallonEntity;
            //			e.advanceCountdown();

            //			e.countdown--;
            //			if ( e.countdown < 0 ) {
            //				// Fire some sort of event and reset the countdown
            //				e.resetCountdown();
            //			}
        }
        protected void SpawnIcons(ICrystallonEntity pParent, Dictionary<string,int> pQualities, Vector4 pColor)
        {
            icon = null;

            Sequence sequence = new Sequence();

            foreach( string key in pQualities.Keys) {
                if (icon != null) {
                    continue;
                }
                if(key=="Orientation") {
                    continue;
                }
                switch(key){
                case("Color"):
                    icon = ColorIcon.Instance;
                    break;
                default:
                    int ix = (int)EnumHelper.FromString<Crystallography.Icons>(key);
                    icon = Support.TiledSpriteFromFile("/Application/assets/images/icons/icons.png", 4, 2 );
                    (icon as SpriteTile).TileIndex1D = ix;
                    (icon as SpriteBase).RegisterPalette((int)FMath.Floor(GameScene.Random.NextFloat()*3));
                    break;
                }
            }

            icon.Position = pParent.Parent.Parent.Position.Xy - iconSize/2.0f;
            if(icon.Parent != null){
                icon.Parent.RemoveChild(icon, false);
            }
            GameScene.Layers[2].AddChild(icon);

            sequence.Add( new DelayTime(0.1f));
            sequence.Add( new CallFunc( () => {icon.Visible = false;}));
            sequence.Add (new DelayTime(0.05f));
            sequence.Add( new CallFunc( () => {icon.Visible = true;}));
            sequence.Add( new DelayTime(0.1f));
            sequence.Add( new CallFunc( () => {icon.Visible = false;}));
            sequence.Add (new DelayTime(0.05f));
            sequence.Add( new CallFunc( () => {icon.Visible = true;}));
            sequence.Add( new DelayTime(0.75f));
            sequence.Add( new CallFunc( () => {icon.Visible = false;}));
            sequence.Add(new CallFunc( () => {
                icon.Visible = true;
                GameScene.Layers[2].RemoveChild(icon, true);
            }));
            icon.RunAction(sequence);
        }
        public ScorePanel( ICrystallonEntity pEntity, int pPoints )
        {
            InitializeWidget();

            ScoreLabel = new Sce.PlayStation.HighLevel.GameEngine2D.Label() {
                Text = pPoints.ToString()
            };
            var font = new Font("Application/assets/fonts/Bariol_Regular.otf", 25, FontStyle.Regular);
            var map = new FontMap(font);
            ScoreLabel.FontMap = map;
            ScoreLabel.Position = new Vector2(-4.0f, 10.0f);
            ScoreLabel.Color = Colors.White;
            ScoreLabel.HeightScale = 1.0f;
            ScoreLabel.Pivot = new Vector2(0.5f, 0.5f);
            Sequence sequence = new Sequence();
            sequence.Add( new DelayTime( 0.5f ) );
            sequence.Add ( new CallFunc( () => { pEntity.getNode().Parent.AddChild(ScoreLabel); } ) );

            //			ScoreText.Font = FontManager.Instance.Get ("Bariol", 20, "Bold");
            //			ScoreText.Text = pPoints.ToString();
            //			ScoreText.Alpha = 0.0f;
            //			_scoreTexture = new Texture2D((int)ScoreText.Width, (int)ScoreText.Height, false, PixelFormat.Rgba);
            //			ScoreText.RenderToTexture(_scoreTexture);
            //			_scoreTextureInfo = new TextureInfo(_scoreTexture);
            //			_scoreSprite = new SpriteUV(_scoreTextureInfo);
            //			_scoreSprite.Pivot = new Vector2(0.5f, 0.5f);
            //			pEntity.getNode().AddChild(_scoreSprite);
            //			_scoreSprite.Position = new Vector2(0.0f, 20.0f);
            //			Vector2 v = ConvertScreenToLocal( pPosition );
            //			this.SetPosition( v.X - ScoreText.Width/2, Director.Instance.GL.Context.GetViewport().Height - (v.Y + 40) );
            //			Sequence sequence = new Sequence();
            //			sequence.Add( new DelayTime( 3.0f ) );
            //			sequence.Add ( new CallFunc( () => {
            //				ScoreText.Visible = false;
            //				this.Dispose();
            //			} ) );
            Director.Instance.CurrentScene.RunAction(sequence);
        }
 // OVERRIDES ----------------------------------------------------------------------
 public override void Apply( ICrystallonEntity pEntity, int pVariant )
 {
     //			CardCrystallonEntity e = pEntity as CardCrystallonEntity;
     //			e.setCountdown( pVariant );
 }
 /// <summary>
 /// Match the specified pEntities.
 /// </summary>
 /// <param name='pEntities'>
 /// P entities.
 /// </param>
 public override int Match(ICrystallonEntity[] pEntities, bool pForScore)
 {
     return base.Match(pEntities, pForScore );
 }
 // OVERRIDES -------------------------------------------------------------
 public override void Apply( ICrystallonEntity pEntity, int pVariant)
 {
     CardCrystallonEntity e = pEntity as CardCrystallonEntity;
     e.setAnim( GetOrientedAnimation(e.getOrientation()), palette[pVariant, 0], palette[pVariant, 1] );
 }
 /// <summary>
 /// Apply the specified Variant of this quality to the ICrystallonEntity.
 /// </summary>
 /// <param name='pEntity'>
 /// <c>ICrystallonEntity</c>
 /// </param>
 /// <param name='pVariant'>
 /// <c>int</c> of variant to apply. Probs 0, 1, or 2.
 /// </param>
 public abstract void Apply( ICrystallonEntity pEntity, int pVariant );
Example #16
0
 public void RemoveChildEntity( ICrystallonEntity pEntity, bool doCleanup )
 {
     _allEntites.Remove( pEntity );
     pEntity.Parent.RemoveChild( pEntity.getNode(), doCleanup );
 }
Example #17
0
 // METHODS -------------------------------------------------------------------------------------------------
 /// <summary>
 /// Adds an entity to the specified layer. 0 = Background. 1 = Gameplay. 2 = Foreground. Defaults to 1.
 /// </summary>
 /// <param name='pEntity'>
 /// entity.
 /// </param>
 /// <param name='pLayerIndex'>
 /// layer index.
 /// </param>
 public void AddChildEntity( ICrystallonEntity pEntity, int pLayerIndex=1 )
 {
     if (_allEntites.Contains(pEntity) == false) {
         _allEntites.Add(pEntity);
     }
     Layers[pLayerIndex].AddChild(pEntity.getNode());
 }
 /// <summary>
 /// Remove the specified <c>ICrystallonEntity</c> from <c>members</c>. DOES NOT detach it from its parent puck.
 /// </summary>
 /// <param name='pEntity'>
 /// <see cref="Crystallography.ICrystallonEntity"/>
 /// </param>
 protected ICrystallonEntity Remove( ICrystallonEntity pEntity )
 {
     int index = Array.IndexOf(members, pEntity);
     if (index != -1) {
         return PopIndex (index);
     }
     return null;
 }
 public void FailedIcons(ICrystallonEntity pParent, Dictionary<string,int> pQualities)
 {
     SpawnIcons (pParent, pQualities, Colors.Pink);
 }
        /// <summary>
        /// Returns whether the qualities possessed by the Array of <c>ICrystallonEntity</c> are all-same-or-all-different.
        /// </summary>
        /// <param name='pEntities'>
        /// Array of <see cref="Crystallography.ICrystallonEntity"/>
        /// </param>
        /// <param name='pForScore'>
        /// Is this to score points, or just to test whether matches are still possible? Default = <c>false</c>.
        /// </param>
        //        private bool EvaluateMatch( ICrystallonEntity[] pEntities, out Dictionary<AbstractQuality, bool> pQDict, bool pForScore) {
        private bool EvaluateMatch( ICrystallonEntity[] pEntities, bool pForScore)
        {
            // TODO this whole function is inefficient... revisit later.

            int score;
            bool failed = false;
            FailedMatchEventArgs.Names.Clear();
            FailedMatchEventArgs failArgs = new FailedMatchEventArgs();
            EventHandler<FailedMatchEventArgs> failHandler;
            allSameScoreDict.Clear();

            foreach ( string key in scoringQualityList ) {
                var variations = qualityDict[key];
                var type = Type.GetType( "Crystallography." + key );
                var quality = (AbstractQuality)type.GetProperty("Instance").GetValue(null, null);
                if (   (variations[0] == null && variations[1] == null)
                    || (variations[1] == null && variations[2] == null)
                    || (variations[0] == null && variations[2] == null ) ) {	// no variations of this quality on any card in this entire level
                    continue;
                } else {
                    score = quality.Match( pEntities, pForScore );
                    if ( score == 0 ) {	//------------------------------------------------------------ No match. Just quit.
                        if (pForScore) { //----------------------------------------------------------- This is a player-triggered Match Evaluation that has failed
                            FailedMatchEventArgs.Names.Add(key.ToString().Substring(1),1); //                      as opposed to one from CardManager.MatchesPossible()
                        }
                        failed = true;
                    } else {	// ------------------------------------------------------------------- Is it an All-Same match?
                        allSameScoreDict.Add ( quality, (score == quality.allSameScore) ) ;
                    }
                }
            }
            if (failed) {
                failArgs.Entity = pEntities[0];
                failHandler = FailedMatchDetected;
                if (failHandler != null) {
                    failHandler( this, failArgs);
                }
                return false;
            }
            return true;
        }
 // METHODS ---------------------------------------------------------------
 /// <summary>
 /// Add the specified <c>ICrystallonEntity</c> to this group.
 /// </summary>
 /// <param name='pEntity'>
 /// <see cref="Crystallography.ICrystallonEntity"/>
 /// </param>
 public virtual GroupCrystallonEntity Add(ICrystallonEntity pEntity)
 {
     if ( pEntity != null ) {
     //				if ( population == 0 && !(this is SelectionGroup) ) {
     //				if ( population == 0 ) {
     //					MemberType = pEntity.GetType();
     //					if ( MemberType == typeof(WildCardCrystallonEntity) ) {
     //						MemberType = typeof(CardCrystallonEntity);
     //					}
     //				}
         if( pEntity.CanBeAddedTo(this) ){
             pEntity.BeAddedToGroup(this);
         }
     }
     return this;
 }