Пример #1
0
        public void Can_add_a_game_to_the_list()
        {
            Games.Initialise(new List <String>());

            Games.Add(new Game {
                Winner = "A", Loser = "B"
            });
            Games.Add(new Game {
                Winner = "A", Loser = "C"
            });
            Games.Add(new Game {
                Winner = "B", Loser = "C"
            });

            var expected = new List <Game>
            {
                new Game {
                    Winner = "A", Loser = "B"
                },
                new Game {
                    Winner = "A", Loser = "C"
                },
                new Game {
                    Winner = "B", Loser = "C"
                },
            };

            Assert.AreEqual(expected, Games.All());
        }
Пример #2
0
        public static void Delete(String Id)
        {
            var table = GetTable(tableName);
            var game  = Games.All().Where(g => g.PartitionKey == ConfigurationManager.AppSettings["Account"] && g.RowKey == Id).First();

            game.Deleted = true;

            TableOperation replaceOp = TableOperation.Replace(game);

            table.Execute(replaceOp);
        }
Пример #3
0
        public async Task MarkReady(int tableId, int depositAmount)
        {
            var user = Context.User.Identity.Name;

            await Deposit(depositAmount, user);

            Users.First(e => e.Name == user).IsReady = true;
            PlayerStateRefresh(tableId);

            if (Users.Where(e => e.TableId == tableId).Count(e => e.IsReady) >= 2 && Games.All(e => e.TableId != tableId))
            {
                await StartGame(tableId, 0);
            }
        }
Пример #4
0
        public async Task CheckIdlingStatus(GameStatus gameStatus)
        {
            if (!IsIdling)
            {
                return;
            }

            foreach (Game game in Games.Where(x => x.Status == gameStatus))
            {
                HtmlDocument document = new HtmlDocument();
                string       response = await UserWebClient.GetHttp($"{UserSettings.ProfileUrl}/gamecards/{game.AppId}");

                document.LoadHtml(response);

                HtmlNode cardsNode = document.DocumentNode.SelectSingleNode(".//span[@class='progress_info_bold']");
                string   cards     = cardsNode?.InnerText.Split(' ').First();

                HtmlNode playtimeNode = document.DocumentNode.SelectSingleNode(".//div[@class='badge_title_stats_playtime']");
                string   playtime     = WebUtility.HtmlDecode(playtimeNode?.InnerText).Trim().Split(' ').First();

                int.TryParse(cards, out int remainingCards);
                double.TryParse(playtime, NumberStyles.Any, new NumberFormatInfo(), out double hoursPlayed);

                game.UpdateStats(remainingCards, hoursPlayed);

                if (!game.HasDrops)
                {
                    game.StopIdling();
                    game.Status = GameStatus.Finished;
                    continue;
                }

                if (game.Status == GameStatus.FastIdling && game.FastIdleTries > 0)
                {
                    game.FastIdleTries--;

                    if (game.FastIdleTries == 0 && game.RemainingCards == game.OriginalRemainingCards)
                    {
                        game.Status = GameStatus.NormalIdling;
                    }
                }
            }

            if (Games.All(x => x.Status == GameStatus.Stopped || x.Status == GameStatus.Finished))
            {
                IsIdling = false;
                IsPaused = false;
            }
        }
Пример #5
0
        private async Task DisconnectPlayer(string user)
        {
            try
            {
                var tableId             = Users.FirstOrDefault(e => e.Name == user)?.TableId ?? -1;
                var smallBlindIndexTemp = 0;

                if (Users.First(e => e.Name == user).InGame)
                {
                    foreach (var player in Games.SelectMany(game => game.Players.Where(player => player.Name == user)))
                    {
                        player.ActionState = PlayerActionState.Left;
                    }

                    if (Games.First(e => e.TableId == tableId).Players.Count(e => e.ActionState != PlayerActionState.Left) < 2)
                    {
                        UpdatePot(tableId);
                        GetAndAwardWinners(tableId);
                        PlayerStateRefresh(tableId);
                        smallBlindIndexTemp = Games.First(e => e.TableId == tableId).SmallBlindIndex;
                        Games.Remove(Games.FirstOrDefault(e => e.TableId == tableId));
                        Thread.Sleep(10000);
                    }
                }

                await Withdraw(user);

                Users.Remove(Users.FirstOrDefault(e => e.Name == user));
                foreach (var e in Users.Where(e => e.TableId == tableId))
                {
                    e.InGame = false;
                }
                if (Users.Count(e => e.IsReady) >= 2 && Games.All(e => e.TableId != tableId))
                {
                    await StartGame(tableId, smallBlindIndexTemp + 1);
                }
                else
                {
                    PlayerStateRefresh(tableId);
                }
            }
            catch (Exception)
            {
                //Log
            }
        }
Пример #6
0
        private static void ProcessGameLetter(string url, int page)
        {
            var console = "XBOX360";

            var webClient    = new WebClient();
            var response     = webClient.DownloadData(url + "?page=" + page.ToString());
            var utf8Encoding = new UTF8Encoding();
            var html         = utf8Encoding.GetString(response);
            var doc          = new HtmlDocument();

            doc.LoadHtml(html);

            var gameNames = doc.DocumentNode.SelectNodes("//div[@class='body']/table/tr/td");

            if (gameNames != null)
            {
                foreach (var item in gameNames)
                {
                    var gameName = item.FirstChild.InnerHtml;

                    gameName = System.Web.HttpUtility.HtmlDecode(gameName);

                    gameName = gameName.Trim();

                    var exclude = new string[] { "---", "MyG", "Q&A", "Pics", "Vids", "Board", "FAQs", "Codes", "Reviews" };

                    if (exclude.Contains(gameName))
                    {
                        continue;
                    }

                    if (gameName.Contains("Ass"))
                    {
                        Console.WriteLine(gameName);
                    }

                    if (games.All(where: "Name = @0", args: new object[] { gameName }).Count() == 0)
                    {
                        games.Insert(new { Name = gameName, console });
                    }
                }

                ProcessGameLetter(url, ++page);
            }
        }
Пример #7
0
        public void Can_reinitialise_the_list_of_games()
        {
            Games.Initialise(new List <String> {
                "D beat B", "B beat C", "C beat D"
            });

            var before = new List <Game>
            {
                new Game {
                    Winner = "D", Loser = "B"
                },
                new Game {
                    Winner = "B", Loser = "C"
                },
                new Game {
                    Winner = "C", Loser = "D"
                },
            };

            Assert.AreEqual(before, Games.All());


            Games.Initialise(new List <String> {
                "A beat B", "A beat C", "B beat C"
            });

            var after = new List <Game>
            {
                new Game {
                    Winner = "A", Loser = "B"
                },
                new Game {
                    Winner = "A", Loser = "C"
                },
                new Game {
                    Winner = "B", Loser = "C"
                },
            };

            Assert.AreEqual(after, Games.All());
        }
Пример #8
0
        public virtual ActionResult Index(GameCreateModel g)
        {
            ViewData["g"] = g;
            if (!ModelState.IsValid)
            {
                return(View(Games.All().WithDocuments()));
            }

            var x = g.CreateGame();

            try
            {
                Games.Save(x);
                return(this.RedirectToAction(c => c.Edit(x.Document.Id)));
            }
            catch (Exception ex)
            {
                Notifier.Notify(ex);
                return(View(Games.All().WithDocuments()));
            }
        }
Пример #9
0
        public void Can_store_a_list_of_games()
        {
            Games.Initialise(new List <String> {
                "A beat B", "A beat C", "B beat C"
            });

            var expected = new List <Game>
            {
                new Game {
                    Winner = "A", Loser = "B"
                },
                new Game {
                    Winner = "A", Loser = "C"
                },
                new Game {
                    Winner = "B", Loser = "C"
                },
            };

            Assert.AreEqual(expected, Games.All());
        }
Пример #10
0
        void newing_up_has_many_association()
        {
            before = () =>
            {
                SetupGameLibraryScenario();

                user = new User(new { Id = 100 });
            };

            context["building a game for a user off of the user object"] = () =>
            {
                act = () => game = user.NewGame(new { Title = "Final Fantasy VII" });

                it["creates a game with specified attributes"] = () =>
                                                                 (game.Title as string).should_be("Final Fantasy VII");
            };


            context["building a game for user"] = () =>
            {
                act = () => game = user.Games().New(new { Title = "Final Fantasy VII" });

                it["creates a game of type defined in projection"] = () =>
                                                                     (game as object).should_cast_to <Game>();

                context["saving newly created game"] = () =>
                {
                    act = () => games.Save(game);

                    it["saves game"] = () =>
                                       games
                                       .All()
                                       .Any(s => s.Title == "Final Fantasy VII")
                                       .should_be_true();

                    it["saving game doesn't automatically associate the has many through"] = () =>
                    {
                        (user.Games(
                             new
                        {
                            discardCache = true
                        }) as IEnumerable <dynamic>).Count().should_be(0);
                    };
                };

                context["saving association through library and game"] = () =>
                {
                    act = () =>
                    {
                        user = users.Single(userId);

                        var game = user.Games().New(new { Title = "Final Fantasy VII" });

                        game.Id = games.Insert(game);

                        var libraryEntry = user.Library().New(new { GameId = game.Id });

                        library.Insert(libraryEntry);
                    };

                    it["game is associated with user"] = () =>
                    {
                        var gameLibrary = user.Games(new { discardCache = true });

                        ((int)gameLibrary.Count()).should_be(2);

                        var game = gameLibrary.Last();

                        (game.Title as string).should_be("Final Fantasy VII");
                    };
                };
            };
        }
Пример #11
0
 public dynamic OpenGames()
 {
     return(games.All(where : "Player1Id is null or Player2Id is null"));
 }
Пример #12
0
 public virtual ActionResult Index()
 {
     return(View(Games.All().WithDocuments()));
 }
Пример #13
0
        private async Task MoveIndex(int tableId, Game currentGame)
        {
            do
            {
                currentGame.SetIndex(currentGame.Index + 1);
                Games.FirstOrDefault(e => e.TableId == tableId)?.SetIndex(currentGame.Index);

                if (Games.First(e => e.TableId == tableId).Index == currentGame.RoundEndIndex)
                {
                    CommunityCardsController(tableId);
                    UpdatePot(tableId);
                    Games.First(e => e.TableId == tableId).RaiseAmount   = 0;
                    Games.First(e => e.TableId == tableId).RoundEndIndex = Games.First(e => e.TableId == tableId).BigBlindIndex + 1;
                    Games.First(e => e.TableId == tableId).Index         = Games.First(e => e.TableId == tableId).BigBlindIndex + 1;
                    Games.First(e => e.TableId == tableId).NormalizeAllIndexes();
                    foreach (var player in Games.First(e => e.TableId == tableId).Players)
                    {
                        player.RoundBet = 0;
                    }
                }
            } while ((currentGame.GetPlayerByIndex(currentGame.Index).ActionState != PlayerActionState.Playing || Users.First(e => e.Name == currentGame.GetPlayerByIndex(currentGame.Index).Name).Balance == 0 ||
                      currentGame.Players.Count(e => e.ActionState == PlayerActionState.Playing) < 2) && Games.First(e => e.TableId == tableId).CommunityCardsActions !=
                     CommunityCardsActions.AfterRiver);

            if (Games.First(e => e.TableId == tableId).CommunityCardsActions ==
                CommunityCardsActions.AfterRiver)
            {
                Thread.Sleep(10000);

                Games.Remove(Games.FirstOrDefault(e => e.TableId == tableId));

                if (Users.Where(e => e.TableId == tableId).Count(e => e.IsReady) >= 2 && Games.All(e => e.TableId != tableId))
                {
                    await StartGame(tableId, currentGame.SmallBlindIndex + 1);
                }
                else
                {
                    foreach (var e in Users.Where(e => e.TableId == tableId))
                    {
                        e.InGame = false;
                    }
                    PlayerStateRefresh(tableId);
                }
            }
            else
            {
                PlayerStateRefresh(tableId);
                await Clients.Group(tableId.ToString())
                .SendAsync("ReceiveTurnPlayer",
                           currentGame.GetPlayerNameByIndex(Games.First(e => e.TableId == tableId).Index));
            }
        }
Пример #14
0
        public async Task ActionFold()
        {
            if (!IsUserInGameHub(Context.User.Identity.Name))
            {
                return;
            }
            var tableId = GetTableByUser(Context.User.Identity.Name);

            var currentGame = Games.First(e => e.TableId == tableId);

            if (currentGame.Players.Any() &&
                currentGame.GetPlayerNameByIndex(currentGame.Index) == Context.User.Identity.Name)
            {
                //PlayerFolded
                Games.First(e => e.TableId == tableId).Players
                .First(e => e.Name == Context.User.Identity.Name).ActionState = PlayerActionState.Folded;

                //Remove from pots
                foreach (var pot in Games.First(e => e.TableId == tableId).Winnings)
                {
                    pot.Players.Remove(Context.User.Identity.Name);
                }

                //CheckIfOnlyOneLeft
                if (Games.First(e => e.TableId == tableId).Players
                    .Count(e => e.ActionState == PlayerActionState.Playing) == 1)
                {
                    UpdatePot(tableId);
                    GetAndAwardWinners(tableId);
                    PlayerStateRefresh(tableId);

                    Thread.Sleep(10000);

                    Games.Remove(Games.FirstOrDefault(e => e.TableId == tableId));

                    if (Users.Where(e => e.TableId == tableId).Count(e => e.IsReady) >= 2 && Games.All(e => e.TableId != tableId))
                    {
                        await StartGame(tableId, currentGame.SmallBlindIndex + 1);
                    }
                    else
                    {
                        foreach (var e in Users.Where(e => e.TableId == tableId))
                        {
                            e.InGame = false;
                        }
                        PlayerStateRefresh(tableId);
                    }
                }
                else
                {
                    await MoveIndex(tableId, currentGame);
                }
            }
        }