Example #1
0
        /// <summary>
        /// Sets a node to a certain state depending on its current state
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Node_Click(object sender, RoutedEventArgs e)
        {
            Button  button = sender as Button;
            GOLNode gnode  = GOLNode.Map.Single(node => node.Name == button.Name);

            if (!gnode.IsTaken)
            {
                gnode.TakeNode();
            }
            else
            {
                gnode.ResetNode();
            }
        }
Example #2
0
 /// <summary>
 /// Does Node Click but only if the user holds down the left mouse button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Node_Hover(object sender, MouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed)
     {
         Button  button = sender as Button;
         GOLNode gnode  = GOLNode.Map.Single(n => n.Name == button.Name);
         if (!gnode.IsTaken)
         {
             gnode.TakeNode();
         }
         else
         {
             gnode.ResetNode();
         }
     }
 }
Example #3
0
        /// <summary>
        /// Gets the nieghbor count of this node
        /// </summary>
        /// <returns></returns>
        public int NeighborCount()
        {
            int     count = 0;
            GOLNode tl    = GOLNode.Map.FirstOrDefault(n => n.X == X - 1 && n.Y == Y + 1);
            GOLNode tt    = GOLNode.Map.FirstOrDefault(n => n.X == X - 0 && n.Y == Y + 1);
            GOLNode tr    = GOLNode.Map.FirstOrDefault(n => n.X == X + 1 && n.Y == Y + 1);
            GOLNode rr    = GOLNode.Map.FirstOrDefault(n => n.X == X + 1 && n.Y == Y + 0);
            GOLNode br    = GOLNode.Map.FirstOrDefault(n => n.X == X + 1 && n.Y == Y - 1);
            GOLNode bb    = GOLNode.Map.FirstOrDefault(n => n.X == X + 0 && n.Y == Y - 1);
            GOLNode bl    = GOLNode.Map.FirstOrDefault(n => n.X == X - 1 && n.Y == Y - 1);
            GOLNode ll    = GOLNode.Map.FirstOrDefault(n => n.X == X - 1 && n.Y == Y - 0);

            if (tl != null && tl.IsTaken)
            {
                count++;
            }
            if (tt != null && tt.IsTaken)
            {
                count++;
            }
            if (tr != null && tr.IsTaken)
            {
                count++;
            }
            if (rr != null && rr.IsTaken)
            {
                count++;
            }
            if (br != null && br.IsTaken)
            {
                count++;
            }
            if (bb != null && bb.IsTaken)
            {
                count++;
            }
            if (bl != null && bl.IsTaken)
            {
                count++;
            }
            if (ll != null && ll.IsTaken)
            {
                count++;
            }
            return(count);
        }