public void MoveCardsWithoutChecking(CardStack stackSrc, int posSrc, CardStack stackDest) { if (!stackSrc.CanPickupRun(posSrc)) { Console.WriteLine("Asked to move cards that are not in a sequential run - bug?"); } for (int i = posSrc; i < stackSrc.Count; i++) { Card card = stackSrc.GetCard(i); stackDest.Add(card); } int cardCount = stackSrc.Count - posSrc; stackSrc.RemoveRange(posSrc, cardCount); if (stackSrc.Count > 0) { Card revealed = stackSrc.GetCard(posSrc - 1); revealed.Reveal(); } MoveCount++; Score -= ScorePerMove; }
public void MoveCards(CardStack stackSrc, int posSrc, CardStack stackDest) { if (posSrc < 0) { return; } if (!stackSrc.CanPickupRun(posSrc)) { Console.WriteLine("Asked to move cards that are not in a sequential run - bug?"); } Card sourceCard = stackSrc.GetCard(posSrc); if (!CanMoveCardToStack(sourceCard, stackDest)) { Console.WriteLine(@"Asked to move cards to an invalid location - bug?"); } for (int i = posSrc; i < stackSrc.Count; i++) { Card card = stackSrc.GetCard(i); stackDest.Add(card); } int cardCount = stackSrc.Count - posSrc; stackSrc.RemoveRange(posSrc, cardCount); bool revealedCard = false; if (stackSrc.Count > 0) { Card revealed = stackSrc.GetCard(posSrc - 1); if (!revealed.Visible) { revealedCard = true; revealed.Reveal(); } } MoveCount++; Score -= ScorePerMove; _undoStack.AddMoveOfCards(cardCount, stackSrc, stackDest, revealedCard); }
public bool Load() { if (ResumeGameExists()) { Reset(); GameSerialization gameSerialization; try { var storage = IsolatedStorageFile.GetUserStoreForApplication(); var stream = storage.OpenFile(ResumeGameFilename, FileMode.Open, FileAccess.Read); TextReader reader = new StreamReader(stream); var serializer = new XmlSerializer(typeof(GameSerialization)); gameSerialization = serializer.Deserialize(reader) as GameSerialization; reader.Close(); } catch (FileNotFoundException) { // We thought we had a file...? return(false); } catch (Exception exc) { // Something else bad happened. Crap. Debug.WriteLine(exc); return(false); } if (gameSerialization == null) { return(false); } SuitCount = gameSerialization.Suits; MoveCount = gameSerialization.MoveCount; Score = gameSerialization.Score; for (int i = 0; i < StackCount; i++) { CardStackSerialization stackSerialization = gameSerialization.Board.Stacks[i]; CardStack stack = GetStack(i); foreach (CardSerialization cardSerialization in stackSerialization.Cards) { var card = new Card((Suit)cardSerialization.Suit, (Value)cardSerialization.Value, new Random()) { Visible = cardSerialization.Visible }; card.View = new CardView(card); stack.Add(card); } } for (int i = 0; i < gameSerialization.Board.Extras.Count; i++) { CardStackSerialization extraSerialization = gameSerialization.Board.Extras[i]; _extras[i] = new List <Card>(); foreach (CardSerialization cardSerialization in extraSerialization.Cards) { var card = new Card((Suit)cardSerialization.Suit, (Value)cardSerialization.Value, new Random()) { Visible = cardSerialization.Visible }; card.View = new CardView(card); _extras[i].Add(card); } } for (int i = 0; i < gameSerialization.Board.Completed.Count; i++) { CardStackSerialization completedSerialization = gameSerialization.Board.Completed[i]; CardSerialization cardSerialization = completedSerialization.Cards[0]; var card = new Card((Suit)cardSerialization.Suit, (Value)cardSerialization.Value, new Random()) { Visible = cardSerialization.Visible }; card.View = new CardView(card); _completed.Add(card); } for (int i = 0; i < gameSerialization.UndoStack.Actions.Count; i++) { UndoActionSerialization actionSerialization = gameSerialization.UndoStack.Actions[i]; var action = new UndoAction(actionSerialization.CardCount, GetStack(actionSerialization.SourceStack), GetStack(actionSerialization.DestStack), actionSerialization.RevealedCard); _undoStack.Stack.Add(action); } for (int i = 0; i < StackCount; i++) { View.FixupStackCardViewRects(GetStack(i)); } // Stats were reset with a suspended game - bump the count since we have a game in progress if (Statistics.TotalGames == 0) { Statistics.TotalGames++; switch (SuitCount) { case 1: Statistics.EasyGames++; break; case 2: Statistics.MediumGames++; break; case 4: Statistics.HardGames++; break; } } return(true); } return(false); }