Пример #1
0
        /// <summary>
        /// Sets everything up for the next turn and switches to the next player
        /// </summary>
        public static void NextTurn()
        {
            // Remove the unplaceable squares
            CurrentPlayer.RemoveDeadSquares();
            // Reset the player's ability to place squares
            CurrentPlayer.CanPlaceSquare(true);
            // Make the place take new squares
            OwnerFrame.GetGridPanel().TakeSquare(CurrentPlayer);

            // Switch to the next player
            Players.Add(Players[0]);
            Players.RemoveAt(0);
            CurrentPlayer = Players[0];

            // Update the player display
            OwnerFrame.UpdatePlayerList();
            // Update the square highlighting
            OwnerFrame.GetGridPanel().UpdateHeldSquares(CurrentPlayer);
            // Reset the amount of stock this player can buy
            CurrentPlayer.NumBuysLeft = 3;

            // Reset the end turn button
            EndTurnCheck();
            // Clear the current dynamic content
            LogMaster.ClearDynamicContent();
            // Tell the users whose turn it is
            LogMaster.Log("It is now " + CurrentPlayer.Name + "'s turn.");

            // If this is an AI player, make them take their turn
            if (CurrentPlayer.Type == PlayerType.AI)
            {
                ((IAIPlayer)CurrentPlayer).TakeTurn();
            }
        }
Пример #2
0
        /// <inheritdoc />
        public void TradeShares(Company deadCompany, Company liveCompany, int numShares)
        {
            // If there are enough shares in the live company to trade all the shares
            if (GetShares(deadCompany) / 2 > liveCompany.Shares)
            {
                LogMaster.Log($"{Name} traded {numShares * 2} shares of {deadCompany.Name} for {numShares} shares of {liveCompany.Name}");

                // Trade the shares
                SetShares(liveCompany, GetShares(liveCompany) + numShares);
                SetShares(deadCompany, GetShares(deadCompany) - numShares * 2);

                // Update the company sizes
                deadCompany.Shares += numShares * 2;
                liveCompany.Shares -= numShares;
            }
            // Otherwise...
            else
            {
                LogMaster.Log($"{Name} traded {GetShares(deadCompany)} shares of {deadCompany.Name} for {GetShares(deadCompany) / 2} shares of {liveCompany.Name}");

                int sharesTraded = GetShares(deadCompany);

                // Trade the shares we can
                SetShares(liveCompany, GetShares(liveCompany) + sharesTraded / 2);
                SetShares(deadCompany, 0);

                // Update the company sizes
                deadCompany.Shares += sharesTraded;
                liveCompany.Shares -= sharesTraded / 2;
            }
        }
Пример #3
0
        protected void UpdateData(int IdCity)
        {
            int IDCity = IdCity;
            NostradamusGeoContextFactory factory = new NostradamusGeoContextFactory();

            using (var context = factory.CreateDbContext(new string[] { Constants.ConnectionGeoLocal }))
            {
                try
                {
                    var data    = context.Cities.Where(x => x.Id == IDCity).FirstOrDefault();
                    var state   = context.StateRegions.Where(x => x.Id == data.RegionState).FirstOrDefault();
                    var country = context.Countries.Where(x => x.Id == data.Country).FirstOrDefault();
                    var TZ      = context.TimeZoneLists.Where(x => x.Idtzone == data.TimeZone).FirstOrDefault();


                    Data = ModelsTransformer.TransferModel <City, MCityData>(data);
                    Data.StateRegionData = ModelsTransformer.TransferModel <StateRegion, MStateRegionData>(state);
                    Data.CountryData     = ModelsTransformer.TransferModel <Country, MCountryData>(country);
                    Data.TimeZoneData    = ModelsTransformer.TransferModel <TimeZoneList, MTimeZoneData>(TZ);
                }
                catch (Exception ex)
                {
                    LogMaster lm = new LogMaster();
                    lm.SetLog($"MCityDataHelper ->UpdateData-> {ex.Message}");
                }
            }
        }
Пример #4
0
        protected void GetData(bool withItemselect)
        {
            NostradamusGeoContextFactory factory = new NostradamusGeoContextFactory();

            using (var context = factory.CreateDbContext(new string[] { Constants.ConnectionGeoLocal }))
            {
                try
                {
                    var data = context.StateRegions.Where(x => x.CountryRef == IDCountry).OrderBy(x => x.StateRegion1).ToList();
                    Data = ModelsTransformer.TransferModelList <StateRegion, MStateRegionData>(data);
                    if (withItemselect)
                    {
                        MStateRegionData mdata = new MStateRegionData()
                        {
                            Acronym      = "NO",
                            CountryRef   = 0,
                            Id           = 0,
                            StateRegion1 = "Please select..."
                        };
                        Data.Insert(0, mdata);
                    }
                }
                catch (Exception ex)
                {
                    LogMaster lm = new LogMaster();
                    lm.SetLog(ex.Message);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Sells a single share of the given company
        /// </summary>
        ///
        /// <param name="company">The company from which to sell a single share</param>
        /// <param name="isMerging">Whether or not this company is merging with another one</param>
        /// <param name="companySize">The size of the company at the time of selling</param>
        private void SellShare(Company company, bool isMerging, int companySize)
        {
            // Can only sell a share if a square has been placed or a company is merging
            if (!canPlaceSquare || isMerging)
            {
                // Can't sell a share we don't have
                if (GetShares(company) > 0)
                {
                    // Give the pPlayer their money
                    int sellPrice = company.SellShare(companySize);
                    Money += sellPrice;

                    string dynamicSold   = LogMaster.DynamicContent(Name + company.Name + "Sold", LogMaster.STANDARD_NUM_PROGRESSION, 1, "Sold");
                    string dynamicShares = LogMaster.DynamicContent(Name + company.Name + "Shares", LogMaster.SHARES, 1, LogMaster.SHARES_TYPE);
                    LogMaster.DynamicLog($"{Name} sold {dynamicSold} {dynamicShares} of {company.Name} for {sellPrice:C0}.");

                    // Subtract one share from the pPlayer
                    SetShares(company, GetShares(company) - 1);
                }
                else
                {
                    LogMaster.Log($"You don't have any shares of {company.Name} to sell.");
                }
            }
            else
            {
                LogMaster.Log("Place a square first!");
            }
        }
Пример #6
0
        public static void RemoveImages(string userId, List <string> listOfTheNamesOfPhotosToBeRemoveWithExtension)
        {
            DBManager    dbm = new DBManager();
            ConnectionBS cbs = new ConnectionBS(userId);

            List <string> photosNameNoExtension = new List <string>();

            foreach (string nameWithExtesion in listOfTheNamesOfPhotosToBeRemoveWithExtension)
            {
                int indexOfPoint = nameWithExtesion.IndexOf('.');

                if (!nameWithExtesion.Contains("_Preview"))
                {
                    photosNameNoExtension.Add(nameWithExtesion.Substring(0, indexOfPoint));
                }

                // Log
                LogMaster.WriteOnLog("user " + userId + " have deleted an image with name " + nameWithExtesion);
            }

            Task removeFromMongoDB     = new Task(() => dbm.PhotoManager.RemovePhotos(photosNameNoExtension));
            Task RemoveFromBlobStorage = new Task(
                () => cbs.UserBSManager.RemovePhotoFromBlobStorage(listOfTheNamesOfPhotosToBeRemoveWithExtension));

            removeFromMongoDB.Start();
            RemoveFromBlobStorage.Start();

            Task.WhenAll(removeFromMongoDB, RemoveFromBlobStorage).Wait();
        }
Пример #7
0
        public ActionResult SignIn(UserModel user)
        {
            if (ModelState.IsValid)
            {
                DBManager dbm = new DBManager();

                if (dbm.UserManager.IsTheEmailInTheDB(user.UserEmail))
                {
                    return(View());
                }

                ConvalidationUser cu = new ConvalidationUser(user);
                if (!cu.isTheUserHaveValidParametres())
                {
                    return(View());
                }

                AsyncFunctionToUse.SendMailForConvalidation(user);

                // Log
                LogMaster.WriteOnLog("a new user have signin with username " + user.UserName);

                return(Content("Abbiamo inviato un'email di conferma"));
            }

            return(View());
        }
Пример #8
0
        public IActionResult btnResetLog()
        {
            var ResultLogMaster            = _LogMaster.GetlogDetails();
            var masterAll                  = _LogMaster.GetAll();
            List <LogMaster> LogMasterBulk = new List <LogMaster>();

            foreach (var item in ResultLogMaster)
            {
                if (masterAll.Any(c => c.productID == item.productID))
                {
                    var productlog = masterAll.FirstOrDefault(c => c.productID == item.productID);
                    productlog.CountVisit += item.CountVisit;

                    _LogMaster.Update(productlog);
                }
                else
                {
                    LogMaster logMaster = new LogMaster()
                    {
                        productID  = item.productID,
                        CountVisit = item.CountVisit
                    };
                    LogMasterBulk.Add(logMaster);
                }
            }
            _LogMaster.insertBulk(LogMasterBulk);
            _LogDetails.DeleteAll();
            ViewBag.SuccessMessage = "<p>Success!</p>";

            return(RedirectToAction("Index", "Review"));
        }
Пример #9
0
        public ActionResult Login(UserForLogin ufl)
        {
            DBManager dbm = new DBManager();

            UserModel user = dbm.UserManager.GetUserData(ufl.UserEmailForLogin);

            if (user == null || !user.ConfirmedEmail)
            {
                return(View());
            }

            ConvalidationUser cu = new ConvalidationUser(user);

            if (cu.CheckPasswordIsTheSame(ufl.UserPasswordForLogin, user.UserPassword))
            {
                Session["user_id"]   = user._id.ToString();
                Session["userEmail"] = user.UserEmail;
                Session["userName"]  = user.UserName;
                Session["login"]     = 1;

                // Log
                LogMaster.WriteOnLog("user " + (string)Session["user_id"] + " is logged in");

                return(RedirectToAction("Home", "Home"));
            }

            return(View());
        }
Пример #10
0
        /// <summary>
        /// Initializes this Game with the given playesr, companies, and AcquireFrame
        /// </summary>
        ///
        /// <param name="players">The players playing this Game</param>
        /// <param name="frame">The AcquireFrame used in this Game</param>
        public static void Initialize(List <IPlayer> players, AcquireFrame frame)
        {
            // Store the provided variables
            Players    = players;
            OwnerFrame = frame;

            // Give the players squares
            foreach (IPlayer pPlayer in Players)
            {
                OwnerFrame.GetGridPanel().TakeSquare(pPlayer);
            }

            // Store the current player
            CurrentPlayer = Players[0];
            // Display their squares
            OwnerFrame.GetGridPanel().UpdateHeldSquares(CurrentPlayer);
            // Output the initial log lines
            LogMaster.Log("Welcome to Acquire!");
            LogMaster.Log("---------------------------------");
            LogMaster.Log("It is " + CurrentPlayer.Name + "'s turn first.");

            // If this is an AI player, get them started
            if (CurrentPlayer.Type == PlayerType.AI)
            {
                ((IAIPlayer)CurrentPlayer).TakeTurn();
            }
        }
Пример #11
0
        /// <summary>
        /// Recursively links every square touching this one with the given company
        ///
        /// Returns the company being linked
        /// </summary>
        ///
        /// <param name="instigator">The square instigating this linking</param>
        /// <param name="newCompany">The company taking over</param>
        ///
        /// <returns>The company being linked</returns>
        private static Company Link(Square instigator, Company newCompany)
        {
            // Add this square to the company
            newCompany.Add(instigator);
            // Increment the size of the company
            newCompany.Size++;
            // Redraw the frame
            Game.Refresh();
            // Get the current player
            IPlayer player = Game.CurrentPlayer;
            // If this company is in the active list, it isn't new
            bool isNew = !ActiveCompanies.Any(c => c.Name.Equals(newCompany.Name));

            // If it is new, add it to the list of active companies
            if (isNew)
            {
                ActiveCompanies.Add(newCompany);
            }

            // If this company isn't marked as placed
            if (!newCompany.IsPlaced)
            {
                // Log that the company is being formed
                LogMaster.Log($"{player.Name} has formed the {newCompany.Name} company.");
                // And give the player the amount of money they need to get 1 "free" share
                player.GiveMoney(newCompany.GetPrice());
                player.BuyShare(newCompany, true);
                // Mark the company as placed
                newCompany.IsPlaced = true;
            }

            // Check if the game is enable
            Game.EndGameCheck();
            // Set the company associated with this square to this company
            instigator.SetCompany(newCompany);

            // Check the boundary squares. If there is a square that needs to be taken over, take it over
            if (instigator.LeftSquare != null && instigator.LeftSquare.Company != newCompany && instigator.LeftSquare.State > SquareState.Placeable)
            {
                newCompany = Link(instigator.LeftSquare, newCompany);
            }

            if (instigator.RightSquare != null && instigator.RightSquare.Company != newCompany && instigator.RightSquare.State > SquareState.Placeable)
            {
                newCompany = Link(instigator.RightSquare, newCompany);
            }

            if (instigator.TopSquare != null && instigator.TopSquare.Company != newCompany && instigator.TopSquare.State > SquareState.Placeable)
            {
                newCompany = Link(instigator.TopSquare, newCompany);
            }

            if (instigator.BottomSquare != null && instigator.BottomSquare.Company != newCompany && instigator.BottomSquare.State > SquareState.Placeable)
            {
                newCompany = Link(instigator.BottomSquare, newCompany);
            }

            return(newCompany);
        }
Пример #12
0
        public ActionResult Logout()
        {
            // Log
            LogMaster.WriteOnLog("user " + (string)Session["user_id"] + " logout");

            Session.Abandon();

            return(RedirectToAction("Index", "Auth"));
        }
Пример #13
0
 /// <summary>
 /// Handles sending the current text in the text box to the game log
 /// </summary>
 ///
 /// <param name="sender">The object sending the event</param>
 /// <param name="args">The arguments sent</param>
 private void SendBox_KeyPress(object sender, KeyPressEventArgs args)
 {
     // Only send if there is something to send and the user pressed enter
     if (args.KeyChar == (char)Keys.Enter && SendBox.Text.Length > 0)
     {
         LogMaster.Log($"{Game.CurrentPlayer.Name}: {SendBox.Text}");
         SendBox.Clear();
     }
 }
Пример #14
0
 /// <summary>
 /// Handles sending the current text in the text box to the game log
 /// </summary>
 ///
 /// <param name="sender">The object sending the event</param>
 /// <param name="args">The arguments sent</param>
 private void SendButton_Click(object sender, EventArgs args)
 {
     // Only send something if there is something to send
     if (SendBox.Text.Length > 0)
     {
         LogMaster.Log($"{Game.CurrentPlayer.Name}: {SendBox.Text}");
         SendBox.Clear();
     }
 }
Пример #15
0
        /// <summary>
        /// Places the given square on the board. Handles un-placeable squares,
        /// forming new companies, growing existing companies, and merging multiple companies together.
        ///
        /// Returns null if the square was not able to be places, an arbitrary value otherwise
        /// </summary>
        ///
        /// <param name="square">The square attempting to be placed</param>
        ///
        /// <returns>True if the square was able to be placed, false otherwise</returns>
        public static bool PlaceSquare(Square square)
        {
            // Only place a square if it is placeable
            if (square.CanBePlaced)
            {
                // Can't place a dead square
                if (square.State != SquareState.Dead)
                {
                    // If there are no other squares around, just put this one down and be done with it
                    if ((square.LeftSquare == null || square.LeftSquare.State < SquareState.Placed) &&
                        (square.RightSquare == null || square.RightSquare.State < SquareState.Placed) &&
                        (square.TopSquare == null || square.TopSquare.State < SquareState.Placed) &&
                        (square.BottomSquare == null || square.BottomSquare.State < SquareState.Placed))
                    {
                        // Update the state
                        square.SetState(SquareState.Placed);
                        // Update the log
                        LogMaster.Log($"{Game.CurrentPlayer.Name} placed a square at {square}.");

                        return(true);
                    }

                    // List of surrounding viable squares
                    List <Square> squares = new List <Square>();

                    // Only add the squares if they exist and they are placed or are part of a company
                    if (square.LeftSquare != null && (square.LeftSquare.IsPlaced || square.LeftSquare.IsCompany))
                    {
                        squares.Add(square.LeftSquare);
                    }

                    if (square.RightSquare != null && (square.RightSquare.IsPlaced || square.RightSquare.IsCompany))
                    {
                        squares.Add(square.RightSquare);
                    }

                    if (square.TopSquare != null && (square.TopSquare.IsPlaced || square.TopSquare.IsCompany))
                    {
                        squares.Add(square.TopSquare);
                    }

                    if (square.BottomSquare != null && (square.BottomSquare.IsPlaced || square.BottomSquare.IsCompany))
                    {
                        squares.Add(square.BottomSquare);
                    }

                    // Merge the list of squares with the placed square
                    return(Merge(squares, square));
                }

                LogMaster.Log("Two or more of the companies you are trying to merge are safe.");
                return(false);
            }

            return(true);
        }
Пример #16
0
        /// <summary>
        /// Handles ending the game
        /// </summary>
        public static void EndGame()
        {
            foreach (IPlayer player in Players)
            {
                foreach (Company company in Companies)
                {
                    if (player.GetShares(company) > 0)
                    {
                        player.SellShares(company, player.GetShares(company), true);
                    }
                }
            }

            // Store the first player as both highest and lowest
            IPlayer highest = Players[0];
            IPlayer lowest  = Players[0];

            // Find the lowest and highest money players
            foreach (IPlayer player in Players)
            {
                if (player.Money > highest.Money)
                {
                    highest = player;
                }

                if (player.Money < lowest.Money)
                {
                    lowest = player;
                }
            }

            // If the amount is the same, there is no winnder
            IPlayer winner = highest.Money == lowest.Money ? null : highest;

            // Let the users know it's all over
            if (winner != null)
            {
                LogMaster.Log(winner.Name + " has won the game with $" + winner.Money + "!");
                IsGameOver = true;
            }
            else if (!IsGameOver)
            {
                LogMaster.Log("There was a tie! All players have $" + Players[0].Money + "!");
                IsGameOver = true;
            }

            // Don't let anything else happen
            OwnerFrame.GetGridPanel().EndGame();
            OwnerFrame.SetEndTurnButtonEnabled(false);
            OwnerFrame.SetEndGameButtonEnabled(false);
        }
Пример #17
0
        public ActionResult DeleteAccount(string confirmUsername)
        {
            if (confirmUsername != (string)Session["userName"])
            {
                return(RedirectToAction("Options", "Home"));
            }

            // Log
            LogMaster.WriteOnLog("user " + (string)Session["user_id"] + " delete his/her account");

            ClearUserData();

            return(RedirectToAction("Logout", "Home"));
        }
Пример #18
0
        /// <inheritdoc />
        public void BuyShare(Company company, bool openingShare)
        {
            // Can only buy a share if we've placed a square or its the opening share
            if (!canPlaceSquare || openingShare)
            {
                // Company has to have shares to buy them...
                if (company.Shares > 0)
                {
                    // Gotta have the money to pay too
                    if (company.GetPrice() <= Money)
                    {
                        // Subtract the cost
                        Money -= company.BuyShare();

                        // Give the pPlayer the share
                        SetShares(company, GetShares(company) + 1);

                        if (!openingShare)
                        {
                            LogMaster.DynamicLog(Name + " bought " + LogMaster.DynamicContent(Name + company.Name + "Buy", LogMaster.STANDARD_NUM_PROGRESSION, 1, "Buy") + " " + LogMaster.DynamicContent(Name + company.Name + "Shares", LogMaster.SHARES, 1, LogMaster.SHARES_TYPE) + " of " + company.Name + ".");
                        }
                        else
                        {
                            LogMaster.Log(Name + " was given one free share of " + company.Name);
                        }

                        // Update the company's holders with this player
                        company.UpdateHolders(this);

                        Game.UpdatePlayerList();
                    }
                    else
                    {
                        LogMaster.Log("Not enough money to buy a share.");
                    }
                }
                else
                {
                    LogMaster.Log("Not enough shares to buy.");
                }
            }
            else
            {
                LogMaster.Log("Place a square first!");
            }
        }
Пример #19
0
        protected void GetData()
        {
            NostradamusGeoContextFactory factory = new NostradamusGeoContextFactory();

            using (var context = factory.CreateDbContext(new string[] { Constants.ConnectionGeoLocal }))
            {
                try
                {
                    var data = context.Countries.OrderBy(x => x.CountryName).ToList();
                    Data = ModelsTransformer.TransferModelList <Country, MCountryData>(data);
                }
                catch (Exception ex)
                {
                    LogMaster lm = new LogMaster();
                    lm.SetLog(ex.Message);
                }
            }
        }
Пример #20
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (file != null && file.ContentType.Contains("image"))
            {
                if (file.ContentLength > 5000000)
                {
                    return(RedirectToAction("UploadPhoto", "Home", new { msg = "The file is too big, max 5 MB" }));
                }

                // Log
                LogMaster.WriteOnLog("user " + (string)Session["user_id"] + " uploaded an image with name " + file.FileName);

                AsyncFunctionToUse.UploadPhoto(file, (string)Session["user_id"]);

                return(RedirectToAction("UploadPhoto", "Home", new { msg = "Uploaded with success" }));
            }

            return(RedirectToAction("UploadPhoto", "Home", new { msg = "Wrong file content type" }));
        }
Пример #21
0
 /// <summary>
 /// Opens the BuyShare form for <paramref name="player"/> to buy shares of <paramref name="company"/>
 /// </summary>
 ///
 /// <param name="player">The player buying shares</param>
 /// <param name="company">The company to buy shares from</param>
 private void BuyShare(IPlayer player, Company company)
 {
     // Can't buy shares if the game is over
     if (!Game.IsGameOver)
     {
         // Can't buy shares until you've placed a square
         if (!player.CanPlaceSquare())
         {
             // Can't buy shares in a company that doesn't exist
             if (company.IsPlaced)
             {
                 // Can't buy more than 3 shares per turn
                 if (player.NumBuysLeft > 0)
                 {
                     // Buy the shares
                     new BuyShareForm(player, company).ShowDialog(this);
                     // Update the player's cash
                     UpdatePlayerList();
                     // Redraw
                     Refresh();
                 }
                 else
                 {
                     LogMaster.Log("You have already bought your 3 stock for this turn.");
                 }
             }
             else
             {
                 LogMaster.Log("That company is not active.");
             }
         }
         else
         {
             LogMaster.Log("Place a square first!");
         }
     }
     else
     {
         LogMaster.Log("The game is already over. You cannot buy more stock.");
     }
 }
Пример #22
0
        /// <summary>
        /// Creates a new Acquire game using the list of players provided
        /// </summary>
        ///
        /// <param name="players">The list of players for this game</param>
        public AcquireFrame(List <IPlayer> players)
        {
            InitializeComponent();
            Utilities.AddCopyCapability(LogBox);

            // Set up the LogMaster to use this text box
            LogMaster.SetListBox(LogBox);

            // Initialize the game using these players, these companies, and this frame
            Game.Initialize(players, this);
            // Set up the list of players
            PlayerList.SetPlayersList(players);

            // Initialize the company status buttons
            // Luxor
            LuxorStatusButton.Company   = Game.Companies.Single(c => c.Name == "Luxor");
            LuxorStatusButton.ImageIcon = LuxorStatusButton.Company.ImageIcon;
            // Tower
            TowerStatusButton.Company   = Game.Companies.Single(c => c.Name == "Tower");
            TowerStatusButton.ImageIcon = TowerStatusButton.Company.ImageIcon;
            // Festival
            FestivalStatusButton.Company   = Game.Companies.Single(c => c.Name == "Festival");
            FestivalStatusButton.ImageIcon = FestivalStatusButton.Company.ImageIcon;
            // Worldwide
            WorldwideStatusButton.Company   = Game.Companies.Single(c => c.Name == "Worldwide");
            WorldwideStatusButton.ImageIcon = WorldwideStatusButton.Company.ImageIcon;
            // American
            AmericanStatusButton.Company   = Game.Companies.Single(c => c.Name == "American");
            AmericanStatusButton.ImageIcon = AmericanStatusButton.Company.ImageIcon;
            // Continental
            ContinentalStatusButton.Company   = Game.Companies.Single(c => c.Name == "Continental");
            ContinentalStatusButton.ImageIcon = ContinentalStatusButton.Company.ImageIcon;
            // Imperial
            ImperialStatusButton.Company   = Game.Companies.Single(c => c.Name == "Imperial");
            ImperialStatusButton.ImageIcon = ImperialStatusButton.Company.ImageIcon;

            // Load up the logo image
            LogoBox.Image = Image.FromFile(@"Images/Acquire_Logo.png", true);
        }
Пример #23
0
        public ActionResult SharePhoto(string photoPath, PhotoShare photoShare)
        {
            DateTime finalDate = new DateTime(
                photoShare.DateOfExpire.Year,
                photoShare.DateOfExpire.Month,
                photoShare.DateOfExpire.Day,
                photoShare.TimeOfExpire.Hours,
                photoShare.TimeOfExpire.Minutes,
                photoShare.TimeOfExpire.Seconds);

            int totalMinutes = (int)finalDate.Subtract(DateTime.Now).TotalMinutes;

            totalMinutes = totalMinutes <= 0 ? 0 : totalMinutes;

            ConnectionBS cbs    = new ConnectionBS((string)Session["user_id"]);
            string       sasKey = cbs.UserBSManager.GetContainerSasUri(totalMinutes);

            // Log
            string[] urlParts = photoPath.Split('/');
            LogMaster.WriteOnLog("user " + (string)Session["user_id"] + " has share an image named " + urlParts.Last() + " for " + totalMinutes + " minutes ");

            return(Content(photoPath + sasKey));
        }
Пример #24
0
        /// <summary>
        /// Places this square
        /// </summary>
        ///
        /// <returns>True if it is successfully placed, false otherwise</returns>
        public bool Place()
        {
            // Can't buy shares if the game is over
            if (!Game.IsGameOver)
            {
                // Only place a square if the player is allowed to
                if (Game.CurrentPlayer.CanPlaceSquare())
                {
                    // Only place a square if the player has it
                    if (Game.CurrentPlayer.HasSquare(this))
                    {
                        // Only place a square if this square can be placed
                        if (CanBePlaced)
                        {
                            // Try to place a square
                            if (GridPanel.PlaceSquare(this))
                            {
                                // If it worked, stop the player from placing more squares
                                Game.CurrentPlayer.CanPlaceSquare(false);
                                // Remove this square from the player's hand
                                Game.CurrentPlayer.Squares.Remove(this);
                                // Update the hand panel to show the player what he has
                                Game.SetHand(Game.CurrentPlayer.Squares);

                                // This square can't be placed because it already has been.
                                CanBePlaced = false;
                                // Check if the game is endable
                                Game.EndTurnCheck();
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            // If the game is over, that's why the player can't place
                            if (Game.IsGameOver)
                            {
                                LogMaster.Log("You cannot place a square, the game is over");
                                return(false);
                            }
                            // Otherwise they don't have the square

                            LogMaster.Log("Cannot place a square there.");
                            return(false);
                        }
                    }
                    else
                    {
                        LogMaster.Log("You don't have that square to place.");
                        return(false);
                    }
                }
                else
                {
                    LogMaster.Log("You have already placed a square this turn.");
                    return(false);
                }
            }
            else
            {
                LogMaster.Log("The game is already over. You cannot place any more squares.");
                return(false);
            }

            // Check and update all the squares
            GridPanel.CheckSquares();
            return(true);
        }
Пример #25
0
        /// <summary>
        /// Handles the merging of a list of squares with a new square.
        /// Handles forming new companies, growing existing companies, and merging multiple companies together.
        ///
        /// Returns null if the square was not able to be places, an arbitrary value otherwise
        /// </summary>
        ///
        /// <param name="squares">The list of squares being merged with <paramref name="instigator"/></param>
        /// <param name="instigator">The square that was placed, causing all this merging business</param>
        ///
        /// <returns>True if the squares were able to be merged, false otherwise</returns>
        private static bool Merge(IList <Square> squares, Square instigator)
        {
            // List of possible companies
            List <Company> options = new List <Company>();
            // List of destroyed companies
            List <Company> destroyedCompanies = new List <Company>();
            // List of companies that were JUST destroyed
            List <Company> newlyDead = new List <Company>();
            // The newly formed company, if any
            Company newCompany = null;
            // Whether the company being formed is new, or just merging with another one
            bool isNewCompany = false;

            // While we still have squares to look at
            while (squares.Count != 0)
            {
                // Get the first one
                Square square = squares[0];
                // Remove it from the list
                squares.RemoveAt(0);

                // If it is a company
                if (!square.IsCompany)
                {
                    continue;
                }

                // And we haven't formed a new company yet
                if (newCompany == null)
                {
                    // The new company will be the company in this square
                    newCompany = square.Company;
                    // Get rid of the old options
                    options.Clear();
                    // Add this company to the list of options and newly dead list
                    options.Add(newCompany);
                    newlyDead.Add(newCompany);
                }
                // If we already have a company, but the one in this square is bigger
                else if (square.Company.Size > newCompany.Size)
                {
                    // Then store the one in this square
                    newCompany = square.Company;
                    // Add the options we already had to companies who will die
                    destroyedCompanies.AddRange(options);
                    // Clear the options
                    options.Clear();
                    // Add the new company to the options and newly dead list
                    options.Add(newCompany);
                    newlyDead.Add(newCompany);
                }
                // If the company in this square is smaller than the current company
                else if (square.Company.Size < newCompany.Size)
                {
                    // It will die
                    newlyDead.Add(square.Company);
                    destroyedCompanies.Add(square.Company);
                }
                // If they are the same size
                else if (square.Company.Size == newCompany.Size)
                {
                    // Add both to the list of options if they aren't there already
                    if (!options.Contains(newCompany))
                    {
                        options.Add(newCompany);
                    }

                    if (!options.Contains(square.Company))
                    {
                        options.Add(square.Company);
                    }

                    // And to the newly dead list too
                    newlyDead.Add(newCompany);
                    newlyDead.Add(square.Company);
                }
            }

            // If we have no options
            if (!options.Any())
            {
                // And we have no dead companies
                if (!Game.GetDeadCompanies().Any())
                {
                    // Then we have no more to make
                    LogMaster.Log("This square can't be placed because no new companies can be created.");
                    return(false);
                }

                // Otherwise we just add the dead companies
                options.AddRange(Game.GetDeadCompanies());
                // And we'll be forming a whole new company
                isNewCompany = true;
            }

            // If there's only one option, that's the one to go for
            if (options.Count == 1)
            {
                newCompany = options[0];
            }
            // If the player is an AI, let them choose a company without the GUI
            else if (Game.CurrentPlayer.Type == PlayerType.AI)
            {
                newCompany = ((IAIPlayer)Game.CurrentPlayer).ChooseCompany(options);
            }
            else
            {
                // Otherwise pop up a dialog to let the user choose
                ChooseCompanyDialog csbDialog = new ChooseCompanyDialog(options);
                csbDialog.ShowDialog();

                // If they don't choose, don't put the square down
                if (csbDialog.ChosenCompany != null)
                {
                    newCompany = csbDialog.ChosenCompany;
                }
                else
                {
                    return(false);
                }
            }

            // If companies are being destroyed
            if (newlyDead.Any())
            {
                // Get each one that isn't the one we're already creating
                foreach (Company company in newlyDead.Where(c => !c.Name.Equals(newCompany.Name)))
                {
                    // Get each player that has shares in this company
                    foreach (IPlayer player in Game.Players.Where(p => p.GetShares(company) > 0))
                    {
                        // To check if they have any shares in the company
                        // If so, let them decide what to do with them
                        if (player.Type != PlayerType.AI)
                        {
                            new MergeDialog(newCompany, company, player).ShowDialog();
                        }
                        // If it's an AI, let them handle it without the GUI
                        else
                        {
                            ((IAIPlayer)player).HandleMerge(newCompany, company);
                        }
                    }

                    // Log who is being destroyed
                    LogMaster.Log($"{Game.CurrentPlayer.Name} has destroyed {company.Name} to expand {newCompany.Name}.");
                }
            }

            // Log where the square is placed, now that it is certain
            LogMaster.Log($"{Game.CurrentPlayer.Name} placed a square at {instigator}.");

            // If this isn't a new company, add the options
            if (!isNewCompany)
            {
                destroyedCompanies.AddRange(options);
            }

            // Remove this company, though
            destroyedCompanies.Remove(newCompany);

            // Reset each dead company
            foreach (Company destroyedCompany in destroyedCompanies)
            {
                destroyedCompany.IsPlaced = false;
                destroyedCompany.Size     = 0;
            }

            // Link the squares with this company
            return(Link(instigator, newCompany) != null);
        }
Пример #26
0
 static AppLogger()
 {
     _log = LogMaster.GetLogger("AngularLayout_Log", Constants.AppSettings["Log_Default"]);
 }
Пример #27
0
 private static void OutLog(string _fomat, params object[] _args)
 {
     LogMaster.Log("Log By HttpPoster: " + string.Format(_fomat, _args));
 }