Beispiel #1
0
        public void GameLoop(SurvivalController sc)
        {
            TurnCount++;

            foreach (Tile T in sc.GetAllTiles())
            {
                if (T.Animal != null) //forskellig fra NULL værdi
                {
                    if (T.Animal.Species == 'R')
                    {
                        Rabbit rabbit = (Rabbit)T.Animal;
                        rabbit.Move(sc);
                    }
                    else if (T.Animal.Species == 'L')
                    {
                        Rabbit rabbit = (Rabbit)T.Animal;
                        rabbit.Move(sc);
                    }
                }
            }
        }
Beispiel #2
0
        public void Move(SurvivalController sc) //vælger target location. Animal kan se tiles omkring sig
        {
            List <Tile> Tiles = new List <Tile>();
            int         row   = Tile.Row;
            int         col   = Tile.Column;

            for (int roffset = -1; roffset <= 1; roffset++)
            {
                int nextRow = row + roffset;
                if (nextRow >= 0 && nextRow < 20)
                {
                    for (int coffset = -1; coffset <= 1; coffset++)
                    {
                        int nextCol = col + coffset;
                        // Exclude invalid locations and the original location.
                        if (nextCol >= 0 && nextCol < 20 && (roffset != 0 || coffset != 0))
                        {
                            Tiles.Add(new Tile(nextRow, nextCol));
                        }
                    }
                }
            }

            Tile availableTile;
            int  count = 1;

            while (count <= Tiles.Count)
            {
                int randomTile = rand.Next(Tiles.Count);
                availableTile = Tiles[randomTile];
                if (availableTile.Animal == null) //grass
                {
                    Tile.RemoveAnimal(this);
                    sc.PlaceOneAnimal(this, availableTile.Row, availableTile.Column);
                    break;
                }
                count++;
            }
            Tiles.Clear();
        }