예제 #1
0
 public GameCell(GameObject gameObject)
 {
     this.gameObject = gameObject;
 }
예제 #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;
 }
예제 #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);
         }
     }
 }
예제 #4
0
 public bool TryGetObjectPosition(GameObject obj, out GameCellPos position)
 {
     return objectDict.TryGetValue(obj, out position);
 }
예제 #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);
 }
예제 #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;
 }
예제 #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;
 }
예제 #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));
 }
예제 #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;
 }
예제 #10
0
 public DrawCellInfo(GameCellPos cellPos, GameCellPos objectPos, GameObject obj)
     : this(cellPos)
 {
     this.objectPos = objectPos;
     this.obj = obj;
 }
예제 #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;
 }
예제 #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;
 }