Exemple #1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            DataContext = this;
            InitializeSettings();

            gameEngine = new GameAI();
            ResetGame();
            DisplayResults(GameAI.value.draw);
        }
Exemple #2
0
        bool SetSelectedGameSquare(Button button, GameAI.opponent toOpponent, int row, int col)
        {
            if(gameEngine.IsPositionEmpty(row, col) == false)
                return false;

            gameEngine.SetBoardPositionToOwner(row, col,
                toOpponent == GameAI.opponent.X ? GameAI.slotState.ownedByX: GameAI.slotState.ownedByO);

            // Determine which image to use
            String imagePath;
            if(toOpponent == GameAI.opponent.X)
                imagePath = "/Images/X.png";
            else
                imagePath = "/Images/O.png";

            // Add the image to the button
            button.Content = new Image();
            Image content = button.Content as Image;
            if (null != content) {
                content.Stretch = Stretch.Fill;
                content.Width = button.Width - 10;
                content.Height = button.Height - 10;
                content.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                content.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

                content.Source = new BitmapImage(new Uri(imagePath, UriKind.Relative));
            }
            return true;
        }
Exemple #3
0
        void UpdateSettings(GameAI.value v)
        {
            if (ComputerMoveFirst == true) {
                if (v == GameAI.value.xWins) {
                    UpdateStorage(phoneWins);
                }
                else if (v == GameAI.value.oWins) {
                    UpdateStorage(playerWins);
                }
            }
            else {
                if (v == GameAI.value.xWins) {
                    UpdateStorage(playerWins);
                }
                else if (v == GameAI.value.oWins) {
                    UpdateStorage(phoneWins);

                }
            }

            if (v == GameAI.value.draw && gameOver == true) {
                UpdateStorage(draws);
            }

            int p, c, d;
            appSettings.TryGetValue<int>(playerWins, out p);
            appSettings.TryGetValue<int>(phoneWins, out c);
            appSettings.TryGetValue<int>(draws, out d);

            Stats = "Player:" + p + " Phone:" + c + " Draw:" + d;
        }
Exemple #4
0
        void DisplayResults(GameAI.value v)
        {
            // update screen
            if (v == GameAI.value.oWins)
                GameResult.Text = "O Wins!";
            else if (v == GameAI.value.xWins)
                GameResult.Text = "X Wins!";
            else if (gameOver == true)
                GameResult.Text = "Draw!";

            // Update settings
            UpdateSettings(v);
        }