Ejemplo n.º 1
0
        //----------------------------------------------------------------------------------------------------------------------------------------

        protected void setPossibleMovesInLoop(Int32 aAddX, Int32 aAddY)
        {
            Int32 xCoord = mFigureToMove.x + aAddX;
            Int32 yCoord = mFigureToMove.y + aAddY;

            while (isValidField(xCoord, yCoord))
            {
                if (mIsCheckChess && isChess(xCoord, yCoord))
                {
                    xCoord += aAddX;
                    yCoord += aAddY;
                    continue;
                }

                FigureItem figureItem = mChessBoard[xCoord][yCoord].figureItem;
                mPossibleMoves.Add((8 * xCoord) + yCoord);

                List <ModelItem> enemyFigures = (mFigureToMove.figureItem.color == Colors.WHITE ? mBlackFigures : mWhiteFigures);
                if (figureItem.figureType != FigureType.NO_FIGURE && figureItem.figureType != FigureType.EN_PASSANT_PAWN && enemyFigures.Contains(mChessBoard[xCoord][yCoord]))                         // when enemies found, break!
                {
                    break;
                }

                xCoord += aAddX;
                yCoord += aAddY;
            }
        }
Ejemplo n.º 2
0
 public ModelItem()
 {
     x          = -1;
     y          = -1;
     figureItem = new FigureItem(Colors.NO_COLOR, FigureType.NO_FIGURE);
     index      = -1;
 }
Ejemplo n.º 3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Constructor for CustomBoardViewModel
        /// </summary>
        public CustomBoardViewModel(Colors aPlayer1Color, Colors aStartingColor, Algorithm aPlayer1Algorithm, Algorithm aPlayer2Algorithm)
        {
            windowState  = "Normal";
            windowWidth  = 640;
            windowHeight = 480;
            fieldSize    = 48;
            boardSize    = 384;

            isStartBtnClicked = false;

            selectedPanelItem = new FigureItem(Colors.NO_COLOR, FigureType.NO_FIGURE);
            mLastClickedField = -1;

            startBtnClicked       = new DelegateCommand(X => onStartBtnClicked());
            cancelBtnClicked      = new DelegateCommand(X => onCancelBtnClicked());
            deleteSelectedClicked = new DelegateCommand(X => onDeleteSelectedClicked());
            saveClicked           = new DelegateCommand(X => onSaveClicked());
            loadClicked           = new DelegateCommand(X => onLoadClicked());

            mChessBoardCollection  = new ObservableCollection <BoardItem>();
            mBlackFigureCollection = new ObservableCollection <BoardItem>();
            mWhiteFigureCollection = new ObservableCollection <BoardItem>();
            savedPositions         = new ObservableCollection <String>();
            mChessBoardModel       = new ChessBoardModel(aPlayer1Color, aStartingColor, aPlayer1Algorithm, aPlayer2Algorithm);

            mTablePositions = new TablePositions();

            setSavedPositions();
            setupCustomBoard();
        }
Ejemplo n.º 4
0
        //----------------------------------------------------------------------------------------------------------------------------------------

        public ModelItem(Int32 aX, Int32 aY, Colors aColor, FigureType aFigureType)
        {
            x          = aX;
            y          = aY;
            figureItem = new FigureItem(aColor, aFigureType);
            index      = (aX * 8 + aY);
        }
Ejemplo n.º 5
0
    // Start is called before the first frame update
    private void OnEnable()
    {
        foreach (var VARIABLE in figureItems)
        {
            VARIABLE.OnShow();
        }

        previousFigureItem = currentFigureItem = figureItems[UIManager.Ins.PlayerFigure - 30];
    }
Ejemplo n.º 6
0
        //----------------------------------------------------------------------------------------------------------------------------------------

        protected Boolean isChess(Int32 aX, Int32 aY)
        {
            Boolean noChess = false;

            List <ModelItem> enemyFigures;
            List <ModelItem> myFigures;

            if (mFigureToMove.figureItem.color == Colors.WHITE)
            {
                myFigures    = mWhiteFigures;
                enemyFigures = mBlackFigures;
            }
            else
            {
                myFigures    = mBlackFigures;
                enemyFigures = mWhiteFigures;
            }

            FigureItem targetItem = new FigureItem(mChessBoard[aX][aY].figureItem.color, mChessBoard[aX][aY].figureItem.figureType);

            mChessBoard[aX][aY].figureItem.color      = mFigureToMove.figureItem.color;
            mChessBoard[aX][aY].figureItem.figureType = mFigureToMove.figureItem.figureType;
            mChessBoard[mFigureToMove.x][mFigureToMove.y].figureItem.color      = Colors.NO_COLOR;
            mChessBoard[mFigureToMove.x][mFigureToMove.y].figureItem.figureType = FigureType.NO_FIGURE;
            ModelItem myFigure = myFigures.Where(X => X.index == mFigureToMove.index).FirstOrDefault();

            myFigure.x     = aX;
            myFigure.y     = aY;
            myFigure.index = (aX * 8) + aY;

            Int32 MyKingPosition = myFigures.Where(X => X.figureItem.figureType == FigureType.KING || X.figureItem.figureType == FigureType.MOVED_KING).FirstOrDefault().index;

            foreach (ModelItem figure in enemyFigures)
            {
                if (figure.x == aX && figure.y == aY)
                {
                    continue;
                }

                List <Int32> possibleMoves = getPossibleMoves(figure);
                if (possibleMoves.Contains(MyKingPosition))
                {
                    noChess = true;
                    break;
                }
            }

            mChessBoard[mFigureToMove.x][mFigureToMove.y].figureItem.color      = mChessBoard[aX][aY].figureItem.color;
            mChessBoard[mFigureToMove.x][mFigureToMove.y].figureItem.figureType = mChessBoard[aX][aY].figureItem.figureType;
            mChessBoard[aX][aY].figureItem.color      = targetItem.color;
            mChessBoard[aX][aY].figureItem.figureType = targetItem.figureType;
            myFigure.x     = mFigureToMove.x;
            myFigure.y     = mFigureToMove.y;
            myFigure.index = mFigureToMove.index;

            return(noChess);
        }
Ejemplo n.º 7
0
        public Object Convert(Object value, Type targetType, Object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || !(value is FigureItem))
            {
                return(Binding.DoNothing);
            }

            FigureItem figure = ( FigureItem )value;

            if (figure.color == Colors.BLACK)
            {
                switch (figure.figureType)
                {
                case FigureType.MOVED_KING:
                case FigureType.KING:   return("/Images/Black_King.png");

                case FigureType.QUEEN:  return("/Images/Black_Queen.png");

                case FigureType.MOVED_ROOK:
                case FigureType.ROOK:   return("/Images/Black_Rook.png");

                case FigureType.BISHOP: return("/Images/Black_Bishop.png");

                case FigureType.KNIGHT: return("/Images/Black_Knight.png");

                case FigureType.PAWN:   return("/Images/Black_Pawn.png");
                }
            }
            else
            {
                switch (figure.figureType)
                {
                case FigureType.MOVED_KING:
                case FigureType.KING:   return("/Images/White_King.png");

                case FigureType.QUEEN:  return("/Images/White_Queen.png");

                case FigureType.MOVED_ROOK:
                case FigureType.ROOK:   return("/Images/White_Rook.png");

                case FigureType.BISHOP: return("/Images/White_Bishop.png");

                case FigureType.KNIGHT: return("/Images/White_Knight.png");

                case FigureType.PAWN:   return("/Images/White_Pawn.png");
                }
            }

            if (figure.color == Colors.NO_COLOR || figure.figureType == FigureType.NO_FIGURE)
            {
                return(DependencyProperty.UnsetValue);
            }

            return(Binding.DoNothing);
        }
Ejemplo n.º 8
0
    private void OnSelectItem(FigureItem figureItem, InfoFigure info)
    {
        // AudioManager.PlaySound(AudioManager.selectFigureName);
        AudioManager1.Ins.PlaySound(SoundType.Click);

        if (currentFigureItem != previousFigureItem || figureItem != previousFigureItem)
        {
            previousFigureItem = currentFigureItem;
            currentFigureItem  = figureItem;

            previousFigureItem.SetActiveBox();
            currentFigureItem.SetActiveBox();

            currentInfoData = info;
        }

        if (!info.isBuy && info.mission != "")
        {
            missionInfo.GetComponentInChildren <Text>().text = info.mission;
            missionInfo.Show();
        }

        if (info.isBuy)
        {
            HideAllButton();
            listButton[0].Show();
        }
        else if (info.costType == CostType.Coin)
        {
            HideAllButton();
            costButtonTxt.text = info.cost.ToString();
            listButton[1].Show();
        }
        else if (info.costType == CostType.Video)
        {
            HideAllButton();
            videoTxt.text = figureItem.videoTxt.text;
            listButton[2].Show();
        }
        else
        {
            HideAllButton();
            // listButton[3].Show();
        }

        if (info.isUsing)
        {
            HideAllButton();
            // listButton[3].Show();
        }
    }
Ejemplo n.º 9
0
 public IHttpActionResult Post([FromBody] FigureItem figureItems)
 {
     try
     {
         using (var entities = new GreatWarriorEntities())
         {
             entities.FigureItems.Add(figureItems);
             entities.SaveChanges();
             return(Content(HttpStatusCode.OK, true));
         }
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.InternalServerError, ex));
     }
 }
Ejemplo n.º 10
0
        //----------------------------------------------------------------------------------------------------------------------------------------

        protected virtual void setOnePossibleMove(Int32 aAddX, Int32 aAddY)
        {
            Int32 xCoord = mFigureToMove.x + aAddX;
            Int32 yCoord = mFigureToMove.y + aAddY;

            if (isValidField(xCoord, yCoord))
            {
                if (mIsCheckChess && isChess(xCoord, yCoord))
                {
                    return;
                }

                FigureItem figureItem = mChessBoard[xCoord][yCoord].figureItem;
                mPossibleMoves.Add((8 * xCoord) + yCoord);
            }
        }
Ejemplo n.º 11
0
        //-----------------------------------------------------------------------------------------------------------------------------------------

        private void onPanelClicked(Object aSender, FieldClickedEventArg aArguments)
        {
            if (selectedPanelItem.color == aArguments.figureItem.color && selectedPanelItem.figureType == aArguments.figureItem.figureType)
            {
                mBlackFigureCollection.Concat(mWhiteFigureCollection).Where(X => X.figureItem.color == selectedPanelItem.color && X.figureItem.figureType == selectedPanelItem.figureType).FirstOrDefault().highlightColor = Colors.NO_COLOR;
                selectedPanelItem = new FigureItem(Colors.NO_COLOR, FigureType.NO_FIGURE);
                return;
            }
            if (selectedPanelItem.figureType != FigureType.NO_FIGURE)
            {
                mBlackFigureCollection.Concat(mWhiteFigureCollection).Where(X => X.figureItem.color == selectedPanelItem.color && X.figureItem.figureType == selectedPanelItem.figureType).FirstOrDefault().highlightColor = Colors.NO_COLOR;
            }

            selectedPanelItem = new FigureItem(aArguments.figureItem);

            mBlackFigureCollection.Concat(mWhiteFigureCollection).Where(X => X.figureItem.color == selectedPanelItem.color && X.figureItem.figureType == selectedPanelItem.figureType).FirstOrDefault().highlightColor = Colors.RED;
        }
Ejemplo n.º 12
0
        //-----------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Constructor for CustomBoardViewModel
        /// </summary>
        public ChessBoardViewModel(ChessBoardModel aChessBoardModel)
        {
            mChessBoardModel = aChessBoardModel;
            mChessBoardModel.fieldClicked += new EventHandler <PutFigureOnTheTableEventArg>(onPutFigureOnTheTableEventArg);
            mChessBoardModel.setHighlight += new EventHandler <SetHighlightEventArg>(onSetHighlight);
            mChessBoardModel.setIsEnable  += new EventHandler <Boolean>(onSetIsEnable);

            windowState           = "Normal";
            windowWidth           = 640;
            windowHeight          = 480;
            fieldSize             = 48;
            boardSize             = 384;
            mChessBoardCollection = new ObservableCollection <BoardItem>();

            selectedPanelItem = new FigureItem(Colors.NO_COLOR, FigureType.NO_FIGURE);

            setupCustomBoard();
            mChessBoardModel.startModel();
        }
Ejemplo n.º 13
0
 public IHttpActionResult Delete([FromBody] FigureItem figureItem)
 {
     try
     {
         using (var entities = new GreatWarriorEntities())
         {
             var figure = entities.FigureItems.SingleOrDefault(f => f.FigureItem_Name == figureItem.FigureItem_Name);
             if (figureItem == null)
             {
                 return(Content(HttpStatusCode.NotFound, false));
             }
             entities.FigureItems.Remove(figureItem);
             entities.SaveChanges();
             return(Content(HttpStatusCode.OK, true));
         }
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.InternalServerError, ex));
     }
 }
Ejemplo n.º 14
0
        //----------------------------------------------------------------------------------------------------------------------------------------

        private void moveFigureTo(ModelItem aPlaceHere)
        {
            if (isCastling(mFigureToMove, aPlaceHere))
            {
                castling(aPlaceHere);
                removeHighLights();
                setLastMoveHighLights(mLastMove, false);
                mLastMove = new Move(mFigureToMove, chessBoard[aPlaceHere.x][aPlaceHere.y]);
                setLastMoveHighLights(mLastMove, true);
                mTimer.Start();
                return;
            }
            updateCastling();

            FigureItem enPassantFigure = chessBoard[aPlaceHere.x][aPlaceHere.y].figureItem;

            if (mFigureToMove.figureItem.figureType == FigureType.PAWN && Math.Abs(mFigureToMove.x - aPlaceHere.x) == 2)
            {
                removeEnPassantPawn();
                Int32 enPassantX = (mFigureToMove.x == 1 ? 2 : 5);
                chessBoard[enPassantX][mFigureToMove.y].figureItem.color      = mFigureToMove.figureItem.color;
                chessBoard[enPassantX][mFigureToMove.y].figureItem.figureType = FigureType.EN_PASSANT_PAWN;
            }
            else if (enPassantFigure.figureType == FigureType.EN_PASSANT_PAWN && mFigureToMove.figureItem.figureType == FigureType.PAWN &&
                     enPassantFigure.color != mFigureToMove.figureItem.color)
            {
                Int32     originalPawnX = (aPlaceHere.x == 2 ? 3 : 4);
                ModelItem originalPawn  = chessBoard[originalPawnX][aPlaceHere.y];
                removeFigureFromWhiteOrBlack(originalPawn);
                originalPawn.figureItem = new FigureItem(Colors.NO_COLOR, FigureType.NO_FIGURE);
                fieldClicked(this, new PutFigureOnTheTableEventArg(originalPawn.x, originalPawn.y, originalPawn.index, Colors.NO_COLOR, FigureType.NO_FIGURE));
            }
            else
            {
                removeEnPassantPawn();
            }

            removeFigureFromWhiteOrBlack(aPlaceHere);

            ModelItem tempItem;

            if (mCurrentColor == Colors.WHITE)
            {
                tempItem      = whiteFigures.Where(X => X.index == mFigureToMove.index).FirstOrDefault();
                mCurrentColor = Colors.BLACK;
            }
            else
            {
                tempItem      = blackFigures.Where(X => X.index == mFigureToMove.index).FirstOrDefault();
                mCurrentColor = Colors.WHITE;
            }

            tempItem.index = aPlaceHere.index;
            tempItem.x     = aPlaceHere.x;
            tempItem.y     = aPlaceHere.y;

            fieldClicked(this, new PutFigureOnTheTableEventArg(mFigureToMove.x, mFigureToMove.y, mFigureToMove.index, Colors.NO_COLOR, FigureType.NO_FIGURE));
            chessBoard[mFigureToMove.x][mFigureToMove.y].figureItem = new FigureItem(Colors.NO_COLOR, FigureType.NO_FIGURE);

            fieldClicked(this, new PutFigureOnTheTableEventArg(aPlaceHere.x, aPlaceHere.y, aPlaceHere.index, mFigureToMove.figureItem.color, mFigureToMove.figureItem.figureType));
            chessBoard[aPlaceHere.x][aPlaceHere.y].figureItem = new FigureItem(mFigureToMove.figureItem.color, mFigureToMove.figureItem.figureType);

            removeHighLights();

            setLastMoveHighLights(mLastMove, false);
            mLastMove = new Move(mFigureToMove, chessBoard[aPlaceHere.x][aPlaceHere.y]);
            setLastMoveHighLights(mLastMove, true);

            if (mTimer != null)
            {
                mTimer.Start();
            }
        }
Ejemplo n.º 15
0
        //-----------------------------------------------------------------------------------------------------------------------------------------

        public String getFigureId(FigureItem aItem)
        {
            String returnString;

            switch (aItem.figureType)
            {
            case FigureType.PAWN:
            {
                returnString = "1";
            } break;

            case FigureType.EN_PASSANT_PAWN:
            {
                returnString = "2";
            } break;

            case FigureType.KNIGHT:
            {
                returnString = "3";
            } break;

            case FigureType.BISHOP:
            {
                returnString = "4";
            } break;

            case FigureType.ROOK:
            {
                returnString = "5";
            } break;

            case FigureType.MOVED_ROOK:
            {
                returnString = "6";
            } break;

            case FigureType.QUEEN:
            {
                returnString = "9";
            } break;

            case FigureType.KING:
            {
                returnString = "10";
            } break;

            case FigureType.MOVED_KING:
            {
                returnString = "11";
            } break;

            default:
            {
                returnString = "0";
            } break;
            }

            if (aItem.color == Colors.BLACK)
            {
                returnString = "-" + returnString;
            }
            return(returnString);
        }
Ejemplo n.º 16
0
        //----------------------------------------------------------------------------------------------------------------------------------------

        public override List <Int32> possibleMoves()
        {
            mPossibleMoves = new List <Int32>();
            Int32   xCoord          = -1;
            Int32   yCoord          = -1;
            Boolean isValid         = false;
            Int32   isPlayer1Turn   = 1;                                     // we adds one to X if player 1 turns
            Int32   isPlayer1Moves2 = 1;                                     // we checks that is the pawn on line 1. If he is, he will able to step 2

            if (mPlayer1Color == mFigureToMove.figureItem.color)
            {
                isPlayer1Turn   = -1;                        // we removes one from X if player 2 turns
                isPlayer1Moves2 = 6;                         // we checks that is the pawn on line 6. If he is, he will able to step 2
            }

            Boolean canWeMoveForward = false;

            xCoord  = (mFigureToMove.x + isPlayer1Turn);              // Depends on the current player, X + 1 or X - 1
            yCoord  = mFigureToMove.y;
            isValid = isValidField(xCoord, yCoord);
            if (isValid && mChessBoard[xCoord][yCoord].figureItem.figureType == FigureType.NO_FIGURE)                   // Can we move forward?
            {
                canWeMoveForward = true;
                if (!mIsCheckChess || !isChess(xCoord, yCoord))
                {
                    mPossibleMoves.Add((8 * xCoord) + yCoord);
                }
            }

            //------

            xCoord += isPlayer1Turn;                                                                                                                 // Depends on the current player, X + 1 or X - 1
            isValid = isValidField(xCoord, yCoord);
            if (canWeMoveForward && mFigureToMove.x == isPlayer1Moves2 && mChessBoard[xCoord][yCoord].figureItem.figureType == FigureType.NO_FIGURE) // Can we make 2 steps forward?
            {
                if (!mIsCheckChess || !isChess(xCoord, yCoord))
                {
                    mPossibleMoves.Add((8 * (xCoord)) + yCoord);
                }
            }
            xCoord -= isPlayer1Turn;

            //------

            yCoord  = (mFigureToMove.y - 1);
            isValid = isValidField(xCoord, yCoord);
            if (isValid && (mChessBoard[xCoord][yCoord].figureItem.figureType != FigureType.NO_FIGURE || mChessBoard[xCoord][yCoord].figureItem.figureType == FigureType.EN_PASSANT_PAWN))                         // Can we hit someone on the left?
            {
                if (!mIsCheckChess || !isChess(xCoord, yCoord))
                {
                    FigureItem figureItem = mChessBoard[xCoord][yCoord].figureItem;
                    mPossibleMoves.Add((8 * xCoord) + yCoord);
                }
            }

            //------

            yCoord  = (mFigureToMove.y + 1);
            isValid = isValidField(xCoord, yCoord);
            if (isValid && (mChessBoard[xCoord][yCoord].figureItem.figureType != FigureType.NO_FIGURE || mChessBoard[xCoord][yCoord].figureItem.figureType == FigureType.EN_PASSANT_PAWN))                         // Can we hit someone on the right?
            {
                if (!mIsCheckChess || !isChess(xCoord, yCoord))
                {
                    FigureItem figureItem = mChessBoard[xCoord][yCoord].figureItem;
                    mPossibleMoves.Add((8 * xCoord) + yCoord);
                }
            }

            return(mPossibleMoves);
        }
Ejemplo n.º 17
0
    public void GenerateBuySkin()
    {
        ClearListSkin();
        if (missionInfo.gameObject.activeSelf)
        {
            missionInfo.Hide();
        }

        if (UIManager.Ins.figureData.figures.Count < 4)
        {
            gridLayout.constraintCount = UIManager.Ins.figureData.figures.Count;
        }
        else
        {
            gridLayout.constraintCount = 3;
        }

        foreach (var item in UIManager.Ins.figureData.figures)
        {
            GameObject newButton  = Instantiate(figureButton, figureContent);
            FigureItem figureItem = newButton.GetComponent <FigureItem>();

            if (!item.isBuy)
            {
                switch (item.costType)
                {
                case CostType.KillEnemy:
                    if (item.number <= UIManager.Ins.NumberKilled)
                    {
                        item.isBuy = true;
                    }
                    break;

                case CostType.Top:
                    if (item.number <= UIManager.Ins.NumberTop)
                    {
                        item.isBuy = true;
                    }
                    break;

                case CostType.Run:
                    if (item.number <= UIManager.Ins.PlayerMoveDistance)
                    {
                        item.isBuy = true;
                    }
                    break;

                case CostType.Video:
                    if (UIManager.Ins.VideoCount >= item.number)
                    {
                        item.isBuy = true;
                    }
                    else
                    {
                        string numberVideoTxt = UIManager.Ins.VideoCount + "/" + item.number;
                        figureItem.videoTxt.text = numberVideoTxt;
                    }
                    break;
                }
            }

            if (item.idFigure == UIManager.Ins.PlayerFigure)
            {
                item.isUsing       = true;
                selectedFigureItem = currentFigureItem = figureItem;
                currentFigureItem.SetActiveBox();
            }
            else if (item.isUsing)
            {
                item.isUsing = false;
            }
            figureItem.SetUp(item);

            newButton.GetComponent <Button>().onClick.AddListener(() => OnSelectItem(figureItem, item));
        }
    }
Ejemplo n.º 18
0
 public void ChangeCurrentFigure(int idFigure)
 {
     _currentFigure = idFigure;
     previousFigureItem.SetActiveBox();
     previousFigureItem = figureItems[idFigure - 30];
 }
Ejemplo n.º 19
0
        //-----------------------------------------------------------------------------------------------------------------------------------------

        public FigureItem(FigureItem aFigure)
        {
            color      = aFigure.color;
            figureType = aFigure.figureType;
        }