示例#1
0
        public Piece(AllPlayers player, int number, allFields placement)
        {
            this.player    = player;
            this.placement = placement;
            this.number    = number;

            picture = MakePiece(placement, number);
        }
示例#2
0
        private PictureBox MakePiece(allFields field, int nr)
        {
            PictureBox Piece = new PictureBox();

            Piece.SizeMode = PictureBoxSizeMode.StretchImage;
            Piece.Image    = Image.FromFile($"Images/Pieces/{playerString()}{nr + 1}.png");
            Piece.Size     = new Size(26, 26);
            Piece.Location = new Point(field.x, field.y);

            return(Piece);
        }
示例#3
0
        public List <Piece> findPiecesAtField(allFields field)
        {
            List <Piece> piecesAtField = new List <Piece>();

            // Adds all pieces at newPlacement to piecesAtField list
            foreach (AllPlayers player in players)
            {
                foreach (Piece piece in player.pieces)
                {
                    if (piece.placement == field)
                    {
                        piecesAtField.Add(piece);
                    }
                }
            }

            return(piecesAtField);
        }
示例#4
0
        private void resetSizeBeforeMove(Piece p, allFields newPlacement)
        {
            List <Piece> piecesAtField = findPiecesAtField(p.placement);

            // Removes itself from the list
            int index = piecesAtField.IndexOf(p);

            piecesAtField.Remove(p);

            // Updates size and location of pieces at old field
            switch (piecesAtField.Count)
            {
            case 1:
                piecesAtField[0].picture.Size     = new Size(26, 26);
                piecesAtField[0].picture.Location = new Point(piecesAtField[0].placement.x, piecesAtField[0].placement.y);
                break;

            case 2:         // Set size acording to two pieces at field
                piecesAtField[0].picture.Location = new Point(piecesAtField[0].placement.x - 4, piecesAtField[0].placement.y + 5);
                piecesAtField[1].picture.Location = new Point(piecesAtField[0].picture.Location.X + 19, piecesAtField[0].picture.Location.Y);
                break;

            case 3:         // Set size acording to three pieces at field
                piecesAtField[0].picture.Location = new Point(piecesAtField[0].placement.x - 4, piecesAtField[0].placement.y + 5 - 9);
                piecesAtField[1].picture.Location = new Point(piecesAtField[0].picture.Location.X + 19, piecesAtField[0].picture.Location.Y);
                piecesAtField[2].picture.Location = new Point(piecesAtField[0].picture.Location.X + 9, piecesAtField[0].picture.Location.Y + 19);
                break;

            default:
                break;
            }

            // Resets size and moves it
            p.picture.Size = new Size(26, 26);    // This resets the size, eg if it came from a field with more pieces on it
            p.newField(newPlacement);
        }
示例#5
0
 public void newField(allFields newPlacement)
 {
     placement        = newPlacement;
     picture.Location = new Point(newPlacement.x, newPlacement.y);
 }
示例#6
0
        double Passive(Piece p, allFields f)
        {
            double points = 0;

            allFields field = f;

            if (p.placement is homeField == false)
            {
                if (gameManager.diceValue == 3 || field is starField)
                {
                    field = gameManager.Ludo.boardFields[gameManager.Ludo.findNextStar(p, 6, true)];
                }

                if (field.index - p.placement.index > 0)
                {
                    points = field.index - p.placement.index;
                }
                else
                {
                    points = gameManager.Ludo.boardFields.Count + field.index - p.placement.index;
                }

                if (f is goalField)
                {
                    if (p.placement is goalField)
                    {
                        points = 1;
                    }
                    else
                    {
                        if (ChaseChecker(p, field.index, 6))
                        {
                            if (p.placement.index - gameManager.Ludo.GetHomeField(this) > 0)
                            {
                                points += p.placement.index - gameManager.Ludo.GetHomeField(this);
                            }
                            else
                            {
                                points += (gameManager.Ludo.boardFields.Count + p.placement.index - gameManager.Ludo.GetHomeField(this));
                            }
                        }
                    }
                }

                if (gameManager.Ludo.findPiecesAtField(field).Count > 0)
                {
                    if (field.team != team)
                    {
                        AllPlayers player = gameManager.Ludo.findPiecesAtField(field)[0].player;
                        if (field.index - gameManager.Ludo.GetHomeField(player) > 0)
                        {
                            points = (field.index - gameManager.Ludo.GetHomeField(player) / 3);
                        }
                        else
                        {
                            points = ((gameManager.Ludo.boardFields.Count + field.index - gameManager.Ludo.GetHomeField(player)) / 3);
                        }
                        Console.WriteLine(gameManager.currentPlayerString(this) + "Knocked Home: " + gameManager.currentPlayerString(player));
                        //points = 25;
                    }
                }

                if (ChaseChecker(p, field.index, 6))
                {
                    if (field.index - gameManager.Ludo.GetHomeField(this) > 0)
                    {
                        points -= field.index - gameManager.Ludo.GetHomeField(this);
                        points  = points * 1;
                    }
                    else
                    {
                        points -= (gameManager.Ludo.boardFields.Count + field.index - gameManager.Ludo.GetHomeField(this));
                        points  = points * 1;
                    }
                }

                if (ChaseChecker(p, p.placement.index, 6))
                {
                    if (field.index - gameManager.Ludo.GetHomeField(this) > 0)
                    {
                        points = field.index - gameManager.Ludo.GetHomeField(this);
                        points = points * 1;
                    }
                    else
                    {
                        points = (gameManager.Ludo.boardFields.Count + field.index - gameManager.Ludo.GetHomeField(this));
                    }
                }

                if (p.placement is starField)
                {
                    if (ChaseChecker(p, (gameManager.Ludo.findNextStar(p, 0, false)), 6))
                    {
                        if (field.index - gameManager.Ludo.GetHomeField(this) > 0)
                        {
                            points = field.index - gameManager.Ludo.GetHomeField(this);
                            points = points * 1;
                        }
                        else
                        {
                            points = gameManager.Ludo.boardFields.Count + field.index - gameManager.Ludo.GetHomeField(this);
                            points = points * 1;
                        }
                    }
                }
            }

            else
            {
                if (gameManager.diceValue == 6 || gameManager.diceValue == 5)
                {
                    points = 10;
                }
            }

            return(points);
        }
示例#7
0
        private void checkIfGoOnPath(Piece p, allFields newPlacement)
        {
            int pathFieldIndex          = getPlayersPathFieldIndex(p);
            List <pathField> pathFields = getPlayersPathFields(p);

            if (newPlacement is homeField || newPlacement is pathField)
            {
                returnOtherPlayerHome(p, newPlacement);
            }
            else if (p.placement.index == pathFieldIndex)   // If the piece is right outside of path
            {
                switch (gameManager.diceValue)
                {
                case 1:
                case 2:
                case 4:
                case 6:
                    moveXfieldsOnPath(p, gameManager.diceValue - 1);
                    break;

                case 3:
                    movePieceGoal(p);
                    break;

                case 5:
                    returnOtherPlayerHome(p, pathFields[0]);
                    break;
                }
            }
            else if (p.placement.index < pathFieldIndex && newPlacement.index > pathFieldIndex ||
                     p.placement.index > newPlacement.index && pathFieldIndex > p.placement.index)                                         // If the piece moves past the path entry
            {
                if (p.placement.index + gameManager.diceValue < 52 && boardFields[p.placement.index + gameManager.diceValue] is starField) // If the piece lands on the star outside it's path
                {
                    movePieceGoal(p);
                }
                else
                {
                    switch (gameManager.diceValue)
                    {
                    case 1:
                    case 2:
                    case 4:
                    case 6:
                        int remainingMoves = newPlacement.index - pathFieldIndex;
                        if (remainingMoves < 0)
                        {
                            remainingMoves = newPlacement.index + 1;     // pathFieldIndex - p.placement.index;
                        }
                        moveXfieldsOnPath(p, remainingMoves - 1);
                        break;

                    case 3:
                        movePieceGoal(p);
                        break;

                    case 5:
                        returnOtherPlayerHome(p, pathFields[0]);
                        break;
                    }
                }
            }
            else if (p.placement is pathField) // If the piece already are on path
            {
                if (gameManager.diceValue == 3 || gameManager.diceValue == 5)
                {
                    movePieceGoal(p);   // Both star and globus moves the piece to goal
                }
                else
                {
                    moveXfieldsOnPath(p, gameManager.diceValue);
                }
            }
            else
            {
                returnOtherPlayerHome(p, newPlacement);
            }
        }
示例#8
0
        private void returnOtherPlayerHome(Piece p, allFields newPlacement)
        {
            List <Piece> piecesAtField = findPiecesAtField(newPlacement);

            piecesAtField.Remove(p);

            // Reacts to how many pieces is in piecesAtField list
            switch (piecesAtField.Count)
            {
            case 0:
                resetSizeBeforeMove(p, newPlacement);
                break;

            case 1:
                if (piecesAtField[0].player == p.player)        // If the pieces are on the same team
                {
                    resetSizeBeforeMove(p, newPlacement);

                    // Sets size and location of piece already on field
                    piecesAtField[0].picture.Size     = new Size(15, 15);
                    piecesAtField[0].picture.Location = new Point(piecesAtField[0].picture.Location.X - 4, piecesAtField[0].picture.Location.Y + 5);

                    // Sets size and location of new piece
                    p.picture.Size     = new Size(15, 15);
                    p.picture.Location = new Point(piecesAtField[0].picture.Location.X + 19, piecesAtField[0].picture.Location.Y);
                }
                else                                // If the two pieces are on different teams
                {
                    if (newPlacement is globeField) // A piece is secured on a globefield
                    {
                        movePieceHome(p);
                    }
                    else
                    {
                        movePieceHome(piecesAtField[0]);        // Moves other player home
                        resetSizeBeforeMove(p, newPlacement);   // Moves current player to field
                    }
                }
                break;

            case 2:                                      // Two pieces at the field
                if (piecesAtField[0].player == p.player) // If the pieces are on the same team
                {
                    int   dx;
                    Piece pLeft, pRight;

                    resetSizeBeforeMove(p, newPlacement);

                    // Find piece on the left
                    dx = piecesAtField[0].picture.Location.X - piecesAtField[1].picture.Location.X;
                    if (dx > 0)
                    {
                        pRight = piecesAtField[0];
                        pLeft  = piecesAtField[1];
                    }
                    else
                    {
                        pRight = piecesAtField[1];
                        pLeft  = piecesAtField[0];
                    }

                    // Relocate the two pieces already on the field
                    pLeft.picture.Location  = new Point(pLeft.picture.Location.X, pLeft.picture.Location.Y - 9);
                    pRight.picture.Location = new Point(pRight.picture.Location.X, pRight.picture.Location.Y - 9);

                    // Sets size and location for new piece at field
                    p.picture.Size     = new Size(15, 15);
                    p.picture.Location = new Point(pLeft.picture.Location.X + 9, pLeft.picture.Location.Y + 19);
                }
                else                  // If not on the same team
                {
                    movePieceHome(p); // Moves current player home
                }
                break;

            case 3:                                      // Three pieces at the field
                if (piecesAtField[0].player == p.player) // If the pieces are on the same team
                {
                    int   dy;
                    Piece pLeft, pRight, pBottomL;

                    resetSizeBeforeMove(p, newPlacement);

                    // Find piece on the bottom, left and right
                    dy = piecesAtField[0].picture.Location.Y - piecesAtField[1].picture.Location.Y;
                    if (dy > 0)
                    {
                        pBottomL = piecesAtField[0];
                        piecesAtField.Remove(pBottomL);
                        pLeft = piecesAtField[findPieceOnLeft(piecesAtField)];
                        piecesAtField.Remove(pLeft);
                        pRight = piecesAtField[0];
                    }
                    else if (dy < 0)
                    {
                        pBottomL = piecesAtField[1];
                        piecesAtField.Remove(pBottomL);
                        pLeft = piecesAtField[findPieceOnLeft(piecesAtField)];
                        piecesAtField.Remove(pLeft);
                        pRight = piecesAtField[0];
                    }
                    else       // If the two piece[0] and piece[1] have the same y, then piece[2] is the bottom one
                    {
                        pBottomL = piecesAtField[2];
                        piecesAtField.Remove(pBottomL);
                        pLeft = piecesAtField[findPieceOnLeft(piecesAtField)];
                        piecesAtField.Remove(pLeft);
                        pRight = piecesAtField[0];
                    }

                    // Relocate the bottom piece
                    pBottomL.picture.Location = new Point(pLeft.picture.Location.X, pBottomL.picture.Location.Y);

                    // Sets size and location for new piece at field
                    p.picture.Size     = new Size(15, 15);
                    p.picture.Location = new Point(pLeft.picture.Location.X + 19, pBottomL.picture.Location.Y);
                }
                else                  // If not on the same team
                {
                    movePieceHome(p); // Moves current player home
                }
                break;
            }
        }