Exemplo n.º 1
0
        public DNA CreateChildDNA(Character character, DNA father, DNA mother, Game game)
        {
            int face = SelectRandomAllowed(faceImages, character, father.Face, mother.Face, game);
            int mouth = SelectRandomAllowed(mouthImages, character, father.Mouth, mother.Mouth, game);
            int nose = SelectRandomAllowed(noseImages, character, father.Nose, mother.Nose, game);
            int eyes = SelectRandomAllowed(eyeImages, character, father.Eyes, mother.Eyes, game);
            int eyebrows = SelectRandomAllowed(eyebrowImages, character, father.Eyebrows, mother.Eyebrows, game);
            int ears = SelectRandomAllowed(earImages, character, father.Ears, mother.Ears, game);
            int hair = SelectRandomAllowed(hairImages, character, father.Hair, mother.Hair, game);
            int skinColor = SelectRandomAllowedColor(skinColors, character, father.SkinColor, mother.SkinColor, game);
            int eyeColor = SelectRandomAllowedColor(eyeColors, character, father.EyeColor, mother.EyeColor, game);
            int hairColor = SelectRandomAllowedColor(hairColors, character, father.HairColor, mother.HairColor, game);
            int shirtColor = CharacterVisualizationManager.GetRandomShirtColor(game);

            return new DNA(face, mouth, nose, eyes, eyebrows, ears, hair, skinColor, eyebrows, hairColor, shirtColor);
        }
Exemplo n.º 2
0
        public Bitmap ComposeFace(DNA dna)
        {
            Bitmap output;
            if(!cache.TryGetValue(dna, out output))
            {
                output = new Bitmap(96, 96);
                using (Graphics G = Graphics.FromImage(output))
                {
                    G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                    G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                    G.DrawImage(faceImages[dna.Face].Bitmap, 0, 0);
                    G.DrawImage(mouthImages[dna.Mouth].Bitmap, 0, 0);
                    G.DrawImage(noseImages[dna.Nose].Bitmap, 0, 0);
                    G.DrawImage(eyeImages[dna.Eyes].Bitmap, 0, 0);
                    G.DrawImage(eyebrowImages[dna.Eyebrows].Bitmap, 0, 0);
                    G.DrawImage(earImages[dna.Ears].Bitmap, 0, 0);
                    G.DrawImage(hairImages[dna.Hair].Bitmap, 0, 0);
                }
                output = ReplaceColors(output, dna);
                cache.Add(dna, output);
            }

            return output;
        }
Exemplo n.º 3
0
        public void AssignFamily(Character spouse, List<Character> children, Room home, DNA husbandDna, DNA wifeDna)
        {
            DNA = husbandDna;
            Home = home;
            Spouse = spouse;
            spouse.Spouse = this;
            spouse.DNA = wifeDna;
            Children = new List<Character>(children);
            spouse.Children = new List<Character>(children);
            CharacterLog("Created family for " + Name + " with spouse: " + spouse.Name + " and children: " + string.Join(", ", children.Select(c => c.Name + "(" + c.Gender.ToString() + ")")));

            //Assign the home to the dependents as well.
            spouse.Home = home;
            foreach(var c in children)
            {
                c.Home = home;
                c.Father = this;
                c.Mother = spouse;
                c.DNA = Game.CreateChildDNA(c, husbandDna, wifeDna);
            }
        }
Exemplo n.º 4
0
 public DNA CreateRandomDNA(Character character, Game game)
 {
     DNA dna = new DNA(SelectRandomAllowed(faceImages, character, game),
         SelectRandomAllowed(mouthImages, character, game), SelectRandomAllowed(noseImages, character, game),
         SelectRandomAllowed(eyeImages, character, game), SelectRandomAllowed(eyebrowImages, character, game),
         SelectRandomAllowed(earImages, character, game), SelectRandomAllowed(hairImages, character, game),
         game.GetRandom(skinColors.Length), game.GetRandom(eyeColors.Length), game.GetRandom(hairColors.Length), game.GetRandom(shirtColors.Length));
     return dna;
 }
Exemplo n.º 5
0
        // Returns a new bitmap created by copying originalImage and replacing all
        // HAIR_PIXEL, SKIN_PIXEL and EYE_PIXEL colors found with the appropriate
        // color from the DNA.
        private Bitmap ReplaceColors(Bitmap originalImage, DNA dna)
        {
            Bitmap result = new Bitmap(originalImage);
            for (int x = 0; x < result.Width; x++)
            {
                for (int y = 0; y < result.Height; y++)
                {
                    // Change the color to new color if it matches,
                    // otherwise just keep going.
                    // I read somewhere that GetPixel was slow so maybe
                    // we want to find a faster way to do this?
                    Color originalPixel = originalImage.GetPixel(x, y);

                    if (originalPixel == SKIN_PIXEL)
                    {
                        result.SetPixel(x, y, skinColors[dna.SkinColor]);
                    }
                    else if (originalPixel == HAIR_PIXEL)
                    {
                        result.SetPixel(x, y, hairColors[dna.HairColor]);
                    }
                    else if (originalPixel == EYE_PIXEL)
                    {
                        result.SetPixel(x, y, eyeColors[dna.EyeColor]);
                    }
                    else if (originalPixel == SHIRT_PIXEL)
                    {
                        result.SetPixel(x, y, shirtColors[dna.ShirtColor]);
                    }
                }
            }
            return result;
        }
Exemplo n.º 6
0
 public Bitmap GetPortrait(DNA dna)
 {
     return cvManager.ComposeFace(dna);
 }
Exemplo n.º 7
0
 public DNA CreateChildDNA(Character character, DNA father, DNA mother)
 {
     return cvManager.CreateChildDNA(character, father, mother, this);
 }