public void mark(int col, int row) { NewCell cell = findCell(col, row); if (cell != null) { cell.mark(); } }
public bool uncover(int col, int row) { NewCell cell = findCell(col, row); if (cell != null) { return(cell.uncover()); } else { return(false); } if (col == 0 && row == 0) { return(uncover()); } else { if (col != 0) { //continue East //eastNeigbor.uncover(col - 1, row); NewCell eastNeighbor; if (neighbors.TryGetValue(Direction.E, out eastNeighbor)) { return(eastNeighbor.uncover(col - 1, row)); } else { return(false); } } else { //continue South //southNeighbor.uncover(col, row - 1); NewCell southNeighbor; if (neighbors.TryGetValue(Direction.S, out southNeighbor)) { return(southNeighbor.uncover(col, row - 1)); } else { return(false); } } } }
public NewMineSweeper(NewCell entrance) { entry = entrance; }
public static void connectCells(NewCell fromCell, NewCell toCell, Direction direction) { fromCell.AddNeighbor(direction, toCell); toCell.AddNeighbor(direction.Opposite(), fromCell); }
public void connectTo(NewCell toCell, Direction direction) { //this.AddNeighbor(direction, toCell); //toCell.AddNeighbor(direction.Opposite(), this); NewCell.connectCells(this, toCell, direction); }
static void Main(string[] args) { bool playing = true; NewCell cell00 = new NewCell(); NewCell cell01 = new NewCell(); NewCell cell10 = new NewCell(); NewCell cell11 = new NewCell(); //Let's connect the cells cell00.connectTo(cell01, Direction.E); cell00.connectTo(cell11, Direction.SE); cell00.connectTo(cell10, Direction.S); cell01.connectTo(cell01, Direction.SW); cell01.connectTo(cell11, Direction.S); cell10.connectTo(cell11, Direction.E); /** * cell00.AddNeighbor(Direction.E, cell01); * cell00.AddNeighbor(Direction.SE, cell11); * cell00.AddNeighbor(Direction.S, cell10); * cell01.AddNeighbor(Direction.W, cell00); * cell01.AddNeighbor(Direction.SW, cell10); * cell01.AddNeighbor(Direction.S, cell11); * cell11.AddNeighbor(Direction.NW, cell00); * * cell11.AddNeighbor(Direction.N, cell01); * cell11.AddNeighbor(Direction.W, cell10); * cell10.AddNeighbor(Direction.N, cell00); * cell10.AddNeighbor(Direction.NE, cell01); * cell10.AddNeighbor(Direction.E, cell11); */ //place a mine cell11.Mine = new Mine(); cell00.updateMineCount(); NewMineSweeper ms = new NewMineSweeper(cell00); while (playing) { Console.WriteLine("Please, enter your choice"); Console.WriteLine("1. Uncover cell"); Console.WriteLine("2. Mark cell"); Console.WriteLine("3. Quit"); Console.WriteLine(ms); string inputLine = Console.ReadLine(); int choice = Convert.ToInt32(inputLine); int inputRow, inputColumn; bool steppedOnMine = false; switch (choice) { case 1: Console.WriteLine("Please, enter the column number:"); inputLine = Console.ReadLine(); inputColumn = Convert.ToInt32(inputLine); Console.WriteLine("Please, enter the row number:"); inputLine = Console.ReadLine(); inputRow = Convert.ToInt32(inputLine); steppedOnMine = ms.uncover(inputColumn, inputRow); break; case 2: Console.WriteLine("Please, enter the column number:"); inputLine = Console.ReadLine(); inputColumn = Convert.ToInt32(inputLine); Console.WriteLine("Please, enter the row number:"); inputLine = Console.ReadLine(); inputRow = Convert.ToInt32(inputLine); ms.mark(inputColumn, inputRow); break; case 3: Console.WriteLine("Thank you for playing"); playing = false; break; default: break; } if (steppedOnMine) { Console.WriteLine("You stepped on a mine. Sorry, game over. You are a loser."); playing = false; } } }
public void AddNeighbor(Direction direction, NewCell neighbor) { neighbors[direction] = neighbor; }