Ejemplo n.º 1
0
        public void Escape(AquariumObject Hunter)
        {
            Pathfinder pathfinder = new Pathfinder(ContainingAquarium.Territory);

            int[,] WaveMap = pathfinder.GetWavemap(Hunter.X, Hunter.Y);
            int xMax = 0, yMax = 0, MaxWave = 0;

            for (int i = 0 > X - 1 ? 0 : X - 1, iMax = X + 1 < xField ? X + 1 : xField - 1; i <= iMax; i++)
            {
                for (int j = 0 > Y - 1 ? 0 : Y - 1, jMax = Y + 1 < yField ? Y + 1 : yField - 1; j <= jMax; j++)
                {
                    if (MaxWave < WaveMap[i, j] && ContainingAquarium.Territory[i, j] == null)
                    {
                        MaxWave = WaveMap[i, j];
                        xMax    = i;
                        yMax    = j;
                    }
                }
            }
            if (MaxWave == 0)
            {
                throw new Exception("Cannot escape death.");
            }
            try
            {
                ContainingAquarium.ObjectIsMovingTo(this, xMax, yMax);
                this.X = xMax;
                this.Y = yMax;
            }
            catch { }
        }
Ejemplo n.º 2
0
        private void PictureBox_Click(object sender, EventArgs e)
        {
            PictureBox pb = sender as PictureBox;

            selectedX = tableLayoutPanel1.GetCellPosition(pb).Row;
            selectedY = tableLayoutPanel1.GetCellPosition(pb).Column;
            AquariumObject SelectedObject = HereWeGo.Territory[selectedX, selectedY];

            if (SelectedObject == null)
            {
                comboBox1.SelectedItem = "Empty";
            }
            if (SelectedObject is Rock)
            {
                comboBox1.SelectedItem = "Rock";
            }
            if (SelectedObject is Seaweed)
            {
                comboBox1.SelectedItem = "Seaweed";
            }
            if (SelectedObject is HerbivoreFish)
            {
                comboBox1.SelectedItem = "Herbivore";
            }
            if (SelectedObject is PredatorFish)
            {
                comboBox1.SelectedItem = "Predator";
            }
            ActivateAppropriateFields(comboBox1.SelectedItem.ToString());
        }
Ejemplo n.º 3
0
 public void ObjectCreatingIn(AquariumObject objectToAppend, int X, int Y)
 {
     if (Territory[X, Y] != null)
     {
         throw new System.InvalidOperationException("That place is already taken");
     }
     Territory[X, Y] = objectToAppend;
 }
Ejemplo n.º 4
0
 public void ObjectIsMovingTo(AquariumObject objectToMove, int newX, int newY)
 {
     if (Territory[newX, newY] != null)
     {
         throw new System.InvalidOperationException("That place is already taken");
     }
     Territory[newX, newY] = objectToMove;
     Territory[objectToMove.X, objectToMove.Y] = null;
 }