Ejemplo n.º 1
0
        public void TestServerMasterModifiedAfterAddPlayer()
        {
            IPlayer        player        = new Player(0, "player1", new CountCallTetriNETCallback());
            IPlayerManager playerManager = CreatePlayerManager(5);

            playerManager.Add(player);

            Assert.AreEqual(playerManager.ServerMaster, player);
        }
Ejemplo n.º 2
0
        public void TestFirstAvailableIdFull()
        {
            IPlayerManager playerManager = CreatePlayerManager(1);

            playerManager.Add(new Player(0, "player1", new CountCallTetriNETCallback()));

            int id = playerManager.FirstAvailableId;

            Assert.AreEqual(id, -1);
        }
Ejemplo n.º 3
0
        public void TestCallbackIndexerFindNonExistingPlayer()
        {
            ITetriNETCallback callback1     = new CountCallTetriNETCallback();
            ITetriNETCallback callback2     = new CountCallTetriNETCallback();
            ITetriNETCallback callback3     = new CountCallTetriNETCallback();
            ITetriNETCallback callback4     = new CountCallTetriNETCallback();
            IPlayer           player1       = new Player(0, "player1", callback1);
            IPlayer           player2       = new Player(1, "player2", callback2);
            IPlayer           player3       = new Player(2, "player3", callback3);
            IPlayer           player4       = new Player(3, "player4", callback4); // NOT ADDED IN PLAYERMANAGER
            IPlayerManager    playerManager = CreatePlayerManager(5);

            playerManager.Add(player1);
            playerManager.Add(player2);
            playerManager.Add(player3);

            IPlayer searched = playerManager[3];

            Assert.IsNull(searched);
        }
Ejemplo n.º 4
0
        public void TestRemoveNullPlayer()
        {
            IPlayerManager playerManager = CreatePlayerManager(5);

            playerManager.Add(new Player(0, "player1", new CountCallTetriNETCallback()));

            bool removed = playerManager.Remove(null);

            Assert.IsFalse(removed);
            Assert.AreEqual(playerManager.PlayerCount, 1);
        }
Ejemplo n.º 5
0
        public void TestRemoveExistingPlayer()
        {
            IPlayerManager playerManager = CreatePlayerManager(5);
            IPlayer        player        = new Player(0, "player1", new CountCallTetriNETCallback());

            playerManager.Add(player);

            bool removed = playerManager.Remove(player);

            Assert.IsTrue(removed);
            Assert.AreEqual(playerManager.PlayerCount, 0);
        }
        public IActionResult Post([FromBody] Player player)
        {
            if (player == null)
            {
                return(BadRequest("Player does not exist!"));
            }

            //if model stace vali

            dataRepository.Add(player);
            return(CreatedAtRoute(
                       "Get",
                       new { player.PlayerId },
                       player));
        }
Ejemplo n.º 7
0
        public void Begin()
        {
            var userName = _messageFactory.LoginMessage();
            var user     = _playerManager.GetByUserName(userName);

            if (user == null)
            {
                var key = _playerManager.Add(new Player {
                    Name = userName
                });
                user = _playerManager.Get(key);
            }
            _messageFactory.PlayerStatisticsMessage(user);
            bool         kartoti          = true;
            List <Words> PanaudotiZodziai = new List <Words>()
            {
                null
            };

            while (kartoti)
            {
                Console.Clear();
                var tema  = RenkuosiTema();
                var zodis = RandomZodzioParinkimas(tema, PanaudotiZodziai);
                if (zodis == null)
                {
                    Console.WriteLine("Temoje nebera zodziu, ar norite rinktis kita tema t/n");
                }
                else
                {
                    _hiddenWordManager = new HiddenWordManager(zodis);
                    bool leidziamaSpeti = true;
                    panaudotiZodziai.Add(zodis);
                    _messageFactory.KartuvesPictureMessage(0);
                    Console.WriteLine();
                    Console.WriteLine(_hiddenWordManager.GetHiddenWordsStructure());
                    while (leidziamaSpeti)
                    {
                        string spejimas      = _messageFactory.WordInputMessage();
                        bool   arSpetasZodis = ArSpetasZodis(spejimas);
                        if (arSpetasZodis)
                        {
                            bool arTeisinga = ArZodisTeisingas(zodis.Text, spejimas);

                            if (arTeisinga)
                            {
                                _messageFactory.WinMessage(zodis.Text);
                                guessWholeWord = _hiddenWordManager.HiddenWords.HiddenLetterCount;
                            }
                            else
                            {
                                _messageFactory.KartuvesPictureMessage(gyvybiuKiekis);
                                _messageFactory.LostMessage(zodis.Text);
                            }
                            leidziamaSpeti = false;
                        }
                        else
                        {
                            bool arBuvoSpeta = _hiddenWordManager.HiddenWords.IncorrectGuesses.Contains(spejimas);
                            if (!arBuvoSpeta)
                            {
                                _hiddenWordManager.CheckLetter(spejimas);
                            }
                            if (_hiddenWordManager.HiddenWords.IncorrectGuesses.Count == gyvybiuKiekis)
                            {
                                _messageFactory.KartuvesPictureMessage(gyvybiuKiekis);
                                _messageFactory.LostMessage(zodis.Text);
                                leidziamaSpeti = false;
                            }
                            else
                            {
                                Console.Clear();
                                _messageFactory.KartuvesPictureMessage(_hiddenWordManager.HiddenWords.IncorrectGuesses.Count);
                                _messageFactory.IncorrectLettersListMessage(_hiddenWordManager.HiddenWords.IncorrectGuesses);
                                Console.WriteLine(_hiddenWordManager.GetHiddenWordsStructure());
                                if (_hiddenWordManager.HiddenWords.HiddenLetterCount == 0)
                                {
                                    _messageFactory.WinMessage(zodis.Text);
                                    _messageFactory.PlayerStatisticsMessage(user);
                                    leidziamaSpeti = false;
                                }
                            }
                        }
                    }
                    _playerManager.AddScoreBoards(GetScoreBoard(zodis, user.PlayerId));
                    //nors ir atnaujinu duomenu baze cia
                }
                guessWholeWord = 0;
                //bet visada atspauzdina senos duomenu bazes duomenis, neissiaiskinau kodel taip yra
                _messageFactory.PlayerStatisticsMessage(user);
                kartoti = _messageFactory.RepeatGameMessage();
            }
        }
Ejemplo n.º 8
0
 public override async Task OnConnectedAsync()
 {
     _playerManager.Add(new Player(Context.ConnectionId));
 }
Ejemplo n.º 9
0
        public void Begin()
        {
            var userName = _massageFactory.LoginMesage();
            var user     = _playerManager.GetByUserName(userName);

            if (user == null)
            {
                var key = _playerManager.Add(new Player {
                    Name = userName
                });
                user = _playerManager.Get(key);
            }
            _massageFactory.PlayerStatisticsMessage(user);

            bool kartoti = true;

            while (kartoti)
            {
                Console.Clear();
                var tema  = SelectSubject();
                var zodis = AtsitiktinisZodzioPasirinkimas(tema);
                if (zodis == null)
                {
                    Console.WriteLine("Temoje nebėra žodžiu, ar norite rinktis kitą temą T/N");
                }
                else
                {
                    _hiddenWordManager = new HiddenWordManager(zodis);
                    bool leidziamaSpeti = true;
                    panaudotiZodziai.Add(zodis);
                    _massageFactory.HangmanPictureMessage(0);
                    Console.WriteLine();
                    Console.WriteLine(_hiddenWordManager.GetHiddedWordStructure());
                    while (leidziamaSpeti)
                    {
                        string spejimas      = _massageFactory.WordInputMessage();
                        bool   arSpetasZodis = ArSpetasZodis(spejimas);
                        if (arSpetasZodis)
                        {
                            bool arTeisinga = ArZodisTeisingas(zodis.Text, spejimas);
                            if (arTeisinga)
                            {
                                _massageFactory.WinGameMessage(zodis.Text);
                            }
                            else
                            {
                                _massageFactory.HangmanPictureMessage(gyvybiuKiekis);
                                _massageFactory.LostGameMessage(zodis.Text);
                            }
                            leidziamaSpeti = false;
                        }
                        else
                        {
                            bool arBuvoSpeta = _hiddenWordManager.HiddenWord.IncorrectGuesses.Contains(spejimas);
                            if (!arBuvoSpeta)
                            {
                                _hiddenWordManager.CheckLetter(spejimas);
                            }
                            if (_hiddenWordManager.HiddenWord.IncorrectGuesses.Count == gyvybiuKiekis)
                            {
                                _massageFactory.HangmanPictureMessage(gyvybiuKiekis);
                                _massageFactory.LostGameMessage(zodis.Text);
                                leidziamaSpeti = false;
                            }
                            else
                            {
                                Console.Clear();
                                _massageFactory.HangmanPictureMessage(_hiddenWordManager.HiddenWord.IncorrectGuesses.Count);
                                _massageFactory.IncorrectLettersListMessage(_hiddenWordManager.HiddenWord.IncorrectGuesses);
                                Console.WriteLine(_hiddenWordManager.GetHiddedWordStructure());
                                if (_hiddenWordManager.HiddenWord.HiddenLetterCount == 0)
                                {
                                    _massageFactory.WinGameMessage(zodis.Text);
                                    leidziamaSpeti = false;
                                }
                            }
                        }
                    }
                }
                _playerManager.AddScoreBoard(GetScoreBoard(zodis, user.PlayerId));

                kartoti = _massageFactory.RepeatGameMessage();
            }
        }