示例#1
0
        public void SetAttempt(RowElements rowElements)
        {
            ValidateRowElements(rowElements);

            rowElements.Result = GetResultAttempt(rowElements);
            _listAttempts.Add(rowElements);
        }
示例#2
0
        //private void DrawRowElementsEmpty()
        //{
        //    DrawRowElementsEmpty(false);
        //}

        private void DrawRowElementsEmpty(bool withQuestion)
        {
            RowElements row = new RowElements();

            row.SetQuestion = withQuestion;
            for (int i = 0; i < this.NumElementPerRow; i++)
            {
                row.AddElement(new ColorElement(ColorElement.eColor._EMPTY));
            }
            Console.WriteLine(row.ToString());
        }
示例#3
0
        private void DrawRowElements(RowElements row, bool drawResult)
        {
            string strDraw = row.ToString();

            if (drawResult)
            {
                strDraw += " => " + row.Result;
            }

            Console.WriteLine(strDraw);
        }
示例#4
0
        /// <summary>
        /// Obtiene una cadena indicando con una 'X' cada acierto de color y posición, y con un '*' cada acierto en otra posición.
        /// </summary>
        /// <param name="rowElements"></param>
        /// <returns></returns>
        public string GetResultAttempt(RowElements rowElements)
        {
            string result = "";

            // Comprobar coincidencia en misma posición.
            result += GetStringResultEqualPosition(rowElements);

            // Comprobar coincidencia en distinta posición.
            result += GetStringResultDistinctPosition(rowElements);

            return(result);
        }
示例#5
0
        private void ValidateRowElements(RowElements rowElements)
        {
            if (rowElements.GetElements().Count != this.NumElementPerRow)
            {
                throw new ArgumentException("El objeto no tiene " + this.NumElementPerRow + " elementos.");
            }

            if (_listAttempts.Count == NumMaxAttempts)
            {
                throw new WarningException("La lista tiene el máximo de intentos (" + NumMaxAttempts + ").");
            }
        }
示例#6
0
 public void GenerateCodeSecret()
 {
     this._rowCodeSecret = new RowElements();
     while (this._rowCodeSecret.GetElements().Count < this.NumElementPerRow)
     {
         ColorElement c = ColorElement.GetElementRandom();
         if (!this._rowCodeSecret.ContainsElement(c))
         {
             this._rowCodeSecret.AddElement(c);
         }
     }
 }
示例#7
0
        private string GetStringResultEqualPosition(RowElements rowElements)
        {
            string       result = "";
            ColorElement cp; // Parameter
            ColorElement cs; // Secret

            for (int i = 0; i < rowElements.GetElements().Count; i++)
            {
                cp = rowElements.GetElements()[i];    // Parameter
                cs = _rowCodeSecret.GetElements()[i]; // Secret

                if (cp.Equals(cs))
                {
                    // Si hay coincidencia de posición.
                    result += OK_POS;
                }
            }
            return(result);
        }
示例#8
0
 private void DrawBody()
 {
     for (int i = NumMaxAttempts; i > 0; i--)
     {
         if (i > this._listAttempts.Count)
         {
             DrawRowElementsEmpty(false);
         }
         else
         {
             for (int j = _listAttempts.Count; j > 0; j--)
             {
                 RowElements row = _listAttempts[j - 1];
                 DrawRowElements(row, true);
             }
             break;
         }
     }
 }
示例#9
0
        private string GetStringResultDistinctPosition(RowElements rowElements)
        {
            string       result = "";
            ColorElement cp; // Parameter
            ColorElement cs; // Secret

            for (int i = 0; i < rowElements.GetElements().Count; i++)
            {
                for (int j = 0; j < _rowCodeSecret.GetElements().Count; j++)
                {
                    if (i != j)
                    {
                        cs = _rowCodeSecret.GetElements()[i]; // Secret
                        cp = rowElements.GetElements()[j];    // Parameter
                        if (cs.Equals(cp))
                        {
                            // Si hay coincidencia en otra posición posición.
                            result += OK_OPOS;
                        }
                    }
                }
            }
            return(result);
        }
示例#10
0
 public void SetCodeSecret(RowElements newRowElements)
 {
     _rowCodeSecret = newRowElements;
 }
示例#11
0
 private void DrawRowElements(RowElements row)
 {
     DrawRowElements(row, false);
 }