Ejemplo n.º 1
0
        private int AddFields(Model.FieldPosition position, Model.FieldPosition newPosition, string axis)
        {
            int numberOfMovements = 0;
            int valueA;

            for (valueA = end + change; AXORB(valueA, begin); valueA += change)
            {
                ChangePosition(ref position, valueA, axis);
                ChangePosition(ref newPosition, valueA - change, axis);

                if (!gameModel.HaveFieldsSameValue(position, newPosition))
                {
                    continue;
                }
                else if (gameModel.IsFieldEmpty(position) || gameModel.IsFieldEmpty(newPosition))
                {
                    continue;
                }
                else if (gameModel.HaveFieldsSameValue(position, newPosition))
                {
                    if (change < 0)
                    {
                        MoveFieldToNonEmptyField(newPosition, position);
                    }
                    else
                    {
                        MoveFieldToNonEmptyField(position, newPosition);
                    }
                }
            }
            return(numberOfMovements);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method sets the value of the random field
        /// </summary>
        private void SetValueOfRandomField()
        {
            try
            {
                Model.FieldPosition position = Model.EmptyFieldPositionFactory.GetRandomEmptyFieldPosition();

                gameModel.UpdateFieldToRandomValue(position, Model.FieldValue.first);
            }
            catch (NoFreeFieldException)
            {
            }
        }
Ejemplo n.º 3
0
 private void ChangePosition(ref Model.FieldPosition position, int value, String axis)
 {
     if (axis.Equals("x"))
     {
         position.x = value;
     }
     else if (axis.Equals("y"))
     {
         position.y = value;
     }
     else if (axis.Equals("z"))
     {
         position.z = value;
     }
 }
Ejemplo n.º 4
0
        private int ZAxisMovement(Model.FieldPosition position)
        {
            int numberOfMovements = 0;

            Model.FieldPosition newPosition = new Model.FieldPosition();
            newPosition.SetFieldPosition(position);

            numberOfMovements += MoveFields(position, newPosition, "z");
            newPosition.SetFieldPosition(position);

            numberOfMovements += AddFields(position, newPosition, "z");
            newPosition.SetFieldPosition(position);

            numberOfMovements += MoveFields(position, newPosition, "z");
            newPosition.SetFieldPosition(position);

            return(numberOfMovements);
        }
Ejemplo n.º 5
0
        private void MoveDown()
        {
            int numberOfMovements = 0;

            Model.FieldPosition pos = new Model.FieldPosition();
            for (pos.z = 0; pos.z < gameModel.numberOfLayers; pos.z++)
            {
                for (pos.x = 0; pos.x < gameModel.boardSize; pos.x++)
                {
                    pos.y = 0;

                    begin  = 0;
                    end    = gameModel.boardSize - 1;
                    change = -1;

                    numberOfMovements += YAxisMovement(pos);
                }
            }
            AfterMoveCheck(numberOfMovements);
        }
Ejemplo n.º 6
0
        private int MoveFields(Model.FieldPosition position, Model.FieldPosition newPosition, String axis)
        {
            int numberOfMovements = 0;
            int valueA;
            int valueB;

            for (valueA = end + change; AXORB(valueA, begin); valueA += change)
            {
                ChangePosition(ref position, valueA, axis);

                if (gameModel.IsFieldEmpty(position))
                {
                    continue;
                }

                for (valueB = valueA - change; AXORB(valueB, end); valueB -= change)
                {
                    ChangePosition(ref newPosition, valueB, axis);

                    if (gameModel.IsFieldNonEmpty(newPosition))
                    {
                        valueB += change;
                        ChangePosition(ref newPosition, valueB, axis);
                        break;
                    }

                    if (valueB == end)
                    {
                        break;
                    }
                }

                if (!position.Equals(newPosition))
                {
                    MoveFieldToEmptyField(position, newPosition);
                    numberOfMovements += 1;
                }
            }
            return(numberOfMovements);
        }
Ejemplo n.º 7
0
        private void MoveBottom()
        {
            if (numberOfLayers == 1)
            {
                return;
            }
            int numberOfMovements = 0;

            Model.FieldPosition pos = new Model.FieldPosition();
            for (pos.x = 0; pos.x < gameModel.boardSize; pos.x++)
            {
                for (pos.y = 0; pos.y < gameModel.boardSize; pos.y++)
                {
                    pos.z = 0;

                    begin  = 0;
                    end    = gameModel.numberOfLayers - 1;
                    change = -1;

                    numberOfMovements += ZAxisMovement(pos);
                }
            }
            AfterMoveCheck(numberOfMovements);
        }
Ejemplo n.º 8
0
        private void MoveFieldToNonEmptyField(Model.FieldPosition from, Model.FieldPosition to)
        {
            AddPoints(to);

            gameModel.MoveFieldToNonEmptyField(from, to);
        }
Ejemplo n.º 9
0
 private void MoveFieldToEmptyField(Model.FieldPosition from, Model.FieldPosition to)
 {
     gameModel.MoveFieldToEmptyField(from, to);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Method sets field value to empty
 /// </summary>
 /// <param name="position"></param>
 private void EmptifyField(FieldPosition position)
 {
     fields[position.z][position.x, position.y] = GameBoardModel.emptyField;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Method removes specified field from list of empty fields
 /// </summary>
 /// <param name="position"></param>
 private void RemoveFieldPositionFromListOfEmptyFields(FieldPosition position)
 {
     RemoveFieldPositionFromListOfEmptyFields(position.z, position.x, position.y);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Method adds specified field to list of empty fields
 /// </summary>
 /// <param name="position"></param>
 private void AddFieldPositionToListOfEmptyFields(FieldPosition position)
 {
     AddFieldPositionToListOfEmptyFields(position.z, position.x, position.y);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Method returns field value
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public FieldValue GetValue(FieldPosition position)
 {
     return(fields[position.z][position.x, position.y]);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Method checks if field is empty
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public bool IsFieldEmpty(FieldPosition position)
 {
     return(!IsFieldNonEmpty(position));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Method checks if field is not empty
 /// </summary>
 /// <param name="position"></param>
 /// <returns></returns>
 public bool IsFieldNonEmpty(FieldPosition position)
 {
     return(fields[position.z][position.x, position.y] > GameBoardModel.emptyField);
 }
Ejemplo n.º 16
0
 private void AddPoints(Model.FieldPosition position)
 {
     gameStatistic.AddPoints((int)gameModel.GetValue(position) * 2);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Method adds specified value on specified position
 /// </summary>
 /// <param name="position"></param>
 /// <param name="fieldValue"></param>
 public void UpdateFieldToRandomValue(FieldPosition position, FieldValue fieldValue)
 {
     fields[position.z][position.x, position.y] = fieldValue;
 }