コード例 #1
0
        public void move()      //Version 1, nicht so genau, läuft später nur am rand und diagonal
        {
            X += Directionx;
            Y += Directiony;
            if ((X < Bereich.GetLength(0) && Y < Bereich.GetLength(1)) && (X >= 0 && Y >= 0))
            {
                Feld Actualfield = Bereich[X, Y];
                Actualfield.maehen();

                if (((((X + Directionx) == Bereich.GetLength(0) || (Y + Directiony) == Bereich.GetLength(1)) || ((X + Directionx) == -1 || (Y + Directiony == -1))) || !Bereich[X + Directionx, Y + Directiony].isinside) && Actualfield.isrand)
                {
                    List <int[]> PossibleNeighbours = new List <int[]>();
                    PossibleNeighbours.Add(new int[2] {
                        X + 1, Y + 1
                    });
                    PossibleNeighbours.Add(new int[2] {
                        X + 1, Y - 1
                    });
                    PossibleNeighbours.Add(new int[2] {
                        X + 0, Y + 1
                    });
                    PossibleNeighbours.Add(new int[2] {
                        X + 0, Y - 1
                    });
                    PossibleNeighbours.Add(new int[2] {
                        X - 1, Y + 1
                    });
                    PossibleNeighbours.Add(new int[2] {
                        X - 1, Y - 1
                    });
                    PossibleNeighbours.Add(new int[2] {
                        X - 1, Y + 0
                    });
                    //PossibleNeighbours.Add(new int[2] { X + 1, Y + 0 });

                    List <int[]> posneigh = new List <int[]>();

                    foreach (int[] item in PossibleNeighbours)
                    {
                        if (item[0] < Bereich.GetLength(0) && item[1] < Bereich.GetLength(1))
                        {
                            if (item[0] > -1 && item[1] > -1)
                            {
                                if (Bereich[item[0], item[1]].isinside)
                                {
                                    posneigh.Add(item);
                                }
                            }
                        }
                    }

                    int[] newField = posneigh[rnd.Next(0, posneigh.Count)];

                    Directionx = newField[0] - X;
                    Directiony = newField[1] - Y;
                }
            }
        }
コード例 #2
0
 private static void initialize(int hoehe, int breite)
 {
     Bereich = new Feld[hoehe, breite];
     for (int x = 0; x < Bereich.GetLength(0); x++)
     {
         for (int y = 0; y < Bereich.GetLength(1); y++)
         {
             Bereich[x, y] = new Feld(((x == 0 || y == 0) || (x == Bereich.GetLength(0) - 1 || y == Bereich.GetLength(1) - 1)) ? true : false, true);
         }
     }
 }