Esempio n. 1
0
        public void AddTwoPlayersWithSameNameAndScoreTest()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add("Pesho", 23);
            scoreBoard.Add("Pesho", 23);
        }
Esempio n. 2
0
        public void AddToScoreBoard()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add("Pesho", 23);
            scoreBoard.Add("Gosho", 13);
            scoreBoard.Add("Tosho", 17);
            string str = scoreBoard.Scores().Values.ToString();

            str += scoreBoard.Scores().Keys.ToString();

            Assert.AreEqual(str, "{Gosho,Tosho,Pesho}{13,17,23}");
        }
Esempio n. 3
0
    public bool CheckHighScore(PlayerStat stat)
    {
        if (ScoreBoard == null)
        {
            return(false);
        }
        if (ScoreBoard.Count == 0)
        {
            ScoreBoard.Add(stat);
            return(true);
        }

        for (int i = 0; i < 10; i++)
        {
            if (i < ScoreBoard.Count)
            {
                if (stat.Score > ScoreBoard[i].Score)
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 4
0
 private void ProcessHit()
 {
     hitMode           = true;
     hitModeExpireTime = Time.time + hitModeLength;
     scoreBoard.Add(hitScore);
     hitsRemaining--;
 }
Esempio n. 5
0
        public void AddShortMaxValueNumberOfPlayersTest()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            for (int i = 0; i < short.MaxValue; i++)
            {
                scoreBoard.Add(i.ToString(), 23);
            }
        }
Esempio n. 6
0
 private void InitializeScoreKeeper()
 {
     foreach (Player player in PhotonNetwork.PlayerList)
     {
         ScoreBoard.Add(player.ActorNumber, 0);
     }
     initialized = true;
     Debug.Log("Score Keeper Initialized");
 }
Esempio n. 7
0
        public void AddEmptyNameToScoreBoard()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add(string.Empty, 23);

            string str = scoreBoard.Scores().Values.ToString();

            str += scoreBoard.Scores().Keys.ToString();
            Assert.AreEqual(str, "{Anonymous}{23}");
        }
        public void ScoreBoard_AddMethod()
        {
            var pesho = new Player("Pesho");

            ScoreBoard<Player> scoreBoard = new ScoreBoard<Player>();
            scoreBoard.Add(pesho);

            foreach (var player in scoreBoard)
            {
                Assert.AreSame(pesho,player);
            }
        }
Esempio n. 9
0
        protected void Start()
        {
            // Create all spaceships.
            var secondaryColorIndex = 0;
            var type2colors         = new Dictionary <SpaceshipBody.Type, HashSet <Color> >();
            var nameCount           = new Dictionary <string, int>();
            var spaceships          = FindObjectsOfType <SpaceshipBody>();

            DebugUtils.Assert(0 < spaceships.Length, "Define spaceship names at 'Game'");
            DebugUtils.Assert(spaceships.Length <= 6, "Max 6 spaceships allowed!");

            foreach (var body in spaceships)
            {
                var spawnPoint = Space.GetSpawnPoint();
                var angle      = UnityEngine.Random.Range(1, 360 / Spaceship.ROTATION_PER_ACTION) * Spaceship.ROTATION_PER_ACTION;
                body.Activate(spawnPoint, angle, space);

                // Check for duplicate type and color.
                var bodyType = body.spaceshipType;
                // Further normaliziation of color to distinguish between similar colors.
                var color = SpaceshipBody.NormalizeColor(body.primaryColor, 0x20);
                if (!type2colors.ContainsKey(bodyType))
                {
                    type2colors[bodyType] = new HashSet <Color>();
                    type2colors[bodyType].Add(color);
                }
                else if (type2colors[bodyType].Contains(color))
                {
                    // Color clash! Set secondary color.
                    body.SetSecondaryColor(secondaryColors[secondaryColorIndex++]);
                }
                else
                {
                    type2colors[bodyType].Add(color);
                }

                var brain = body.Brain;
                if (nameCount.ContainsKey(brain.DefaultName))
                {
                    ++nameCount[brain.DefaultName];
                    brain.Name = brain.DefaultName + " " + nameCount[brain.DefaultName];
                }
                else
                {
                    nameCount[brain.DefaultName] = 1;
                }

                // Register to score board.
                scoreBoard.Add(brain.Name, color, body.secondaryColor);
            }

            deaths = 0;
        }
Esempio n. 10
0
        public void ScoreBoard_AddMethod()
        {
            var pesho = new Player("Pesho");

            ScoreBoard <Player> scoreBoard = new ScoreBoard <Player>();

            scoreBoard.Add(pesho);

            foreach (var player in scoreBoard)
            {
                Assert.AreSame(pesho, player);
            }
        }
Esempio n. 11
0
        void Try()
        {
            var fullRows = GetFullRows().ToList();

            if (fullRows.Count > 0)
            {
                scoreBoard.StartAdding();
                var cellsClone = CellsClone;
                fullRows.ForEach(y => {
                    RemoveRow(cellsClone, y);
                    scoreBoard.Add();
                });
                CellsClone = cellsClone;
            }
        }
Esempio n. 12
0
        private async void writeToXml(IStorageFile newFile, Score score)
        {
            var serializer  = new XmlSerializer(typeof(ScoreBoard));
            var writeStream = await newFile.OpenStreamForWriteAsync();

            var board = new ScoreBoard();

            using (writeStream)
            {
                board.Add(score);
                serializer.Serialize(writeStream, board);
            }

            writeStream.Dispose();
        }
Esempio n. 13
0
    //
    // End Game: Return to menu
    //
    void ReturnButtonPress()
    {
//		Debug.Log ("ReturnButton Pressed. Return to menu");

        // Add score to database
        chooseMode.setGameMode = GameType;
        ScoreBoard.Add(weightedScore, GameType);
        LevelControl.AddExperience(weightedScore, GameType);
        GameType = null;


//		print("WeightedScore: " + weightedScore);

        // Load menu
        UnityEngine.SceneManagement.SceneManager.LoadScene("Menu", UnityEngine.SceneManagement.LoadSceneMode.Single);
    }
Esempio n. 14
0
        protected void Start()
        {
            // Create all spaceships.
            var secondaryColorIndex = 0;
            var type2colors         = new Dictionary <SpaceshipBody.Type, HashSet <Color> >();
            var nameCount           = new Dictionary <string, int>();

            foreach (var spaceshipName in spaceshipNames)
            {
                var brain      = BrainFactory.GetBrain(spaceshipName);
                var spawnPoint = Space.GetSpawnPoint();
                var angle      = UnityEngine.Random.Range(1, 360 / Spaceship.ROTATION_PER_ACTION) * Spaceship.ROTATION_PER_ACTION;
                var body       = spaceshipBodiesPool.Borrow <SpaceshipBody>(spawnPoint, angle, space, brain);

                // Check for duplicate type and color.
                var bodyType = body.spaceshipType;
                var color    = body.primaryColor;
                if (!type2colors.ContainsKey(bodyType))
                {
                    type2colors[bodyType] = new HashSet <Color>();
                    type2colors[bodyType].Add(color);
                }
                else if (type2colors[bodyType].Contains(color))
                {
                    // Color clash! Set secondary color.
                    body.SetSecondaryColor(secondaryColors[secondaryColorIndex++]);
                }
                else
                {
                    type2colors[bodyType].Add(color);
                }

                if (nameCount.ContainsKey(brain.DefaultName))
                {
                    ++nameCount[brain.DefaultName];
                    brain.Name = brain.DefaultName + " " + nameCount[brain.DefaultName];
                }
                else
                {
                    nameCount[brain.DefaultName] = 1;
                }

                // Register to score board.
                scoreBoard.Add(brain.Name, color, body.secondaryColor);
            }
        }
Esempio n. 15
0
        public void AddMoreThanFiveOnScoreBoardTest()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add("Pesho", 23);
            scoreBoard.Add("Gosho", 13);
            scoreBoard.Add("Ivan", 18);
            scoreBoard.Add("Kiro", 17);
            scoreBoard.Add("Stamat", 14);
            scoreBoard.Add("Mimi", 12);
            scoreBoard.Add("Tosho", 10);

            string str = scoreBoard.Scores().Values.ToString();

            str += scoreBoard.Scores().Keys.ToString();
            Assert.AreEqual(str, "{Tosho,Mimi,Gosho,Stamat,Kiro,Ivan,Pesho}{10,12,13,14,17,18,23}");
        }
Esempio n. 16
0
        private void InitPlayers(int numberOfplayers)
        {
            List <string> weaponStrings;

            bool writeToFile = false;

            try
            {
                weaponStrings = Utility.ReadFromFile("weapons.ini");
                writeToFile   = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception when loading weapons: " + e + "... defaulting to default weapons!");
                weaponStrings = new List <string>();
                weaponStrings.Add("Pistol|60|1|20|30|10|false|false|10|0|1|0|1|pistol|pistol");
                weaponStrings.Add("Shotgun|120|20|12|10|10|false|false|8|1|10|0.1|1|shotgun|shotgun");
                weaponStrings.Add("SMG|90|1|50|10|10|false|true|10|0|1|0.1|1|smg|MP5");
                weaponStrings.Add("Sniper Rifle|120|20|12|60|15|false|false|20|0|1|0|1|sniperRifle|AG3");
                weaponStrings.Add("Grenade Launcher|120|30|6|150|50|true|true|8|0|1|0|2|grenadeLauncher|SMG");
            }
            for (int i = 0; i < numberOfplayers; i++)
            {
                Player p = new Player();
                p.Health = 200;

                foreach (string s in weaponStrings)
                {
                    p.Weapons.Add(HandgunWeapon.WeaponFromString(s));
                }
                if (!writeToFile)
                {
                    Weapon.WriteWeaponsToIniFile(p.Weapons);
                    writeToFile = true;
                }
                p.CurrentWeapon = p.Weapons.ElementAt(0);
                PlacePlayer(p);
                Add(p);
                ScoreBoard.Add(p, new Scores());
            }
        }
Esempio n. 17
0
        public void NegativeScoreTest()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add("pesho", -23);
        }
Esempio n. 18
0
        public void AddNullNameToScoreBoard()
        {
            ScoreBoard scoreBoard = new ScoreBoard();

            scoreBoard.Add(null, 23);
        }
Esempio n. 19
0
        /// <summary>
        /// Executes the commands for "Restart", for top players and to exit from the game
        /// </summary>
        /// <param name="commandList">Takes the command from the list at a specified index</param>
        public void ExecuteCommand(List <string> commandList)
        {
            if (commandList.Count == 0)
            {
                this.NextCommand();
            }

            try
            {
                string firstCommand = commandList.ElementAt(0);
                switch (firstCommand)
                {
                case "RESTART":
                    this.Start();
                    break;

                case "TOP":
                    this.PrintScoreBoard();
                    this.NextCommand();
                    break;

                case "EXIT":
                    this.Exit();
                    break;

                default:
                {
                    int  row      = 0;
                    int  column   = 0;
                    bool tryParse = false;

                    tryParse = int.TryParse(commandList.ElementAt(0), out row);
                    tryParse = int.TryParse(commandList.ElementAt(1), out column) && tryParse;

                    if (!tryParse || commandList.Count < 2)
                    {
                        throw new CommandUnknownException();
                    }

                    if (Grid.RevealCell(row, column) == '*')
                    {
                        Grid.MarkCell('-');
                        Grid.RevealMines();
                        Console.WriteLine(Grid.ToString());
                        Console.WriteLine(string.Format("Booooom! You were killed by a mine. You revealed {0} cells without mines.", this.Score));
                        Console.Write("Please enter your name for the top scoreboard: ");
                        string playerName = Console.ReadLine();
                        ScoreBoard.Add(new ScoreRecord(playerName, Score));
                        Console.WriteLine();
                        this.PrintScoreBoard();
                        this.Start();
                    }
                    else
                    {
                        Console.WriteLine(Grid.ToString());
                        this.Score++;
                        this.NextCommand();
                    }
                }

                break;
                }
            }
            catch (InvalidCellException)
            {
                Console.WriteLine("Illegal move!");
                this.NextCommand();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                this.NextCommand();
            }
        }
Esempio n. 20
0
 public void AddScore(PlayerStat newStat)
 {
     ScoreBoard.Add(newStat);
     ScoreBoard = SortScoreBoard(ScoreBoard, SortingType.Descending);
     _jsonController.SaveData(ScoreBoard);
 }
Esempio n. 21
0
        public void NextCommand()//console -  output grid and message to request command
        {
            Console.Write("Enter row and column:");

            string commandLine = Console.ReadLine().ToUpper().Trim();

            List <string> commandList = commandLine.Split(' ').ToList();

            if (commandList.Count == 0)//if command list is empty
            {
                NextCommand();
            }

            try
            {
                string firstCommand = commandList.ElementAt(0);
                switch (firstCommand)
                {
                case "RESTART": Start(); break;

                case "TOP":
                {
                    PrintScoreBoard();
                    NextCommand();
                }; break;

                case "EXIT": Exit(); break;

                //case "EXPLOREMINES":
                //    {
                //        Grid.RevealMines();
                //        Console.WriteLine(Grid.ToString());
                //        NextCommand();
                //    }; break;
                default:
                {
                    int  row      = 0;
                    int  column   = 0;
                    bool tryParse = false;

                    if (commandList.Count < 2)
                    {
                        throw new CommandUnknownException();
                    }

                    tryParse = (Int32.TryParse(commandList.ElementAt(0), out row) || tryParse);
                    tryParse = (Int32.TryParse(commandList.ElementAt(1), out column) || tryParse);

                    if (!tryParse)
                    {
                        throw new CommandUnknownException();
                    }


                    if (Grid.RevealCell(row, column) == '*')
                    {
                        Grid.mark('-');
                        Grid.RevealMines();
                        Console.WriteLine(Grid.ToString());
                        Console.WriteLine(String.Format("Booooom! You were killed by a mine. You revealed {0} cells without mines.", Score));
                        Console.Write("Please enter your name for the top scoreboard: ");
                        string playerName = Console.ReadLine();
                        ScoreBoard.Add(new ScoreRecord(playerName, Score));
                        Console.WriteLine();
                        PrintScoreBoard();
                        Start();
                    }
                    else
                    {
                        Console.WriteLine(Grid.ToString());
                        Score++;
                        NextCommand();
                    }
                }; break;
                }
            }
            catch (InvalidCellException)
            {
                Console.WriteLine("Illegal move!");
                NextCommand();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                NextCommand();
            }
        }