public void FirstMove(int x, int y) { Random rand = new Random(); //For any board, take the user's first revealed panel + any neighbors of that panel, and mark them as unavailable for mine placement. var neighbors = GetNeighbors(x, y); //Get all neighbors neighbors.Add(Panels.First(z => z.X == x && z.Y == y)); //Select random panels from set which are not excluded var mineList = Panels.Except(neighbors).OrderBy(user => rand.Next()); var mineSlots = mineList.Take(MineCount).ToList().Select(z => new { z.X, z.Y }); //Place the mines foreach (var mineCoord in mineSlots) { Panels.Single(panel => panel.X == mineCoord.X && panel.Y == mineCoord.Y).IsMine = true; } //For every panel which is not a mine, determine and save the adjacent mines. foreach (var openPanel in Panels.Where(panel => !panel.IsMine)) { var nearbyPanels = GetNeighbors(openPanel.X, openPanel.Y); openPanel.AdjacentMines = nearbyPanels.Count(z => z.IsMine); } Status = GameStatus.InProgress; Stopwatch.Start(); }
public void RevealPanel(int x, int y) { //Step 1: Find and reveal the clicked panel var selectedPanel = Panels.First(panel => panel.X == x && panel.Y == y); selectedPanel.Reveal(); //Step 2: If the panel is a mine, show all mines. Game over! if (selectedPanel.IsMine) { Status = GameStatus.Failed; RevealAllMines(); return; } //Step 3: If the panel is a zero, cascade reveal neighbors. if (selectedPanel.AdjacentMines == 0) { RevealZeros(x, y); } //Step 4: If this move caused the game to be complete, mark it as such CompletionCheck(); }
public void RevealPanel(int x, int y) { //Step 1: Find the Specified Panel var selectedPanel = Panels.First(panel => panel.X == x && panel.Y == y); selectedPanel.IsRevealed = true; selectedPanel.IsFlagged = false; //Revealed panels cannot be flagged //Step 2: If the panel is a mine, game over! if (selectedPanel.IsMine) { Status = GameStatus.Failed; //Game over! } //Step 3: If the panel is a zero, cascade reveal neighbors if (!selectedPanel.IsMine && selectedPanel.AdjacentMines == 0) { RevealZeros(x, y); } //Step 4: If this move caused the game to be complete, mark it as such if (!selectedPanel.IsMine) { CompletionCheck(); } }
public override void Activate() { Reservation = Values.SafeGetValue <Reservation>("Reservation"); var reservee = Values.SafeGetValue <Reservee>("Reservee"); var rfids = Values.SafeGetValue <IEnumerable <string> >("Visitors"); if (rfids != null) { int num = 0; foreach (string rfid in rfids) { num++; var panel = new VisitorInfoPanel { Dock = DockStyle.Top, Tag = rfid, Title = num + ": " + rfid }; View.FlowLayoutPanel.Controls.Add(panel); Panels.Add(panel); } } if (reservee != null) { VisitorInfoPanel panel = Panels.First(); panel.FirstName = reservee.FirstName; panel.Insertion = reservee.Insertion; panel.LastName = reservee.LastName; panel.PhoneNumber = reservee.Phone; } }
public void RevealPanel(int x, int y) { var selectedPanel = Panels.First(panel => panel.X == x && panel.Y == y); selectedPanel.IsRevealed = true; selectedPanel.IsFlagged = false; //Revealed panels cannot be flagged solvedanything = true; }
//Marcar painel public void Flag(int x, int y) { var panel = Panels.First(z => z.X == x && z.Y == y); if (!panel.IsRevealed) { panel.IsFlagged = !panel.IsFlagged; } }
public void FirstMove(int x, int y) { Random rand = new Random(); //For any board, take the user's first revealed panel // and any neighbors of that panel, and mark them // as unavailable for mine placement. var neighbors = GetNeighbors(x, y); //Get all neighbors //Add the clicked panel to the "unavailable for mines" group. neighbors.Add(Panels.First(z => z.X == x && z.Y == y)); //Select all panels from set which are available for mine placement. //Order them randomly. var mineList = Panels.Except(neighbors) .OrderBy(user => rand.Next()); //Select the first Z random panels. var mineSlots = mineList.Take(MineCount) .ToList() .Select(z => new { z.X, z.Y }); //Place the mines in the randomly selected panels. foreach (var mineCoord in mineSlots) { Panels.Single(panel => panel.X == mineCoord.X && panel.Y == mineCoord.Y) .IsMine = true; } //For every panel which is not a mine, // including the unavailable ones from earlier, // determine and save the adjacent mines. foreach (var openPanel in Panels.Where(panel => !panel.IsMine)) { var nearbyPanels = GetNeighbors(openPanel.X, openPanel.Y); openPanel.AdjacentMines = nearbyPanels.Count(z => z.IsMine); } //Mark the game as started. Status = GameStatus.InProgress; Stopwatch.Start(); }
public Panel GetPanel(int x, int y) { return(Panels.First(z => z.X == x && z.Y == y)); }
public void Reveal(int x, int y) { //1. Encontrar o painel var selectedPanel = Panels.First(panel => panel.X == x && panel.Y == y); //2. Apenas revelar se não estiver marcado if (!selectedPanel.IsFlagged) { var first = false; //3. Se não há nenhum painel revelado é o primeiro movimento if (Panels.All(panel => !panel.IsRevealed)) { //O primeiro movimento adiciona as minas FirstMove(x, y, rand); first = true; } //4. Spawnar cogumelo if (selectedPanel.IsMushroom) { coroutines.Start(SpawnMushroom(x, y, rand)); } //Revelar o painel selectedPanel.IsRevealed = true; selectedPanel.ShowSelection = false; //5. Checar se o painel clicado é mina if (selectedPanel.IsMine) { //Se o jogador não tiver mais chances terminar o jogo if (chances <= 0) { GameOver(); } else { chances--; } } //6. se o painel é um zero, revelar vizinhos em cascata if (!selectedPanel.IsMine && selectedPanel.AdjacentMines == 0) { RevealZeros(x, y); } //7. Adicionar Cogumelos se for o primeiro movimento if (first) { PlaceMushrooms(rand); } //8. se o movimento causar o fim do jogo, terminar o jogo if (!selectedPanel.IsMine) { CompletionCheck(); } } }