public void SetAttempt(RowElements rowElements) { ValidateRowElements(rowElements); rowElements.Result = GetResultAttempt(rowElements); _listAttempts.Add(rowElements); }
//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()); }
private void DrawRowElements(RowElements row, bool drawResult) { string strDraw = row.ToString(); if (drawResult) { strDraw += " => " + row.Result; } Console.WriteLine(strDraw); }
/// <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); }
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 + ")."); } }
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); } } }
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); }
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; } } }
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); }
public void SetCodeSecret(RowElements newRowElements) { _rowCodeSecret = newRowElements; }
private void DrawRowElements(RowElements row) { DrawRowElements(row, false); }