Beispiel #1
0
    //permet de lire les pixels d'un image et d'en extraire les composantes rgb
    public void ImageRead(string name)
    {
        Bitmap  bitmap = new Bitmap(name);
        int     sizeW  = bitmap.Width;
        int     sizeH  = bitmap.Height;
        CodeRGB id;

        for (int i = 0; i < sizeW; i++)
        {
            for (int j = 0; j < sizeH; j++)
            {
                Color clr = bitmap.GetPixel(j, i);
                byte  R   = clr.R;
                byte  G   = clr.G;
                byte  B   = clr.B;
                byte  A   = clr.A;
                id = new CodeRGB(R, G, B);

                if (index.ContainsKey(id) == true)
                {
                    Console.WriteLine("le pixel correspond à " + index[id] + " dans la base de données");
                    Console.WriteLine("la ligne du pixel est " + i + " et sa colonne est " + j);
                    Console.WriteLine(" -> R: " + R + " G: " + G + " B: " + B + " A: " + A);
                }
            }
        }
    }
Beispiel #2
0
    //permet de lire un index d'objets dans un fichier txt
    public Dictionary <CodeRGB, string> readLibrary(string name)
    {
        Dictionary <CodeRGB, string> code = new Dictionary <CodeRGB, string>();
        CodeRGB transition;
        string  nom;

        // Example #2
        // Read each line of the file into a string array. Each element
        // of the array is one line of the file.
        Console.WriteLine(name);
        string[] lines = name.Split('\n');

        // Display the file contents by using a foreach loop.
        //Console.WriteLine("Contents of WriteLines2.txt = ");
        foreach (string line in lines)
        {
            transition = new CodeRGB(line);
            nom        = line;
            int position = nom.IndexOf(" ");
            nom      = nom.Substring(position + 1);
            position = nom.IndexOf(" ");
            nom      = nom.Substring(position + 1);
            position = nom.IndexOf(" ");
            nom      = nom.Substring(position + 1);
            code.Add(transition, nom);
            // Use a tab to indent each line of the file.
            //Console.WriteLine("\t" + nom);
        }


        return(code);
    }
Beispiel #3
0
    //permet d'implémenter la comparaison entre deux objets rbg
    public int CompareTo(object obj)
    {
        if (obj == null)
        {
            return(1);
        }

        CodeRGB otherCode = obj as CodeRGB;

        if (otherCode != null)
        {
            if (this.red != otherCode.red)
            {
                return(this.red.CompareTo(otherCode.red));
            }
            else if (this.green != otherCode.green)
            {
                return(this.green.CompareTo(otherCode.green));
            }
            else
            {
                return(this.blue.CompareTo(otherCode.blue));
            }
        }

        else
        {
            throw new ArgumentException("Object is not a CodeRGB");
        }
    }
Beispiel #4
0
    //lit une image précedemment utilisée pour initialiser les salles pour remplir les salles d'objets
    public void fillRoom(Bitmap image)
    {
        int   xStart;
        int   yStart;
        int   width;
        int   height;
        Color clr;
        byte  R;
        byte  G;
        byte  B;

        foreach (Salle room in floor)
        {
            //Console.WriteLine("Parcours de la salle n°" + room.getId_salle());
            width  = (int)room.getContour().GetLongueurRectangle();
            height = (int)room.getContour().GetLargeurRectangle();
            xStart = (int)room.getContour().getUsefulPoint().getAbscisse();
            yStart = (int)room.getContour().getUsefulPoint().getOrdonnee();
            for (int i = 1; i < height; i++)
            {
                for (int j = 1; j < width; j++)
                {
                    clr = image.GetPixel(xStart + j, yStart + i);
                    R   = clr.R;
                    G   = clr.G;
                    B   = clr.B;
                    CodeRGB idObject = new CodeRGB(R, G, B);


                    if (index.ContainsKey(idObject) && index[idObject] != "vide de gimp")
                    {
                        //Console.WriteLine("x: " + (xStart + j) + " y: " + (yStart + i) + " l'objet est un : " + index[idObject]);
                        float     abscisse_rel = j;
                        float     ordonnee_rel = i;
                        float     abscisse_abs = xStart + j;
                        float     ordonnee_abs = yStart + i;
                        int       entity_type;
                        int       shape_type;
                        string    nom;
                        short     id;
                        bool      passThrough;
                        Rectangle rec;
                        string[]  info = index[idObject].Split('|');
                        nom         = info[0];
                        entity_type = Int32.Parse(info[1]);
                        id          = Int16.Parse(info[2]);
                        shape_type  = Int32.Parse(info[3]);
                        int string_index = 3;
                        rec = new Rectangle();
                        switch (shape_type)
                        {
                        case 0:
                            rec.setPoint(new Point(abscisse_rel, ordonnee_rel));
                            rec.SetLongueurRectangle(Int32.Parse(info[++string_index]));
                            rec.SetLargeurRectangle(Int32.Parse(info[++string_index]));

                            break;
                        }
                        if (Int32.Parse(info[++string_index]) == 0)
                        {
                            passThrough = false;
                        }
                        else
                        {
                            passThrough = true;
                        }

                        switch (entity_type)
                        {
                        case 0:

                            Decor bob = new Decor(nom, id, rec.GetPointRectangle(), rec.GetLongueurRectangle(), rec.GetLargeurRectangle(), new Point(), passThrough, 0);
                            bob.AbsoluteCoordinate = new Point(abscisse_abs, ordonnee_abs);
                            //bob.AfficherDecor();
                            room.Elements.Add(bob);

                            break;
                        }
                    }
                }
            }
            room.AfficherContenueSalle();
        }
    }
Beispiel #5
0
    //permet d'ajouter des salles avec leur nombre de portes associées dans un monde à partir d'une image
    public void ImageReadSalle2(Bitmap bitmap)
    {
        int     sizeW = bitmap.Width;
        int     sizeH = bitmap.Height;
        CodeRGB id;
        int     longueur = 0;
        int     largeur  = 0;
        int     xB       = 0;
        int     yB       = 0;
        Color   clr;
        byte    R;
        byte    G;
        byte    B;

        for (int i = 0; i < sizeW; i++)
        {
            for (int j = 0; j < sizeH; j++)
            {
                clr = bitmap.GetPixel(j, i);
                R   = clr.R;
                G   = clr.G;
                B   = clr.B;
                id  = new CodeRGB(R, G, B);
                int compteurportes = 0;

                if (index.ContainsKey(id) == true)
                {
                    if (index[id] == "salle beacon")
                    {
                        xB = j;
                        yB = i;
                        while (index[id] != "corner")
                        {
                            j++;
                            clr = bitmap.GetPixel(j, i);
                            R   = clr.R;
                            G   = clr.G;
                            B   = clr.B;
                            id  = new CodeRGB(R, G, B);
                            if (index[id] == "porte")
                            {
                                ++compteurportes;
                            }
                        }
                        longueur = j;
                        i++;
                        clr = bitmap.GetPixel(j, i);
                        R   = clr.R;
                        G   = clr.G;
                        B   = clr.B;
                        id  = new CodeRGB(R, G, B);
                        while (index[id] != "corner")
                        {
                            i++;
                            clr = bitmap.GetPixel(j, i);
                            R   = clr.R;
                            G   = clr.G;
                            B   = clr.B;
                            id  = new CodeRGB(R, G, B);
                            if (index[id] == "porte")
                            {
                                ++compteurportes;
                            }
                        }

                        largeur = i;

                        j--;
                        clr = bitmap.GetPixel(j, i);
                        R   = clr.R;
                        G   = clr.G;
                        B   = clr.B;
                        id  = new CodeRGB(R, G, B);
                        while (index[id] != "corner")
                        {
                            j--;
                            clr = bitmap.GetPixel(j, i);
                            R   = clr.R;
                            G   = clr.G;
                            B   = clr.B;
                            id  = new CodeRGB(R, G, B);
                            if (index[id] == "porte")
                            {
                                ++compteurportes;
                            }
                        }


                        i--;
                        clr = bitmap.GetPixel(j, i);
                        R   = clr.R;
                        G   = clr.G;
                        B   = clr.B;
                        id  = new CodeRGB(R, G, B);
                        while (index[id] != "salle beacon")
                        {
                            i--;
                            clr = bitmap.GetPixel(j, i);
                            R   = clr.R;
                            G   = clr.G;
                            B   = clr.B;
                            id  = new CodeRGB(R, G, B);
                            if (index[id] == "porte")
                            {
                                ++compteurportes;
                            }
                        }


                        Point test = new Point(longueur, largeur);
                        this.floor.Add(new Salle((nbSalles), new Point(xB, yB), test, compteurportes));
                        //Console.WriteLine("ajout de la salle n° " + nbSalles);
                        nbSalles++;
                        j = xB;
                        i = yB;
                    }
                }
            }
        }
    }
Beispiel #6
0
    //permet d'implémenter la comparaison entre deux objets rbg
    public override bool Equals(object obj)
    {
        CodeRGB other = obj as CodeRGB;

        return(other != null && other.red == this.red && other.green == this.green && other.blue == this.blue);
    }