internal Cell GetRandomNeigborCell(Cell cell, eDirections excludeDir)
    {
        List <eDirections> newDirs = new List <eDirections>();

        eDirections[] dirs = Utilities.GetDirectionsArray();
        for (int i = 0; i < dirs.Length; i++)
        {
            if (dirs[i] == excludeDir)
            {
                continue;
            }
            if (dirs[i] == Utilities.GetOppositeDirection(excludeDir))
            {
                continue;
            }

            Cell ncell = GetNextCell(cell, dirs[i]);
            if (ncell == null)
            {
                continue;
            }

            Item item = ncell.Item;
            if (item != null && (item is Snake.SnakeBody || item is Bullet))
            {
                continue;
            }

            newDirs.Add(dirs[i]);
        }

        Cell result = GetRandomCell(cell, newDirs);

        return(result);
    }
    internal static Vector3 ConvertDirection(eDirections dir)
    {
        switch (dir)
        {
        case eDirections.BACKWARD:
            return(new Vector3(0f, 0f, -1f));

        case eDirections.FORWARD:
            return(new Vector3(0f, 0f, 1f));

        case eDirections.UP:
            return(new Vector3(0f, 1f, 0f));

        case eDirections.DOWN:
            return(new Vector3(0f, -1f, 0f));

        case eDirections.RIGHT:
            return(new Vector3(1f, 0f, 0f));

        case eDirections.LEFT:
            return(new Vector3(-1f, 0f, 0f));
        }

        return(Vector3.forward);
    }
    internal static eDirections GetOppositeDirection(eDirections excludeDir)
    {
        switch (excludeDir)
        {
        case eDirections.FORWARD:
            return(eDirections.BACKWARD);

        case eDirections.BACKWARD:
            return(eDirections.FORWARD);

        case eDirections.UP:
            return(eDirections.DOWN);

        case eDirections.DOWN:
            return(eDirections.UP);

        case eDirections.RIGHT:
            return(eDirections.LEFT);

        case eDirections.LEFT:
            return(eDirections.RIGHT);
        }

        return(eDirections.BACKWARD);
    }
Example #4
0
    static string dirToStr(eDirections dir)
    {
        switch (dir)
        {
        case eDirections.NORTH:
            return("NORTH");

        case eDirections.NORTH_EAST:
            return("NORTH_EAST");

        case eDirections.EAST:
            return("EAST");

        case eDirections.SOUTH_EAST:
            return("SOUTH_EAST");

        case eDirections.SOUTH:
            return("SOUTH");

        case eDirections.SOUTH_WEST:
            return("SOUTH_WEST");

        case eDirections.WEST:
            return("WEST");

        case eDirections.NORTH_WEST:
            return("NORTH_WEST");
        }

        return("NONE");
    }
Example #5
0
    private bool goalIsInGeneralDirection(Point curr, eDirections dir, Point goal)
    {
        int diff_column = goal.column - curr.column;
        int diff_row    = goal.row - curr.row;

        // note: north would be DECREASING in row, not increasing. Rows grow positive while going south!
        switch (dir)
        {
        case eDirections.NORTH:
            return(diff_row < 0 && diff_column == 0);

        case eDirections.NORTH_EAST:
            return(diff_row < 0 && diff_column > 0);

        case eDirections.EAST:
            return(diff_row == 0 && diff_column > 0);

        case eDirections.SOUTH_EAST:
            return(diff_row > 0 && diff_column > 0);

        case eDirections.SOUTH:
            return(diff_row > 0 && diff_column == 0);

        case eDirections.SOUTH_WEST:
            return(diff_row > 0 && diff_column < 0);

        case eDirections.WEST:
            return(diff_row == 0 && diff_column < 0);

        case eDirections.NORTH_WEST:
            return(diff_row < 0 && diff_column < 0);
        }

        return(false);
    }
Example #6
0
        private Point CalculateCellsToChange(Point i_Point, eDirections i_Rule)
        {
            switch (i_Rule)
            {
            case eDirections.UpperLeftDiagonal:
            {
                i_Point.AxisXValue -= 1;
                i_Point.AxisYValue -= 1;
                break;
            }

            case eDirections.UpperRow:
            {
                i_Point.AxisXValue -= 1;
                break;
            }

            case eDirections.UpperRightDiagonal:
            {
                i_Point.AxisXValue -= 1;
                i_Point.AxisYValue += 1;
                break;
            }

            case eDirections.RightColoum:
            {
                i_Point.AxisYValue += 1;
                break;
            }

            case eDirections.DownRightDiagonal:
            {
                i_Point.AxisYValue += 1;
                i_Point.AxisXValue += 1;
                break;
            }

            case eDirections.DownRow:
            {
                i_Point.AxisXValue += 1;
                break;
            }

            case eDirections.DownLeftDiagonal:
            {
                i_Point.AxisXValue += 1;
                i_Point.AxisYValue -= 1;
                break;
            }

            case eDirections.LeftColoumn:
            {
                i_Point.AxisYValue -= 1;
                break;
            }
            }

            return(i_Point);
        }
Example #7
0
        private Point RecoverPreviousPointValue(Point i_Point, eDirections i_Rule)
        {
            switch (i_Rule)
            {
            case eDirections.UpperLeftDiagonal:
            {
                i_Point.AxisXValue += 1;
                i_Point.AxisYValue += 1;
                break;
            }

            case eDirections.UpperRow:
            {
                i_Point.AxisXValue += 1;
                break;
            }

            case eDirections.UpperRightDiagonal:
            {
                i_Point.AxisXValue += 1;
                i_Point.AxisYValue -= 1;
                break;
            }

            case eDirections.RightColoum:
            {
                i_Point.AxisYValue -= 1;
                break;
            }

            case eDirections.DownRightDiagonal:
            {
                i_Point.AxisYValue -= 1;
                i_Point.AxisXValue -= 1;
                break;
            }

            case eDirections.DownRow:
            {
                i_Point.AxisXValue -= 1;
                break;
            }

            case eDirections.DownLeftDiagonal:
            {
                i_Point.AxisXValue -= 1;
                i_Point.AxisYValue += 1;
                break;
            }

            case eDirections.LeftColoumn:
            {
                i_Point.AxisYValue += 1;
                break;
            }
            }

            return(i_Point);
        }
Example #8
0
    private bool isJumpPoint(int row, int column, eDirections dir)
    {
        if (isInBounds(row, column))
        {
            Node node = gridNodes[column + (row * rowSize)];
            return(node.isJumpPoint && node.jumpPointDirection[(int)dir]);
        }

        return(false);         // If we are out of bounds, then we are def a wall
    }
Example #9
0
    // Returns Grid Index of node in the given direction
    // Returns -1 if index is out of bounds
    private int getIndexOfNodeTowardsDirection(int index, eDirections direction)
    {
        int row, column;

        row    = index / rowSize;
        column = index % rowSize;

        int change_row    = 0;
        int change_column = 0;

        // Change in the Row Direction
        switch (direction)
        {
        case eDirections.NORTH_EAST:
        case eDirections.NORTH:
        case eDirections.NORTH_WEST:
            change_row = -1;
            break;

        case eDirections.SOUTH_EAST:
        case eDirections.SOUTH:
        case eDirections.SOUTH_WEST:
            change_row = 1;
            break;
        }

        // Change in the Column Direction
        switch (direction)
        {
        case eDirections.NORTH_EAST:
        case eDirections.EAST:
        case eDirections.SOUTH_EAST:
            change_column = 1;
            break;

        case eDirections.SOUTH_WEST:
        case eDirections.WEST:
        case eDirections.NORTH_WEST:
            change_column = -1;
            break;
        }

        // Calc new rows and columns
        int new_row    = row + change_row;
        int new_column = column + change_column;

        // Check bounds
        if (isInBounds(new_row, new_column))
        {
            return(new_column + (new_row * rowSize));
        }

        return(-1);           // Out of bounds is -1
    }
Example #10
0
    private eDirections TryChangeDirection(eDirections dir)
    {
        float rnd = URandom.value;

        if (rnd < 0.2f)
        {
            dir = Utilities.GetRandomDirection(dir);
        }

        return(dir);
    }
Example #11
0
    internal static eDirections GetRandomDirection(eDirections excludeDir)
    {
        List <eDirections> dirs = GetDirectionsList();

        dirs.Remove(excludeDir);
        dirs.Remove(GetOppositeDirection(excludeDir));

        int rnd = URandom.Range(0, dirs.Count);

        return(dirs[rnd]);
    }
Example #12
0
    internal void Fire(FieldController.Cell cell, eDirections dir)
    {
        //Debug.Log("Fire!");

        m_timeCurrent   = 0f;
        IsFireAvailable = false;

        m_bullet = new Bullet(m_color)
        {
            Cell = cell, Direction = dir
        };
    }
    // ======================================================================================
    // PUBLIC MEMBERS
    // ======================================================================================
    public void Awake()
    {
        if (m_animator == null)
        {
            m_animator = this.GetComponent <Animator>();
        }

        Debug.Assert(m_animator != null, this.gameObject.name + " - PlayerAnimatorController : MISSING ANIMATOR!");

        m_transform = this.transform;
        m_currDir   = eDirections.Right;
    }
Example #14
0
    /// <summary>
    /// Get the Node, starting at the given position, in the given direction, at the given distance away.
    /// </summary>
    private PathfindingNode getNodeDist(int row, int column, eDirections direction, int dist)
    {
        PathfindingNode new_node = null;
        int             new_row = row, new_column = column;

        switch (direction)
        {
        case eDirections.NORTH:
            new_row -= dist;
            break;

        case eDirections.NORTH_EAST:
            new_row    -= dist;
            new_column += dist;
            break;

        case eDirections.EAST:
            new_column += dist;
            break;

        case eDirections.SOUTH_EAST:
            new_row    += dist;
            new_column += dist;
            break;

        case eDirections.SOUTH:
            new_row += dist;
            break;

        case eDirections.SOUTH_WEST:
            new_row    += dist;
            new_column -= dist;
            break;

        case eDirections.WEST:
            new_column -= dist;
            break;

        case eDirections.NORTH_WEST:
            new_row    -= dist;
            new_column -= dist;
            break;
        }

        // w/ the new coordinates, get the node
        if (isInBounds(new_row, new_column))
        {
            new_node = this.pathfindingNodes[this.rowColumnToIndex(new_row, new_column)];
        }

        return(new_node);
    }
Example #15
0
    private bool isCardinal(eDirections dir)
    {
        switch (dir)
        {
        case eDirections.SOUTH:
        case eDirections.EAST:
        case eDirections.NORTH:
        case eDirections.WEST:
            return(true);
        }

        return(false);
    }
Example #16
0
    private bool isDiagonal(eDirections dir)
    {
        switch (dir)
        {
        case eDirections.SOUTH_EAST:
        case eDirections.SOUTH_WEST:
        case eDirections.NORTH_EAST:
        case eDirections.NORTH_WEST:
            return(true);
        }

        return(false);
    }
    internal Cell GetNextCell(Cell cell, eDirections dir)
    {
        switch (dir)
        {
        case eDirections.RIGHT:
            if (cell.FieldPosition[0] + 1 < FIELD_SIZE)
            {
                return(m_field[cell.FieldPosition[0] + 1, cell.FieldPosition[1], cell.FieldPosition[2]]);
            }
            break;

        case eDirections.LEFT:

            if (cell.FieldPosition[0] > 0)
            {
                return(m_field[cell.FieldPosition[0] - 1, cell.FieldPosition[1], cell.FieldPosition[2]]);
            }
            break;

        case eDirections.UP:

            if (cell.FieldPosition[1] + 1 < FIELD_SIZE)
            {
                return(m_field[cell.FieldPosition[0], cell.FieldPosition[1] + 1, cell.FieldPosition[2]]);
            }
            break;

        case eDirections.DOWN:
            if (cell.FieldPosition[1] > 0)
            {
                return(m_field[cell.FieldPosition[0], cell.FieldPosition[1] - 1, cell.FieldPosition[2]]);
            }
            break;

        case eDirections.FORWARD:
            if (cell.FieldPosition[2] + 1 < FIELD_SIZE)
            {
                return(m_field[cell.FieldPosition[0], cell.FieldPosition[1], cell.FieldPosition[2] + 1]);
            }
            break;

        case eDirections.BACKWARD:
            if (cell.FieldPosition[2] > 0)
            {
                return(m_field[cell.FieldPosition[0], cell.FieldPosition[1], cell.FieldPosition[2] - 1]);
            }
            break;
        }

        return(null);
    }
    // ======================================================================================
    public void SetDirection(eDirections _direction)
    {
        // TODO : Create Blend Trees for != directions
        switch (_direction)
        {
        case eDirections.Left:
            m_transform.localScale = new Vector3(-1, 1, 1);
            break;

        case eDirections.Right:
            m_transform.localScale = new Vector3(1, 1, 1);
            break;
        }
    }
    private Cell GetRandomCell(Cell cell, List <eDirections> dirs)
    {
        Cell result = null;

        if (dirs.Count > 0)
        {
            int         rnd = URandom.Range(0, dirs.Count);
            eDirections dir = dirs[rnd];

            result = GetNextCell(cell, dir);
        }

        return(result);
    }
Example #20
0
    private FieldController.Cell GetNextCell(FieldController.Cell cell, eDirections dir)
    {
        FieldController.Cell result = m_field.GetNextCell(cell, dir);
        if (result == null)
        {
            //Debug.Log("Cell is null!");
            result = m_field.GetRandomNeigborCell(cell, dir);
            if (result == null)
            {
                //no more empty cells
                //Debug.LogError("Cell is null!");
            }
        }

        return(result);
    }
Example #21
0
        private bool UpdateBoard(Player i_Player, Point i_Point, eDirections i_Rule, eOnlyCheck i_Mode)
        {
            Point copyPoint            = new Point(i_Point.AxisXValue, i_Point.AxisYValue);
            char  washerAgainstPlayer  = GetAgainstCurrentPlayerSign(i_Player);
            int   amountOppositeWasher = 0;
            bool  moveResult           = false;

            while (copyPoint > m_StartRange && copyPoint < m_EndRange)
            {
                copyPoint = CalculateCellsToChange(copyPoint, i_Rule);
                if (m_Board.GetCellOnBoard(copyPoint).SignValue == washerAgainstPlayer)
                {
                    amountOppositeWasher++;
                }
                else if (amountOppositeWasher > 0 && m_Board.GetCellOnBoard(copyPoint).SignValue == i_Player.PlayerWasher)
                {
                    amountOppositeWasher++;
                    moveResult = true;
                    break;
                }
                else
                {
                    break;
                }
            }

            if (moveResult && i_Mode == eOnlyCheck.No)
            {
                for (int i = 0; i < amountOppositeWasher; i++)
                {
                    copyPoint = RecoverPreviousPointValue(copyPoint, i_Rule);
                    m_Board.UpdateSignCellOnBoardByPoint(i_Player.PlayerWasher, copyPoint);
                    onUpdateCellSignValue(i_Player.PlayerWasher, copyPoint);
                }
            }
            else if (moveResult && i_Mode == eOnlyCheck.Yes)
            {
                for (int i = 0; i < amountOppositeWasher; i++)
                {
                    copyPoint = RecoverPreviousPointValue(copyPoint, i_Rule);
                }

                onUpdateLegalCell(copyPoint);
            }

            return(moveResult);
        }
Example #22
0
    private void TryKillAlienSnake()
    {
        SnakeBody   head = m_bodies[0];
        eDirections dir  = head.Direction;

        if (m_field.IsAlienStraightAhead(head.Cell, dir, Idx))
        {
            if (m_snakeFire != null && m_snakeFire.IsFireAvailable)
            {
                FieldController.Cell nextcell = m_field.GetNextCell(head.Cell, dir);
                if (nextcell != null)
                {
                    m_snakeFire.Fire(nextcell, dir);
                }
            }
        }
    }
    internal Cell GetRandomNeigborCell(Cell cell)
    {
        List <eDirections> dirs = Utilities.GetDirectionsList();

        Cell ncell = null;

        while (ncell == null && dirs.Count > 0)
        {
            int         rnd = URandom.Range(0, dirs.Count);
            eDirections dir = dirs[rnd];

            ncell = GetNextCell(cell, dir);

            dirs.Remove(dir);
        }

        return(ncell);
    }
Example #24
0
    private void TryCatchFood()
    {
        if (m_targetFoodCell != null)
        {
            return;
        }

        SnakeBody   head  = m_bodies[0];
        eDirections exDir = Utilities.GetOppositeDirection(head.Direction);

        Tuple <FieldController.Cell, eDirections> target = m_field.GetFoodCellDirection(head.Cell, exDir);

        if (target != null && target.Item1 != null)
        {
            m_targetFoodCell = target.Item1;
            head.Direction   = target.Item2;
        }
    }
Example #25
0
    private void CreateSnake()
    {
        FieldController.Cell cell = null;
        for (int i = 0; i < SIZE_MIN; i++)
        {
            SnakeBody body = new SnakeBody(this, string.Format(m_nameTemplate, Idx, i));
            if (i == 0)
            {
                cell = m_field.GetRandomCell();
                if (cell == null)
                {
                    Debug.LogError("Snake Error!");
                    continue;
                }

                body.Cell = cell;

                //set direction
                body.Direction = Utilities.GetRandomDirection();
            }
            else
            {
                eDirections dir     = m_bodies[i - 1].Direction;
                eDirections nextDir = Utilities.GetOppositeDirection(dir);

                FieldController.Cell bcell = m_field.GetNextCell(cell, nextDir);
                if (bcell == null)
                {
                    //need other cell
                    Debug.LogWarning("Snake Error!");

                    bcell = m_field.GetRandomNeigborCell(cell, nextDir);
                }

                body.Cell      = bcell;
                body.Direction = Utilities.GetNextCellDirection(bcell.FieldPosition, cell.FieldPosition);

                cell = body.Cell;
            }

            m_bodies.Add(body);
        }
    }
 // ======================================================================================
 public void SetDirection(eDirections _direction)
 {
     // TODO : Create Blend Trees for != directions
     //switch(_direction)
     //{
     //    case eDirections.Left:
     //        m_transform.localScale = new Vector3(-1, 1, 1);
     //        break;
     //    case eDirections.Right:
     //        m_transform.localScale = new Vector3(1, 1, 1);
     //        break;
     //}
     if (m_currDir != _direction)
     {
         Vector3 scale = m_transform.localScale;
         scale.x *= -1;
         m_transform.localScale = scale;
         m_currDir = _direction;
     }
 }
Example #27
0
    void AddSection()
    {
        SnakeBody   body = new SnakeBody(this, string.Format(m_nameTemplate, Idx, m_bodies.Count - 1));
        SnakeBody   last = m_bodies[m_bodies.Count - 1];
        eDirections dir  = last.Direction;

        FieldController.Cell bcell = m_field.GetNextCell(last.Cell, Utilities.GetOppositeDirection(dir));
        if (bcell == null)
        {
            //need other cell
            Debug.LogWarning("Snake Error!");

            bcell = m_field.GetRandomNeigborCell(last.Cell, dir);
        }

        body.Cell      = bcell;
        body.Direction = dir;

        m_bodies.Add(body);

        SetColor();
    }
Example #28
0
        /// <summary>
        /// Makes ProfileTopic priority higher or lower depending on the chosen direction
        /// </summary>
        /// <param name="id">id identifying ProfileTopic's priority to be changed</param>
        /// <param name="direction">direction in which selected topic is going to move in the list of topics
        /// up: alter current topic priority to lower
        /// down: alter current topic priority to higher
        /// </param>
        public static void ChangeOrder(int id, eDirections direction)
        {
            string direction_ = "";
            switch (direction)
            {
                case eDirections.Up:
                    direction_ = "up";
                    break;
                case eDirections.Down:
                    direction_ = "down";
                    break;
            }

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlHelper.ExecuteNonQuery(conn, "ChangeProfileTopicOrder", id, direction_);
            }

            if (HttpContext.Current != null)
            {
                string cacheKey = "ProfileTopic_Fetch";
                if (HttpContext.Current.Cache[cacheKey] != null)
                    HttpContext.Current.Cache.Remove(cacheKey);
                if (id > 0)
                {
                    cacheKey = String.Format("ProfileTopic_Fetch_{0}", id);
                    if (HttpContext.Current.Cache[cacheKey] != null)
                        HttpContext.Current.Cache.Remove(cacheKey);
                }
            }
        }
Example #29
0
        /// <summary>
        /// Makes ProfileQuestion priority higher or lower depending on the chosen direction
        /// </summary>
        /// <param name="topicID"></param>
        /// <param name="questionID">id identifying ProfileQuestion's priority to be changed</param>
        /// <param name="direction">direction in which selected question is going to move in the list of topics
        /// up: alter current question priority to lower
        /// down: alter current question priority to higher
        /// </param>
        public static void ChangeOrder(int topicID, int questionID, eDirections direction)
        {
            string direction_ = "";
            switch (direction)
            {
                case eDirections.Up:
                    direction_ = "up";
                    break;
                case eDirections.Down:
                    direction_ = "down";
                    break;
            }

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlHelper.ExecuteNonQuery(conn, "ChangeProfileQuestionOrder", topicID, questionID, direction_);
            }

            if (HttpContext.Current != null)
            {
                string cacheKey = String.Format("ProfileQuestion_FetchByTopicID_{0}", topicID);
                if (HttpContext.Current.Cache[cacheKey] != null)
                    HttpContext.Current.Cache.Remove(cacheKey);
                cacheKey = String.Format("ProfileQuestion_SloganQuestionID");
                if (HttpContext.Current.Cache[cacheKey] != null)
                    HttpContext.Current.Cache.Remove(cacheKey);
                cacheKey = String.Format("ProfileQuestion_SkypeQuestionID");
                if (HttpContext.Current.Cache[cacheKey] != null)
                    HttpContext.Current.Cache.Remove(cacheKey);
                cacheKey = String.Format("ProfileQuestion_Fetch");
                if (HttpContext.Current.Cache[cacheKey] != null)
                    HttpContext.Current.Cache.Remove(cacheKey);

                if (questionID > 0)
                {
                    cacheKey = String.Format("ProfileQuestion_Fetch_{0}", questionID);
                    if (HttpContext.Current.Cache[cacheKey] != null)
                        HttpContext.Current.Cache.Remove(cacheKey);
                }
            }
        }
Example #30
0
        private static void updatePossibleMovesArray(LinkedList <MoveOption> i_MoveOptions, Point currentPoint, eDirections i_UpOrDown, eDirections i_LeftOrRight, ePossibleDirections i_OptionalDiractions, char i_OpponentCoin)
        {
            int   numOfFlippedCoins  = 0;
            Point tempOfcurrentPoint = new Point();

            tempOfcurrentPoint = currentPoint;
            MoveOption foundOptionalMove    = new MoveOption(new Point(0, 0));
            bool       isPointInListAlready = false;

            tempOfcurrentPoint.X += (int)i_UpOrDown;
            tempOfcurrentPoint.Y += (int)i_LeftOrRight;

            while (tempOfcurrentPoint.X <= m_PlayerPositionsInDemiBoard.GetLength(0) - 1 && tempOfcurrentPoint.X >= 0 && tempOfcurrentPoint.Y >= 0 && tempOfcurrentPoint.Y <= m_PlayerPositionsInDemiBoard.GetLength(0) - 1)
            {
                if (m_PlayerPositionsInDemiBoard[tempOfcurrentPoint.X, tempOfcurrentPoint.Y] != i_OpponentCoin && m_PlayerPositionsInDemiBoard[tempOfcurrentPoint.X, tempOfcurrentPoint.Y] != 0)
                {
                    break;
                }

                if (m_PlayerPositionsInDemiBoard[tempOfcurrentPoint.X, tempOfcurrentPoint.Y] == 0)
                {
                    if (!InputManager.IsInputInListOfPossibleMoves(i_MoveOptions, tempOfcurrentPoint, ref foundOptionalMove))
                    {
                        foundOptionalMove.PossibleMove = tempOfcurrentPoint;
                        i_MoveOptions.AddFirst(foundOptionalMove);
                    }
                    else
                    {
                        isPointInListAlready = InputManager.IsInputInListOfPossibleMoves(i_MoveOptions, tempOfcurrentPoint, ref foundOptionalMove);
                    }

                    foundOptionalMove.m_WhereIsTheDamageOfTheMove[(int)i_OptionalDiractions] = numOfFlippedCoins;
                    foundOptionalMove.DamageOfMove = numOfFlippedCoins + foundOptionalMove.DamageOfMove;

                    break;
                }

                numOfFlippedCoins++;
                tempOfcurrentPoint.X += (int)i_UpOrDown;
                tempOfcurrentPoint.Y += (int)i_LeftOrRight;
            }
        }
Example #31
0
        private bool scanForAnotherDiscInDirection(eDirections i_Direction, int i_X, int i_Y, Disc.eColors i_Color)
        {
            bool IsMoveLeagle = false;

            switch (i_Direction)
            {
            case eDirections.Up:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y - j, i_X];

                while (CurrentDisc != null && i_Y - j >= 0)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_Y - j >= 0)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y - j, i_X];
                    }
                }

                break;
            }

            case eDirections.Down:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y + j, i_X];

                while (CurrentDisc != null && i_Y + j < m_Size)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_Y + j < m_Size)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y + j, i_X];
                    }
                }

                break;
            }

            case eDirections.Left:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y, i_X - j];

                while (CurrentDisc != null && i_X - j >= 0)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_X - j >= 0)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y, i_X - j];
                    }
                }

                break;
            }

            case eDirections.Right:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y, i_X + j];

                while (CurrentDisc != null && i_X + j < m_Size)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_X + j < m_Size)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y, i_X + j];
                    }
                }

                break;
            }

            case eDirections.UpLeft:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y - j, i_X - j];

                while (CurrentDisc != null && i_Y - j >= 0 && i_X - j >= 0)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_Y - j >= 0 && i_X - j >= 0)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y - j, i_X - j];
                    }
                }

                break;
            }

            case eDirections.UpRight:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y - j, i_X + j];

                while (CurrentDisc != null && i_Y - j >= 0 && i_X + j < m_Size)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_Y - j >= 0 && i_X + j < m_Size)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y - j, i_X + j];
                    }
                }

                break;
            }

            case eDirections.DownLeft:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y + j, i_X - j];

                while (CurrentDisc != null && i_Y + j < m_Size && i_X - j >= 0)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_Y + j < m_Size && i_X - j >= 0)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y + j, i_X - j];
                    }
                }

                break;
            }

            case eDirections.DownRight:
            {
                int  j           = 1;
                Disc CurrentDisc = r_BoardMatrix[i_Y + j, i_X + j];

                while (CurrentDisc != null && i_Y + j < m_Size && i_X + j < m_Size)
                {
                    if (CurrentDisc.Color == i_Color)
                    {
                        IsMoveLeagle = true;
                    }

                    j++;
                    if (i_Y + j < m_Size && i_X + j < m_Size)
                    {
                        CurrentDisc = r_BoardMatrix[i_Y + j, i_X + j];
                    }
                }

                break;
            }
            }

            return(IsMoveLeagle);
        }
Example #32
0
		/// <summary>
		/// Changes the order.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <param name="direction">The direction.</param>
		public static void ChangeOrder(int id, eDirections direction) {
	
            string direction_ = "";
			switch(direction) {
				case eDirections.Up:
					direction_ = "up";
					break;
				case eDirections.Down:
					direction_ = "down";
					break;
			}
			using(SqlConnection conn = Config.DB.Open()) {
                SqlHelper.GetDB().ExecuteNonQuery( "ChangeAskAboutQuestionOrder", id, direction_);
			}
            string cacheKey = String.Format("AskAboutQuestion_FetchAll");
			if(HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) {
				HttpContext.Current.Cache.Remove(cacheKey);
			}
		}
Example #33
0
        public static void ChangeOrder(int id, eDirections direction)
        {
            string direction_ = "";
            switch (direction)
            {
                case eDirections.Up:
                    direction_ = "up";
                    break;
                case eDirections.Down:
                    direction_ = "down";
                    break;
            }

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlHelper.GetDB().ExecuteNonQuery( "ChangeCategoryOrder", id, direction_);
            }

//            if (HttpContext.Current != null)
//            {
//                string cacheKey = "Category_Fetch";
//                if (HttpContext.Current.Cache[cacheKey] != null)
//                    HttpContext.Current.Cache.Remove(cacheKey);
//                if (id > 0)
//                {
//                    cacheKey = String.Format("Category_Fetch_{0}", id);
//                    if (HttpContext.Current.Cache[cacheKey] != null)
//                        HttpContext.Current.Cache.Remove(cacheKey);
//                }
//            }
        }
Example #34
0
		/// <summary>
		/// Changes the order.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <param name="direction">The direction.</param>
		public static void ChangeOrder(int id, eDirections direction) {

            string cacheKey = String.Format("FAQ_FetchAll_{0}", Fetch(id).CategoryId);
            //string direction_ = "";
            FAQ faq = Fetch(id);
            FAQ[] faqs = FetchAll(faq.CategoryId);
            switch (direction)
            {
				case eDirections.Down:
                    //direction_ = "down";
                    var above = faqs.ToList().Where(x => x.Order > faq.Order);
                    if (above == null || above.Count() == 0) return;
                    int nextOrder = above.Min(x => x.Order);
                    int nextId = faqs.ToList().Where(x => x.Order == nextOrder).First().Id;
                    FAQ nextFaq = Fetch(nextId);
                    nextFaq.Order = faq.Order;
                    nextFaq.SaveOrder();
                    faq.Order = nextOrder;
                    faq.SaveOrder();
					break;
				case eDirections.Up:
                    //direction_ = "up";
                    var below = faqs.ToList().Where(x => x.Order < faq.Order);
                    if (below == null || below.Count() == 0) return;
                    int prevOrder = below.Max(x => x.Order);
                    int prevId = faqs.ToList().Where(x => x.Order == prevOrder).First().Id;
                    FAQ prevFaq = Fetch(prevId);
                    prevFaq.Order = faq.Order;
                    prevFaq.SaveOrder();
                    faq.Order = prevOrder;
                    faq.SaveOrder();
					break;
			}
            ////using (var conn = Config.DB.Open()) {
            //    SqlHelper.GetDB().ExecuteNonQuery( "ChangeFAQOrder", id, Fetch(id).CategoryId, direction_);
            //}
            if(HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) {
				HttpContext.Current.Cache.Remove(cacheKey);
			}
		}
    internal Tuple <FieldController.Cell, eDirections> GetFoodCellDirection(Cell cell, eDirections excludeDir)
    {
        Tuple <FieldController.Cell, eDirections> result = null;

        List <eDirections> dirs = Utilities.GetDirectionsList();

        dirs.Remove(excludeDir);

        for (int i = 0; i < dirs.Count; i++)
        {
            Cell cellNext = cell;
            while (cellNext != null)
            {
                cellNext = GetNextCell(cellNext, dirs[i]);
                if (cellNext != null && cellNext.Item != null && cellNext.Item is Food)
                {
                    result = Tuple.Create(cellNext, dirs[i]);
                    break;
                }
            }
        }

        return(result);
    }