public RemotePlayer(ITurnGame game, User userInfo, Tile symbol )
 {
     Game = game;
     Symbol = symbol;
     Player = PlayerType.Remote;
     UserInfo = userInfo;
 }
 public LocalPlayer(ITurnGame game, User user, Tile symbol)
 {
     Game = game;
     Symbol = symbol;
     Player = PlayerType.Local;
     UserName = user.UserName;
     ID = user.id;
 }
 /// <summary>
 /// Add a friend for a user. The friend relationship is required in order to 
 /// initiate a game.
 /// </summary>
 /// <param name="key1"></param>
 /// <param name="user2"></param>
 /// <returns></returns>
 public async Task AddUserFriend(string key1, User user2)
 {
     UserFriend userFriend = new UserFriend { User1Key = key1, User2Key = user2.id, User2Name = user2.UserName };
     await client.GetTable<UserFriend>().InsertAsync(userFriend);
 }
        /// <summary>
        /// Add a new user to the users table in the mobile service.
        /// </summary>
        /// <param name="userName">The username of the new user.</param>
        /// <returns></returns>
        public async Task AddUser(string userName)
        {
            User userObj = new User
            {
                UserId = mobileServiceUser.UserId,
                UserName = userName
            };

            await client.GetTable<User>().InsertAsync(userObj);

        }
 public TicTacToeMobileServiceClient(MobileServiceClient clientIn, PushNotificationChannel channelIn, MobileServiceUser userIn)
 {
     client = clientIn;
     mobileServiceUser = userIn;
     channel = channelIn;
     userInfo = new User();
 }
        /// <summary>
        /// Create a new game with the chosen opponent.
        /// </summary>
        /// <param name="parameter"></param>
        async void CreateNewGame(object parameter)
        {
            // Update the friend list
            PopulateFriendsList();
            UserFriend opponent = null;
            bool isRemoteUserGame = false;

            currentGame = new TicTacToeGame();
            User user = new User(this.userKey, this.userNameText);
            currentGame.Players.Add(new LocalPlayer(currentGame, user, currentGame.Pieces[0]));


            isRemoteUserGame = true;
            opponent = friendList[SelectedPlayerOption];
            User opponentUserInfo = new User(opponent.User2Key, opponent.User2Name);
            currentGame.Players.Add(new RemotePlayer(currentGame, opponentUserInfo, currentGame.Pieces[1]));

            ResetCells();
           
            currentGame.InitializeBoard();

            // If this game involves a remote user, then create the game in the mobile service.
            if (isRemoteUserGame)
            {
                currentGame.ID = await mobileServiceClient.CreateGame(userKey, opponent.User2Key, currentGame);
            }

            // Hide the game setup area and previous game's result text.
            gameResultString = "";
            OnPropertyChanged("GameResult");
            isGameInProgress = true;
            OnPropertyChanged("IsGameInProgress");
            OnPropertyChanged("CanCreateNewGame");
            OnPropertyChanged("UserSymbol");
            OnPropertyChanged("OpponentName");
            OnPropertyChanged("OpponentSymbol");


            // Reset any selection in the list of games (in case some other game was selected)
            SelectedGameIndex = -1;

            // Player 1 starts.
            currentGame.Start();

            RefreshGamesLists();

        }
        /// <summary>
        /// Create a list of playable TicTacToe games from the basic information from the service.
        /// </summary>
        /// <returns></returns>
        public async Task<List<GameInfo>> GetGamesForUser()
        {
            List<GameInfo> gameInfoList = await mobileServiceClient.GetAllMyGames(this.userKey);
            gameList = new List<ITurnGame>();
            foreach (GameInfo gameInfo in gameInfoList)
            {
                var users = new List<User>();
                User user1, user2;
                user1 = new User(gameInfo.User1Key, gameInfo.User1Name);
                users.Add(user1);
                user2 = new User(gameInfo.User2Key, gameInfo.User2Name);
                users.Add(user2);
                ITurnGame newGame = new TicTacToeGame(this, gameInfo, users, this.UserKey);
                gameList.Add(newGame);

            }

            return gameInfoList;
        }