コード例 #1
0
        void HandleCellMove(ICell cell)
        {
            int x1 = cell.GetX(), y1 = cell.GetY(), x2, y2;

            cell.CalcMoveDirectionAspiration(this);
            MoveDirection md = cell.GetMoveDisperation();

            switch (md)
            {
            case MoveDirection.up:
                x2 = x1; y2 = y1 - 1;
                break;

            case MoveDirection.down:
                x2 = x1; y2 = y1 + 1;
                break;

            case MoveDirection.left:
                x2 = x1 - 1; y2 = y1;
                break;

            case MoveDirection.right:
                x2 = x1 + 1; y2 = y1;
                break;

            default:
                return;
            }

            if (!ValidateCords(x2, y2))
            {
                return;
            }

            IUniverseObject unObj = GetMatrixElement(x2, y2);
            int             desc  = unObj.GetDescriptor();

            if (unObj.isDisposed())
            {
                RelocateUniverseObject(x1, y1, x2, y2);
            }
            else if (desc == -2 || desc == -1)
            {
                cell.AddEnergy((unObj as IFood).GetEnergyLevel());
                RelocateUniverseObject(x1, y1, x2, y2);
            }
            else if (GetMatrixElement(x1, y1).GetDescriptor() == unObj.GetDescriptor())
            {
                cell.AddEnergy(ConstsUniverse.EnergyLevel_MovesFriendly);
                (unObj as ICell).AddEnergy(ConstsUniverse.EnergyLevel_MovesFriendly);
            }
            else
            {
                cell.AddEnergy((float)(ConstsUniverse.EnergyLevel_MovesAggression * 0.8));
                (unObj as ICell).AddEnergy(-ConstsUniverse.EnergyLevel_MovesAggression);
            }
        }
コード例 #2
0
 bool AddUniverseObject(int x, int y, IUniverseObject universeObject, bool canReSetPrevObject)
 {
     if (GetMatrixElement(x, y) == null)
     {
         SetMatrixElement(x, y, universeObject);
         return(true);
     }
     else if (canReSetPrevObject || GetMatrixElement(x, y).isDisposed())
     {
         GetMatrixElement(x, y).Dispose();
         SetMatrixElement(x, y, universeObject);
         return(true);
     }
     return(false);
 }
コード例 #3
0
 void SetMatrixElement(int x, int y, IUniverseObject universeObject)
 {
     universeMatrix[x, y] = universeObject;
     universeObject.SetCords(x, y);
 }