Exemplo n.º 1
0
        static void Main()
        {
            //gen uniq points(x,y) for 5x as and 5x bs
            //an array of 10 uniq points
            Pos[] points = GenRndUniqPointArray(0, 10, 0, 10, 10);

            string[] a_names = new string[5] {
                "Achim", "Albert", "Alex", "Anton", "August"
            };
            List <A> alist = new List <A>();

            //fill a_man list
            for (int i = 0; i < 5; i++)
            {
                alist.Add(new A(a_names[i], points[i].X, points[i].Y));
            }
            string[] b_names = new string[5] {
                "Bert", "Benjamin", "Bjoern", "Bodo", "Bruno"
            };
            List <B> blist = new List <B>();

            //fill b_man list
            for (int i = 5; i < 10; i++)
            {
                blist.Add(new B(b_names[i - 5], points[i].X, points[i].Y));
            }
            //setup done - print gamefield
            PrintGF(alist, blist);
            do
            {
                //first is a`s turn
                for (int i = alist.Count - 1; i >= 0; i--)
                {
                    Pos  p     = Move(alist[i].x, alist[i].y);
                    bool moved = false;
                    foreach (A am in alist)
                    {
                        if (am.ImSpiel && am.x == p.X && am.y == p.Y)
                        {
                            //in case a_man meets another a_man
                            alist[i].Gruessen(am);
                            //Console.WriteLine(am);
                            moved = true;
                            break;
                        }
                    }
                    if (moved)
                    {
                        alist[i].x = p.X;
                        alist[i].y = p.Y;
                        continue;
                    }
                    foreach (B bm in blist)
                    {
                        if (bm.ImSpiel && bm.x == p.X && bm.y == p.Y)
                        {
                            //a_man meets b_man = fight with random result!!!!
                            int isA_winner = rnd.Next(0, 2);
                            //if 0 a wins else b wins
                            if (isA_winner == 0)
                            {
                                alist[i].Jubeln();
                                bm.Heulen();
                                blist[blist.IndexOf(bm)].ImSpiel = false;
                                blist.RemoveAt(blist.IndexOf(bm));
                            }
                            else
                            {
                                alist[i].Heulen();
                                alist[i].ImSpiel = false;
                                alist.RemoveAt(i);
                            }
                            break;
                        }
                    }
                    if (i < alist.Count)
                    {
                        alist[i].x = p.X;
                        alist[i].y = p.Y;
                    }
                }

                //b´s turn
                for (int i = blist.Count - 1; i >= 0; i--)
                {
                    Pos  p     = Move(blist[i].x, blist[i].y);
                    bool moved = false;
                    foreach (B bm in blist)
                    {
                        if (bm.x == p.X && bm.y == p.Y)
                        {
                            //b_man meets another b_man
                            blist[i].Gruessen(bm);
                            moved = true;
                            break;
                        }
                    }
                    if (moved)
                    {
                        blist[i].x = p.X;
                        blist[i].y = p.Y;
                        continue;
                    }
                    foreach (A am in alist)
                    {
                        if (am.ImSpiel && am.x == p.X && am.y == p.Y)
                        {
                            //b_man meets a_man=fight with random result
                            int isA_winner = rnd.Next(0, 2);
                            //if n0 a wins else b wins
                            if (isA_winner == 0)
                            {
                                blist[i].Jubeln();
                                am.Heulen();
                                alist[alist.IndexOf(am)].ImSpiel = false;
                                alist.RemoveAt(alist.IndexOf(am));
                            }
                            else
                            {
                                blist[i].Heulen();
                                blist[i].ImSpiel = false;
                                blist.RemoveAt(i);
                            }
                            break;
                        }
                    }
                    if (i < blist.Count)
                    {
                        blist[i].x = p.X;
                        blist[i].y = p.Y;
                    }
                }
                Console.WriteLine($"a{alist.Count} - b{blist.Count}");
                PrintGF(alist, blist);
                System.Threading.Thread.Sleep(1000);
                if (blist.Count <= 1 || alist.Count <= 1)
                {
                    break;
                }
            }while (blist.Count > 1 && alist.Count > 1);
            //done - print gamefield
            Console.WriteLine($"a{alist.Count} - b{blist.Count}");
            PrintGF(alist, blist);
            Console.WriteLine("press any key ...");
            Console.ReadKey(true);
            if (blist.Count == 1)
            {
                Console.WriteLine("team a wins!!!!!!!!!!!!! b count " + 1);
            }
            else if (alist.Count == 1)
            {
                Console.WriteLine("team b wins!!!!!!!!!!!!! a count" + 1);
            }
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static Pos Move(int x, int y)
        {
            Pos result = new Pos {
                X = x, Y = y
            };

            bool[] can = new bool[4] {
                true, true, true, true
            };
            int move;

            if (x == 0)
            {
                can[0] = false;
            }
            if (x == 9)
            {
                can[1] = false;
            }
            if (y == 0)
            {
                can[3] = false;
            }
            if (y == 9)
            {
                can[2] = false;
            }

            do
            {
                move = rnd.Next(0, 4);
            } while (!can[move]);

            switch (move)
            {
            case 0:
                //move UP
                result.X = x - 1;
                break;

            case 1:
                //move Down
                result.X = x + 1;
                break;

            case 2:
                //move Right
                result.Y = y + 1;
                break;

            case 3:
                //move Left
                result.Y = y - 1;
                break;
            }
            if (result.X < 0 || result.Y < 0 || result.X > 9 || result.Y > 9)
            {
                Console.WriteLine("bad!!!!!!!!!!!!!!!!!!!");
            }
            return(result);
        }