Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace MinesweeperConsole
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool active = true;
- while (active)
- {
- // Printing selection menu
- Thread.Sleep(750);
- Console.Clear();
- Console.WriteLine("-----------------------------------------------");
- Console.WriteLine("Minesweeper 0.01");
- Console.WriteLine("By Debby Collaris, Kevin Withoff & Twan Slegers");
- Console.WriteLine("-----------------------------------------------");
- Console.WriteLine("1. Start new game");
- Console.WriteLine("2. Scoreboard");
- Console.WriteLine("3. Exit game");
- Console.WriteLine("-----------------------------------------------");
- // Assigning values
- int choice = 0;
- // Reading key entered by user
- string charEntered = Console.ReadKey(true).KeyChar.ToString();
- try
- {
- choice = Convert.ToInt16(charEntered);
- switch (choice)
- {
- case 1:
- MinesweeperGame();
- break;
- case 2:
- Console.WriteLine("Not yet finished");
- break;
- case 3:
- Console.WriteLine("Exiting game...");
- Thread.Sleep(1250);
- return;
- }
- }
- catch(Exception ex)
- {
- Console.WriteLine("");
- Console.WriteLine(ex.Message);
- }
- }
- }
- static string cursor = "█";
- // Y X coordinates
- /* Y = up down
- * X = left right
- */
- static int[] cursorPosition = new int[] { 6, 11 };
- static string[,] raster = new string[12, 22]
- //raster
- {
- { "╔","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","╗" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "║","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","#","║" },
- { "╚","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","═","╝" }
- };
- private static void BombGenerator()
- {
- Random r = new Random();
- string[] bombArray = new string[30];
- //Creating HashSet, because HashSet removes duplicate values
- HashSet <string> numberSet = new HashSet<string>();
- while (numberSet.Count < 30)
- {
- numberSet.Add(r.Next(1, 11) + "," + r.Next(1, 21));
- }
- // Copy value from HashSet numberSet to Array bombArray
- numberSet.CopyTo(bombArray);
- }
- private static void MinesweeperGame()
- {
- BombGenerator();
- while (true)
- {
- Console.Clear();
- PrintGameField();
- ConsoleKeyInfo key = Console.ReadKey(true);
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- cursorPosition = new int[] { cursorPosition[0] - 1, cursorPosition[1] };
- break;
- case ConsoleKey.DownArrow:
- cursorPosition = new int[] { cursorPosition[0] + 1, cursorPosition[1] };
- break;
- case ConsoleKey.LeftArrow:
- cursorPosition = new int[] { cursorPosition[0], cursorPosition[1] - 1 };
- break;
- case ConsoleKey.RightArrow:
- cursorPosition = new int[] { cursorPosition[0], cursorPosition[1] + 1 };
- break;
- }
- }
- }
- private static void PrintGameField()
- {
- for (int i = 0; i < 12; i++)
- {
- for (int j = 0; j < 22; j++)
- {
- //index 0 is Y
- //index 1 is X
- if (i == cursorPosition[0] && j == cursorPosition[1])
- {
- Console.Write(cursor);
- }
- else
- {
- Console.Write(raster[i, j]);
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement