public string AttackResult(FormCollection collection)
        {
            string id             = Request.Form["PlayerId"];
            string opponentid     = Request.Form["opponenId"];
            int    gatheredCoin   = Int32.Parse(Request.Form["gatheredCoin"]);
            int    gatheredElixir = Int32.Parse(Request.Form["gatheredElixir"]);


            PlayerForDataBase PlayerData   = dataBase.PlayerinDataBase.Find(id);
            PlayerForDataBase opponentData = dataBase.PlayerinDataBase.Find(opponentid);

            if (PlayerData != null && opponentData != null)
            {
                PlayerData.UpdatePropertyByTime();
                opponentData.UpdatePropertyByTime();
                AddNew.WaitOne();
                opponentData.coin   -= gatheredCoin;
                opponentData.elixir -= gatheredElixir;
                PlayerData.coin     += gatheredCoin;
                PlayerData.elixir   += gatheredElixir;
                dataBase.Entry(PlayerData).State   = EntityState.Modified;
                dataBase.Entry(opponentData).State = EntityState.Modified;
                dataBase.SaveChanges();
                AddNew.ReleaseMutex();
                new PlayerListManager().UpdatePlayerInfo(PlayerData);
                new PlayerListManager().UpdatePlayerInfo(opponentData);
                return(true.ToString());
            }
            else
            {
                return(false.ToString());
            }
        }
        public string LoadPlayerData2(FormCollection collection)
        {
            string id                  = Request.Form["PlayerId"];
            string Shipname            = Request.Form["Shipname"];
            string Password            = Request.Form["Password"];
            string PasswordForCreation = "11111";
            string PasswordForEdit     = "11111";

            new Theif2dDataDBContext().LoadForFisttimeIfNessecary();
            if (Shipname == "PlayerShip")
            {
                ShipForDataBase findedShip = dataBase.AllShips.Find(id);
                if (findedShip == null)
                {
                    AddNew.WaitOne();
                    findedShip = new Utlities().returnDefultShip();
                    //AllShips.buildingCode = dataBase.ShipBaseDataBase.Find(1).BaseString;
                    string ss    = new Random().NextDouble().ToString();
                    int    index = dataBase.PlayerinDataBase.Count <PlayerForDataBase>() + 1;
                    findedShip.OwnerID = index.ToString() + ss;
                    dataBase.AllShips.Add(findedShip);
                    dataBase.SaveChanges();
                    AddNew.ReleaseMutex();
                    // new PlayerListManager().AddPlayerInfo(PlayerData);
                }
                else
                {
                    findedShip.UpdatePropertyByTime();
                    dataBase.Entry(findedShip).State = EntityState.Modified;
                    dataBase.SaveChanges();
                    // new PlayerListManager().UpdatePlayerInfo(PlayerData);
                }
                LogSystem.AddPlayerLog(findedShip.OwnerID, "Ship" + findedShip.OwnerID.ToString() + " added ");
                ShipForSerialize fors = new ShipForSerialize();
                fors.SetAccordingTodataBAse(findedShip);
                string uu = new JavaScriptSerializer().Serialize(fors);
                return(uu);
            }
            else
            {
                string          code       = Shipname + Password;
                ShipForDataBase findedShip = dataBase.AllShips.Find(code);
                if (findedShip == null)
                {
                    if (Password == PasswordForCreation)
                    {
                        return("UnderConstuction");
                    }
                    else
                    {
                        return("shipNotFinded  & CreationPaswordIsWrong");
                    }
                }
                else
                {
                    return("UnderConstuction");
                }
            }
        }
Esempio n. 3
0
        public string UpdateBuilding(string buildst)
        {
            string id = Request.Form["PlayerId"];
            string BulidngString = Request.Form["BulidngString"];            
            PlayerForDataBase PlayerData = dataBase.PlayerinDataBase.Find(id);
            if (PlayerData != null)
            {
                PlayerData.buildingCode = BulidngString;
                dataBase.Entry(PlayerData).State = EntityState.Modified;
                dataBase.SaveChanges();

                return true.ToString();
            }
            else
            {
                return false.ToString();
            }
        }