Ejemplo n.º 1
0
 public UndoRedoAction(BoardItem item, UndoRedoType type, object ParamA, object ParamB)
 {
     this.item = item;
     this.type = type;
     this.ParamA = ParamA;
     this.ParamB = ParamB;
 }
Ejemplo n.º 2
0
 public JsonResult AddNewBoardItem(BoardItem boardItem)
 {
     boardItem.BoardStructure = boardItem.BoardStructure;
     //TODO: change to current user
     boardItem.UserId = 1;
     boardItem.BoardImageUrl = "iboard-new-empty.jpg";
     BoardDbContext.BoardItems.Add(boardItem);
     var isSuccess = BoardDbContext.SaveChanges() > 0;
     return Json(isSuccess);
 }
Ejemplo n.º 3
0
 public JsonResult DeleteBoardItem(BoardItem boardItem)
 {
     var currentBoardItem = BoardDbContext.BoardItems.FirstOrDefault(b => b.Id == boardItem.Id && b.UserId == 1);
     var isSuccess = false;
     if (currentBoardItem != null)
     {
         BoardDbContext.BoardItems.Remove(currentBoardItem);
         isSuccess = BoardDbContext.SaveChanges() > 0;
     }
     return Json(isSuccess);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Destroys items in a given shape.
        /// </summary>
        /// <returns>Points of destroyed items.</returns>
        /// <param name="refBoard">Reference to the game board.</param>
        /// <param name="centerX">X-coord of the shape centre.</param>
        /// <param name="centerY">Y-coord of the shape centre.</param>
        public ArrayList ApplyBonus(BoardItem[,] refBoard, int centerX, int centerY)
        {
            switch (bonusShape) {

                case BonusShape.Cross:
                    return DestroyItemsInCrossShape(refBoard, centerX, centerY);
            }
            return null;
        }
Ejemplo n.º 5
0
 public static UndoRedoAction ItemZChanged(BoardItem item, int oldZ, int newZ)
 {
     return new UndoRedoAction(item, UndoRedoType.ItemZChanged, oldZ, newZ);
 }
Ejemplo n.º 6
0
 public static UndoRedoAction ItemsUnlinked(BoardItem parent, BoardItem child, Point distance)
 {
     return(new UndoRedoAction(parent, UndoRedoType.ItemsUnlinked, child, distance));
 }
Ejemplo n.º 7
0
 public void SetHeldInfo(MapleDrawableInfo newInfo)
 {
     lock (Board.ParentControl)
     {
         Clear();
         if (newInfo.Image == null)
             ((MapleExtractableInfo)newInfo).ParseImage();
         currAddedInfo = newInfo;
         currAddedObj = newInfo.CreateInstance(Board.SelectedLayer, Board, X + currAddedInfo.Origin.X - newInfo.Image.Width / 2, Y + currAddedInfo.Origin.Y - newInfo.Image.Height / 2, 50, false);
         Board.BoardItems.Add(currAddedObj, false);
         BindItem(currAddedObj, new Microsoft.Xna.Framework.Point(newInfo.Origin.X - newInfo.Image.Width / 2, newInfo.Origin.Y - newInfo.Image.Height / 2));
         state = MouseState.StaticObjectAdding;
     }
 }
Ejemplo n.º 8
0
 public override void ReleaseItem(BoardItem item)
 {
     lock (Board.ParentControl)
     {
         if (BoundItems.ContainsKey(item))
         {
             BoundItems.Remove(item);
             item.Parent = item.tempParent;
             item.tempParent = null;
         }
     }
 }
Ejemplo n.º 9
0
 public void Clear()
 {
     lock (Board.ParentControl)
     {
         if (currAddedObj != null)
         {
             currAddedObj.RemoveItem(null);
             currAddedObj = null;
         }
         if (state == MouseState.Ropes || state == MouseState.Tooltip)
         {
             if (state == MouseState.Ropes)
                 ((RopeAnchor)BoundItems.Keys.ElementAt(0)).RemoveItem(null);
             else
                 ((ToolTipDot)BoundItems.Keys.ElementAt(0)).ParentTooltip.RemoveItem(null);
         }
         else if (state == MouseState.Footholds && connectedLines.Count > 0)
         {
             FootholdLine fh = (FootholdLine)connectedLines[0];
             fh.Remove(false, null);
             Board.BoardItems.FootholdLines.Remove(fh);
         }
         else if (state == MouseState.Clock)
         {
             List<BoardItem> items = BoundItems.Keys.ToList();
             foreach (BoardItem item in items)
             {
                 item.RemoveItem(null);
             }
         }
         InputHandler.ClearBoundItems(Board);
         InputHandler.ClearSelectedItems(Board);
         IsDown = false;
     }
 }
Ejemplo n.º 10
0
 public Chair(Board board, BoardItem.SerializationForm json)
     : base(board, json)
 {
 }
Ejemplo n.º 11
0
    /// <summary>
    /// Performs game update and touch and mouse input.
    /// </summary>
    void Update()
    {
        // Back button.
        if (Input.GetKeyDown(KeyCode.Escape))
            Application.Quit();

        // Wait for all animations to finish - TODO optimize.
        if (!ItemsIdle()) {
            return;
        }

        // ------ Game Update -------
        switch (gameState) {

            // Check if move has been valid.
            case GameState.MoveCheck:
                if (match3.CheckMove(selObj1.X, selObj1.Y, selObj2.X, selObj2.Y)) {
                    // Move has been valid, swap objects (animation has only changed real positions).
                    SwapObjects(selObj1, selObj2, false);
                    possibleHighlightObj.renderer.enabled = false;
                    gameState = GameState.MatchOrPossibleGet;
                }
                else {
                    // Move hasn't been valid, animate items back.
                    selObj1.AnimateMove(selObj2.transform.position, swapAnimSpeed);
                    selObj2.AnimateMove(selObj1.transform.position, swapAnimSpeed);
                    gameState = GameState.Idle;
                }

                // Clear selection.
                selObj1 = null;
                selObj2 = null;

                break;

            // Get matches or possible moves (and check for game over).
            case GameState.MatchOrPossibleGet:
                // Get matches.
                ArrayList matches = match3.GetMatches();
                if (matches.Count == 0) {
                    // No matches found, check for possible moves.
                    ArrayList possibleMoves = match3.GetPossibleMoves();
                    if (possibleMoves.Count > 0) {
                        // There are some possible moves, highlight one of them (by random).
                        Match3.Point p = possibleMoves[Random.Range(0, possibleMoves.Count)] as Match3.Point;
                        ShowPossibleMove(p.x, p.y);
                        gameState = GameState.Idle;
                    }
                    else {
                        // No possible moves found, game is over.
                        gameState = GameState.GameOver;
                    }
                }
                else {
                    // Matches found.
                    foreach (ArrayList match in matches) {
                        foreach (Match3.Point p in match) {
                            // Animate destroy of matched items.
                            boardAll[p.x, p.y].AnimateDestroy(destroyAnimSpeed);
                        }
                    }
                    gameState = GameState.ItemGenerateAndDrop;
                }
                break;

            // Generate new items and perform drop.
            case GameState.ItemGenerateAndDrop:
                // Get drop swaps of existing items.
                ArrayList dropSwaps = match3.GetDropSwaps();

                // Begin drop animations and swap items data.
                foreach (Match3.Point[] p in dropSwaps) {
                    BoardItem bi1 = boardAll[p[0].x, p[0].y];
                    BoardItem bi2 = boardAll[p[1].x, p[1].y];

                    bi1.AnimateMove(GetPosOnBoard(p[1].x, p[1].y), dropAnimSpeed);
                    SwapObjects(bi1, bi2, false); // Swap without positions.
                }

                // Get positions of destroyed items (already dropped) and generate new ones.
                ArrayList destroyed = match3.GetDestroyedItemsAndGenerateNew();
                int lastX = -1, firstDestroyedY = -1;

                // Destroy old items, create new ones (above the board) and begin drop animations of them.
                foreach (Match3.Point p in destroyed) {
                    Destroy(boardAll[p.x, p.y].gameObject);

                    // Get y-coord where to put new items above the board (array is sorted,
                    // going through every column from left to right, bottom to top.
                    if (p.x != lastX) {
                        // New column.
                        firstDestroyedY = p.y;
                        lastX = p.x;
                    }

                    // Create item with adjusted y-position.
                    BoardItem clone = CreateBoardItem(p.x, p.y, 0, boardSizeY - firstDestroyedY);
                    // Begin move animation to the right position.
                    clone.AnimateMove(GetPosOnBoard(p.x, p.y), dropAnimSpeed);
                }

                // Check for the new matches.
                gameState = GameState.MatchOrPossibleGet;

                break;
        }

        // ----------- Input ----------
        // Touch input.
        if (Input.touchCount == 1) {
            Touch touch = Input.GetTouch(0);

            switch (touch.phase) {

                case TouchPhase.Began:
                    MyMouseDown(touch.position);
                    break;

                case TouchPhase.Moved:
                    MyMouseMove(touch.position);
                    break;

                case TouchPhase.Ended:
                case TouchPhase.Canceled:
                    MyMouseUp(touch.position);
                    break;
            }
        }
        // Mouse input.
        else {
            if (Input.GetMouseButtonDown(0)) {
                MyMouseDown(Input.mousePosition);
            }
            else if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0) {
                MyMouseMove(Input.mousePosition);
            }
            else if (Input.GetMouseButtonUp(0)) {
                MyMouseUp(Input.mousePosition);
            }
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Swaps board items - coords, positions, names and updates the boardAll array.
    /// </summary>
    /// <param name='f'>First item.</param>
    /// <param name='s'>Second item.</param>  
    /// <param name='positions'>If <c>false</c>, real positions are not swapped.</param>  
    void SwapObjects(BoardItem f, BoardItem s, bool positions = true)
    {
        // Swap coord properties (position on the board).
        int tmpX = f.X; f.X = s.X; s.X = tmpX;
        int tmpY = f.Y; f.Y = s.Y; s.Y = tmpY;

        // Swap positions (real position in the world).
        if (positions) {
            Vector3 pos = f.transform.position;
            f.transform.position = s.transform.position;
            s.transform.position = pos;
        }

        // Swap names.
        string name = f.transform.name;
        f.transform.name = s.transform.name;
        s.transform.name = name;

        // Swap references in array.
        BoardItem bi = boardAll[f.X, f.Y];
        boardAll[f.X, f.Y] = boardAll[s.X, s.Y];
        boardAll[s.X, s.Y] = bi;
    }
Ejemplo n.º 13
0
 /// <summary>
 /// Called on touch ended/mouse up; resets first selected board item.
 /// </summary>
 /// <param name='position'>Touch/mouse position.</param>
 void MyMouseUp(Vector2 position)
 {
     if (selObj1) {
         selObj1.ResetColor();
         selObj1 = null;
     }
 }
Ejemplo n.º 14
0
    /// <summary>
    /// Called on touch/mouse moved; performs swap of board items.
    /// </summary>
    /// <param name='position'>Touch/mouse position.</param>
    void MyMouseMove(Vector2 position)
    {
        if (!selObj1)
            return;

        Vector2 dragVec = position - dragOrigin;

        if (dragVec.sqrMagnitude >= dragLength * dragLength) {
            // Drag detected, perform item swap.
            int x1 = selObj1.X;
            int y1 = selObj1.Y;

            int x2 = x1;
            int y2 = y1;

            DragDirection dir = GetDragDirFromVec(dragVec);

            switch (dir) {
                case DragDirection.Left:
                    x2--;
                    break;

                case DragDirection.Right:
                    x2++;
                    break;

                case DragDirection.Up:
                    y2++;
                    break;

                case DragDirection.Down:
                    y2--;
                    break;
            }

            if (x2 >= 0 && x2 < boardSizeX && y2 >= 0 && y2 < boardSizeY) {
                selObj2 = boardAll[x2, y2];

                // Start swap animation.
                selObj1.AnimateMove(selObj2.transform.position, swapAnimSpeed);
                selObj2.AnimateMove(selObj1.transform.position, swapAnimSpeed);

                gameState = GameState.MoveCheck;
            }

            selObj1.ResetColor();
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Called on touch began/mouse down; selects board item.
    /// </summary>
    /// <param name='position'>Touch/mouse position.</param>
    void MyMouseDown(Vector2 position)
    {
        RaycastHit hitInfo = new RaycastHit();
        if (Physics.Raycast(Camera.main.ScreenPointToRay(position), out hitInfo)) {
            // Save selected object.
            selObj1 = hitInfo.transform.gameObject.GetComponent(typeof(BoardItem)) as BoardItem;

            // Null if it is not a BoardItem.
            if (selObj1) {
                selObj1.renderer.material.color *= 1.5f;
                dragOrigin = position;
            }
        }
        else {
            selObj1 = null;
        }
    }
Ejemplo n.º 16
0
 public static UndoRedoAction ItemZChanged(BoardItem item, int oldZ, int newZ)
 {
     return(new UndoRedoAction(item, UndoRedoType.ItemZChanged, oldZ, newZ));
 }
Ejemplo n.º 17
0
        private void parentBoard_ShortcutKeyPressed(Board selectedBoard, bool ctrl, bool shift, bool alt, Keys key)
        {
            lock (parentBoard)
            {
                if (parentBoard == null || parentBoard.SelectedBoard == null)
                {
                    return;
                }
                OnUserInteraction();
                List <UndoRedoAction> actions = new List <UndoRedoAction>();
                if (key == Keys.ControlKey || key == Keys.ShiftKey || key == Keys.Menu /*ALT key*/)
                {
                    return;
                }
                bool clearRedo = true;
                switch (key)
                {
                case Keys.Left:
                    foreach (BoardItem item in selectedBoard.SelectedItems)
                    {
                        if (!item.BoundToSelectedItem(selectedBoard))
                        {
                            item.X--;
                            actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(1, 0)));
                        }
                    }
                    break;

                case Keys.Right:
                    foreach (BoardItem item in selectedBoard.SelectedItems)
                    {
                        if (!item.BoundToSelectedItem(selectedBoard))
                        {
                            item.X++;
                            actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(-1, 0)));
                        }
                    }
                    break;

                case Keys.Up:
                    foreach (BoardItem item in selectedBoard.SelectedItems)
                    {
                        if (!item.BoundToSelectedItem(selectedBoard))
                        {
                            item.Y--;
                            actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(0, 1)));
                        }
                    }
                    break;

                case Keys.Down:
                    foreach (BoardItem item in selectedBoard.SelectedItems)
                    {
                        if (!item.BoundToSelectedItem(selectedBoard))
                        {
                            item.Y++;
                            actions.Add(CreateItemUndoMoveAction(item, new XNA.Point(0, -1)));
                        }
                    }
                    break;

                case Keys.Delete:
                    switch (selectedBoard.Mouse.State)
                    {
                    case MouseState.Selection:
                        bool             askedVr = false, askedMm = false;
                        List <BoardItem> selectedItems = selectedBoard.SelectedItems.ToList();        // Dupe the selection list
                        foreach (BoardItem item in selectedItems)
                        {
                            if (item is ToolTipDot || item is MiscDot)
                            {
                                continue;
                            }
                            else if (item is VRDot)
                            {
                                if (!askedVr)
                                {
                                    askedVr = true;
                                    if (MessageBox.Show("This will remove the map's VR. This is not undoable, you must re-add VR from the map's main menu. Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                                    {
                                        selectedBoard.VRRectangle.RemoveItem(null);
                                    }
                                }
                            }
                            else if (item is MinimapDot)
                            {
                                if (!askedMm)
                                {
                                    askedMm = true;
                                    if (MessageBox.Show("This will remove the map's minimap. This is not undoable, you must re-add the minimap from the map's main menu. Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                                    {
                                        selectedBoard.MinimapRectangle.RemoveItem(null);
                                    }
                                }
                            }
                            else
                            {
                                item.RemoveItem(actions);
                            }
                        }
                        break;

                    case MouseState.RandomTiles:
                    case MouseState.StaticObjectAdding:
                    case MouseState.Chairs:
                    case MouseState.Ropes:
                        parentBoard.InvokeReturnToSelectionState();
                        break;

                    case MouseState.Footholds:
                        while (selectedBoard.Mouse.connectedLines.Count > 0 && selectedBoard.Mouse.connectedLines[0].FirstDot.connectedLines.Count > 0)
                        {
                            selectedBoard.Mouse.connectedLines[0].FirstDot.connectedLines[0].Remove(false, actions);
                        }
                        break;
                    }
                    break;

                case Keys.F:
                    if (ctrl)
                    {
                        foreach (BoardItem item in selectedBoard.SelectedItems)
                        {
                            if (item is IFlippable)
                            {
                                ((IFlippable)item).Flip = !((IFlippable)item).Flip;
                                actions.Add(UndoRedoManager.ItemFlipped((IFlippable)item));
                            }
                        }
                    }
                    break;

                case Keys.Add:
                    foreach (BoardItem item in selectedBoard.SelectedItems)
                    {
                        item.Z += UserSettings.zShift;
                        actions.Add(UndoRedoManager.ItemZChanged(item, item.Z - UserSettings.zShift, item.Z));
                    }
                    selectedBoard.BoardItems.Sort();
                    break;

                case Keys.Subtract:
                    foreach (BoardItem item in selectedBoard.SelectedItems)
                    {
                        item.Z -= UserSettings.zShift;
                        actions.Add(UndoRedoManager.ItemZChanged(item, item.Z + UserSettings.zShift, item.Z));
                    }
                    selectedBoard.BoardItems.Sort();
                    break;

                case Keys.A:
                    if (ctrl)
                    {
                        foreach (BoardItem item in selectedBoard.BoardItems.Items)
                        {
                            if ((selectedBoard.EditedTypes & item.Type) == item.Type)
                            {
                                if (item is LayeredItem)
                                {
                                    LayeredItem li = (LayeredItem)item;
                                    if (li.CheckIfLayerSelected(selectedBoard.GetUserSelectionInfo()))
                                    {
                                        item.Selected = true;
                                    }
                                }
                                else
                                {
                                    item.Selected = true;
                                }
                            }
                        }
                    }
                    clearRedo = false;
                    break;

                case Keys.X:     // Cut
                    if (ctrl && selectedBoard.Mouse.State == MouseState.Selection)
                    {
                        Clipboard.SetData(SerializationManager.HaClipboardData,
                                          selectedBoard.SerializationManager.SerializeList(selectedBoard.SelectedItems.Cast <ISerializableSelector>()));
                        int selectedItemIndex = 0;
                        while (selectedBoard.SelectedItems.Count > selectedItemIndex)
                        {
                            BoardItem item = selectedBoard.SelectedItems[selectedItemIndex];
                            if (item is ToolTipDot || item is MiscDot || item is VRDot || item is MinimapDot)
                            {
                                selectedItemIndex++;
                            }
                            else
                            {
                                item.RemoveItem(actions);
                            }
                        }
                        break;
                    }
                    break;

                case Keys.C:     // Copy
                    if (ctrl)
                    {
                        Clipboard.SetData(SerializationManager.HaClipboardData,
                                          selectedBoard.SerializationManager.SerializeList(selectedBoard.SelectedItems.Cast <ISerializableSelector>()));
                    }
                    break;

                case Keys.V:     // Paste
                    if (ctrl && Clipboard.ContainsData(SerializationManager.HaClipboardData))
                    {
                        List <ISerializable> items;
                        try
                        {
                            items = selectedBoard.SerializationManager.DeserializeList((string)Clipboard.GetData(SerializationManager.HaClipboardData));
                        }
                        catch (SerializationException de)
                        {
                            MessageBox.Show(de.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(string.Format("An error occurred: {0}", e.ToString()), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        bool needsLayer = false;

                        // Make sure we dont have any tS conflicts
                        string tS = null;
                        foreach (ISerializable item in items)
                        {
                            if (item is TileInstance)
                            {
                                TileInstance tile   = (TileInstance)item;
                                string       currtS = ((TileInfo)tile.BaseInfo).tS;
                                if (currtS != tS)
                                {
                                    if (tS == null)
                                    {
                                        tS = currtS;
                                    }
                                    else
                                    {
                                        MessageBox.Show("Clipboard contains two tiles with different tile sets, cannot paste.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        return;
                                    }
                                }
                            }
                            if (item is IContainsLayerInfo)
                            {
                                needsLayer = true;
                            }
                        }
                        if (needsLayer && (selectedBoard.SelectedLayerIndex < 0 || selectedBoard.SelectedPlatform < 0))
                        {
                            MessageBox.Show("Layered items in clipboard and no layer/platform selected, cannot paste.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        if (tS != null && selectedBoard.SelectedLayer.tS != null && tS != selectedBoard.SelectedLayer.tS)
                        {
                            MessageBox.Show("Clipboard contains tile in a different set than the current selected layer, cannot paste.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        // Calculate offsetting
                        XNA.Point minPos = new XNA.Point(int.MaxValue, int.MaxValue);
                        XNA.Point maxPos = new XNA.Point(int.MinValue, int.MinValue);
                        foreach (ISerializable item in items)
                        {
                            if (item is BoardItem)
                            {
                                BoardItem bi = (BoardItem)item;
                                if (bi.Left < minPos.X)
                                {
                                    minPos.X = bi.Left;
                                }
                                if (bi.Top < minPos.Y)
                                {
                                    minPos.Y = bi.Top;
                                }
                                if (bi.Right > maxPos.X)
                                {
                                    maxPos.X = bi.Right;
                                }
                                if (bi.Bottom > maxPos.Y)
                                {
                                    maxPos.Y = bi.Bottom;
                                }
                            }
                            else if (item is Rope)
                            {
                                Rope r    = (Rope)item;
                                int  x    = r.FirstAnchor.X;
                                int  minY = Math.Min(r.FirstAnchor.Y, r.SecondAnchor.Y);
                                int  maxY = Math.Max(r.FirstAnchor.Y, r.SecondAnchor.Y);
                                if (x < minPos.X)
                                {
                                    minPos.X = x;
                                }
                                if (x > maxPos.X)
                                {
                                    maxPos.X = x;
                                }
                                if (minY < minPos.Y)
                                {
                                    minPos.Y = minY;
                                }
                                if (maxY > maxPos.Y)
                                {
                                    maxPos.Y = maxY;
                                }
                            }
                        }
                        XNA.Point center = new XNA.Point((maxPos.X + minPos.X) / 2, (maxPos.Y + minPos.Y) / 2);
                        XNA.Point offset = new XNA.Point(selectedBoard.Mouse.X - center.X, selectedBoard.Mouse.Y - center.Y);

                        // Add the items
                        ClearSelectedItems(selectedBoard);
                        List <UndoRedoAction> undoPipe = new List <UndoRedoAction>();
                        foreach (ISerializable item in items)
                        {
                            item.AddToBoard(undoPipe);
                            item.PostDeserializationActions(true, offset);
                        }
                        selectedBoard.BoardItems.Sort();
                        selectedBoard.UndoRedoMan.AddUndoBatch(undoPipe);
                    }
                    break;

                case Keys.Z:
                    if (ctrl && selectedBoard.UndoRedoMan.UndoList.Count > 0)
                    {
                        selectedBoard.UndoRedoMan.Undo();
                    }
                    clearRedo = false;
                    break;

                case Keys.Y:
                    if (ctrl && selectedBoard.UndoRedoMan.RedoList.Count > 0)
                    {
                        selectedBoard.UndoRedoMan.Redo();
                    }
                    clearRedo = false;
                    break;

                case Keys.S:
                    if (ctrl)
                    {
                        parentBoard.OnExportRequested();
                    }
                    break;

                case Keys.O:
                    if (ctrl)
                    {
                        parentBoard.OnLoadRequested();
                    }
                    break;

                case Keys.Escape:
                    if (selectedBoard.Mouse.State == MouseState.Selection)
                    {
                        ClearBoundItems(selectedBoard);
                        ClearSelectedItems(selectedBoard);
                        clearRedo = false;
                    }
                    else if (selectedBoard.Mouse.State == MouseState.Footholds)
                    {
                        selectedBoard.Mouse.Clear();
                    }
                    else
                    {
                        parentBoard.InvokeReturnToSelectionState();
                    }
                    break;

                default:
                    clearRedo = false;
                    break;

                case Keys.W:
                    if (ctrl)
                    {
                        parentBoard.OnCloseTabRequested();
                    }
                    break;

                case Keys.Tab:
                    if (ctrl)
                    {
                        parentBoard.OnSwitchTabRequested(shift);
                    }
                    break;
                }
                if (actions.Count > 0)
                {
                    selectedBoard.UndoRedoMan.AddUndoBatch(actions);
                }
                if (clearRedo)
                {
                    selectedBoard.UndoRedoMan.RedoList.Clear();
                }
            }
        }
Ejemplo n.º 18
0
 private UndoRedoAction CreateItemUndoMoveAction(BoardItem item, XNA.Point posChange)
 {
     if (item is BackgroundInstance)
         return UndoRedoManager.BackgroundMoved((BackgroundInstance)item, new XNA.Point(((BackgroundInstance)item).BaseX + posChange.X, ((BackgroundInstance)item).BaseY + posChange.Y), new XNA.Point(((BackgroundInstance)item).BaseX, ((BackgroundInstance)item).BaseY));
     else
         return UndoRedoManager.ItemMoved(item, new XNA.Point(item.X + posChange.X, item.Y + posChange.Y), new XNA.Point(item.X, item.Y));
 }
Ejemplo n.º 19
0
        private void parentBoard_LeftMouseDown(Board selectedBoard, BoardItem item, BoardItem selectedItem, XNA.Point realPosition, XNA.Point virtualPosition, bool selectedItemHigher)
        {
            lock (parentBoard)
            {
                OnUserInteraction();
                if (ClickOnMinimap(selectedBoard, realPosition) && selectedBoard.Mouse.State == MouseState.Selection)
                {
                    //ClearSelectedItems(selectedBoard);
                    selectedBoard.Mouse.MinimapBrowseOngoing = true;
                    HandleMinimapBrowse(selectedBoard, realPosition);
                }
                else if (selectedBoard.Mouse.State == MouseState.Selection)
                {
                    //handle drag-drop, multiple selection and all that
                    bool ctrlDown = (Control.ModifierKeys & Keys.Control) == Keys.Control;
                    if (item == null && selectedItem == null) //drag-selection is starting
                    {
                        if (!ctrlDown)
                        {
                            ClearSelectedItems(selectedBoard);
                        }
                        selectedBoard.Mouse.MultiSelectOngoing = true;
                        selectedBoard.Mouse.MultiSelectStart = virtualPosition;
                    }
                    else //Single click on item
                    {
                        BoardItem itemToSelect = null;
                        bool itemAlreadySelected = false;

                        if (item == null) // If user didn't click on any non-selected item, we want to keep selectedItem as our bound item
                        {
                            itemToSelect = selectedItem;
                            itemAlreadySelected = true;
                        }
                        else if (selectedItem == null) // We are guaranteed (item != null) at this point, so just select item
                        {
                            itemToSelect = item;
                        }
                        else if (!selectedItemHigher) // item needs to be selected but there is already a selectedItem; only switch selection if the selectedItem is not higher
                        {
                            itemToSelect = item;
                        }
                        else // Otherwise, just mark selectedItem as the item we are selecting
                        {
                            itemToSelect = selectedItem;
                            itemAlreadySelected = true;
                        }

                        if (!itemAlreadySelected && !ctrlDown) // If we are changing selection and ctrl is not down, clear current selected items
                        {
                            ClearSelectedItems(selectedBoard);
                        }
                        if (ctrlDown) // If we are clicking an item and ctrl IS down, we need to toggle its selection
                        {
                            itemToSelect.Selected = !itemToSelect.Selected;
                        }
                        else // Otherwise, mark the item as selected (if it's already selected nothing will happen) and bind it to the mouse to start drag-drop action
                        {
                            itemToSelect.Selected = true;
                            selectedBoard.Mouse.SingleSelectStarting = true;
                            selectedBoard.Mouse.SingleSelectStart = virtualPosition;
                            //BindAllSelectedItems(selectedBoard); // not binding selected items here because we will bind them after significant movement
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public override void BindItem(BoardItem item, Microsoft.Xna.Framework.Point distance)
 {
     lock (Board.ParentControl)
     {
         if (BoundItems.ContainsKey(item))
             return;
         BoundItems[item] = distance;
         item.tempParent = item.Parent;
         item.Parent = this;
     }
 }
Ejemplo n.º 21
0
 private void parentBoard_LeftMouseUp(Board selectedBoard, BoardItem target, BoardItem selectedTarget, XNA.Point realPosition, XNA.Point virtualPosition, bool selectedItemHigher)
 {
     lock (parentBoard)
     {
         OnUserInteraction();
         if (selectedBoard.Mouse.State == MouseState.Selection)//handle drag-drop selection end
         {
             ClearBoundItems(selectedBoard);
         }
         else if (selectedBoard.Mouse.State == MouseState.StaticObjectAdding ||
             selectedBoard.Mouse.State == MouseState.RandomTiles ||
             selectedBoard.Mouse.State == MouseState.Chairs ||
             selectedBoard.Mouse.State == MouseState.Ropes ||
             selectedBoard.Mouse.State == MouseState.Tooltip ||
             selectedBoard.Mouse.State == MouseState.Clock) //handle clicks that are meant to add an item to the board
         {
             selectedBoard.Mouse.PlaceObject();
         }
         else if (selectedBoard.Mouse.State == MouseState.Footholds)
         {
             selectedBoard.Mouse.TryConnectFoothold();
         }
     }
 }
Ejemplo n.º 22
0
 public void PlaceObject()
 {
     lock (Board.ParentControl)
     {
         if (state == MouseState.StaticObjectAdding || state == MouseState.RandomTiles)
         {
             List<UndoRedoAction> undoPipe = new List<UndoRedoAction>();
             currAddedObj.OnItemPlaced(undoPipe);
             Board.UndoRedoMan.AddUndoBatch(undoPipe);
             ReleaseItem(currAddedObj);
             if (currAddedObj is LayeredItem)
             {
                 int highestZ = 0;
                 foreach (LayeredItem item in Board.BoardItems.TileObjs)
                     if (item.Z > highestZ) highestZ = item.Z;
                 currAddedObj.Z = highestZ;
                 Board.BoardItems.Sort();
             }
             if (state == MouseState.StaticObjectAdding)
                 currAddedObj = currAddedInfo.CreateInstance(Board.SelectedLayer, Board, X + currAddedInfo.Origin.X - currAddedInfo.Image.Width / 2, Y + currAddedInfo.Origin.Y - currAddedInfo.Image.Height / 2, 50, false);
             else
                 currAddedObj = tileRandomList[NextInt32(tileRandomList.Length)].CreateInstance(Board.SelectedLayer, Board, X + currAddedInfo.Origin.X - currAddedInfo.Image.Width / 2, Y + currAddedInfo.Origin.Y - currAddedInfo.Image.Height / 2, 50, false);
             Board.BoardItems.Add(currAddedObj, false);
             BindItem(currAddedObj, new Microsoft.Xna.Framework.Point(currAddedInfo.Origin.X - currAddedInfo.Image.Width / 2, currAddedInfo.Origin.Y - currAddedInfo.Image.Height / 2));
         }
         else if (state == MouseState.Chairs)
         {
             Board.UndoRedoMan.AddUndoBatch(new List<UndoRedoAction> { UndoRedoManager.ItemAdded(currAddedObj) });
             ReleaseItem(currAddedObj);
             currAddedObj = new Chair(Board, X, Y);
             Board.BoardItems.Add(currAddedObj, false);
             BindItem(currAddedObj, new Microsoft.Xna.Framework.Point());
         }
         else if (state == MouseState.Ropes)
         {
             int count = BoundItems.Count;
             RopeAnchor anchor = (RopeAnchor)BoundItems.Keys.ElementAt(0);
             ReleaseItem(anchor);
             if (count == 1)
             {
                 Board.UndoRedoMan.AddUndoBatch(new List<UndoRedoAction> { UndoRedoManager.RopeAdded(anchor.ParentRope) });
                 CreateRope();
             }
         }
         else if (state == MouseState.Tooltip)
         {
             int count = BoundItems.Count;
             ToolTipDot dot = (ToolTipDot)BoundItems.Keys.ElementAt(0);
             ReleaseItem(dot);
             if (count == 1)
             {
                 List<UndoRedoAction> undoPipe = new List<UndoRedoAction>();
                 dot.ParentTooltip.OnItemPlaced(undoPipe);
                 Board.UndoRedoMan.AddUndoBatch(undoPipe);
                 CreateTooltip();
             }
         }
         else if (state == MouseState.Clock)
         {
             int count = BoundItems.Count;
             List<BoardItem> items = BoundItems.Keys.ToList();
             Clock clock = null;
             foreach (BoardItem item in items)
             {
                 if (item is Clock)
                 {
                     clock = (Clock)item;
                 }
             }
             foreach (BoardItem item in items)
             {
                 ReleaseItem(item);
             }
             List<UndoRedoAction> undoPipe = new List<UndoRedoAction>();
             clock.OnItemPlaced(undoPipe);
             Board.UndoRedoMan.AddUndoBatch(undoPipe);
             CreateClock();
         }
     }
 }
Ejemplo n.º 23
0
 public UndoRedoAction(BoardItem item, UndoRedoType type, object ParamA, object ParamB, object ParamC)
     : this(item, type, ParamA, ParamB)
 {
     this.ParamC = ParamC;
 }
Ejemplo n.º 24
0
 public void SetChairMode()
 {
     lock (Board.ParentControl)
     {
         Clear();
         currAddedObj = new Chair(Board, X, Y);
         Board.BoardItems.Add(currAddedObj, false);
         BindItem(currAddedObj, new Microsoft.Xna.Framework.Point());
         state = MouseState.Chairs;
     }
 }
Ejemplo n.º 25
0
 public static UndoRedoAction ItemMoved(BoardItem item, Point oldPos, Point newPos)
 {
     return new UndoRedoAction(item, UndoRedoType.ItemMoved, oldPos, newPos);
 }
Ejemplo n.º 26
0
 private void parentBoard_MouseDoubleClick(Board selectedBoard, BoardItem target, XNA.Point realPosition, XNA.Point virtualPosition)
 {
     lock (parentBoard)
     {
         OnUserInteraction();
         if (ClickOnMinimap(selectedBoard, realPosition)) return;
         if (target != null)
         {
             ClearSelectedItems(selectedBoard);
             target.Selected = true;
             parentBoard.EditInstanceClicked(target);
         }
         else if (selectedBoard.Mouse.State == MouseState.Footholds)
         {
             selectedBoard.Mouse.CreateFhAnchor();
         }
     }
 }
Ejemplo n.º 27
0
        private void parentBoard_LeftMouseDown(Board selectedBoard, BoardItem item, BoardItem selectedItem, XNA.Point realPosition, XNA.Point virtualPosition, bool selectedItemHigher)
        {
            lock (parentBoard)
            {
                OnUserInteraction();
                if (ClickOnMinimap(selectedBoard, realPosition) && selectedBoard.Mouse.State == MouseState.Selection)
                {
                    //ClearSelectedItems(selectedBoard);
                    selectedBoard.Mouse.MinimapBrowseOngoing = true;
                    HandleMinimapBrowse(selectedBoard, realPosition);
                }
                else if (selectedBoard.Mouse.State == MouseState.Selection)
                {
                    //handle drag-drop, multiple selection and all that
                    bool ctrlDown = (Control.ModifierKeys & Keys.Control) == Keys.Control;
                    if (item == null && selectedItem == null) //drag-selection is starting
                    {
                        if (!ctrlDown)
                        {
                            ClearSelectedItems(selectedBoard);
                        }
                        selectedBoard.Mouse.MultiSelectOngoing = true;
                        selectedBoard.Mouse.MultiSelectStart   = virtualPosition;
                    }
                    else //Single click on item
                    {
                        BoardItem itemToSelect        = null;
                        bool      itemAlreadySelected = false;

                        if (item == null) // If user didn't click on any non-selected item, we want to keep selectedItem as our bound item
                        {
                            itemToSelect        = selectedItem;
                            itemAlreadySelected = true;
                        }
                        else if (selectedItem == null) // We are guaranteed (item != null) at this point, so just select item
                        {
                            itemToSelect = item;
                        }
                        else if (!selectedItemHigher) // item needs to be selected but there is already a selectedItem; only switch selection if the selectedItem is not higher
                        {
                            itemToSelect = item;
                        }
                        else // Otherwise, just mark selectedItem as the item we are selecting
                        {
                            itemToSelect        = selectedItem;
                            itemAlreadySelected = true;
                        }

                        if (!itemAlreadySelected && !ctrlDown) // If we are changing selection and ctrl is not down, clear current selected items
                        {
                            ClearSelectedItems(selectedBoard);
                        }
                        if (ctrlDown) // If we are clicking an item and ctrl IS down, we need to toggle its selection
                        {
                            itemToSelect.Selected = !itemToSelect.Selected;
                        }
                        else // Otherwise, mark the item as selected (if it's already selected nothing will happen) and bind it to the mouse to start drag-drop action
                        {
                            itemToSelect.Selected = true;
                            selectedBoard.Mouse.SingleSelectStarting = true;
                            selectedBoard.Mouse.SingleSelectStart    = virtualPosition;
                            //BindAllSelectedItems(selectedBoard); // not binding selected items here because we will bind them after significant movement
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
 public static UndoRedoAction ItemDeleted(BoardItem item)
 {
     return new UndoRedoAction(item, UndoRedoType.ItemDeleted, null, null);
 }
Ejemplo n.º 29
0
 private void parentBoard_RightMouseClick(Board selectedBoard, BoardItem rightClickTarget, XNA.Point realPosition, XNA.Point virtualPosition, MouseState mouseState)
 {
     lock (parentBoard)
     {
         OnUserInteraction();
         if (mouseState == MouseState.Selection)
         {
             ClearBoundItems(selectedBoard);
             if (ClickOnMinimap(selectedBoard, realPosition)) return;
             if (rightClickTarget == null)
                 return;
             if (!rightClickTarget.Selected)
                 ClearSelectedItems(selectedBoard);
             rightClickTarget.Selected = true;
             BoardItemContextMenu bicm = new BoardItemContextMenu(parentBoard, selectedBoard, rightClickTarget);
             bicm.Menu.Show(parentBoard.PointToScreen(new System.Drawing.Point(realPosition.X, realPosition.Y)));
         }
         else parentBoard.InvokeReturnToSelectionState();
     }
 }
Ejemplo n.º 30
0
 public static UndoRedoAction ItemsUnlinked(BoardItem parent, BoardItem child, Point distance)
 {
     return new UndoRedoAction(parent, UndoRedoType.ItemsUnlinked, child, distance);
 }
Ejemplo n.º 31
0
 public JsonResult SaveBoardItem(BoardItem boardItem)
 {
     var currentBoardItem = BoardDbContext.BoardItems.FirstOrDefault(b => b.Id == boardItem.Id && b.UserId == 1);
     var isSuccess = false;
     if (currentBoardItem != null)
     {
         currentBoardItem.Title = boardItem.Title;
         currentBoardItem.Description = boardItem.Description;
         currentBoardItem.IsShowProfile = boardItem.IsShowProfile;
         if (currentBoardItem.BoardStructure != boardItem.BoardStructure && !string.IsNullOrWhiteSpace(boardItem.BoardStructure))
         {
             currentBoardItem.BoardStructure = boardItem.BoardStructure;
             ImageHelpers.CombineImages(currentBoardItem.BoardStructure, Server.MapPath("~/App_Data/"),
                                     currentBoardItem.Id.ToString());
             currentBoardItem.BoardImageUrl = currentBoardItem.Id.ToString() + ".PNG";
         }
         isSuccess = BoardDbContext.SaveChanges() > 0;
     }
     return Json(isSuccess);
 }
Ejemplo n.º 32
0
    /// <summary>
    /// Makes new board and initializes new game.
    /// </summary>
    /// <param name='boardSizeX'>Board width.</param>
    /// <param name='boardSizeY'>Board height.</param>
    /// <param name='variousItemCount'>Various item count.</param>
    public void MakeNewBoard(int boardSizeX, int boardSizeY, int variousItemCount)
    {
        board = new BoardItem[boardSizeX, boardSizeY];
        this.boardSizeX = boardSizeX;
        this.boardSizeY = boardSizeY;
        this.variousItemCount = variousItemCount;
        score = 0;

        int generateCount = 0;

        // Valid board generation.
        while (true) {
            // Fill the board with random items.
            for (int y = 0; y < boardSizeY; y++) {
                for (int x = 0; x < boardSizeX; x++) {
                    board[x, y] = new BoardItem(0, variousItemCount);
                }
            }

            generateCount++;

            // Check for existing matches.
            if (LookForMatches(false).Count > 0) {
                continue;
            }

            // Check if there is at least one possible move for the player.
            ArrayList possibles = LookForPossibles(false);
            if (possibles.Count == 0) {
                continue;
            }

            // Suitable board found.
            break;
        }
        Debug.Log("Board re-generated: " + (generateCount - 1).ToString() + "x");

        gameState = GameState.GamePlaying;
    }
Ejemplo n.º 33
0
 public JsonResult UpdateBoardItem(BoardItem boardItem)
 {
     var currentBoardItem = BoardDbContext.BoardItems.FirstOrDefault(b => b.Id == boardItem.Id && b.UserId == 1);
     var isSuccess = false;
     if (currentBoardItem != null)
     {
         currentBoardItem.Title = boardItem.Title;
         currentBoardItem.Description = boardItem.Description;
         isSuccess = BoardDbContext.SaveChanges() > 0;
     }
     return Json(isSuccess);
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Destroys items in a cross shape.
        /// </summary>
        /// <returns>Points of destroyed items.</returns>
        /// <param name="refBoard">Reference to the game board.</param>
        /// <param name="centerX">X-coord of the shape centre.</param>
        /// <param name="centerY">Y-coord of the shape centre.</param>
        public ArrayList DestroyItemsInCrossShape(BoardItem[,] refBoard, int centerX, int centerY)
        {
            ArrayList destroyed = new ArrayList();

            // X-line.
            for (int x = centerX - itemCountX; x <= centerX + itemCountX; x++) {
                if (x >= 0 && x < refBoard.GetLength(0)) {
                    if (!refBoard[x, centerY].destroyed) {
                        refBoard[x, centerY].destroyed = true;
                        destroyed.Add(new Point(x, centerY));
                    }
                }
            }
            // Y-line.
            for (int y = centerY - itemCountY; y <= centerY + itemCountY; y++) {
                if (y >= 0 && y < refBoard.GetLength(1)) {
                    if (!refBoard[centerX, y].destroyed) {
                        refBoard[centerX, y].destroyed = true;
                        destroyed.Add(new Point(centerX, y));
                    }
                }
            }

            return destroyed;
        }
Ejemplo n.º 35
0
        /// Construtor.

        /// <param name="name">Name.</param>
        /// <param name="color">color</param>
        /// <param name="boardItem">Item.</param>
        public Players(string name, ConsoleColor color, BoardItem boardItem)
        {
            this.Name      = name;
            this.Color     = color;
            this.BoardItem = boardItem;
        }