Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //using System.Drawing;
- namespace DFSAlgorithmMaze
- {
- /// <summary>
- /// Summary description for Cell.
- /// </summary>
- public class Cell
- {
- public static int kCellSize = 10;
- public int mCellSize = kCellSize;
- public static int kPadding = 5;
- public int[] Walls = new int[4]{1, 1, 1, 1};
- public int Row;
- public int Column;
- private static long Seed = DateTime.Now.Ticks;
- static public Random TheRandom = new Random((int)Cell.Seed);
- public Cell()
- {
- //
- // TODO: Add constructor logic here
- //
- }
- public bool HasAllWalls()
- {
- for (int i = 0; i < 4; i++)
- {
- if (Walls[i] == 0)
- return false;
- }
- return true;
- }
- public void KnockDownWall(int theWall)
- {
- Walls[theWall] = 0;
- }
- public void KnockDownWall(Cell theCell)
- {
- // find adjacent wall
- int theWallToKnockDown = FindAdjacentWall(theCell);
- Walls[theWallToKnockDown] = 0;
- int oppositeWall = (theWallToKnockDown + 2) % 4;
- theCell.Walls[oppositeWall] = 0;
- }
- public int FindAdjacentWall(Cell theCell)
- {
- if (theCell.Row == Row)
- {
- if (theCell.Column < Column)
- return 0;
- else
- return 2;
- }
- else // columns are the same
- {
- if (theCell.Row < Row)
- return 1;
- else
- return 3;
- }
- }
- public int GetRandomWall()
- {
- int nextWall = TheRandom.Next(0, 3);
- while ( (Walls[nextWall] == 0)
- || ((Row == 0) && (nextWall == 0)) ||
- ((Row == Maze.kDimension - 1) && (nextWall == 2)) ||
- ((Column == 0) && (nextWall == 1)) ||
- ((Column == Maze.kDimension - 1) && (nextWall == 3))
- )
- {
- nextWall = TheRandom.Next(0, 3);
- }
- return nextWall;
- }
- /*public void Draw(Graphics g)
- {
- if (Walls[0] == 1)
- {
- g.DrawLine(Pens.Blue, Row*kCellSize + kPadding, Column*kCellSize + kPadding, (Row+1) * kCellSize + kPadding, Column*kCellSize + kPadding);
- }
- if (Walls[1] == 1)
- {
- g.DrawLine(Pens.Blue, Row*kCellSize + kPadding, Column*kCellSize + kPadding, Row*kCellSize + kPadding, (Column+1)*kCellSize + kPadding);
- }
- if (Walls[2] == 1)
- {
- g.DrawLine(Pens.Blue, Row*kCellSize + kPadding, (Column+1)*kCellSize + kPadding, (Row+1)*kCellSize + kPadding, (Column+1)*kCellSize + kPadding);
- }
- if (Walls[3] == 1)
- {
- g.DrawLine(Pens.Blue,(Row+1)*kCellSize + kPadding , Column*kCellSize + kPadding, (Row+1)*kCellSize + kPadding, (Column+1)*kCellSize + kPadding);
- }
- }
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement