// TODO: Abstract a lot of this out into a new SolitaireGameBuilder class. public SolitaireGame() { StatusMessages = new List <string>(); deck = new DeckBuilder().BuildDeck(true); drawStack = new CardStack(true); drawer = new SolitaireDrawer(); columns = new List <StackColumn>(); // Create 7 stacks of face down cards. for (int i = 0; i < 7; i++) { CardStack stack = new CardStack(false); StackColumn column = new StackColumn(); column.FaceDownStack = stack; columns.Add(column); } // Distribute the cards across the stacks. for (int i = 0; i < 7; i++) { for (int ii = i; ii < 7; ii++) { CardStack stack = columns[ii].FaceDownStack; Card drawnCard = deck.DrawCard(); stack.Add(drawnCard); } } // Transfer top cards to their own stacks. for (int i = 0; i < columns.Count; i++) { StackColumn column = columns[i]; CardStack faceDownStack = column.FaceDownStack; CardStack faceUpStack = new CardStack(true); Card topCard = faceDownStack.DrawCard(); faceUpStack.Add(topCard); column.FaceUpStack = faceUpStack; } TransferCardToDrawStack(); }
public CardStack GetStack(int stackIndex) { CardStack chosenStack = null; if (stackIndex == 0) { chosenStack = drawStack; } else if (stackIndex > 0 && stackIndex <= columns.Count) { StackColumn chosenColumn = columns[stackIndex - 1]; if (chosenColumn.FaceUpStack.Count > 0) { chosenStack = chosenColumn.FaceUpStack; } else if (chosenColumn.FaceDownStack.Count > 0) { chosenStack = chosenColumn.FaceDownStack; } } return(chosenStack); }