Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Title = "Console Minesweeper";

            ConsoleInput.ResetColours();
            Console.Clear();

            //  Game Width
            int width = ConsoleInput.GetNumberValue("Please input the game grid width: ", 5, 50);
            int height = ConsoleInput.GetNumberValue("Please input the game grid height: ", 5, 50);

            //  Go!
            Game game = new Game(width, height);
            ConsoleInput.SetGameReference(game);
            game.Play();
        }
        /// <summary>
        /// Calculates which other squares are neighbours for this square
        /// </summary>
        /// <param name="game"></param>
        public void CalculateNeightbours(Game game)
        {
            this.BombNeighbours = 0;
            List<GameSquare> neighbours = new List<GameSquare>();
            for (int x = this.X - 1; x <= this.X + 1; x++)
            {
                if (x < 0 || x > game.Width-1) { continue; }
                for (int y = this.Y - 1; y <= this.Y + 1; y++)
                {
                    if (y < 0 || y > game.Height - 1) { continue; }
                    if (x == this.X && y == this.Y) { continue; }
                    neighbours.Add(game.GameSquares[x, y]);
                }
            }

            foreach (GameSquare square in neighbours)
            { if (square.IsMine) { this.BombNeighbours++; } }
            this.Neighbours = neighbours.ToArray();
        }
Exemplo n.º 3
0
 public MainWindow()
 {
     InitializeComponent();
      Game game = new Game(BoardGrid, TitleName, MyPanel);
 }
Exemplo n.º 4
0
Arquivo: Main.cs Projeto: Emp3r/School
 // podle vstupů inicializuje vlastní hrací desku
 private static void InitializeGame()
 {
     int x, y, d;
     while (true) {
         Console.WriteLine("Zadej šířku: ");
         string s = Console.ReadLine ();
         if (IsSizeNumber (s)) {
             x = Convert.ToInt32 (s);
             break;
         } else {
             Console.WriteLine("Chyba. Zadávej pouze čísla v rozmezí 4-26.");
             continue;
         }
     }
     while (true) {
         Console.WriteLine("Zadej výšku: ");
         string s = Console.ReadLine ();
         if (IsSizeNumber (s)) {
             y = Convert.ToInt32 (s);
             break;
         } else {
             Console.WriteLine("Chyba. Zadávej pouze čísla v rozmezí 4-26.");
             continue;
         }
     }
     while (true) {
         Console.WriteLine("A obtížnost: ");
         string s = Console.ReadLine ();
         if (IsSizeNumber (s) ) {
             d = Convert.ToInt32 (s);
             break;
         } else {
             Console.WriteLine("Chyba. Zadávej pouze čísla v rozmezí 4-26.");
             continue;
         }
     }
     g = new Game(x, y, d);
 }
Exemplo n.º 5
0
Arquivo: Main.cs Projeto: Emp3r/School
        // zahájí hru a obsluhuje vstupy
        private static bool Start()
        {
            if (WantCustom ()) {
                isDefault = false;
                InitializeGame ();
            } else {
                isDefault = true;
                g = new Game (defaultSize, defaultSize, 10);
                timer = new Stopwatch();
                timer.Start();
            }

            Console.Clear ();
            PrintGame();

            while (true) {
                string s = Console.ReadLine();
                switch (s) {
                case "k":
                    Console.WriteLine("Ukončuji program.");
                    return false;
                case "n":
                    return true;
                case "s":
                    Console.WriteLine(dm.HighscoreTable());
                    break;
                case "?":
                    PrintHelp();
                    break;
                case "f":
                    int[] inp = IsInput(Console.ReadLine());
                    if (inp != null) {
                        Flag (inp);
                        Console.Clear();
                        PrintGame();
                    }
                    break;
                default:
                    if (IsInput(s) != null) {
                        Click(IsInput(s));
                        Console.Clear();
                        PrintGame();
                    }
                    break;
                }

                if (CheckWinLoose())
                    return true;
            }
        }
 public static void SetGameReference(Game GameReference)
 {
     ConsoleInput.GameReference = GameReference;
 }
Exemplo n.º 7
0
        private void NewGame()
        {
            ClearForm();

            _gameSettings = new GameSettings(10, 10, 10);
            _gameButtons = new Button[_gameSettings.GameFieldHeight * _gameSettings.GameFieldWidth];
            _game = new Game(_gameSettings);

            InitializeButtons();
        }
Exemplo n.º 8
0
        void InitGame(int height, int width, int mines, int tileSize)
        {
            minePanel.Children.Clear();
             minePanel.Height = tileSize * height;
             minePanel.Width = tileSize * width;

             game = Game.RandomGame(width, height, mines);
             covers = new List<Rectangle>();
             for (int i = 0; i < height; i++)
            for (int j = 0; j < width; j++)
            {
               var tile = game.GetTile(i, j);
               TextBlock txt = null;
               if (tile.IsMine)
               {
                  txt = new TextBlock();
                  txt.Text = "X";
               }
               else if (tile.SurroundMines > 0)
               {
                  txt = new TextBlock();
                  txt.Foreground = flagColors[tile.SurroundMines - 1];
                  txt.Text = tile.SurroundMines.ToString();
               }

               if (txt != null)
               {
                  txt.Height = txt.Width = tileSize;
                  txt.TextAlignment = TextAlignment.Center;
                  Canvas.SetLeft(txt, j * tileSize);
                  Canvas.SetTop(txt, i * tileSize);
                  minePanel.Children.Add(txt);
               }

               var cover = new Rectangle();
               cover.Tag = i * width + j;
               cover.Fill = new SolidColorBrush(Colors.Blue);
               cover.Height = cover.Width = tileSize;
               cover.MouseLeftButtonDown += new MouseButtonEventHandler(cover_MouseLeftButtonDown);
               Canvas.SetLeft(cover, j * tileSize);
               Canvas.SetTop(cover, i * tileSize);
               minePanel.Children.Add(cover);
               covers.Add(cover);
            }

             //grid lines
             for (int x = 0; x <= width * tileSize; x += tileSize)
             {
            var line = new Line();
            line.Stroke = new SolidColorBrush(Colors.Black);
            line.X1 = line.X2 = x;
            line.Y1 = 0;
            line.Y2 = height * tileSize;
            minePanel.Children.Add(line);
             }

             for (int y = 0; y <= height * tileSize; y += tileSize)
             {
            var line = new Line();
            line.Stroke = new SolidColorBrush(Colors.Black);
            line.Y1 = line.Y2 = y;
            line.X1 = 0;
            line.X2 = width * tileSize;
            minePanel.Children.Add(line);
             }
        }