Beispiel #1
0
 public void Reset()
 {
     Appearence.Reset();
     Analysis.Reset();
     Report.Reset();
     Logger.Reset();
 }
Beispiel #2
0
 public void Validate()
 {
     Appearence.Validate();
     Analysis.Validate();
     Report.Validate();
     Logger.Validate();
 }
Beispiel #3
0
        public Breed(
            string name, Pronoun pronoun, Glyph glyph,
            List <Attack> attacks, List <Move> moves,
            Drop drop,
            int maxHealth,
            int tracking,
            int meander,
            int speed,
            List <string> flags,
            string slug)
        {
            this.name = name;
            Pronoun   = pronoun;

            Appearance = new Appearence {
                Glyph = glyph.Appearance, ForeGroundColor = glyph.Fore, Slug = slug, Type = AppearenceType.Monster
            };

            Attacks   = attacks;
            Moves     = moves;
            Drop      = drop;
            MaxHealth = maxHealth;
            Tracking  = tracking;
            Meander   = meander;
            Speed     = speed;
            Flags     = flags;

            if (Flags.Contains(""))
            {
                throw new ArgumentException();
            }
        }
Beispiel #4
0
        public void SaveToConfigFile()
        {
            // Internal models should call Validate method themself
            // because SaveToConfigFile can be called for separate model too.

            Appearence.SaveToConfigFile();
            Analysis.SaveToConfigFile();
            Report.SaveToConfigFile();
            Logger.SaveToConfigFile();
        }
Beispiel #5
0
        public Appearence CalculateAppearence(string id)
        {
            var parsedId = ParseLetters(id);

            var result = new Appearence
            {
                ContainsThree = parsedId.Any(s => s.Value == 3),
                ContainsTwo   = parsedId.Any(s => s.Value == 2)
            };

            return(result);
        }
Beispiel #6
0
        public void Fill(string glyph, ConsoleColor foreGroundColor, ConsoleColor backGroundColor)
        {
            var appearance = new Appearence {
                Glyph = glyph, ForeGroundColor = foreGroundColor.ToString(), BackGroundColor = backGroundColor.ToString()
            };

            var numberOfElementsInBuffer = Width * Height;

            for (var i = 0; i < numberOfElementsInBuffer; i++)
            {
                Buffer[i].Attributes = ConvertColors(appearance);
                Buffer[i].AsciiChar  = Convert.ToByte(appearance.Glyph[0]);
            }
        }
Beispiel #7
0
        public void Draw(Appearence source, int x, int y)
        {
            var bufferIndex = y * Width + x;

            Buffer[bufferIndex].Attributes = ConvertColors(source);
            if (source.Glyph[0] > 255)
            {
                int problemByte   = source.Glyph[0];
                var unicodeString = "\\u" + problemByte.ToString("X").PadLeft(4, '0');
                var unicodeChar   = Convert.ToChar(problemByte);

                Buffer[bufferIndex].UnicodeChar = unicodeChar;
            }
            else
            {
                Buffer[bufferIndex].AsciiChar = Convert.ToByte(source.Glyph[0]);
            }
        }
Beispiel #8
0
        public void Write(string message, int x, int y, ConsoleColor foreGroundColor = ConsoleColor.White, ConsoleColor backGroundColor = ConsoleColor.Black)
        {
            if (message == null)
            {
                return;
            }

            var offsetX = 0;

            foreach (var character in message)
            {
                var appearence = new Appearence {
                    Glyph = character.ToString(), ForeGroundColor = foreGroundColor.ToString(), BackGroundColor = backGroundColor.ToString()
                };

                Draw(appearence, x + offsetX, y);

                offsetX++;
            }
        }
Beispiel #9
0
        public Appearence GetTileAppearence(int columnIndex, int rowIndex)
        {
            Appearence tile = null;

            // Is the tile visible
            var currentTile = Tiles[columnIndex, rowIndex];

            // Is there an actor at that position?
            bool isHandled = false;
            var  actor     = _actorsByTile[columnIndex, rowIndex];

            if (actor != null)
            {
                if (actor is Hero)
                {
                    var hero = actor as Hero;
                    tile      = hero.Appearance;
                    isHandled = true;
                }
                else if (actor is Monster)
                {
                    var distanceToHero = (GameState.Instance.Game.Hero.Position - actor.Position).kingLength();
                    if (distanceToHero <= Option.HeroSightRange || Option.ShowAll)
                    {
                        var monster = actor as Monster;
                        tile      = monster.Appearance;
                        isHandled = true;
                    }
                }
                else
                {
                    throw new ApplicationException("have not cast the appearance of the actor");
                }
            }

            if (isHandled == false)
            {
                if (currentTile.Type == null)
                {
                    tile = new Appearence {
                        Glyph = "."
                    };
                }
                else if (currentTile.Type.IsWall)
                {
                    tile = new Appearence {
                        Glyph = currentTile.Type.DebugCharacter, ForeGroundColor = currentTile.Type.Appearance.Fore
                    };
                }
                else if (currentTile.Type.Name == "floor")
                {
                    tile = new Appearence {
                        Glyph = "."
                    };
                }
                else if (currentTile.Type.Name == "grass")
                {
                    tile = new Appearence {
                        Glyph = ".", ForeGroundColor = currentTile.Type.Appearance.Fore
                    };
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(currentTile.Type.DebugCharacter))
                    {
                        tile = new Appearence {
                            Glyph = currentTile.Type.DebugCharacter, ForeGroundColor = currentTile.Type.Appearance.Fore
                        };
                    }
                    else
                    {
                        tile = new Appearence {
                            Glyph = currentTile.Type.Name[0].ToString(), ForeGroundColor = currentTile.Type.Appearance.Fore
                        };
                    }
                }
            }

            if (tile == null)
            {
                System.Diagnostics.Debugger.Break();
            }

            tile.Position = new VectorBase(columnIndex, rowIndex);

            return(tile);
        }
Beispiel #10
0
        private Appearence[,] BuildAppearance()
        {
            var debugger = Debugger.Instance;
            var message  = string.Empty;

            var appearanceMatrix = new Appearence[Width, Height];

            for (var rowIndex = 0; rowIndex < Height; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < Width; columnIndex++)
                {
                    var appearance = GetTileAppearence(columnIndex, rowIndex);
                    appearanceMatrix[columnIndex, rowIndex] = appearance.Clone();
                }
            }

            CheckPositionsForMatrix(appearanceMatrix, "After Initial Creation");

            foreach (var item in Items)
            {
                // Only show items if the actor is not on top of the item
                var actor = _actorsByTile[item.Position.x, item.Position.y];
                if (actor == null)
                {
                    if (item is Item)
                    {
                        var appearance = item.Appearance;
                        if (appearance == null)
                        {
                            System.Diagnostics.Debugger.Break();
                        }
                        appearanceMatrix[item.Position.x, item.Position.y] = appearance;
                    }
                }
            }
            CheckPositionsForMatrix(appearanceMatrix, "After Item Inclusion");

            for (var rowIndex = 0; rowIndex < Height; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < Width; columnIndex++)
                {
                    var appearance = appearanceMatrix[columnIndex, rowIndex];
                    var tile       = Tiles[columnIndex, rowIndex];
                    var shadow     = Shadows[columnIndex, rowIndex];

                    appearance.IsExplored = tile.IsExplored;

                    // Basically if they are standing on a tile that
                    // has yet to be explored then they
                    // must be hidden
                    if (!tile.IsExplored)
                    {
                        appearance.IsHidden = true;
                    }

                    appearance.IsInShadow = shadow.IsInShadow;

                    var actor = _actorsByTile[columnIndex, rowIndex];
                    if (actor != null)
                    {
                        if (actor is Monster)
                        {
                            //message =
                            //   $"[{columnIndex.ToString().PadLeft(2, '0')},{rowIndex.ToString().PadLeft(2, '0')}]" +
                            //   $" s = [{shadow.IsInShadow.ToString()[0]}]" +
                            //   $" t(e) [{tile.IsExplored.ToString()[0]}]" +
                            //   $" a(e/h/s) [{appearance.IsExplored.ToString()[0]}/{appearance.IsHidden.ToString()[0]}/{appearance.IsInShadow.ToString()[0]}]" +
                            //   $" [{appearance.Position.x.ToString().PadLeft(2, '0')},{appearance.Position.y.ToString().PadLeft(2, '0')}]";

                            //debugger.Info(message);
                        }
                    }
                }
            }

            CheckPositionsForMatrix(appearanceMatrix, "After Hidding / Shadow Logic");

            return(appearanceMatrix);
        }
Beispiel #11
0
        private Appearence[,] AddRulers(Appearence[,] rawTileAppearances)
        {
            var ruledAppearances = new Appearence[Width + 3, Height + 2];

            for (var rowIndex = 0; rowIndex < Height + 2; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < Width + 3; columnIndex++)
                {
                    ruledAppearances[columnIndex, rowIndex] = new Appearence {
                        Glyph = " ", IsExplored = true, IsHidden = false, IsInShadow = false
                    };
                }
            }

            for (var rowIndex = 0; rowIndex < Height; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < Width; columnIndex++)
                {
                    if (rowIndex == 0)
                    {
                        if (columnIndex % 10 == 0)
                        {
                            ruledAppearances[columnIndex + 3, rowIndex] = new Appearence {
                                Glyph = Math.Floor((double)columnIndex / 10).ToString(), IsExplored = true, IsHidden = false, IsInShadow = false
                            };
                        }

                        ruledAppearances[columnIndex + 3, rowIndex + 1] = new Appearence {
                            Glyph = (columnIndex % 10).ToString(), IsExplored = true, IsHidden = false, IsInShadow = false
                        };

                        ruledAppearances[columnIndex + 3, rowIndex + 2] = new Appearence {
                            Glyph = " ", IsExplored = true, IsHidden = false, IsInShadow = false
                        };
                    }

                    if (columnIndex == 0)
                    {
                        if (rowIndex % 10 == 0)
                        {
                            ruledAppearances[columnIndex, rowIndex + 2] = new Appearence {
                                Glyph = Math.Floor((double)rowIndex / 10).ToString(), IsExplored = true, IsHidden = false, IsInShadow = false
                            };
                        }

                        ruledAppearances[columnIndex + 1, rowIndex + 2] = new Appearence {
                            Glyph = (rowIndex % 10).ToString(), IsExplored = true, IsHidden = false, IsInShadow = false
                        };

                        //ruledAppearances[columnIndex + 2, rowIndex + 3] = new Appearence()
                        //{
                        //    Glyph = " ",
                        //    IsExplored = true,
                        //    IsHidden = false,
                        //    IsInShadow = false
                        //};
                    }

                    ruledAppearances[columnIndex + 3, rowIndex + 2] = rawTileAppearances[columnIndex, rowIndex].Clone();
                }
            }
            return(ruledAppearances);
        }
Beispiel #12
0
        private Appearence[,] GetMatrixViewPort()
        {
            var matrixWidth  = Tiles.GetUpperBound(0) + 1;
            var matrixHeight = Tiles.GetUpperBound(1) + 1;

            // This is to ensure that the view port is not bigger than the size of the tile matrix
            var adjustedViewPost = new Rect(0, 0, Math.Min(matrixWidth, ViewPort.width), Math.Min(matrixHeight, ViewPort.height));

            int halfViewPortWidth  = (int)Math.Floor((double)adjustedViewPost.width / 2);
            int halfViewPortHeight = (int)Math.Floor((double)adjustedViewPost.height / 2);

            // Adjustments for the x axis
            int viewPortLeft = HeroPosition.x - halfViewPortWidth;

            if (viewPortLeft + adjustedViewPost.width > matrixWidth)
            {
                viewPortLeft = matrixWidth - adjustedViewPost.width;
            }
            if (viewPortLeft < 0)
            {
                viewPortLeft = 0;
            }

            // Adjuments for the y axis
            int viewPortTop = HeroPosition.y - halfViewPortHeight;

            if (viewPortTop + adjustedViewPost.height > matrixHeight)
            {
                viewPortTop = matrixHeight - adjustedViewPost.height;
            }
            if (viewPortTop < 0)
            {
                viewPortTop = 0;
            }

            var alteredViewPortMatrix = new Appearence[adjustedViewPost.width, adjustedViewPost.height];

            for (var rowIndex = 0; rowIndex < adjustedViewPost.height; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < adjustedViewPost.width; columnIndex++)
                {
                    int sourceColumnIndex = columnIndex + viewPortLeft;
                    int sourceRowIndex    = rowIndex + viewPortTop;
                    // make sure the rulers are in the view port
                    if (rowIndex < 2)
                    {
                        sourceRowIndex = rowIndex;
                    }

                    if (columnIndex < 3)
                    {
                        sourceColumnIndex = columnIndex;
                    }

                    var currentTile = Tiles[sourceColumnIndex, sourceRowIndex];
                    alteredViewPortMatrix[columnIndex, rowIndex] = currentTile.Clone();
                }
            }

            return(alteredViewPortMatrix);;
        }
Beispiel #13
0
        private Appearence[,] GetMatrixViewPort(Appearence[,] source, VectorBase heroPosition)
        {
            var matrixWidth  = source.GetUpperBound(0) + 1;
            var matrixHeight = source.GetUpperBound(1) + 1;

            // This is to ensure that the view port is not bigger than the size of the tile matrix
            var adjustedViewPost = new Rect(0, 0, Math.Min(matrixWidth, ViewPort.width), Math.Min(matrixHeight, ViewPort.height));

            int halfViewPortWidth  = (int)Math.Floor((double)adjustedViewPost.width / 2);
            int halfViewPortHeight = (int)Math.Floor((double)adjustedViewPost.height / 2);

            // Adjustments for the x axis
            int viewPortLeft = heroPosition.x - halfViewPortWidth;

            if (viewPortLeft + adjustedViewPost.width > matrixWidth)
            {
                viewPortLeft = matrixWidth - adjustedViewPost.width;
            }
            if (viewPortLeft < 0)
            {
                viewPortLeft = 0;
            }

            // Adjuments for the y axis
            int viewPortTop = heroPosition.y - halfViewPortHeight;

            if (viewPortTop + adjustedViewPost.height > matrixHeight)
            {
                viewPortTop = matrixHeight - adjustedViewPost.height;
            }
            if (viewPortTop < 0)
            {
                viewPortTop = 0;
            }

            var ascii = new ASCII();

            var alteredViewPortMatrix = new Appearence[adjustedViewPost.width, adjustedViewPost.height];

            for (var rowIndex = 0; rowIndex < adjustedViewPost.height; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < adjustedViewPost.width; columnIndex++)
                {
                    int sourceColumnIndex = columnIndex + viewPortLeft;
                    int sourceRowIndex    = rowIndex + viewPortTop;
                    // make sure the rulers are in the view port
                    if (rowIndex < 2)
                    {
                        sourceRowIndex = rowIndex;
                    }

                    if (columnIndex < 3)
                    {
                        sourceColumnIndex = columnIndex;
                    }

                    var currentTile = source[sourceColumnIndex, sourceRowIndex].Clone();
                    alteredViewPortMatrix[columnIndex, rowIndex] = currentTile.Clone();

                    // Mark the Current Target
                    if (Target != null)
                    {
                        if (
                            (Target.Position.x - 1 + 3 == sourceColumnIndex && Target.Position.y + 2 == sourceRowIndex) ||
                            (Target.Position.x + 1 + 3 == sourceColumnIndex && Target.Position.y + 2 == sourceRowIndex)
                            )
                        {
                            alteredViewPortMatrix[columnIndex, rowIndex].ForeGroundColor = "LightGold";
                            alteredViewPortMatrix[columnIndex, rowIndex].Glyph           = "-";
                        }
                        if (
                            (Target.Position.x + 3 == sourceColumnIndex && Target.Position.y - 1 + 2 == sourceRowIndex) ||
                            (Target.Position.x + 3 == sourceColumnIndex && Target.Position.y + 1 + 2 == sourceRowIndex)
                            )
                        {
                            alteredViewPortMatrix[columnIndex, rowIndex].Glyph           = "|";
                            alteredViewPortMatrix[columnIndex, rowIndex].ForeGroundColor = "LightGold";
                        }

                        if (Game.CurrentStage.getHeroDistanceTo(currentTile.Position) > Range)
                        {
                            alteredViewPortMatrix[columnIndex, rowIndex].ForeGroundColor = "Red";
                        }
                    }
                }
            }

            return(alteredViewPortMatrix);;
        }
Beispiel #14
0
 public short ConvertColors(Appearence source)
 {
     return((short)(ConvertColour(source.ForeGroundColor) | (ConvertColour(source.BackGroundColor) << 4)));
 }