コード例 #1
0
ファイル: TransparentCube.cs プロジェクト: CodeXoR/ROYGBIV
 void GetAdjacentObjs(CheckDirection dir)
 {
     if (rayDir == CheckDirection.forward)
     {
         Ray rayF = new Ray(transform.position + transform.forward, transform.forward);
         Ray rayB = new Ray(transform.position + transform.forward / 2, -transform.forward);
         //Debug.DrawRay(rayF.origin, rayF.direction, Color.red);
         //Debug.DrawRay(rayB.origin, rayB.direction, Color.red);
         RaycastHit hit;
         if (Physics.Raycast(rayF, out hit, 1.0f))
         {
             TransparentCube tC = hit.transform.GetComponent <TransparentCube>();
             if (tC != null)
             {
                 adjacentObjs.Add(hit.transform.GetComponent <TransparentCube>());
             }
         }
         if (Physics.Raycast(rayB, out hit, 1.0f))
         {
             TransparentCube tC = hit.transform.GetComponent <TransparentCube>();
             if (tC != null)
             {
                 adjacentObjs.Add(hit.transform.GetComponent <TransparentCube>());
             }
         }
     }
     else
     {
         Ray rayR = new Ray(transform.position + transform.forward * .7f, transform.right);
         Ray rayL = new Ray(transform.position + transform.forward * .7f, -transform.right);
         //Debug.DrawRay(rayR.origin, rayR.direction, Color.red);
         //Debug.DrawRay(rayL.origin, rayL.direction, Color.red);
         RaycastHit hit;
         if (checkRAdjs)
         {
             if (Physics.Raycast(rayR, out hit, 1.0f))
             {
                 TransparentCube tC = hit.transform.GetComponent <TransparentCube>();
                 if (tC != null)
                 {
                     adjacentObjs.Add(hit.transform.GetComponent <TransparentCube>());
                 }
             }
         }
         if (checkLAdjs)
         {
             if (Physics.Raycast(rayL, out hit, 1.0f))
             {
                 TransparentCube tC = hit.transform.GetComponent <TransparentCube>();
                 if (tC != null)
                 {
                     adjacentObjs.Add(hit.transform.GetComponent <TransparentCube>());
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: TransparentCube.cs プロジェクト: CodeXoR/ROYGBIV
 void GetAdjacentObjs(CheckDirection dir)
 {
     if(rayDir==CheckDirection.forward)
     {
         Ray rayF = new Ray(transform.position + transform.forward, transform.forward);
         Ray rayB = new Ray(transform.position + transform.forward/2, -transform.forward);
         //Debug.DrawRay(rayF.origin, rayF.direction, Color.red);
         //Debug.DrawRay(rayB.origin, rayB.direction, Color.red);
         RaycastHit hit;
         if(Physics.Raycast(rayF, out hit, 1.0f))
         {
             TransparentCube tC = hit.transform.GetComponent<TransparentCube>();
             if( tC != null )
                 adjacentObjs.Add(hit.transform.GetComponent<TransparentCube>());
         }
         if(Physics.Raycast(rayB, out hit, 1.0f))
         {
             TransparentCube tC = hit.transform.GetComponent<TransparentCube>();
             if( tC != null )
                 adjacentObjs.Add(hit.transform.GetComponent<TransparentCube>());
         }
     }
     else
     {
         Ray rayR = new Ray(transform.position + transform.forward * .7f, transform.right);
         Ray rayL = new Ray(transform.position + transform.forward * .7f, -transform.right);
         //Debug.DrawRay(rayR.origin, rayR.direction, Color.red);
         //Debug.DrawRay(rayL.origin, rayL.direction, Color.red);
         RaycastHit hit;
         if(checkRAdjs)
         {
             if(Physics.Raycast(rayR, out hit, 1.0f))
             {
                 TransparentCube tC = hit.transform.GetComponent<TransparentCube>();
                 if( tC != null )
                     adjacentObjs.Add(hit.transform.GetComponent<TransparentCube>());
             }
         }
         if(checkLAdjs)
         {
             if(Physics.Raycast(rayL, out hit, 1.0f))
             {
                 TransparentCube tC = hit.transform.GetComponent<TransparentCube>();
                 if( tC != null )
                     adjacentObjs.Add(hit.transform.GetComponent<TransparentCube>());
             }
         }
     }
 }
コード例 #3
0
ファイル: TreeListView.cs プロジェクト: moisesiq/aupaga
        /// <summary>
        /// Raises the ItemCheck event
        /// </summary>
        /// <param name="e">An ItemCheckEventArgs that contains the event data</param>
        protected override void OnItemCheck(System.Windows.Forms.ItemCheckEventArgs e)
        {
            base.OnItemCheck(e);
                ListView.ListViewItemCollection baseItems = base.Items;
                if(e.Index >= base.Items.Count || e.Index < 0)
                    return;
                TreeListViewItem item = (TreeListViewItem) base.Items[e.Index];
                if(item == null) return;
                if(this._checkDirection == CheckDirection.None) return;
                CheckDirection oldDirection = _checkDirection;

                TreeListViewItem parentItem = item.Parent;
                if(parentItem != null && (oldDirection & CheckDirection.Upwards) == CheckDirection.Upwards)
                {
                    _checkDirection = CheckDirection.Upwards;
                    while(parentItem != null)
                    {
                        if(e.NewValue == CheckState.Checked)
                        {
                            if(!parentItem.Checked)
                            {
                                parentItem.Checked = true;
                                break;
                            }
                            else
                            {
                                bool allChecked = true;
                                foreach(TreeListViewItem childItem in parentItem.Items)
                                {
                                    if(childItem == item) continue;
                                    if(!childItem.Checked)
                                    {
                                        allChecked = false;
                                        break;
                                    }
                                }
                                if(allChecked) parentItem.Redraw();
                            }
                        }
                        else
                        {
                            bool allUnChecked = true;
                            foreach(TreeListViewItem childItem in parentItem.Items)
                            {
                                if(childItem == item) continue;
                                if(childItem.Checked)
                                {
                                    allUnChecked = false;
                                    break;
                                }
                            }
                            if(allUnChecked && parentItem.Checked)
                            {
                                parentItem.Checked = false;
                                break;
                            }
                        }
                        parentItem = parentItem.Parent;
                    }
                }

                if((oldDirection & CheckDirection.Downwards) == CheckDirection.Downwards)
                {
                    _checkDirection = CheckDirection.Downwards;
                    foreach(TreeListViewItem childItem in item.Items)
                        childItem.Checked = e.NewValue == CheckState.Checked;
                }
                _checkDirection = oldDirection;
        }
コード例 #4
0
ファイル: TreeListView.cs プロジェクト: moisesiq/aupaga
        /// <summary>
        /// Raises the ColumnClick event
        /// </summary>
        /// <param name="e">A ColumnClickEventArgs that contains the event data</param>
        protected override void OnColumnClick(System.Windows.Forms.ColumnClickEventArgs e)
        {
            base.OnColumnClick(e);
                Cursor = Cursors.WaitCursor;
                ListViewItem[] selItems = new ListViewItem[base.SelectedItems.Count];
                base.SelectedItems.CopyTo(selItems, 0);

                // Must set ListView.checkDirection to CheckDirection.None.
                // Forbid recursively checking.
                CheckDirection oldDirection = _checkDirection;
                _checkDirection = CheckDirection.None;
                BeginUpdate();
                if(Comparer.Column == e.Column)
                    Sorting = (Sorting == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending);
                else
                {
                    Comparer.Column = e.Column;
                    Items.SortOrderRecursivelyWithoutSort = SortOrder.Ascending;
                    try{Items.Sort(true);}
                    catch{}
                }

                if(FocusedItem != null) FocusedItem.EnsureVisible();
                foreach(ListViewItem item in selItems)
                    if(item.Index > -1) item.Selected = true;
                EndUpdate();
                // Reset ListView.checkDirection
                _checkDirection = oldDirection;
                Cursor = Cursors.Default;
        }
コード例 #5
0
ファイル: TreeListViewItem.cs プロジェクト: utobe/QuickMon
        internal void ExpandInternal()
        {
            if (IsInATreeListView)
            {
                if (ListView.InvokeRequired)
                {
                    throw (new Exception("Invoke Required"));
                }
            }

            TreeListViewItem selItem = null;

            if (TreeListView != null)
            {
                selItem = TreeListView.FocusedItem;
            }

            // Must set ListView.checkDirection to CheckDirection.None.
            // Forbid recursively checking.
            CheckDirection oldDirection = CheckDirection.All;

            if (ListView != null)
            {
                oldDirection             = ListView._checkDirection;
                ListView._checkDirection = CheckDirection.None;
            }

            // The item wasn't expanded -> raise an event
            if (Visible && !_isexpanded && ListView != null)
            {
                TreeListViewCancelEventArgs e = new TreeListViewCancelEventArgs(
                    this, TreeListViewAction.Expand);
                ListView.RaiseBeforeExpand(e);
                if (e.Cancel)
                {
                    return;
                }
            }

            if (Visible)
            {
                for (int i = Items.Count - 1; i >= 0; i--)
                {
                    TreeListViewItem item = this.Items[i];
                    if (!item.Visible)
                    {
                        ListView LView = this.ListView;
                        LView.Items.Insert(
                            this.Index + 1, item);
                        item.SetIndentation();
                    }
                    if (item.IsExpanded)
                    {
                        item.Expand();
                    }
                }
            }
            // The item wasn't expanded -> raise an event
            if (Visible && !_isexpanded && IsInATreeListView)
            {
                this._isexpanded = true;
                TreeListViewEventArgs e = new TreeListViewEventArgs(
                    this, TreeListViewAction.Expand);
                ListView.RaiseAfterExpand(e);
                if (AfterExpand != null)
                {
                    AfterExpand(this);
                }
            }
            this._isexpanded = true;

            // Reset ListView.checkDirection
            if (IsInATreeListView)
            {
                ListView._checkDirection = oldDirection;
            }
            if (TreeListView != null && selItem != null)
            {
                if (selItem.Visible)
                {
                    selItem.Focused = true;
                }
            }
        }
コード例 #6
0
ファイル: TreeListViewItem.cs プロジェクト: windygu/WMS-4
        internal void ExpandInternal()
        {
            if (IsInATreeListView && ListView.InvokeRequired)
            {
                throw new Exception("Invoke Required");
            }
            TreeListViewItem treeListViewItem = null;

            if (TreeListView != null)
            {
                treeListViewItem = TreeListView.FocusedItem;
            }
            CheckDirection checkDirection = CheckDirection.All;

            if (ListView != null)
            {
                checkDirection          = ListView.CheckDirection;
                ListView.CheckDirection = CheckDirection.None;
            }
            if (Visible && !_IsExpanded && ListView != null)
            {
                TreeListViewCancelEventArgs treeListViewCancelEventArgs = new TreeListViewCancelEventArgs(this, TreeListViewAction.Expand);
                ListView.RaiseBeforeExpand(treeListViewCancelEventArgs);
                if (treeListViewCancelEventArgs.Cancel)
                {
                    return;
                }
            }
            if (Visible)
            {
                for (int num = Items.Count - 1; num >= 0; num--)
                {
                    TreeListViewItem treeListViewItem2 = Items[num];
                    if (!treeListViewItem2.Visible)
                    {
                        ListView treeListView = TreeListView;
                        treeListView.Items.Insert(base.Index + 1, treeListViewItem2);
                        treeListViewItem2.SetIndentation();
                    }
                    if (treeListViewItem2.IsExpanded)
                    {
                        treeListViewItem2.Expand();
                    }
                }
            }
            if (Visible && !_IsExpanded && IsInATreeListView)
            {
                _IsExpanded = true;
                TreeListViewEventArgs e = new TreeListViewEventArgs(this, TreeListViewAction.Expand);
                ListView.RaiseAfterExpand(e);
                if (this.AfterExpand != null)
                {
                    this.AfterExpand(this);
                }
            }
            _IsExpanded = true;
            if (IsInATreeListView)
            {
                ListView.CheckDirection = checkDirection;
            }
            if (TreeListView != null && treeListViewItem != null && treeListViewItem.Visible)
            {
                treeListViewItem.Focused = true;
            }
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: NotAPenguin0/TicTacToe
        private bool CheckRowAtWithDirection(PlayerId player, uint startX, uint startY, CheckDirection direction)
        {
            DirectionOffset offset = directionMap[direction];
            // You need 3 symbols in a row to win
            const uint RowWinLength = 3;

            for (int i = 0; i < RowWinLength; ++i)
            {
                // Cast to int to avoid signed/unsigned madness
                int xInt = (int)startX + i * offset.X;
                int yInt = (int)startY + i * offset.Y;

                if (xInt < 0 || yInt < 0)
                {
                    return(false);
                }
                // Cast back to unsigned now that we have verified that the result is positive
                uint x = (uint)xInt;
                uint y = (uint)yInt;

                BoardState playerSymbolState = player switch
                {
                    PlayerId.X => BoardState.X,
                    PlayerId.O => BoardState.O,
                    _ => throw new NotImplementedException("Invalid player to check")
                };

                // Make sure to short-circuit on invalid location.
                // If any of these conditions fail, there is no winning direction here
                if (!board.IsValidLocation(x, y) || board[x, y] != playerSymbolState)
                {
                    return(false);
                }
            }
            // If we made it through the loop, there is a winning row here
            return(true);
        }
コード例 #8
0
        public bool IsValidStep(int x1, int y1, int x2, int y2)
        {
            CheckDirection mode = CheckDirection.None;

            // calculate differences
            if (x1 > x2)
            {
                // Left
                mode = CheckDirection.Left;
            }
            else if (x2 > x1)
            {
                // right
                mode = CheckDirection.Right;
            }
            else // X1 == X2
            {
                // Check changes on y
                if (y1 > y2)
                {
                    // Up
                    mode = CheckDirection.Up;
                }
                else if (y2 > y1)
                {
                    // Down
                    mode = CheckDirection.Down;
                }
            }
            switch (mode)
            {
            case CheckDirection.Up:
                for (int y = y1; y >= y2; y--)
                {
                    if (isWall[x1, y])
                    {
                        return(false);
                    }
                }
                return(true);

            case CheckDirection.Down:
                for (int y = y1; y <= y2; y++)
                {
                    if (isWall[x1, y])
                    {
                        return(false);
                    }
                }
                return(true);

            case CheckDirection.Left:
                for (int x = x1; x >= x2; x--)
                {
                    if (isWall[x, y1])
                    {
                        return(false);
                    }
                }
                return(true);

            case CheckDirection.Right:
                for (int x = x1; x <= x2; x++)
                {
                    if (isWall[x, y1])
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }