Beispiel #1
0
 // checks if a piece is a part of a mill
 private bool IsInMill(MillPiece target)
 {
     if ((pieces[target.PotentialMill1[0] - 1].PieceColor == target.PieceColor &&
          pieces[target.PotentialMill1[1] - 1].PieceColor == target.PieceColor) ||
         (pieces[target.PotentialMill2[0] - 1].PieceColor == target.PieceColor &&
          pieces[target.PotentialMill2[1] - 1].PieceColor == target.PieceColor))
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
0
 // checks if a move has formed a mill
 private void MillFormed(MillPiece moved)
 {
     if (IsInMill(moved))
     {
         RemovePiece();
     }
     else
     {
         ChangeTurn();
     }
 }
Beispiel #3
0
        // handles all inserting, moving and removing
        private void Piece_Click(object sender, RoutedEventArgs e)
        {
            MillPiece target = (MillPiece)sender;

            if (remove)
            {
                if (target.PieceColor == Turn || target.PieceColor == baseColor)
                {
                    return;
                }
                if (IsInMill(target) && !AreAllInMill())
                {
                    Notification = "Cannot remove from a mill.";
                    return;
                }
                target.PieceColor = baseColor; remove = false; Notification = ""; ChangeTurn();
                if (addCounter == 18)
                {
                    int counter = 0;
                    foreach (MillPiece mp in pieces)
                    {
                        if (mp.PieceColor == Turn)
                        {
                            counter++;
                        }
                    }
                    if (counter < 3)
                    {
                        Notification = "Game over.";
                    }
                }
                return;
            }

            if (insert)
            {
                if (target.PieceColor == players[0] || target.PieceColor == players[1])
                {
                    return;
                }
                addCounter++; target.PieceColor = Turn; insert = false;
                MillFormed(target); return;
            }

            if (move)
            {
                if (beingMoved == null)
                {
                    if (target.PieceColor != Turn)
                    {
                        return;
                    }
                    else
                    {
                        beingMoved = target; beingMoved.PieceColor = moveColor; return;
                    }
                }

                else if (target.PieceColor != players[0] && target.PieceColor != players[1] &&
                         target.PieceColor != moveColor &&
                         (beingMoved.Neighbors.Contains(pieces.IndexOf(target) + 1) ||
                          ThreeRemaining()))
                {
                    target.PieceColor     = Turn;
                    beingMoved.PieceColor = baseColor;
                    move = false; beingMoved = null; MillFormed(target); return;
                }
                else
                {
                    beingMoved.PieceColor = Turn;
                    move = false; beingMoved = null; return;
                }
            }
        }