Beispiel #1
0
        public Nomino GetGhostDrop(IStateOwner pOwner, Nomino Source, out int dropLength, int CancelProximity = 3)
        {
            //routine returns the Ghost Drop representor of this Nomino.
            //this function will also return null if the dropped block is CancelProximity or closer to the place it would be dropped.
            Nomino Duplicator = new Nomino(Source);

            dropLength = 0;
            while (true)
            {
                var fitresult = CanFit(Duplicator, Duplicator.X, Duplicator.Y + 1, true, new Nomino[] { Source });
                //ghost drops will show up "through" any active blocks, since active blocks don't actual set blocks..
                if (new CanFitResultConstants[] { CanFitResultConstants.CanFit, CanFitResultConstants.CantFit_Active }.Contains(fitresult))
                {
                    dropLength++;
                    Duplicator.SetY(pOwner, Duplicator.Y + 1);
                }
                else
                {
                    break;
                }
            }

            if (dropLength < CancelProximity)
            {
                return(null);
            }
            foreach (var iterate in Duplicator)
            {
                iterate.Block.Owner = Source;
            }
            return(Duplicator);
        }
Beispiel #2
0
 public void RemoveBlockGroup(Nomino oldGroup)
 {
     lock (ActiveBlockGroups)
     {
         ActiveBlockGroups.Remove(oldGroup);
     }
 }
Beispiel #3
0
        public override void ApplyTheme(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field, ThemeApplicationReason Reason)
        {
            var LineCount = (GameHandler.Statistics is TetrisStatistics ts) ? ts.LineCount : 0;
            int CurrLevel = Field == null ? 0 : (int)(LineCount / 10);

            ApplyColorSet(Group, CurrLevel);
        }
Beispiel #4
0
        public void Apply_I(Nomino Group, TetrisField Field, int CurrLevel)
        {
            //mottled. need to set rotation images as well.

            //we have four indices:
            //index one is left side
            //index two is left middle
            //index three is right middle
            //index four is right side.
            var BlockData = Group.GetBlockData();

            if (BlockData.Count < 4)
            {
                BlockData = new List <NominoElement>(BlockData);
                while (BlockData.Count < 4)
                {
                    BlockData.Add(null);
                }
                BlockData = TetrisGame.Shuffle(BlockData).ToList();
            }
            var LeftSide    = BlockData[0];
            var LeftMiddle  = BlockData[1];
            var RightMiddle = BlockData[2];
            var RightSide   = BlockData[3];

            if (LeftSide != null && LeftSide.Block is StandardColouredBlock)
            {
                var scb = (LeftSide.Block as StandardColouredBlock);
                scb.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
                scb._RotationImagesSK = NominoTheme.GetImageRotations(SkiaSharp.Views.Desktop.Extensions.ToSKBitmap(new Bitmap(GetLeftCap(CurrLevel))));
                //scb._RotationImages = new Image[] {TetrisGame.Imageman.getLoadedImage("FLIPX:mottle_right_cap",ReductionFactor), TetrisGame.Imageman.getLoadedImage("FLIPXROT90:mottle_right_cap",ReductionFactor),
                //        TetrisGame.Imageman.getLoadedImage("FLIPXROT180:mottle_right_cap",ReductionFactor), TetrisGame.Imageman.getLoadedImage("FLIPXROT270:mottle_right_cap",ReductionFactor) };
            }
            if (LeftMiddle != null && LeftMiddle.Block is StandardColouredBlock)
            {
                var scb = (LeftMiddle.Block as StandardColouredBlock);
                scb.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
                scb._RotationImagesSK = NominoTheme.GetImageRotations(SkiaSharp.Views.Desktop.Extensions.ToSKBitmap(new Bitmap(GetHorizontal(CurrLevel))));
                //scb._RotationImages = new Image[] {TetrisGame.Imageman.getLoadedImage("mottle_horizontal",ReductionFactor), TetrisGame.Imageman.getLoadedImage("ROT90:mottle_horizontal",ReductionFactor),
                //    TetrisGame.Imageman.getLoadedImage("ROT180:mottle_horizontal",ReductionFactor), TetrisGame.Imageman.getLoadedImage("ROT270:mottle_horizontal",ReductionFactor) };
            }

            if (RightMiddle != null && RightMiddle.Block is StandardColouredBlock)
            {
                var scb = (RightMiddle.Block as StandardColouredBlock);
                scb.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
                scb._RotationImagesSK = NominoTheme.GetImageRotations(SkiaSharp.Views.Desktop.Extensions.ToSKBitmap(new Bitmap(GetHorizontal(CurrLevel))));
                //scb._RotationImages = new Image[] {TetrisGame.Imageman.getLoadedImage("mottle_horizontal",ReductionFactor), TetrisGame.Imageman.getLoadedImage("ROT90:mottle_horizontal",ReductionFactor),
                //    TetrisGame.Imageman.getLoadedImage("ROT180:mottle_horizontal",ReductionFactor), TetrisGame.Imageman.getLoadedImage("ROT270:mottle_horizontal",ReductionFactor) };
            }
            if (RightSide != null && RightSide.Block is StandardColouredBlock)
            {
                var scb = (RightSide.Block as StandardColouredBlock);
                scb.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
                scb._RotationImagesSK = NominoTheme.GetImageRotations(SkiaSharp.Views.Desktop.Extensions.ToSKBitmap(new Bitmap(GetRightCap(CurrLevel))));
                //scb._RotationImages = new Image[] {TetrisGame.Imageman.getLoadedImage("mottle_right_cap",ReductionFactor), TetrisGame.Imageman.getLoadedImage("ROT90:mottle_right_cap",ReductionFactor),
                //    TetrisGame.Imageman.getLoadedImage("ROT180:mottle_right_cap",ReductionFactor), TetrisGame.Imageman.getLoadedImage("ROT270:mottle_right_cap",ReductionFactor) };
            }
        }
Beispiel #5
0
 public void AddBlockGroup(Nomino newGroup)
 {
     Debug.Print("Added:" + newGroup.ToString());
     lock (ActiveBlockGroups)
     {
         ActiveBlockGroups.Add(newGroup);
     }
 }
Beispiel #6
0
        public bool CanRotate(Nomino bg, bool ccw)
        {
            Nomino duped = new Nomino(bg);

            duped.Rotate(ccw);
            duped.Clamp(RowCount, ColCount);
            //we need to pass in bg for the additional argument this time, since we duplicated to a new nomino it will incorrectly get blocked by the original by CanFit otherwise.
            return(CanFit(duped, bg.X, bg.Y, false, new Nomino[] { bg }) == CanFitResultConstants.CanFit);
        }
Beispiel #7
0
 public Nomino(Nomino sourcebg)
 {
     FallSpeed = sourcebg.FallSpeed;
     X         = sourcebg.X;
     Y         = sourcebg.Y;
     foreach (var cloneentry in sourcebg.BlockData)
     {
         AddBlock(new NominoElement(cloneentry));
     }
 }
Beispiel #8
0
        public CanFitResultConstants CanFit(Nomino bg, int X, int Y, bool SkipActiveChecks, Nomino[] AdditionalIgnores = null)
        {
            HashSet <Point> ActiveBlocks = new HashSet <Point>();

            //this routine handles other Block Groups as well, allowing multiple to exist at once in the play field, and be moved.
            //eg you cannot rotate or move an Active Group such that it will interfere with another active Group.
            //One consideration here is that the order of the groups will matter, in the sense that if one is processed to move first then it can be blocked even if it would be able to move
            //after a later group moves, which may create as few unusual side-effects.
            //let's start off by creating a HashSet of Point structs listing the field positions of other active groups than the specified Nomino.
            foreach (var active in ActiveBlockGroups)
            {
                if (active != bg && (AdditionalIgnores == null || !AdditionalIgnores.Contains(active)))
                {
                    foreach (var check in active)
                    {
                        ActiveBlocks.Add(new Point(active.X + check.X, active.Y + check.Y));
                    }
                }
            }
            IList <NominoElement> Contacts = new List <NominoElement>();
            bool result        = true;
            bool ActiveTouched = false;

            foreach (var checkblock in bg)
            {
                int CheckRow = Y + checkblock.Y;
                int CheckCol = X + checkblock.X;
                if (CheckRow < 0 || CheckCol < 0)
                {
                    result = false;
                    Contacts.Add(checkblock);
                }
                else if (CheckRow >= RowCount || CheckCol >= ColCount)
                {
                    result = false;
                    Contacts.Add(checkblock);
                }
                else
                {
                    var grabpos       = FieldContents[CheckRow][CheckCol];
                    var touchesactive = !SkipActiveChecks && ActiveBlocks.Contains(new Point(CheckCol, CheckRow));
                    if (touchesactive)
                    {
                        ActiveTouched |= touchesactive;
                    }
                    if (grabpos != null || touchesactive)
                    {
                        result = false;
                        Contacts.Add(checkblock);
                    }
                }
            }
            return(ActiveTouched ? CanFitResultConstants.CantFit_Active : result?CanFitResultConstants.CanFit : CanFitResultConstants.CantFit_Field);
        }
        protected void ApplyTheme_T(Nomino Target, int CurrentLevel)
        {
            Color baseColor = GetLevelColor(CurrentLevel);

            ApplyImages(Target, new Image[]
            {
                GetOutlinedImage(BlockOutlines.Outline_Bottom | BlockOutlines.Square_Bottom_Right | BlockOutlines.Square_Bottom_Left, baseColor),
                GetOutlinedImage(BlockOutlines.Outline_Top | BlockOutlines.Outline_Left | BlockOutlines.Outline_Bottom, baseColor),
                GetOutlinedImage(BlockOutlines.Outline_Left | BlockOutlines.Outline_Top | BlockOutlines.Outline_Right, baseColor),
                GetOutlinedImage(BlockOutlines.Outline_Bottom | BlockOutlines.Outline_Right | BlockOutlines.Outline_Top, baseColor)
            });
        }
Beispiel #10
0
        public static Nomino GetTetromino_Array(Point[][] Source, String pName)
        {
            Nomino bg = new Nomino();

            bg.SpecialName = pName;
            foreach (var bge in GetNominoEntries(Source))
            {
                bge.Block.Owner = bg;
                bg.AddBlock(bge);
            }

            return(bg);
        }
        private void ApplyImages(Nomino Target, Image[] BlockImages)
        {
            var BlockData = Target.GetBlockData();

            for (int i = 0; i < BlockData.Count; i++)
            {
                if (BlockData[i].Block is StandardColouredBlock)
                {
                    ((StandardColouredBlock)BlockData[i].Block).DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
                    ((StandardColouredBlock)BlockData[i].Block)._RotationImagesSK = (from p in GetImageRotations(BlockImages[i]) select SkiaSharp.Views.Desktop.Extensions.ToSKImage(new Bitmap(p))).ToArray();
                }
            }
        }
Beispiel #12
0
 public void Apply_T(Nomino Group, TetrisField Field, int CurrLevel)
 {
     //inset bevel
     foreach (var blockcheck in Group)
     {
         if (blockcheck.Block is StandardColouredBlock)
         {
             StandardColouredBlock scb = blockcheck.Block as StandardColouredBlock;
             scb.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
             scb._RotationImagesSK = new SKImage[] { SkiaSharp.Views.Desktop.Extensions.ToSKImage(new Bitmap(GetInsetBevel(CurrLevel))) };
             //scb.BaseImageKey = Solid_Square;
         }
     }
 }
Beispiel #13
0
 public void Apply_J(Nomino Group, TetrisField Field, int CurrLevel)
 {
     //darker outline with a middle white square.
     foreach (var blockcheck in Group)
     {
         if (blockcheck.Block is StandardColouredBlock)
         {
             StandardColouredBlock scb = blockcheck.Block as StandardColouredBlock;
             scb.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
             scb._RotationImagesSK = new SKImage[] { SkiaSharp.Views.Desktop.Extensions.ToSKImage(new Bitmap(GetDottedLight(CurrLevel))) };
             //scb.BaseImageKey = Solid_Square;
         }
     }
 }
Beispiel #14
0
        public override void ApplyRandom(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field)
        {
            PrepareTheme();
            int RandomLevel = TetrisGame.rgen.Next(25);
            Action <Nomino, TetrisField, int> SelectL = Apply_L;

            Action <Nomino, TetrisField, int>[] Types = new Action <Nomino, TetrisField, int>[]
            {
                Apply_L, Apply_J, Apply_I, Apply_O, Apply_S, Apply_Z, Apply_T
            };
            var selected = TetrisGame.Choose(Types);

            selected(Group, Field, RandomLevel);
        }
Beispiel #15
0
        public override void ApplyTheme(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field, ThemeApplicationReason Reason)
        {
            PrepareTheme();
            var LineCount = (GameHandler.Statistics is TetrisStatistics ts) ? ts.LineCount : 0;
            int CurrLevel = Field == null ? 0 : (int)(LineCount / 10);

            if (Group is Tetromino_L)
            {
                Apply_L(Group as Tetromino_L, Field, CurrLevel);
            }
            else if (Group is Tetromino_J)
            {
                Apply_J(Group as Tetromino_J, Field, CurrLevel);
            }
            else if (Group is Tetromino_I)
            {
                Apply_I(Group as Tetromino_I, Field, CurrLevel);
            }
            else if (Group is Tetromino_O)
            {
                Apply_O(Group as Tetromino_O, Field, CurrLevel);
            }
            else if (Group is Tetromino_S)
            {
                Apply_S(Group as Tetromino_S, Field, CurrLevel);
            }
            else if (Group is Tetromino_Z)
            {
                Apply_Z(Group as Tetromino_Z, Field, CurrLevel);
            }
            else if (Group is Tetromino_T)
            {
                Apply_T(Group as Tetromino_T, Field, CurrLevel);
            }
            else
            {
                foreach (var blockcheck in Group)
                {
                    if (blockcheck.Block is StandardColouredBlock)
                    {
                        StandardColouredBlock scb = blockcheck.Block as StandardColouredBlock;
                        scb.DisplayStyle = StandardColouredBlock.BlockStyle.Style_Custom;
                        TetrisGame.Choose(new Image[] { GetSolidSquare(CurrLevel), GetDottedLight(CurrLevel), GetDottedDark(CurrLevel), GetFatDotted(CurrLevel), GetInsetBevel(CurrLevel) });
                        scb._RotationImagesSK = new SKImage[] { SkiaSharp.Views.Desktop.Extensions.ToSKImage(new Bitmap(GetInsetBevel(CurrLevel))) };
                        //scb.BaseImageKey = Solid_Square;
                    }
                }
            }
        }
Beispiel #16
0
        public static Color GetStandardColor(Nomino source, int Level)
        {
            Color[] Colors   = new Color[] { Color.Cyan, Color.Yellow, Color.Purple, Color.Green, Color.Red, Color.Blue, Color.OrangeRed };
            int     useIndex = -1;

            if (source is Tetromino_I)
            {
                useIndex = 0;
            }
            else if (source is Tetromino_O)
            {
                useIndex = 1;
            }
            else if (source is Tetromino_T)
            {
                useIndex = 2;
            }
            else if (source is Tetromino_S)
            {
                useIndex = 3;
            }
            else if (source is Tetromino_Z)
            {
                useIndex = 4;
            }
            else if (source is Tetromino_J)
            {
                useIndex = 5;
            }
            else if (source is Tetromino_L)
            {
                useIndex = 6;
            }

            if (useIndex == -1)
            {
                useIndex = rg.Next(Colors.Length);
                return(Colors[useIndex]);
            }

            return(Colors[(useIndex + Level) % Colors.Length]);
        }
        public override void ApplyTheme(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field, ThemeApplicationReason Reason)
        {
            char DesiredNomino = 'I';
            Dictionary <Type, char> NominoLookup = new Dictionary <Type, char>()
            {
                { typeof(Tetromino_T), 'T' },
                { typeof(Tetromino_S), 'S' },
                { typeof(Tetromino_Z), 'Z' },
                { typeof(Tetromino_L), 'L' },
                { typeof(Tetromino_J), 'J' },
                { typeof(Tetromino_O), 'O' },
                { typeof(Tetromino_I), 'I' },
                { typeof(Tetromino_Y), 'Y' }
            };

            if (NominoLookup.ContainsKey(Group.GetType()))
            {
                DesiredNomino = NominoLookup[Group.GetType()];
            }
            else
            {
                DesiredNomino = TetrisGame.Choose(TetOrder);
            }
            foreach (var iterate in Group)
            {
                if (iterate.Block is StandardColouredBlock)
                {
                    StandardColouredBlock sbc = iterate.Block as StandardColouredBlock;
                    sbc.DisplayStyle = StandardColouredBlock.BlockStyle.Style_Custom;
                    sbc.BlockColor   = Color.Black;
                    if (Field.GetActiveBlockGroups().Contains(Group))
                    {
                        sbc._RotationImagesSK = new SKImage[] { SKImage.FromBitmap(GetUnsetImage(ColourData[Field.Level > 12 ? 12 : Field.Level].GetColor(DesiredNomino))) }
                    }
                    ;
                    else
                    {
                        sbc._RotationImagesSK = new SKImage[] { SKImage.FromBitmap(GetSetImage(ColourData[Field.Level > 12 ? 12 : Field.Level].GetColor(DesiredNomino))) };
                    }
                }
            }
        }
        public override void ApplyRandom(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field)
        {
            //choose a random level...
            int Randomlevel = TetrisGame.rgen.Next(0, 13);

            //choose a random tetromino type.
            char randomTet = TetrisGame.Choose(TetOrder.ToCharArray());

            //get the image for it

            foreach (var iterate in Group)
            {
                if (iterate.Block is StandardColouredBlock)
                {
                    StandardColouredBlock sbc = iterate.Block as StandardColouredBlock;
                    sbc.DisplayStyle      = StandardColouredBlock.BlockStyle.Style_Custom;
                    sbc._RotationImagesSK = new SKImage[] { SKImage.FromBitmap(GetSetImage(ColourData[Randomlevel].GetColor(randomTet))) };
                }
            }
        }
        public override void ApplyTheme(Nomino Group, IGameCustomizationHandler handler, TetrisField Field, ThemeApplicationReason Reason)
        {
            var LineCount = (handler.Statistics is TetrisStatistics ts) ? ts.LineCount : 0;
            int CurrLevel = Field == null ? 0 : (int)(LineCount / 10);

            if (Group is Tetromino_I)
            {
                ApplyTheme_I(Group, CurrLevel);
            }
            else if (Group is Tetromino_J)
            {
                ApplyTheme_J(Group, CurrLevel);
            }
            else if (Group is Tetromino_L)
            {
                ApplyTheme_L(Group, CurrLevel);
            }
            else if (Group is Tetromino_O)
            {
                ApplyTheme_O(Group, CurrLevel);
            }
            else if (Group is Tetromino_S)
            {
                ApplyTheme_S(Group, CurrLevel);
            }
            else if (Group is Tetromino_Z)
            {
                ApplyTheme_Z(Group, CurrLevel);
            }
            else if (Group is Tetromino_T)
            {
                ApplyTheme_T(Group, CurrLevel);
            }
            else
            {
                ApplyImages(Group, new Image[] { GetOutlinedImage(BlockOutlines.Outline_Bottom | BlockOutlines.Outline_Top | BlockOutlines.Outline_Right | BlockOutlines.Outline_Left, GetLevelColor(CurrLevel)) });
            }
        }
Beispiel #20
0
        private void ApplyColorSet(Nomino bg, int Level)
        {
            if (bg == null)
            {
                return;
            }

            if (UseStyles == null)
            {
                UseStyles = GetBlockStyleLookup(new Type[] { typeof(Tetromino_I), typeof(Tetromino_J), typeof(Tetromino_L), typeof(Tetromino_O), typeof(Tetromino_S), typeof(Tetromino_T), typeof(Tetromino_Z), typeof(Tetromino_Y) });
            }
            StandardColouredBlock.BlockStyle applystyle = _Style;
            if (UseStyles.ContainsKey(bg.GetType()))
            {
                applystyle = UseStyles[bg.GetType()];
            }

            foreach (var iterate in bg)
            {
                if (iterate.Block is StandardColouredBlock)
                {
                    StandardColouredBlock bl = iterate.Block as StandardColouredBlock;


                    bl.DisplayStyle = applystyle; //TetrisGame.Choose(new StandardColouredBlock.BlockStyle[] { StandardColouredBlock.BlockStyle.Style_HardBevel, StandardColouredBlock.BlockStyle.Style_CloudBevel, StandardColouredBlock.BlockStyle.Style_Shine });
                    Color useColor = GetStandardColor(bg, Level);
                    bl.BlockColor = bl.InnerColor = useColor;

                    /*QColorMatrix qc = new QColorMatrix();
                     * qc.RotateHue(Level * 50);
                     *
                     * useColor = HSLColor.RotateHue(useColor, Level * 50);
                     * bl.BlockColor = bl.InnerColor = useColor;
                     */
                }
            }
        }
Beispiel #21
0
 public abstract void ApplyRandom(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field);
Beispiel #22
0
        public override void ApplyRandom(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field)
        {
            int useLevel = TetrisGame.rgen.Next(50);

            ApplyColorSet(Group, useLevel);
        }
Beispiel #23
0
 public OnRemoveActiveBlockGroupEventArgs(Nomino RemovingGroup)
 {
     BlockGroupRemove = RemovingGroup;
 }
Beispiel #24
0
 public virtual String GetNominoKey(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field)
 {
     return(GetNominoTypeKey(Group.GetType(), GameHandler, Field));
 }
Beispiel #25
0
 public abstract void ApplyTheme(Nomino Group, IGameCustomizationHandler GameHandler, TetrisField Field, ThemeApplicationReason Reason);
        public override void ApplyRandom(Nomino Group, IGameCustomizationHandler Handler, TetrisField Field)
        {
            int LevelUse = TetrisGame.rgen.Next(10);

            ApplyImages(Group, new Image[] { GetOutlinedImage(BlockOutlines.Outline_Bottom | BlockOutlines.Outline_Top | BlockOutlines.Outline_Right | BlockOutlines.Outline_Left, GetLevelColor(LevelUse)) });
        }