Exemplo n.º 1
0
        public void zufallsAktion(A_Mann a)
        {
            int actions = r.Next(0, 4);

            switch (actions)
            {
            case 0:
                if (a.x > 0)
                {
                    a.x = x - 1;    //nach oben (rows)
                }
                else
                {
                }
                break;

            case 1:
                if (a.x < 9)
                {
                    a.x = x + 1;     //nachunten (rows)
                }
                else
                {
                }
                break;

            case 2:
                if (a.y > 0)
                {
                    a.y = y - 1;     //nach links
                }
                else
                {
                }
                break;

            case 3:
                if (a.y < 9)
                {
                    a.y = y + 1;
                }
                else
                {
                }
                break;
            }
        }
Exemplo n.º 2
0
 public void Gruessen(A_Mann a)
 {
     Console.WriteLine("Hallo  " + a.name);
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            int[,] spielfeld = new int[10, 10];

            Random rnd   = new Random(Guid.NewGuid().GetHashCode());
            var    nums  = Enumerable.Range(0, 10).ToArray();
            var    numsb = Enumerable.Range(0, 10).ToArray();

            // Shuffle the array
            for (int i = 0; i < 5; ++i)
            {
                int randomIndex = rnd.Next(nums.Length);
                int temp        = nums[randomIndex];
                nums[randomIndex] = nums[i];
                nums[i]           = temp;
            }
            // Now your     WriteLine(nums[i]);
            var a1 = new A_Mann()
            {
                name = "Achim", x = nums[0], y = rnd.Next(0, 10), ImSpiel = true
            };
            var a2 = new A_Mann()
            {
                name = "Albert", x = nums[1], y = rnd.Next(0, 10), ImSpiel = true
            };
            var a3 = new A_Mann()
            {
                name = "Alex", x = nums[2], y = rnd.Next(0, 10), ImSpiel = true
            };
            var a4 = new A_Mann()
            {
                name = "Anton", x = nums[3], y = rnd.Next(0, 10), ImSpiel = true
            };
            var a5 = new A_Mann()
            {
                name = "August", x = nums[4], y = rnd.Next(0, 10), ImSpiel = true
            };
            List <A_Mann> aliste = new List <A_Mann>();

            aliste.Add(a1);
            aliste.Add(a2);
            aliste.Add(a3);
            aliste.Add(a4);
            aliste.Add(a5);
            // Shuffle the array
            for (int i = 0; i < 5; ++i)
            {
                int randomIndex = rnd.Next(numsb.Length);
                int temp        = numsb[randomIndex];
                numsb[randomIndex] = numsb[i];
                numsb[i]           = temp;
            }
            // Now your array is randomized and you can simply print them in order
            for (int i = 0; i < 5; ++i)
            {
                Console.WriteLine(numsb[i]);
            }
            var b1 = new B_Mann()
            {
                name = "Bert", x = numsb[0], y = rnd.Next(0, 10), ImSpiel = true
            };
            var b2 = new B_Mann()
            {
                name = "Benjamin", x = numsb[1], y = rnd.Next(0, 10), ImSpiel = true
            };
            var b3 = new B_Mann()
            {
                name = "Bjoern", x = numsb[2], y = rnd.Next(0, 10), ImSpiel = true
            };
            var b4 = new B_Mann()
            {
                name = "Bodo", x = numsb[3], y = rnd.Next(0, 10), ImSpiel = true
            };
            var b5 = new B_Mann()
            {
                name = "Bruno", x = numsb[4], y = rnd.Next(0, 10), ImSpiel = true
            };
            List <B_Mann> bliste = new List <B_Mann>();

            bliste.Add(b1);
            bliste.Add(b2);
            bliste.Add(b3);
            bliste.Add(b4);
            bliste.Add(b5);

            for (int h = 0; h < 10; h++)
            {
                for (int b = 0; b < 10; b++)
                {
                    //  Console.SetCursorPosition(startX + b, startY + h);
                }
            }


            do
            {
                foreach (A_Mann a_1 in aliste)
                {
                    foreach (A_Mann a_2 in aliste)
                    {
                        if (!a_1.Equals(a_2))
                        {
                            if (a_1.x == a_2.x && a_1.y == a_2.y)
                            {
                                a_1.Gruessen(a_2);
                            }
                        }
                    }
                }
                foreach (B_Mann b_1 in bliste)
                {
                    foreach (B_Mann b_2 in bliste)
                    {
                        if (!b_1.Equals(b_2))
                        {
                            if (b_1.x == b_2.x && b_1.y == b_2.y)
                            {
                                b_1.Gruessen(b_2);
                            }
                        }
                    }
                }
                foreach (A_Mann al in aliste)
                {
                    al.zufallsAktion(al);
                    // Console.SetCursorPosition(al.x, al.y);
                    //Console.Write("A");
                }
                foreach (B_Mann bl in bliste)
                {
                    bl.zufallsAktion(bl);
                }
                foreach (A_Mann al in aliste.ToList())
                {
                    foreach (B_Mann bl in bliste.ToList())
                    {
                        if (bl.x == al.x && bl.y == al.y)
                        {
                            Console.WriteLine("B-mann auf " + bl.x + "," + bl.y + " kollidiert mit A_mann auf " + al.x + "," + al.y);
                            int gewinner = rnd.Next(2);
                            switch (gewinner)
                            {
                            case (int)Sieger.ist_A_Mann:
                                al.Jubeln();
                                bl.Heulen();
                                bl.ImSpiel = false;
                                bliste.Remove(bl);
                                Console.WriteLine("A: " + aliste.Count());
                                Console.WriteLine("B: " + bliste.Count());

                                break;

                            case (int)Sieger.ist_B_Mann:
                                bl.Jubeln();
                                al.Heulen();
                                al.ImSpiel = false;
                                aliste.Remove(al);
                                Console.WriteLine("A: " + aliste.Count());
                                Console.WriteLine("B: " + bliste.Count());
                                break;

                            default:
                                continue;
                            }
                        }
                    }
                }

                PrintGF(aliste, bliste);
                System.Threading.Thread.Sleep(500);
            } while (aliste.Count() > 0 && bliste.Count() > 0);
            // PrintGF(aliste, bliste);
            Console.ReadKey();
        }