protected void OnExistGameClick(object sender, EventArgs e)
        {
            //rest start game message if exists
            GeneralErrorStartGame.Text = "";

            DTO_GamePlay selectedGame    = ((DTO_GamePlay[])Session[WebSiteManager.WATING_GAMES_LIST_SESSION])[gamesGV.SelectedRow.RowIndex];
            DTO_ACCOUNT  loggedInAccount = (DTO_ACCOUNT)(Session[WebSiteManager.LOGGEDIN_ACCOUNT_SESSION]);
            DTO_Player   joiningPlayer   = loggedInAccount.players[PlayerList2.SelectedIndex];


            if (selectedGame.hostPlayerID == joiningPlayer.Id)
            {
                GeneralError.ForeColor = Color.Red;
                GeneralError.Text      = "You are owner of this game,You allowed to close the game";
            }
            else if (selectedGame.joinedPlayerID != joiningPlayer.Id)
            {
                GeneralError.ForeColor = Color.Red;
                GeneralError.Text      = "You are not player in this game";
            }
            else
            {
                WebSiteManager.ExistGame(selectedGame.Key);
                loadWatingGames();
                // first time page loades we color the tabel for player at index 0
                ColorGamesTableRows(PlayerList2.SelectedIndex);
                gamesGridViewPanel.Update();
            }
        }
示例#2
0
    public int AddGame(DTO_GamePlay game)
    {
        GamePlay gp = new GamePlay {
            Host_Player_ID = game.hostPlayerID, Join_Player_ID = game.joinedPlayerID, Start_Date = game.createDate, Status = Application_Constants.GAME_STATUS_WATING_FOR_PLAYER, Name = game.gameName
        };

        db.GamePlays.InsertOnSubmit(gp);
        db.SubmitChanges();
        return(gp.GAME_ID);
    }
示例#3
0
        public static int  AddGame(DTO_GamePlay game)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DTO_GamePlay));
            MemoryStream stream            = new MemoryStream();

            ser.WriteObject(stream, game);
            string    data      = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length);
            WebClient webClient = new WebClient();

            webClient.Headers["Content-type"] = "application/json";
            webClient.Encoding = Encoding.UTF8;
            string res = webClient.UploadString(SERVICE_URL + "/WebAddGame", "POST", data);

            return(Int32.Parse(res));
        }
示例#4
0
        // registation of new local game of player vs computer for storing game movments.
        public static void RegisterNewLocalGamePlay()
        {
            GameForm form1Ref = (GameForm)Application.OpenForms["GameForm"];

            Thread thread = new Thread(delegate()
            {
                DTO_GamePlay gamePlay = new DTO_GamePlay {
                    hostPlayerID = GameController.loggedInAccountPlayerPlaying.Id, joinedPlayerID = Constants.GM_PLAYER_ID, createDate = DateTime.Now.ToLocalTime(), gameName = GameController.loggedInAccount.NAME + " VS Checkers"
                };
                GameController.currentPlayingGameID = duplexServiceClient.ClientAddGame(gamePlay);
                form1Ref.ShowAndStartLocalGamePlay();
            });

            thread.Start();
        }
        protected void OnStartGameClick(object sender, EventArgs e)
        {
            if (isPlayerHostingOrJoinedGame(((DTO_ACCOUNT)Session[WebSiteManager.LOGGEDIN_ACCOUNT_SESSION]).players[PlayerList.SelectedIndex].Id))
            {
                GeneralErrorStartGame.ForeColor = Color.Red;
                GeneralErrorStartGame.Text      = "You Allready registared to game";
                return;
            }

            try
            {
                DTO_ACCOUNT  loggedInAccount = (DTO_ACCOUNT)(Session[WebSiteManager.LOGGEDIN_ACCOUNT_SESSION]);
                DTO_Player   hostGamePlayer  = loggedInAccount.players[PlayerList.SelectedIndex];
                DTO_GamePlay game            = new DTO_GamePlay {
                    gameName = GameNameTB.Text, hostPlayerID = hostGamePlayer.Id, createDate = DateTime.Now.ToLocalTime()
                };
                int gameKey = WebSiteManager.AddGame(game);

                // load the wating games from db and bind to girdview table
                loadWatingGames();
                // first time page loades we color the tabel for player at index 0
                ColorGamesTableRows(PlayerList2.SelectedIndex);
                gamesGridViewPanel.Update();

                GeneralErrorStartGame.ForeColor = Color.Green;
                GeneralErrorStartGame.Text      = "Game successfully registared, Key : " + gameKey;
            }
            catch (WebException ex)
            {
                using (WebResponse response = ex.Response)
                {
                    var httpResponse = (HttpWebResponse)response;

                    using (Stream data = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(data);
                    }
                }
            }
        }
示例#6
0
 public int ClientAddGame(DTO_GamePlay game)
 {
     return(AddGame(game));
 }
示例#7
0
 public int WebAddGame(DTO_GamePlay game)
 {
     return(AddGame(game));
 }