Advertisement
Elec0

Cell

Oct 13th, 2012 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. //using System.Drawing;
  3.  
  4. namespace DFSAlgorithmMaze
  5. {
  6.     /// <summary>
  7.     /// Summary description for Cell.
  8.     /// </summary>
  9.     public class Cell
  10.     {
  11.         public static int kCellSize = 10;
  12.         public int mCellSize = kCellSize;
  13.         public static int kPadding = 5;
  14.         public int[] Walls  = new int[4]{1, 1, 1, 1};
  15.         public int Row;
  16.         public int Column;
  17.         private static long Seed =  DateTime.Now.Ticks;
  18.         static public Random TheRandom = new Random((int)Cell.Seed);
  19.        
  20.        
  21.         public Cell()
  22.         {
  23.             //
  24.             // TODO: Add constructor logic here
  25.             //
  26.         }
  27.  
  28.         public bool HasAllWalls()
  29.         {
  30.             for (int i = 0; i < 4; i++)
  31.             {
  32.                  if (Walls[i] == 0)
  33.                      return false;
  34.             }
  35.  
  36.             return true;
  37.         }
  38.  
  39.         public void KnockDownWall(int theWall)
  40.         {
  41.             Walls[theWall] = 0;
  42.         }
  43.  
  44.         public void KnockDownWall(Cell theCell)
  45.         {
  46.             // find adjacent wall
  47.             int theWallToKnockDown = FindAdjacentWall(theCell);
  48.             Walls[theWallToKnockDown] = 0;
  49.             int oppositeWall = (theWallToKnockDown + 2) % 4;
  50.             theCell.Walls[oppositeWall] = 0;
  51.         }
  52.  
  53.  
  54.         public  int FindAdjacentWall(Cell theCell)
  55.         {
  56.             if (theCell.Row == Row)
  57.             {
  58.                 if (theCell.Column < Column)
  59.                     return 0;
  60.                 else
  61.                     return 2;
  62.             }
  63.             else // columns are the same
  64.             {
  65.                 if (theCell.Row < Row)
  66.                     return 1;
  67.                 else
  68.                     return 3;
  69.             }
  70.         }
  71.  
  72.         public int GetRandomWall()
  73.         {
  74.             int nextWall = TheRandom.Next(0, 3);
  75.             while ( (Walls[nextWall] == 0)  
  76.             ||      ((Row == 0) && (nextWall == 0)) ||
  77.                     ((Row == Maze.kDimension - 1) && (nextWall == 2)) ||
  78.                     ((Column == 0) && (nextWall == 1)) ||
  79.                     ((Column == Maze.kDimension - 1) && (nextWall == 3))
  80.                    )
  81.             {
  82.                 nextWall = TheRandom.Next(0, 3);
  83.             }
  84.  
  85.             return nextWall;
  86.         }
  87.        
  88.         /*public void Draw(Graphics g)
  89.         {
  90.             if (Walls[0] == 1)
  91.             {
  92.                 g.DrawLine(Pens.Blue, Row*kCellSize + kPadding, Column*kCellSize + kPadding, (Row+1) * kCellSize + kPadding, Column*kCellSize + kPadding);
  93.             }
  94.             if (Walls[1] == 1)
  95.             {
  96.                 g.DrawLine(Pens.Blue, Row*kCellSize  + kPadding, Column*kCellSize + kPadding, Row*kCellSize + kPadding, (Column+1)*kCellSize + kPadding);
  97.             }
  98.             if (Walls[2] == 1)
  99.             {
  100.                 g.DrawLine(Pens.Blue, Row*kCellSize + kPadding, (Column+1)*kCellSize + kPadding, (Row+1)*kCellSize + kPadding, (Column+1)*kCellSize + kPadding);
  101.             }
  102.             if (Walls[3] == 1)
  103.             {
  104.                 g.DrawLine(Pens.Blue,(Row+1)*kCellSize + kPadding , Column*kCellSize + kPadding, (Row+1)*kCellSize + kPadding, (Column+1)*kCellSize + kPadding);
  105.             }
  106.  
  107.  
  108.  
  109.         }
  110.         */
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement