示例#1
0
        public void InitializeScreen()
        {
            Models.Player playerData = MainMenuDataCache.PlayerData;
            if (playerData == null || playerData.PlayerBase == null)
            {
                Debug.LogError("Player base missing");
                throw new System.ArgumentNullException("Player base missing!");
            }

            buildingsAndButtons = new Dictionary <GameObject, BaseBuilding>();

            // TODO: When I'm not tired. Do this in more maintainable way. Thanks future Santeri. :D
            buildingsAndButtons.Add(Building1Btn, playerData.PlayerBase.Building1);
            buildingsAndButtons.Add(Building2Btn, playerData.PlayerBase.Building2);
            buildingsAndButtons.Add(Building3Btn, playerData.PlayerBase.Building3);
            buildingsAndButtons.Add(Building4Btn, playerData.PlayerBase.Building4);
            buildingsAndButtons.Add(Building5Btn, playerData.PlayerBase.Building5);
            buildingsAndButtons.Add(Building6Btn, playerData.PlayerBase.Building6);
            buildingsAndButtons.Add(Building7Btn, playerData.PlayerBase.Building7);
            buildingsAndButtons.Add(Building8Btn, playerData.PlayerBase.Building8);
            buildingsAndButtons.Add(Building9Btn, playerData.PlayerBase.Building9);
            buildingsAndButtons.Add(Building10Btn, playerData.PlayerBase.Building10);

            foreach (KeyValuePair <GameObject, BaseBuilding> entry in buildingsAndButtons)
            {
                PopulateButtonValues(entry.Key, entry.Value);
            }
        }
示例#2
0
        private static void AddPlayerToTeam(string firstName, string lastName, decimal salary, DateTime dateOfBirth, string team)
        {
            Player player = new Player(firstName, lastName, salary, dateOfBirth, GetTeamByName(team));
            GetTeamByName(team).AddPlayer(player);

            Console.WriteLine("{0} {1} was added to {2}", player.FirstName, player.LastName, player.Team.Name);
        }
示例#3
0
        public void GetUserData()
        {
            if (UseMockedVersion)
            {
                if (SceneManagement.MainMenuDataCache.PlayerData == null)
                {
                    string jsonPlayer = Development.MockDataService.GetPlayerData(69);

                    Models.Player user = JsonConvert.DeserializeObject <Models.Player>(jsonPlayer);

                    if (user == null)
                    {
                        _uiFsm.SendEvent(Constants.UiConstants.NoUserEvent);
                        return;
                    }
                    Debug.Log($"User {user.Name} loaded!");
                    SceneManagement.MainMenuDataCache.PlayerData = user;
                    _uiFsm.SendEvent(Constants.UiConstants.UserExistsEvent);
                    InitializePlayerDataToUi(user);
                }
                else
                {
                    _uiFsm.SendEvent(Constants.UiConstants.UserExistsEvent);
                    InitializePlayerDataToUi(SceneManagement.MainMenuDataCache.PlayerData);
                }
            }
        }
        public void JsonSerializer_ShouldReturnCorrectResultWhenCorrectInput()
        {
            var serializer = new JsonSerializer();
            Player input = new Player { Name = "Test", Score = 65, Id = "1" };
            string expResult = "{\"Name\":\"Test\",\"Score\":65,\"Id\":\"1\"}";

            Assert.AreEqual(expResult, serializer.Serialize<Player>(input));
        }
        public void JsonSerializer_ShouldReturnCorrectResultWhenInputHasNoProperies()
        {
            var serializer = new JsonSerializer();
            Player input = new Player { };
            string expResult = "{\"Name\":null,\"Score\":0,\"Id\":null}";

            Assert.AreEqual(expResult, serializer.Serialize<Player>(input));
        }
示例#6
0
        public static string GetPlayerData(int playerId)
        {
            Models.Player player       = CreateMockPlayer();
            string        playerAsJson = JsonConvert.SerializeObject(player);

            Debug.Log($"Loading data to the game: {playerAsJson}");
            return(playerAsJson);
        }
示例#7
0
 public void SaveUserData()
 {
     try
     {
         string        username    = UsernameText.text;
         Models.Player savedPlayer = DataService.CreateUser(username);
         DataService.SavePlayerDataLocally(savedPlayer);
     }
     catch (Exception e)
     {
         Debug.LogError("Failed to save player data");
         throw e;
     }
 }
        public void Run()
        {
            this.isStarted = true;

            IExecutable command = null;

            while (this.isStarted)
            {
                if (flag)
                {
                    this.Writer.WriteLine(
                        "Lets play “Mini4KI”. Try your luck to find all cells wuthout mines."
                        + " Command 'top' showes the scores, 'restart' starts new game, 'exit' quits the game!");

                    MakeBorders(gameField);

                    this.flag = false;
                }

                this.Writer.Write("Enter row[0...4] and column[0...9], separated by space: ");

                this.input = Console.ReadLine().Trim();

                string line = this.Reader.ReadNextLine().Trim();

                // string[] inputArgs = line.Split(' ');
                //
                // command = this.commandManager.ManageCommand(line);
                //
                // try
                // {
                //     command.OnExecuting += (sender, args) =>
                //     {
                //         this.isStarted = !args.Stopped;
                //     };
                //
                //     command.Execute();
                // }
                // catch (Exception e)
                // {
                //     this.Writer.WriteLine(e.Message);
                // }

                if (this.input.Length >= 3)
                {
                    int row = 0;
                    int column = 0;

                    if (int.TryParse(this.input[0].ToString(), out row) && int.TryParse(this.input[2].ToString(), out column)
                        && row <= this.gameField.Board.GetLength(0) && column <= this.gameField.Board.GetLength(1))
                    {
                        this.input = "turn";
                    }
                }

                switch (this.input)
                {
                    case "top":
                        ShowScores(this.players);
                        break;
                    case "restart":
                        this.gameField = FieldsFactory.Create();
                        this.mines = InsertMines();
                        MakeBorders(this.gameField);
                        this.grum = false;
                        this.flag = false;
                        break;
                    case "exit":
                        this.Writer.WriteLine("Bye, bye, bye!");

                        break;
                    case "turn":
                        if (this.mines.Board[row, column] != '*')
                        {
                            if (this.mines.Board[row, column] == '-')
                            {
                                ChancheTurns(this.gameField, this.mines, row, column);
                                this.counter++;
                            }

                            if (maks == this.counter)
                            {
                                this.flag2 = true;
                            }
                            else
                            {
                                MakeBorders(gameField);
                            }
                        }
                        else
                        {
                            grum = true;
                        }

                        break;
                    default:
                        this.Writer.WriteLine("\nError! Invalid input\n");
                        break;
                }

                if (grum)
                {
                    MakeBorders(mines);

                    this.Writer.Write(string.Format("\nHrrrrrr! You have died with {0} scores. " + "Enter nickName: ", counter));

                    string nickName = this.Reader.ReadNextLine();

                    Player player = new Player(nickName, counter);

                    if (players.Count < 5)
                    {
                        players.Add(player);
                    }
                    else
                    {
                        for (int i = 0; i < players.Count; i++)
                        {
                            if (players[i].Scores < player.Scores)
                            {
                                players.Insert(i, player);
                                players.RemoveAt(players.Count - 1);
                                break;
                            }
                        }
                    }

                    players.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Name.CompareTo(firstPlayer.Name));

                    players.Sort((Player firstPlayer, Player secondPlayer) => secondPlayer.Scores.CompareTo(firstPlayer.Scores));
                    ShowScores(players);

                    gameField = FieldsFactory.Create();
                    mines = InsertMines();
                    counter = 0;
                    grum = false;
                    flag = true;
                }

                if (flag2)
                {
                    this.Writer.WriteLine("\nBRAVOOOS! Otvri 35 kletki bez kapka kryv.");
                    MakeBorders(mines);
                    this.Writer.WriteLine("Enter your name: ");

                    string name = this.Reader.ReadNextLine();

                    Player player = new Player(name, counter);
                    players.Add(player);
                    ShowScores(players);
                    gameField = FieldsFactory.Create();
                    mines = InsertMines();
                    counter = 0;
                    flag2 = false;
                    flag = true;
                }

                this.Writer.WriteLine("Made in Bulgaria - Uauahahahahaha!");
                this.Writer.WriteLine("AREEEEEEeeeeeee.");

                Console.Read();
            }
        }
        public void PlayerShouldCreateAPlayerWithValidScore()
        {
            var player = new Player { Name = "Pesho", Score = 5, Id = "1" };

            Assert.AreEqual(5, player.Score);
        }
 public void PlayerShouldThrowArgumentExceptionWhenScoreIsNegative()
 {
     var player = new Player { Name = "Pesho", Score = -5, Id = "1" };
 }
 public void PlayerShouldThrowArgumentExceptionWhenNameIsWhiteSpace()
 {
     var player = new Player { Name = "   ", Score = 5, Id = "1" };
 }
 public void PlayerShouldThrowArgumentExceptionWhenNameIsEmptyString()
 {
     var player = new Player { Name = string.Empty, Score = 5, Id = "1" };
 }
 public void PlayerShouldThrowArgumentExceptionWhenNameIsNull()
 {
     var player = new Player { Name = null, Score = 5, Id = "1" };
 }
示例#14
0
        private void ProcessGuess(int guess, Player player)
        {
            if (guess == this.realWeight)
            {
                lock (this.thisLock)
                {
                    if (this.isWeightFound == false)
                    {
                        this.isWeightFound = true;
                        this.winner = player;
                    }
                }
            }
            else
            {
                int currentGuessDelta = Math.Abs(this.realWeight - guess);
                lock (this.thisLock)
                {
                    int closestGuessDelta = Math.Abs(this.realWeight - this.closestWeight);
                    if (currentGuessDelta < closestGuessDelta)
                    {
                        this.closestWeight = guess;
                        this.winner = player;
                    }
                }

                Thread.Sleep(currentGuessDelta);
            }
        }
示例#15
0
 private void InitializePlayerDataToUi(Models.Player user)
 {
     SetPlayerMoneyText(user.Money);
     PlayerNameText.SetText(user.Name);
 }