public void CreateMap()
 {
     MineMap = new MineMap(5, 5);
     MineMap.GenerateBombs(1);
     MineMap.GenerateCountNearBombs();
     MineMap.ConvertMap();
 }
        public static void SavePreSelection(WorldClient client, string[] args)
        {
            if (PreSelectionElementsIds == null)
            {
                client.Character.ReplyError("Create a pre-selection first using <i>.mine preselect</i>.");
                return;
            }

            var mapId = PreSelectionMapId;

            var mineMap = Mine.Maps.Find(map => map.MapId == mapId);

            if (mineMap == null)
            {
                mineMap = new MineMap(mapId);
                Mine.AddMap(ref mineMap);
            }

            for (int i = 1; i < PreSelectionElementsIds.Count; i++)
            {
                int elementId = PreSelectionElementsIds[i].ElementId;
                mineMap.AddElement(elementId);
            }

            client.Character.Reply($"Added {PreSelectionElementsIds.Count - 1} mine elements to map {mapId}.");
        }
        public static void AddMap(WorldClient client, string[] args)
        {
            if (Mine == null)
            {
                client.Character.ReplyError("You must initialize your mine first. See <i>.mine init</i>.");
                return;
            }

            if (args.Length < 2)
            {
                client.Character.Reply(".mine addmap|am [$ElementId ...]");
                client.Character.Reply(".mine <b>$ElementId</b> ⇒ The ID of the elements (see <i>.el show</i>) on your map.");
                return;
            }

            var mapId = client.Character.Map.Id;

            var mineMap = Mine.Maps.Find(map => map.MapId == mapId);

            if (mineMap == null)
            {
                mineMap = new MineMap(mapId);
                Mine.AddMap(ref mineMap);
            }

            for (int i = 1; i < args.Length; i++)
            {
                int elementId = int.Parse(args[i]);
                mineMap.AddElement(elementId);
            }

            client.Character.Reply($"Added {args.Length - 1} mine elements to map {mapId}.");
        }
Esempio n. 4
0
        public void Should_EndGame()
        {
            MineItem[,] expect = new MineItem[3, 3]
            {
                {
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                },
            };

            // Act
            var mineMap = new MineMap(3, 3);

            mineMap.MineItems[0, 0].IsBomb = true;

            mineMap.GenerateCountNearBombs();
            //mineMap.Click(2, 2);

            //mineMap.Click(0, 0);

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    mineMap.Click(i, j);
                }
            }
            // Assert
            mineMap.CheckEndGame().Should().Be(true);
        }
Esempio n. 5
0
        public void CreateMap(int height, int width)
        {
            Width  = width;
            Height = height;

            minemap = new MineMap(Height, Width);
            minemap.GenerateBombs(4);
            minemap.GenerateCountNearBombs();
            minemap.ConvertMap();
        }
Esempio n. 6
0
        //public DelegateCommand ClickCommand { get; set; }
        //public ObservableCollection<MineMap> mineitem { get; set; }


        public MineMapViewModel()
        {
            MineMap minemap = new MineMap(5, 5);

            minemap.GenerateBombs(2);
            minemap.GenerateCountNearBombs();


            //mineitem = new ObservableCollection<MineMap>();


            //mineitem.Add(minemap);

            //CreateMap(5, 5);
            //CreateGrid();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;


            if (button != null)
            {
                int row  = Grid.GetRow(button);
                int col  = Grid.GetColumn(button);
                var Item = MineMap.MineItems[row, col];

                if (Item.IsBomb == false)
                {
                    if (Item.IsCovered == true)
                    {
                        Item.IsCovered = false;
                        button.Content = Item.NearBombsCount;

                        if (Item.NearBombsCount == 0)
                        {
                            MineMap.Click(row, col);
                        }
                    }
                    else
                    {
                        button.Content = Item.NearBombsCount;
                    }
                }
                else
                {
                    MessageBox.Show("Boom!");
                }
            }
            else
            {
                MessageBox.Show("Button is null");
            }
        }
Esempio n. 8
0
        public void Should_GenerateBombs(int expectBombCount)
        {
            // arrange

            // act
            var mineMap = new MineMap(5, 5);

            mineMap.GenerateBombs(expectBombCount);

            // assert
            int countBombs = 0;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    if (mineMap.MineItems[i, j].IsBomb)
                    {
                        countBombs++;
                    }
                }
            }
            countBombs.Should().Be(expectBombCount);
        }
        public void Should_Generated_Bombs()
        {
            // Arrange
            var actualMineMap = new MineMap(9, 9, 10);

            // Act
            actualMineMap.GeneratedBombs();

            // Assert
            int countBombs = 0;

            for (int j = 0; j < actualMineMap.Height; j++)
            {
                for (int i = 0; i < actualMineMap.Width; i++)
                {
                    if (actualMineMap[j, i].IsBomb)
                    {
                        countBombs++;
                    }
                }
            }

            countBombs.Should().Be(10);
        }
Esempio n. 10
0
        public void Should_Generated_All_Near_Bombs_Count()
        {
            // Arrange
            var expectedMineItems = new MineItem[9, 9]
            {
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 3
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 3
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
            };

            var actualMineMap = new MineMap(9, 9);

            actualMineMap[1, 2].IsBomb = true;
            actualMineMap[1, 7].IsBomb = true;
            actualMineMap[3, 4].IsBomb = true;
            actualMineMap[3, 7].IsBomb = true;
            actualMineMap[4, 0].IsBomb = true;
            actualMineMap[4, 4].IsBomb = true;
            actualMineMap[5, 2].IsBomb = true;
            actualMineMap[5, 6].IsBomb = true;
            actualMineMap[7, 1].IsBomb = true;
            actualMineMap[7, 4].IsBomb = true;


            // Act
            actualMineMap.GenerateAllNearBombsCount();

            // Assert
            for (int j = 0; j < actualMineMap.Height; j++)
            {
                for (int i = 0; i < actualMineMap.Width; i++)
                {
                    actualMineMap[j, i].Value.Should().Be(expectedMineItems[j, i].Value, $"[{j}, {i}]");
                }
            }
        }
Esempio n. 11
0
        public void Should_GenerateCountNearBombs2()
        {
            // arrange
            MineItem[,] expect = new MineItem[5, 5]
            {
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 3
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 3
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
            };

            // act
            var mineMap = new MineMap(5, 5);

            mineMap.MineItems[0, 3].IsBomb = true;
            mineMap.MineItems[1, 2].IsBomb = true;
            mineMap.MineItems[3, 1].IsBomb = true;
            mineMap.MineItems[3, 2].IsBomb = true;

            mineMap.GenerateCountNearBombs();

            // assert
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    mineMap.MineItems[i, j].ToString().Should().Be(expect[i, j].ToString(), $"[{i}, {j}]");
                }
            }
        }
Esempio n. 12
0
        public void Should_Click2()
        {
            MineItem[,] expect = new MineItem[5, 5]
            {
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1, IsCovered = false
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 3
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 3
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = true
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
                {
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 2
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 1
                    },
                    new MineItem {
                        IsBomb = false, NearBombsCount = 0
                    }
                },
            };

            // Act
            var mineMap = new MineMap(5, 5);

            mineMap.MineItems[0, 3].IsBomb = true;
            mineMap.MineItems[1, 2].IsBomb = true;
            mineMap.MineItems[3, 1].IsBomb = true;
            mineMap.MineItems[3, 2].IsBomb = true;

            mineMap.GenerateCountNearBombs();

            int y = 0;
            int x = 1;

            mineMap.Click(y, x);
            //mineMap.MineItems[y,x].ToString().Should().Be(expect[y, x].ToString(), $"[{y}, {x}]");

            // assert
            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    mineMap.MineItems[i, j].ToString().Should().Be(expect[i, j].ToString(), $"[{i}, {j}]");
                }
            }
        }