private void AssignTopAndBottom(LinkedGameObject l) { int i = 0; var temp = l; while (temp.ObjectPrevious != null) { temp = temp.ObjectPrevious; i++; } var match = FirstInPreviousRow; for (int x = 0; x < i; x++) { if (match.ObjectNext == null) { break; } match = match.ObjectNext; } l.ObjectAbove = match; match.ObjectBelow = l; }
// move with chest private void SwapTwo(LinkedGameObject first, LinkedGameObject second, bool withChest) { var temp = first.GameObject; first.GameObject = second.GameObject; second.GameObject = temp; }
// normal move private void SwapTwo(LinkedGameObject first, LinkedGameObject second) { var temp = first.GameObject; first.GameObject = second.GameObject; second.GameObject = temp; _playerObject = second; }
private bool NormalMove(LinkedGameObject move) { if (move.GameObject.GetChar() == (char)Characters.Tile) { if (_isOnSpecialSquare) { move.GameObject.SetChar((char)Characters.Player); _playerObject.GameObject.SetChar(_tempChar); _playerObject = move; _isOnSpecialSquare = false; // reset object return(true); } SwapTwo(_playerObject, move); return(true); } return(false); }
// set PlayerObject public void SetPlayer(LinkedList currentLevel) { var rows = currentLevel.First; var columns = currentLevel.First; while (rows != null) { while (columns != null) { if (columns.GameObject.GetChar() == (char)Characters.Player) { _playerObject = columns; return; } columns = columns.ObjectNext; } rows = rows.ObjectBelow; columns = rows; } }
private bool MoveOntoDestinationOrTrap(LinkedGameObject move) { if (move.GameObject.GetChar() == (char)Characters.Destination || move.GameObject.GetChar() == (char)Characters.Trap || move.GameObject.GetChar() == (char)Characters.OpenTrap) { if (_isOnSpecialSquare) { _playerObject.GameObject.SetChar(_tempChar); // player becomes a tile } else { _playerObject.GameObject.SetChar((char)Characters.Tile); // player becomes a tile } _isOnSpecialSquare = true; SetChar(move.GameObject.GetChar()); move.GameObject.SetChar((char)Characters.Player); _playerObject = move; return(true); } return(false); }
public void InsertInRow(BaseObject obj, int currRow) { // first row if (First == null) { First = new LinkedGameObject(); First.GameObject = obj; Last = First; FirstInCurrentRow = First; return; } else if (currRow == 0) { Last.ObjectNext = new LinkedGameObject(); Last.ObjectNext.GameObject = obj; Last.ObjectNext.ObjectPrevious = Last; Last = Last.ObjectNext; _prevRow = currRow; return; } // new row if (_prevRow != currRow) { FirstInPreviousRow = FirstInCurrentRow; FirstInCurrentRow = null; _prevRow = currRow; } var mostRightObj = new LinkedGameObject(); // find most right element in current row if (FirstInCurrentRow != null) { mostRightObj = FirstInCurrentRow; while (mostRightObj.ObjectNext != null) { mostRightObj = mostRightObj.ObjectNext; } } LinkedGameObject l = new LinkedGameObject(); if (FirstInCurrentRow == null) { // first object in new row FirstInCurrentRow = l; Last = l; } else { // current object(l) has a neighbor to his left mostRightObj.ObjectNext = l; l.ObjectPrevious = mostRightObj; Last = l; } // set game object l.GameObject = obj; // Assign top neighbor if (l == FirstInCurrentRow) { l.ObjectAbove = FirstInPreviousRow; FirstInPreviousRow.ObjectBelow = l; } else { AssignTopAndBottom(l); } }
private bool CheckCrateMove(LinkedGameObject move, LinkedGameObject moveAfter) { if (move.GameObject.GetChar() == (char)Characters.Crate && moveAfter.GameObject.GetChar() == (char)Characters.Tile) { SwapTwo(move, moveAfter, true); if (_isOnSpecialSquare) { move.GameObject.SetChar(_tempChar); _isOnSpecialSquare = false; } SwapTwo(_playerObject, move); return(true); } if (move.GameObject.HasChest) { if (moveAfter.GameObject.GetChar() == (char)Characters.CrateOnDestination) { return(false); } if (moveAfter.GameObject.GetChar() == (char)Characters.Destination) { // SITUATION: // @-0-X SwapTwo(move, moveAfter, true); _isOnSpecialSquare = true; _tempChar = (char)Characters.Destination; move.GameObject.SetChar((char)Characters.Tile); SwapTwo(_playerObject, move); return(true); } if (_isOnSpecialSquare) { move.GameObject.SetChar(_tempChar); } else { _isOnSpecialSquare = true; _tempChar = (char)Characters.Destination; move.GameObject.SetChar((char)Characters.Tile); } _tempChar = (char)Characters.Destination; move.GameObject.HasChest = false; SwapTwo(_playerObject, move); moveAfter.GameObject.SetChar((char)Characters.Crate); } if (move.GameObject.GetChar() == (char)Characters.Crate && moveAfter.GameObject.GetChar() == (char)Characters.Destination) { moveAfter.GameObject.HasChest = true; moveAfter.GameObject.SetChar((char)Characters.CrateOnDestination); if (_isOnSpecialSquare) { move.GameObject.SetChar(_tempChar); _isOnSpecialSquare = false; } else { move.GameObject.SetChar((char)Characters.Tile); } SwapTwo(_playerObject, move); return(true); } return(false); }