public void Prepare(IMonster monster) { CellAreaInfo areaInfo = monster.AreaInfo as CellAreaInfo; CellArea area = areaInfo.Area as CellArea; int x = areaInfo.X; int y = areaInfo.Y; int startBit = 0; startBit = SetContentType(startBit, area.GetCellAt(x, y - 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x - 1, y - 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x + 1, y - 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x - 1, y).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x + 1, y).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x - 1, y + 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x + 1, y + 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x, y + 1).ContentType); }
public void MoveTo(int x, int y) { CellArea cellArea = Area as CellArea; while (x < 0) { x += cellArea.Width; } while (y < 0) { y += cellArea.Height; } x %= cellArea.Width; y %= cellArea.Height; if (x == X && y == Y) { return; } Cell destinationCell = cellArea.GetCellAt(x, y); if (destinationCell.ContentType != ContentType.Empty) { return; } Cell currentCell = cellArea.GetCellAt(this); destinationCell.Content = currentCell.Content; destinationCell.ContentType = currentCell.ContentType; currentCell.Content = null; currentCell.ContentType = ContentType.Empty; X = x; Y = y; }
public void Do(IMonster monster) { CellAreaInfo areaInfo = monster.AreaInfo as CellAreaInfo; CellArea area = areaInfo.Area as CellArea; int x = areaInfo.X; int y = areaInfo.Y; int moveNr = (this[0] ? 1 : 0) + (this[1] ? 2 : 0); switch (moveNr) { case 0: y--; break; case 1: y++; break; case 2: x--; break; case 3: x++; break; } Collision = false; Cell targetCell = area.GetCellAt(x, y); switch (targetCell.ContentType) { case ContentType.Empty: areaInfo.MoveTo(x, y); break; case ContentType.Wall: Collision = true; break; case ContentType.Food: monster.Energy += CellArea.FOOD_ENERGY; targetCell.ContentType = ContentType.Empty; break; case ContentType.Monster: Collision = true; if (monster.Energy < CellArea.MONSTER_ACTIVE_SEX_ENERGY) { break; } IMonster targetMonster = (IMonster)targetCell.Content; if (targetMonster.Energy < CellArea.MONSTER_PASSIVE_SEX_ENERGY) { break; } Genome genome = sex.MakeChild(monster.Brain.Genome, targetMonster.Brain.Genome); if (genome != null) { monster.Energy -= CellArea.MONSTER_INIT_ENERGY * 0.5; targetMonster.Energy -= CellArea.MONSTER_INIT_ENERGY * 0.5; area.UsedEnergy -= CellArea.MONSTER_INIT_ENERGY; SimpleMonster.Monster m = area.AddNewMonster(genome) as SimpleMonster.Monster; m.Parents = (monster as SimpleMonster.Monster).Parents + "S"; } //else //{ // // Get energy from target monster // targetMonster.Energy -= CellArea.FOOD_ENERGY; // monster.Energy += CellArea.FOOD_ENERGY; //} break; } }