Example #1
0
 public GameCell(GameObject gameObject)
 {
     this.gameObject = gameObject;
 }
Example #2
0
 public CanMoveResult TryMoveObjectHere(GameObject obj, int startRow, int startColumn)
 {
     CanMoveResult result = CanMoveObjectHere(obj, startRow, startColumn);
     if (result != CanMoveResult.Success) return result;
     RemoveObject(obj);
     FillObjectCells(obj, startRow, startColumn);
     objectDict[obj] = new GameCellPos(startRow, startColumn);
     return CanMoveResult.Success;
 }
Example #3
0
 void FillObjectCells(GameObject obj, int startRow, int startColumn)
 {
     for (int i = 0; i < obj.Height; i++) {
         for (int j = 0; j < obj.Width; j++) {
             if (!obj.Bitmap[i, j]) continue;
             cells[i + startRow][j + startColumn] = new GameCell(obj);
         }
     }
 }
Example #4
0
 public bool TryGetObjectPosition(GameObject obj, out GameCellPos position)
 {
     return objectDict.TryGetValue(obj, out position);
 }
Example #5
0
 public CanMoveResult TryMoveObject(GameObject obj, int deltaRow, int deltaColumn)
 {
     GameCellPos start;
     if (!TryGetObjectPosition(obj, out start)) return CanMoveResult.ObjectNotFound;
     return TryMoveObjectHere(obj, start.Row + deltaRow, start.Column + deltaColumn);
 }
Example #6
0
 public CanMoveResult CanMoveObjectHere(GameObject obj, int startRow, int startColumn)
 {
     for (int i = 0; i < obj.Height; i++) {
         for (int j = 0; j < obj.Width; j++) {
             if (!obj.Bitmap[i, j]) continue;
             int iTable = i + startRow;
             int jTable = j + startColumn;
             if (iTable < 0 || iTable >= Height || jTable < 0 || jTable >= Width) return CanMoveResult.TableBoundsCollision;
         }
     }
     for (int i = 0; i < obj.Height; i++) {
         for (int j = 0; j < obj.Width; j++) {
             if (!obj.Bitmap[i, j]) continue;
             int iTable = i + startRow;
             int jTable = j + startColumn;
             if (cells[iTable][jTable].GameObject != null && cells[iTable][jTable].GameObject != obj) return CanMoveResult.ObjectCollision;
         }
     }
     return CanMoveResult.Success;
 }
Example #7
0
 public bool RemoveObject(GameObject obj)
 {
     GameCellPos oldStart;
     if (!objectDict.TryGetValue(obj, out oldStart)) return false;
     ClearObjectCells(obj, oldStart.Row, oldStart.Column);
     objectDict.Remove(obj);
     return true;
 }
Example #8
0
 public void AddObject(GameObject obj, int startRow, int startColumn)
 {
     if (TryMoveObjectHere(obj, startRow, startColumn) != CanMoveResult.Success) throw new InvalidOperationException(string.Format("Can't place object here {0}:{1}.", startRow, startColumn));
 }
Example #9
0
 public bool RemoveObjectFromColorCache(GameObject obj)
 {
     bool colorResult = objectColorDict.Remove(obj);
     Image image;
     if (objectImageDict.TryGetValue(obj, out image)) {
         image.Dispose();
         return true;
     }
     return colorResult;
 }
Example #10
0
 public DrawCellInfo(GameCellPos cellPos, GameCellPos objectPos, GameObject obj)
     : this(cellPos)
 {
     this.objectPos = objectPos;
     this.obj = obj;
 }
Example #11
0
 public Image GetObjectImage(GameObject obj, Color objectColor)
 {
     if (obj == null || grayCellImageData == null) return null;
     Image objectImage;
     if (!objectImageDict.TryGetValue(obj, out objectImage)) {
         objectImage = CommonHelper.GetColorImage(grayCellImageData, objectColor);
         objectImageDict.Add(obj, objectImage);
     }
     return objectImage;
 }
Example #12
0
 public Color GetObjectColor(GameObject obj)
 {
     if (obj == null) {
         return Color.MidnightBlue;
     }
     Color color;
     if (!objectColorDict.TryGetValue(obj, out color)) {
         color = Color.FromArgb(100 + randomize.Next(155),
             100 + randomize.Next(155),
             100 + randomize.Next(155));
         objectColorDict.Add(obj, color);
     }
     return color;
 }