Esempio n. 1
0
        private void FinishAuctionProcessor(Move move)
        {
            using (var ctx = new MonopolyModelContainer())
            {
                Player player = ctx.Players.SingleOrDefault(p => p.Id == move.PlayerId);
                // process ongoing auctions
                var auctions = ctx.Auctions.Where(au => au.Game.Id == player.Game.Id);
                foreach (var auction in auctions)
                {
                    if (auction.Winner != null)
                    {
                        Reality reality = ctx.Realities1.SingleOrDefault(r => r.Field.Name == auction.Field.Name && r.Player.Game.Id == player.Game.Id);
                        if (reality != null)
                        {
                            Player owner = reality.Player;
                            player.Money -= auction.Price;
                            owner.Money += auction.Price;
                            owner.Realities.Remove(reality);
                        }
                        else
                        {
                            player.Money -= auction.Price;
                            reality = new Reality()
                            {
                                Field = auction.Field,
                                Hotels = 0,
                                Houses = 0,
                                IsMortgaged = false,
                                Player = player
                            };
                        }

                        player.Realities.Add(reality);
                        ctx.SaveChanges();
                    }

                    ctx.Auctions.Remove(auction);
                }

                ctx.SaveChanges();
            }
        }
Esempio n. 2
0
 private void BuyMoveProcessor(Move move)
 {
     using (var ctx = new MonopolyModelContainer())
     {
         Player player = ctx.Players.SingleOrDefault(p => p.Id == move.PlayerId);
         Reality reality = new Reality()
         {
             Field = player.Position,
             Hotels = 0,
             Houses = 0,
             IsMortgaged = false,
             Player = player
         };
         player.Realities.Add(reality);
         player.Money -= player.Position.Price;
         ctx.SaveChanges();
     }
 }