예제 #1
0
        public void TestNoStartCard()
        {
            var noEntryCards = _repo.CreateCards(5);

            noEntryCards[0].CityFrom = noEntryCards[4].CityTo;

            CardHelpers.SetStartCard(noEntryCards);
        }
예제 #2
0
        public void TestMissingCard()
        {
            var missingCards = _repo.CreateCards(5).ToList();

            missingCards.RemoveAt(2);

            CardHelpers.SetRestCards(missingCards.ToArray());
        }
예제 #3
0
        public IActionResult IndexPost(CardIndexViewModel homeIndexVm)
        {
            homeIndexVm = CardHelpers.SetDefaultFindModel(homeIndexVm);

            CardHelpers.SetupViewBag(homeIndexVm, ViewBag);

            var vmData = JsonConvert.SerializeObject(homeIndexVm);

            HttpContext.Session.SetString(SearchVMCacheKey, vmData);

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public void TestSorting()
        {
            var init = _repo.CreateCards(20);
            var copy = new TravelCard[init.Length];

            Array.Copy(init, copy, init.Length);

            CardHelpers.ShuffleCards(copy);

            CardHelpers.OrderCards(copy);

            CollectionAssert.AreEqual(init, copy);
        }
예제 #5
0
        private Queue <CommunityCard> LoadCommunityCards()
        {
            var CardsArr = new[]
            {
                new CommunityCard("Your HDD burnt - you lose $150", CardType.Lose, 150),
                new CommunityCard("Your RAM burnt - you lose $100", CardType.Lose, 100),
                new CommunityCard("You get a raise - you win $150", CardType.Win, 150),
                new CommunityCard("You receive 2GB RAM - you win $100", CardType.Win, 100),
                new CommunityCard("Your laptop computer crashed - you lose $50", CardType.Lose, 50),
                new CommunityCard("You spill coffe on your keyboard - you lose $20", CardType.Lose, 20),
                new CommunityCard("Your dog ate you laptop computer recharger - you lose $75", CardType.Lose, 75),
                new CommunityCard("You receive a new battery for your laptop computer - you win $75", CardType.Win, 75),
                new CommunityCard("A gift! - new smartphone for you - you win $50", CardType.Win, 50),
                new CommunityCard("You have a birthday! - you win $20", CardType.Win, 20),
            };

            return(CardHelpers.ShuffleCards(CardsArr));
        }
예제 #6
0
        private Queue <ChanceCard> LoadChanceCards()
        {
            var CardsArr = new[]
            {
                new ChanceCard("Destributed Dental System Attack - you lose $150", CardType.Lose, 150),
                new ChanceCard("Ouch - Heartbleed - you lose $100", CardType.Lose, 100),
                new ChanceCard("You used float insted of decimal - you lose $50", CardType.Lose, 50),
                new ChanceCard("Your Visual Studio license expired - you lose $75", CardType.Lose, 75),
                new ChanceCard("Blue Screen of Death!!! - you lose $20", CardType.Lose, 20),
                new ChanceCard("A flush of inspiration - your code compiled without any errors! - you win $100", CardType.Win, 100),
                new ChanceCard("You fixed a nasty bug - you win $50", CardType.Win, 50),
                new ChanceCard("You received a Telerik Academy Ninja Certificate - you win $150", CardType.Win, 150),
                new ChanceCard("Internet Explorer has extincted! - you win $75", CardType.Win, 75),
                new ChanceCard("Intenet boost! - you win $20", CardType.Win, 20),
            };

            return(CardHelpers.ShuffleCards(CardsArr));
        }
예제 #7
0
        public async Task <IActionResult> Index()
        {
            var value = HttpContext.Session.GetString(SearchVMCacheKey);
            CardIndexViewModel cardIndexViewModel = string.IsNullOrEmpty(value) ?
                                                    CardHelpers.SetDefaultFindModel(new CardIndexViewModel()) :
                                                    JsonConvert.DeserializeObject <CardIndexViewModel>(value);

            CardHelpers.SetupViewBag(cardIndexViewModel, ViewBag);

            var result = await _cardRepository.ConfigureSearchAsync(cardIndexViewModel);

            var count = await _cardRepository.GetTotalCards();

            ViewBag.MaxPage = count / cardIndexViewModel.Page;

            ViewBag.Page             = cardIndexViewModel.Page;
            cardIndexViewModel.Cards = result;
            return(View(cardIndexViewModel));
        }
예제 #8
0
        public void Setup()
        {
            roomManagerInstance = new RoomManager();
            room    = new RoomHub();
            player1 = new Player
            {
                ConnectionId = Guid.NewGuid().ToString(),
                PlayerInGame = new PlayerInGame()
                {
                    Name        = Guid.NewGuid().ToString(),
                    Side        = PlayerSide.Blue,
                    CardsInHand = new List <ICard>(),
                    Deck        = CardHelpers.GetAllTierOneCards()
                }
            };
            player2 = new Player
            {
                ConnectionId = Guid.NewGuid().ToString(),
                PlayerInGame = new PlayerInGame()
                {
                    Name        = Guid.NewGuid().ToString(),
                    Side        = PlayerSide.Red,
                    CardsInHand = new List <ICard>(),
                    Deck        = CardHelpers.GetAllTierOneCards()
                }
            };
            room.Player1 = player1;
            room.Player2 = player2;

            boardManager = BoardManagerObject.CreateBoardManager(player1.PlayerInGame, player2.PlayerInGame);

            room = new RoomHub
            {
                BoardManager = boardManager,
                Player1      = player1,
                Player2      = player2
            };
        }
예제 #9
0
        public void PlayerTurn(Player player, Board boar, int firstRoll, int secondRoll)
        {
            Tile currentTile;

            this.MovePlayer(player, firstDice, secondDice, board);
            currentTile = board.GetTileAtPosition(player.Position);

            Console.WriteLine("Current tile {0}", currentTile);
            IChoosableAction actionTile = currentTile as IChoosableAction;

            if (actionTile != null)
            {
                this.ExecuteActionFromTile(actionTile, player);
            }

            if (currentTile is CommunityTile)
            {
                CommunityCard card = CardHelpers.DrawCard(this.communityCards);

                Console.WriteLine("Community Card");
                Console.WriteLine("Card Desciption: {0}", card.Description);
                Console.ReadLine();

                this.ExecuteActionFromCard(card, player);
            }
            else if (currentTile is ChanceTile)
            {
                ChanceCard card = CardHelpers.DrawCard(this.chanceCards);

                Console.WriteLine("Chance Card");
                Console.WriteLine("Card Desciption: {0}", card.Description);
                Console.ReadLine();

                this.ExecuteActionFromCard(card, player);
            }
        }
예제 #10
0
        public static void RegisterRoute(ServerTcpListener server)
        {
            server.EndPointApi.RegisterEndPoint("POST", "^/battles$", (IRequestContext httpRequest) =>
            {
                try
                {
                    httpRequest.Headers.TryGetValue("Authorization", out string token);
                    if (!Regex.IsMatch(token, "^Basic (.*)-mtcgToken$"))
                    {
                        httpRequest.ReponseHandler.SendDefaultStatus(httpRequest.Stream, "400");
                        return(400);
                    }
                    string querystring    = @$ "select LoginName from users where LoginName='{Regex.Match(token, " ^ Basic(.*) - mtcgToken$ ").Groups[1].Value}'";
                    NpgsqlConnection conn = DbHelper.ConnectObj();
                    conn.Open();

                    string UserID;
                    using (NpgsqlCommand command = new NpgsqlCommand(querystring, conn))
                    {
                        NpgsqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows == false)
                        {
                            httpRequest.ReponseHandler.SendDefaultStatus(httpRequest.Stream, "401");
                            conn.Close();
                            return(401);
                        }
                        reader.Read();
                        UserID = reader[0].ToString();
                        reader.Close();
                    }
                    Player player = new Player();
                    querystring   = @$ "select loginname,Elo from users join Scoreboard on users.LoginName = Scoreboard.LoginName_fk where loginname='{UserID}'";
                    using (NpgsqlCommand command = new NpgsqlCommand(querystring, conn))
                    {
                        NpgsqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows == false)
                        {
                            httpRequest.ReponseHandler.SendDefaultStatus(httpRequest.Stream, "500");
                            conn.Close();
                            return(500);
                        }
                        reader.Read();
                        player.Elo      = reader[1].ToString();
                        player.UserName = reader[0].ToString();
                        reader.Close();
                    }
                    querystring      = @$ "select CardID,Cardtype,CardName,BaseDamage,CardElement,CardStyle from Card join UserhasCardsinDeck on Card.CardID = UserhasCardsinDeck.CardId_fk where LoginName_fk='{UserID}'";
                    List <Card> Deck = new List <Card>();
                    using (NpgsqlCommand command = new NpgsqlCommand(querystring, conn))
                    {
                        NpgsqlDataReader reader = command.ExecuteReader();
                        if (reader.HasRows == false)
                        {
                            httpRequest.ReponseHandler.SendDefaultStatus(httpRequest.Stream, "400");
                            conn.Close();
                            return(400);
                        }
                        while (reader.Read())
                        {
                            Card.CardelEmentEnum Type;
                            if (reader[4].ToString() == "fire")
                            {
                                Type = Card.CardelEmentEnum.fire;
                            }
                            else if (reader[4].ToString() == "water")
                            {
                                Type = Card.CardelEmentEnum.water;
                            }
                            else
                            {
                                Type = Card.CardelEmentEnum.normal;
                            }
                            string whatcard;
                            if (reader[5].ToString() == "Spell")
                            {
                                whatcard = "Spell";
                            }
                            else
                            {
                                whatcard = reader[1].ToString();
                            }

                            Deck.Add(CardHelpers.Cardmaker(Int32.Parse(reader[3].ToString()), reader[2].ToString(), reader[0].ToString(), Type, whatcard));
                        }
                    }
                    if (Deck.Count != 4)
                    {
                        httpRequest.ReponseHandler.SendDefaultStatus(httpRequest.Stream, "400");
                        conn.Close();
                        return(400);
                    }
                    player.Deck            = Deck;
                    AutoResetEvent myEvent = new AutoResetEvent(false);
                    Programm.fightApi.QueUpForFight(player, myEvent);
                    myEvent.WaitOne();

                    switch (player.Status)
                    {
                    case FightHandler.BattleStatus.Win:
                        DbHelper.IncreaseWin(UserID);
                        httpRequest.ReponseHandler.SendDefaultMessage(httpRequest.Stream, "200", player.AssignedBattleLog);
                        conn.Close();
                        return(200);

                    case FightHandler.BattleStatus.Lose:
                        DbHelper.IncreaseLose(UserID);
                        httpRequest.ReponseHandler.SendDefaultMessage(httpRequest.Stream, "200", player.AssignedBattleLog);
                        conn.Close();
                        return(200);

                    case FightHandler.BattleStatus.Tie:
                        DbHelper.IncreaseTie(UserID);
                        httpRequest.ReponseHandler.SendDefaultMessage(httpRequest.Stream, "200", player.AssignedBattleLog);
                        conn.Close();
                        return(200);

                    default:
                        httpRequest.ReponseHandler.SendDefaultStatus(httpRequest.Stream, "500");
                        conn.Close();
                        return(500);
                    }
                }
        public void ShouldTierOneCardCountBeMoreThanZero()
        {
            var tierOneCards = CardHelpers.GetAllTierOneCards();

            Assert.That(tierOneCards.Count() > 0);
        }
예제 #12
0
 public void MaskCardNumberShouldCorrectlyMaskTheCardNumber(string cardNumber, string expectedMaskedCardNumber)
 {
     Assert.Equal(expectedMaskedCardNumber, CardHelpers.MaskCardNumber(cardNumber));
 }
예제 #13
0
        public void ResetGame()
        {
            try
            {
                // Extract method
                ImmutableArray <string> emojis = CardHelpers.AllAnimals;
                var random = new Random();
                emojis = emojis.OrderBy(item => random.Next()).ToImmutableArray();
                // Wrap call chain
                var shuffledCards = emojis.Concat(emojis).OrderBy(item => random.Next()).Select(item => CardHelpers.CreateCard(item)).ToImmutableArray();

                ShuffledCards = shuffledCards.CastArray <ICard>();
                MatchesFound  = 0;
                timerStart    = timerEnd = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }