public void Play() { if (!_gameOver) { Console.WriteLine("\n[ Score: " + _acesUp.Score + " ]"); Console.WriteLine(_acesUp); Console.Write("-> PLAYER: "); string userCommand = Console.ReadLine(); _gameOver = _acesUp.IsGameOver(); try { if (userCommand.Trim().Length == 1) { _acesUp.RemoveCardFromPile(Convert.ToInt32(userCommand.Trim())); } else if (userCommand.Trim().ToLower() == "deal") { _acesUp.Deal(); } else if (userCommand.Trim().ToLower().Substring(0, 4) == "move") { _acesUp.MoveCard(Convert.ToInt32(userCommand[5].ToString()), Convert.ToInt32(userCommand[7].ToString())); } else if ((userCommand.Trim().ToLower() == "help") | (userCommand.Trim() == "?")) { showHelp(); } } catch (Exception exception) { // Do nothing... } finally { Play(); } } else { if (_acesUp.Won) { Console.WriteLine("GAME OVER: You've Won"); } else { Console.WriteLine("GAME OVER: No More Moves"); } return; } }
private void Simulate() { try { for (int i = 0; i < _acesUp.StackOfPiles.Length; i++) { int x = (i * 96) + 20; int y = 10; for (int j = 0; j < _acesUp.StackOfPiles[i].Count; j++) { CustomImage currentCardImage = new CustomImage(_acesUp.StackOfPiles[i][j]); currentCardImage.Margin = new Thickness(x, y, 0, 0); currentCardImage.pileIndex = i + 1; y += 30; if (j == _acesUp.StackOfPiles[i].Count() - 1) { currentCardImage.MouseLeftButtonDown += new MouseButtonEventHandler(delegate(object sender, MouseButtonEventArgs mouseButtonEventArgs) { if (_acesUp.IsGameOver()) { mouseEnterBorderColor = mouseLeaveBorderColor = Colors.Red; deckBorder.BorderBrush = new SolidColorBrush(mouseEnterBorderColor); if (_acesUp.Won) { MessageBox.Show( "Game Over: You won."); } else { MessageBox.Show( "GAME OVER: No more moves"); } } else { bool validToMove = false; int count = 0; foreach (var pile in _acesUp.StackOfPiles) { count++; if (pile.Count == 0) { validToMove = true; break; } } if (validToMove) { _acesUp.MoveCard(currentCardImage.pileIndex, count); } else { _acesUp.RemoveCardFromPile(currentCardImage.pileIndex); } this.Title = "ACES UP: Score : " + _acesUp.Score; } this.mainCanvas.Children.Clear(); deal(); Simulate(); }); currentCardImage.MouseEnter += new MouseEventHandler(delegate(object sender, MouseEventArgs mouseEventArgs) { currentCardImage.Cursor = Cursors.Hand; }); } mainCanvas.Children.Add(currentCardImage); } } } catch (Exception) { // Do nothing... } }