Ejemplo n.º 1
0
 /// <summary>
 /// update the score of a player
 /// </summary>
 /// <param name="gameMm"></param>
 /// <param name="lost"></param>
 public void Update(GameMm gameMm, bool lost)
 {
     // update the number of playd games
     NmbGames++;
     // opdate the total number of trails
     TotalTrails += gameMm.CodeRank + 1;
     // update the average number of trails per game
     AvgTrail = TotalTrails / NmbGames;
     // update total number of lost games
     if (lost)
     {
         TotalLost++;
     }
     // update the succes rate
     SuccessRate = 100 * (NmbGames - TotalLost) / NmbGames;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// generates a text to help the player
        /// to enter a valid code
        /// </summary>
        /// <param name="gameMm"></param>
        /// <returns>the string to be displayed in the InfoBox</returns>
        public string Info(GameMm gameMm)
        {
            // show help text for a valid code
            var sb = new StringBuilder();

            sb.AppendLine("You may only enter codes of:");

            // add number of positions
            sb.AppendLine($"{gameMm.Pos} characters");
            sb.AppendLine("you may choose from:");
            for (int i = (int)gameMm.FirstChr; i < (int)gameMm.FirstChr + gameMm.Chr; i++)
            {
                sb.Append(" " + (char)i);
            }
            // return the help string
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// checks if a valid code is entered
        /// </summary>
        /// <param name="codeStr"></param>
        /// <param name="gameMm"></param>
        /// <returns>True if the code is valid</returns>
        public bool CheckValid(string codeStr, GameMm gameMm)
        {
            // check if code has obliged nmb of characters
            if (codeStr.Length != gameMm.Pos)
            {
                return(false);
            }

            // check if only vaild characters are used
            byte[] asciiBytes = Encoding.ASCII.GetBytes(codeStr);
            if (asciiBytes.Min() < (int)gameMm.FirstChr || asciiBytes.Max() > (int)gameMm.FirstChr + gameMm.Chr - 1)
            {
                return(false);
            }
            // code is valid, return true
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generate a random valid code
        /// </summary>
        /// <param name="gameMm"></param>
        /// <returns>a random valid code</returns>
        public string GenCode(GameMm gameMm)
        {
            // get an instance of a random object
            Random rd = new Random();
            // init CodeStr as empty
            string CodeStr = string.Empty;

            // generate the random valid code
            for (int i = 0; i < gameMm.Pos; i++)
            {
                // random next character
                int rand_num = rd.Next((int)gameMm.FirstChr, (int)gameMm.FirstChr + gameMm.Chr);
                // add to the code sofar
                CodeStr += (char)rand_num;
            }
            // return the valid secret code
            return(CodeStr);
        }