Exemple #1
0
 /// <summary>
 /// Performs a valid move on the board
 /// </summary>
 /// <param name="selected">marbles that are selected</param>
 /// <param name="direction">direction of push movement</param>
 /// <returns></returns>
 public bool DoMove(List <Marble> selected, Direction direction)
 {
     if (Rules.MoveIsValid(this, selected, direction))
     {
         MoveType mt = Rules.DetermineMoveType(selected, direction);
         if (mt == MoveType.Line)
         {
             Marble current = selected[0];
             while (current != null)
             {
                 Marble next = null;
                 //get marble at the destination location of current marble
                 ICoordinates nc = Rules.NextCoordinates(current.Coordinates, direction);
                 next = GetMarble(nc, false);
                 //move the current marble afterwards, to prevent two marbles at same location
                 current.Move(direction);
                 if (current.IsOut)
                 {
                     //marble was thrown out, get the direction of r
                     direction = Rules.ConvertDirection(current.Coordinates as OuterRingCoordinates, direction);
                 }
                 //repeat until there is no marble left in the line
                 current = next;
             }
             return(true);
         }
         else if (mt == MoveType.Broad)
         {
             //simply move all selected marbles in the desired direction
             foreach (Marble m in selected)
             {
                 m.Move(direction);
             }
             return(true);
         }
     }
     return(false);
 }