Exemplo n.º 1
0
        public static Aknamezo Generate(int height, int width, int mines)
        {
            Aknamezo.mezo[,] Out = new Aknamezo.mezo[height, width];
            int    mineCount = 0;
            Random rand      = new Random();

            while (mineCount < mines)
            {
                var pos = new Tuple <int, int>(rand.Next(height), rand.Next(width));
                if (Out[pos.Item1, pos.Item2].value == -1)
                {
                    continue;
                }
                Out[pos.Item1, pos.Item2].value = -1;
                ++mineCount;
                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; ++j)
                    {
                        try
                        {
                            if (Out[pos.Item1 + i, pos.Item2 + j].value != -1)
                            {
                                ++Out[pos.Item1 + i, pos.Item2 + j].value;
                            }
                        }
                        catch {
                        }
                    }
                }
            }
            Aknamezo retval = new Aknamezo(Out);

            return(retval);
        }
Exemplo n.º 2
0
        public static Aknamezo Load(string path)
        {
            StreamReader f = new StreamReader(path);

            string[] s = f.ReadLine().Split(';');
            int      m = int.Parse(s[0]);
            int      n = int.Parse(s[1]);

            Aknamezo.mezo[,] Out = new Aknamezo.mezo[m, n];
            for (int i = 0; i < m; i++)
            {
                s = f.ReadLine().Split(';');
                for (int j = 0; j < n; j++)
                {
                    string[] seg = s[j].Split(',');
                    Out[i, j].value   = int.Parse(seg[0]);
                    Out[i, j].visible = bool.Parse(seg[1]);
                    Out[i, j].flagged = bool.Parse(seg[2]);
                }
            }
            Aknamezo BeviteliAknamezo = new Aknamezo(Out);

            f.Close();
            return(BeviteliAknamezo);
        }