Exemplo n.º 1
0
        /// <summary>
        /// Method converts splitted string to highest field value and field values
        /// </summary>
        /// <param name="highestValue"></param>
        /// <param name="gameBoardModel"></param>
        public void ImportGameBoardModelFromString(string highestValue, string gameBoardModel)
        {
            this.highestValue = (FieldValue)Math.Pow(2, TranslateData.TranslateCharToNumber(highestValue[0]));
            int fieldValue = 0;

            EmptyFieldsPosition emptyFieldsPositions = EmptyFieldsPosition.Instance;

            emptyFieldsPositions.ClearListOfEmptyFields();

            for (int z = 0; z < numberOfLayers; z++)
            {
                for (int x = 0; x < boardSize; x++)
                {
                    for (int y = 0; y < boardSize; y++)
                    {
                        fieldValue = (int)Math.Pow(2, TranslateData.TranslateCharToNumber(
                                                       gameBoardModel[z * boardSize * boardSize + x * boardSize + y]));
                        if (fieldValue > 1)
                        {
                            this.fields[z][x, y] = (FieldValue)fieldValue;
                        }
                        else
                        {
                            this.fields[z][x, y] = FieldValue.empty;
                            emptyFieldsPositions.AddEmptyFieldToList(z, x, y);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Method converts splitted string to game settings
 /// </summary>
 /// <param name="boardSize"></param>
 /// <param name="numberOfLayers"></param>
 /// <param name="numberOfFieldsToAdd"></param>
 /// <param name="targetFieldValue"></param>
 /// <param name="continuousGame"></param>
 public void ImportSettingsFromString(string boardSize, string numberOfLayers,
                                      string numberOfFieldsToAdd,
                                      string targetFieldValue,
                                      string continuousGame)
 {
     this.boardSize             = TranslateData.TranslateCharToNumber(boardSize[0]);
     this.numberOfLayers        = TranslateData.TranslateCharToNumber(numberOfLayers[0]);
     this.numberOfFieldsToAdd   = TranslateData.TranslateCharToNumber(numberOfFieldsToAdd[0]);
     this.targetValueOfTheField = (FieldValue)Math.Pow(2, TranslateData.TranslateCharToNumber(targetFieldValue[0]));
     if (TranslateData.TranslateCharToNumber(continuousGame[0]) == 0)
     {
         this.ifTheGameIsOver = false;
     }
     else
     {
         this.ifTheGameIsOver = true;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Method converts game settings to string.
        /// </summary>
        /// <returns>string</returns>
        public String ExportSettingsToString()
        {
            String result = "";

            result += TranslateData.TrasnlateNumberToChar(boardSize) + ".";
            result += TranslateData.TrasnlateNumberToChar(numberOfLayers) + ".";
            result += TranslateData.TrasnlateNumberToChar(numberOfFieldsToAdd) + ".";
            result += TranslateData.TrasnlateNumberToChar((int)Math.Log((int)targetValueOfTheField, 2)) + ".";

            if (ifTheGameIsOver == false)
            {
                result += TranslateData.TrasnlateNumberToChar(0) + ".";
            }
            else
            {
                result += TranslateData.TrasnlateNumberToChar(1) + ".";
            }
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method converts field values and highest field value to string
        /// </summary>
        /// <returns></returns>
        public String ExportGameBoardModelToString()
        {
            String result = "";

            result += TranslateData.TrasnlateNumberToChar((int)Math.Log((int)highestValue, 2)) + ".";

            for (int z = 0; z < numberOfLayers; z++)
            {
                for (int x = 0; x < boardSize; x++)
                {
                    for (int y = 0; y < boardSize; y++)
                    {
                        result += TranslateData.TrasnlateNumberToChar((int)Math.Log((int)fields[z][x, y], 2));
                    }
                }
            }
            result += ".";
            return(result);
        }