Exemplo n.º 1
0
        public void PlaceUserOnFreeSeat(Game game, User user, int gameActionID)
        {
            int      freeSeat = GetFreeSeat(game);
            UserSeat seat     = new UserSeat()
            {
                GameID = game.GameID,
                Seat   = freeSeat,
                UserID = user.UserID
            };

            ctx.UserSeat.InsertOnSubmit(seat);
            ctx.SubmitChanges();

            Console.WriteLine(String.Format("{0} is placed on seat {1}.", user.Name, freeSeat));

            GameAction action = ctx.GameAction.Single(ga => ga.GameActionID == gameActionID);

            action.Data = seat.Seat.ToString();

            action.IsCommitted = true;
            ctx.SubmitChanges();
        }
Exemplo n.º 2
0
        public void PlaceUserOnFreeSeat(Game game, User user, int gameActionID)
        {
            int freeSeat = GetFreeSeat(game);
            UserSeat seat = new UserSeat()
            {
                GameID = game.GameID,
                Seat = freeSeat,
                UserID = user.UserID
            };
            ctx.UserSeat.InsertOnSubmit(seat);
            ctx.SubmitChanges();

            Console.WriteLine(String.Format("{0} is placed on seat {1}.", user.Name, freeSeat));

            GameAction action = ctx.GameAction.Single(ga => ga.GameActionID == gameActionID);
            action.Data = seat.Seat.ToString();

            action.IsCommitted = true;
            ctx.SubmitChanges();
        }
Exemplo n.º 3
0
 partial void DeleteUserSeat(UserSeat instance);
Exemplo n.º 4
0
 partial void UpdateUserSeat(UserSeat instance);
Exemplo n.º 5
0
 partial void InsertUserSeat(UserSeat instance);
Exemplo n.º 6
0
 private void detach_UserSeat(UserSeat entity)
 {
     this.SendPropertyChanging();
     entity.User = null;
 }
Exemplo n.º 7
0
 private void attach_UserSeat(UserSeat entity)
 {
     this.SendPropertyChanging();
     entity.User = this;
 }
Exemplo n.º 8
0
 partial void DeleteUserSeat(UserSeat instance);
Exemplo n.º 9
0
 partial void UpdateUserSeat(UserSeat instance);
Exemplo n.º 10
0
 partial void InsertUserSeat(UserSeat instance);
Exemplo n.º 11
0
		private void detach_UserSeat(UserSeat entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
Exemplo n.º 12
0
		private void attach_UserSeat(UserSeat entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
Exemplo n.º 13
0
        public void PayBlinds(Game game)
        {
            // the next round begins!
            game.Round++;
            Console.WriteLine(string.Format("Round {0} begins.", game.Round));

            // advance button position
            int             buttonPosition = game.CurrentButtonPosition;
            List <UserSeat> seats          = ctx.UserSeat.Where(us => us.GameID == game.GameID)
                                             .OrderBy(us => us.Seat)
                                             .ToList();

            // get next occupied seat
            while (!seats.Any(s => s.Seat == buttonPosition))
            {
                buttonPosition++;

                if (buttonPosition > seatCount)
                {
                    buttonPosition = 1;
                }
            }

            Console.WriteLine("Move dealer button, pay blinds.");
            game.CurrentButtonPosition = buttonPosition;

            int dealer     = seats.Single(s => s.Seat == buttonPosition).UserID;
            int smallBlind = -1;
            int bigBlind   = -1;

            if (seats.Count == 2)
            {
                // special heads up rule: dealer pays the small blind
                smallBlind = seats.Single(s => s.Seat == buttonPosition).UserID;
                // the other player pays the big blind
                bigBlind = seats.Single(s => s.UserID != smallBlind).UserID;
            }
            else // get players left of dealer seat
            {
                int cursor = buttonPosition;
                while (smallBlind == -1 || bigBlind == -1)
                {
                    cursor++;
                    if (cursor > seatCount)
                    {
                        cursor = 1;
                    }

                    UserSeat nextOccupiedSeat = seats.SingleOrDefault(s => s.Seat == cursor);
                    if (nextOccupiedSeat != null)
                    {
                        if (smallBlind == -1)
                        {
                            smallBlind = nextOccupiedSeat.UserID;
                        }
                        else
                        {
                            bigBlind = nextOccupiedSeat.UserID;
                        }
                    }
                }
            }

            // insert "blinds" action
            GameAction payBlindsAction = new GameAction()
            {
                ActionTypeID = (int)ActionTypes.Blinds,
                GameID       = game.GameID,
                Timestamp    = DateTime.Now,
                IsCommitted  = true,
                Data         = String.Join("|", new object[] { dealer, smallBlind, bigBlind })
            };

            ctx.GameAction.InsertOnSubmit(payBlindsAction);
            ctx.SubmitChanges(); // submit all (advance game round, button position and playBlindsAction)
        }