public GameState(DekShape from, DekShape to, List<CardShape> cards, int score) { From = from; To = to; Cards = cards; Score = score; }
public MainWindow() { InitializeComponent(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += timer_Tick; Canvas.SetLeft(dealer, 10); Canvas.SetTop(dealer, space); Canvas.SetZIndex(dealer, 1); cnv.Children.Add(dealer); Canvas.SetLeft(stack, 10); Canvas.SetTop(stack, space + 100); Canvas.SetZIndex(stack, 1); cnv.Children.Add(stack); //Игровая зона for (int i = 0; i < 3; i++) { for (int j = 0; j < 7; j++) { DekShape ds = new DekShape(); Canvas.SetLeft(ds, 100 + j * (CardShape.CardWidth + 10)); Canvas.SetTop(ds, space + (CardShape.CardHeight + space) * i); Canvas.SetZIndex(ds, 1); cnv.Children.Add(ds); ds.CardSpace = 17; ground.Add(ds); } } }
public void MakeMove(DekShape From, DekShape To, bool calcScore = false) { if (MoveCount != Moves.Count) { int n = Moves.Count; for (int i = MoveCount; i < n; i++) { Moves.RemoveAt(Moves.Count - 1); } } List<CardShape> cards = new List<CardShape>(); while (From.Count > 0) { if (calcScore) Score++; var card = From.TopCardShape; From.Remove(card); To.Add(card); cards.Add(card); } Moves.Add(new GameState(From, To, cards, MoveCount)); }
void cp_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { CardShape current = sender as CardShape; if (current.DeckShape == dealer) { gameShape.MoveCount++; foreach (var d in ground) { if (d.Count > 0 && d.Deck.TopCard.Visible && dealer.Count > 0) { var card = dealer.TopCardShape; dealer.Remove(card); d.Add(card); gameShape.Moves.Add(new GameState(dealer, d, new List<CardShape>() { card }, gameShape.MoveCount)); d.Deck.TopCard.Visible = true; } } oldDeck = null; } if (oldDeck != null) { foreach (var d in ground) { if (d.Deck == current.Card.Deck) { if (current.DeckShape.Deck.TopCard.Number == oldDeck.Deck.TopCard.Number) { var firstDeck = ground.IndexOf(current.DeckShape); var secondDeck = ground.IndexOf(oldDeck); if (Math.Abs(secondDeck - firstDeck) == 2) { gameShape.MoveCount++; if (firstDeck > secondDeck) { MakeMove(d, stack, true); MakeMove(ground[firstDeck - 1], stack, true); } else { MakeMove(oldDeck, stack, true); MakeMove(ground[secondDeck - 1], stack, true); } if (firstDeck % 7 == 0 || secondDeck % 7 == 0) { for (int i = 0; i < 3; i++) { int k = 0; for (int j = 0; j < 7; j++) { if (ground[(i * 7) + j].Count > 0) k++; } if (k == 1) { for (int j = 0; j < 7; j++) { MakeMove(ground[(i * 7) + j], stack, true); } } } } for (int i = 0; i < 3; i++) for (int j = 0; j < 7; j++) { if (ground[(i * 7) + j].Count == 0) { for (int k = j; k < 6; k++) MakeMove(ground[(i * 7) + k + 1], ground[(i * 7) + k]); } } for (int i = 0; i < 3; i++) for (int j = 0; j < 7; j++) { if (ground[(i * 7) + j].Count == 0) { for (int k = j; k < 6; k++) MakeMove(ground[(i * 7) + k + 1], ground[(i * 7) + k]); } } } } break; } } oldDeck = null; } else { foreach (var d in ground) { if (d.Deck == current.Card.Deck) { oldDeck = d; break; } } } }
private void MakeMove(DekShape From, DekShape To, bool calcScore = false) { gameShape.MakeMove(From, To, calcScore); stack.Deck.TopCard.Visible = true; TotalScore.Text = gameShape.Score.ToString(); TotalMoves.Text = gameShape.MoveCount.ToString(); }