Commit f9134b81 by adbaga

better

parent 2c9d0a76
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a128ca0c-796d-4da2-8db0-062a4837d105" name="Default Changelist" comment=""> <list default="true" id="a128ca0c-796d-4da2-8db0-062a4837d105" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/Game/GameConfigHandler.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/GameSettings.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.IDoMinesweeper/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.IDoMinesweeper/.idea/contentModel.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.IDoMinesweeper/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.IDoMinesweeper/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.IDoMinesweeper/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.IDoMinesweeper/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleUserInt/GameUI.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/GameUI.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ConsoleUserInt/GameUI.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/GameUI.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleUserInt/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ConsoleUserInt/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" afterDir="false" />
...@@ -14,30 +11,21 @@ ...@@ -14,30 +11,21 @@
<change beforePath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.csprojAssemblyReference.cache" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.csprojAssemblyReference.cache" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.csprojAssemblyReference.cache" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.csprojAssemblyReference.cache" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleUserInt/obj/Debug/netcoreapp3.0/ConsoleUserInt.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/CellState.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Game/CellState.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Engine.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Engine.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/Engine.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Engine.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Game/bin/Debug/netcoreapp3.0/Game.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.dll" beforeDir="false" afterPath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/Game/obj/Debug/netcoreapp3.0/Game.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/IDoMinesweeper.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/IDoMinesweeper.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/Program.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/Program.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/ConsoleUserInt.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/Game.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.deps.json" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.deps.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/bin/Debug/netcoreapp3.0/IDoMinesweeper.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.assets.cache" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.assets.cache" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.csproj.FileListAbsolute.txt" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.csproj.FileListAbsolute.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.csprojAssemblyReference.cache" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.csprojAssemblyReference.cache" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.csprojAssemblyReference.cache" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.csprojAssemblyReference.cache" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.dll" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.dll" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.dll" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.pdb" afterDir="false" /> <change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.pdb" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/Debug/netcoreapp3.0/IDoMinesweeper.pdb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/IDoMinesweeper.csproj.nuget.cache" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/IDoMinesweeper.csproj.nuget.cache" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/IDoMinesweeper.csproj.nuget.dgspec.json" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/IDoMinesweeper.csproj.nuget.dgspec.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/project.assets.json" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/project.assets.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDoMinesweeper/obj/project.packagespec.json" beforeDir="false" afterPath="$PROJECT_DIR$/IDoMinesweeper/obj/project.packagespec.json" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
...@@ -75,8 +63,8 @@ ...@@ -75,8 +63,8 @@
<option value="$PROJECT_DIR$/Game/GameSettings.cs" /> <option value="$PROJECT_DIR$/Game/GameSettings.cs" />
<option value="$PROJECT_DIR$/Game/GameConfigHandler.cs" /> <option value="$PROJECT_DIR$/Game/GameConfigHandler.cs" />
<option value="$PROJECT_DIR$/JsonTest/Class1.cs" /> <option value="$PROJECT_DIR$/JsonTest/Class1.cs" />
<option value="$PROJECT_DIR$/ConsoleUserInt/GameUI.cs" />
<option value="$PROJECT_DIR$/IDoMinesweeper/Program.cs" /> <option value="$PROJECT_DIR$/IDoMinesweeper/Program.cs" />
<option value="$PROJECT_DIR$/ConsoleUserInt/GameUI.cs" />
<option value="$PROJECT_DIR$/Game/Engine.cs" /> <option value="$PROJECT_DIR$/Game/Engine.cs" />
</list> </list>
</option> </option>
...@@ -144,7 +132,7 @@ ...@@ -144,7 +132,7 @@
<workItem from="1571052402368" duration="4070000" /> <workItem from="1571052402368" duration="4070000" />
<workItem from="1571651125428" duration="10380000" /> <workItem from="1571651125428" duration="10380000" />
<workItem from="1571827801729" duration="8314000" /> <workItem from="1571827801729" duration="8314000" />
<workItem from="1571984846202" duration="21683000" /> <workItem from="1571984846202" duration="33205000" />
</task> </task>
<task id="LOCAL-00001" summary="yes"> <task id="LOCAL-00001" summary="yes">
<created>1570973690674</created> <created>1570973690674</created>
...@@ -188,7 +176,21 @@ ...@@ -188,7 +176,21 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1572070201697</updated> <updated>1572070201697</updated>
</task> </task>
<option name="localTasksCounter" value="7" /> <task id="LOCAL-00007" summary="yes">
<created>1572111833461</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1572111833462</updated>
</task>
<task id="LOCAL-00008" summary="yes">
<created>1572111834021</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1572111834021</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
......
...@@ -8,12 +8,21 @@ namespace ConsoleUserInt ...@@ -8,12 +8,21 @@ namespace ConsoleUserInt
{ {
public static class GameUI public static class GameUI
{ {
private static readonly string _verticalSeparator = "┇"; private static readonly string _verticalSeparator = "┇";
private static readonly string _horizontalSeparator = "-"; private static readonly string _horizontalSeparator = "-";
private static readonly string _centerSeparator = "◉"; private static readonly string _centerSeparator = "◉";
public static void PrintBoard(Engine.BoardDim game) public static void PrintBoard(Engine.BoardDim game)
{ {
var g = new Engine.BoardDim.Mines();
// g.GetMineCount();
var board = game.GetBoard(); var board = game.GetBoard();
for (int yIndex = 0; yIndex < game.BoardHeight; yIndex++) for (int yIndex = 0; yIndex < game.BoardHeight; yIndex++)
{ {
...@@ -50,10 +59,14 @@ namespace ConsoleUserInt ...@@ -50,10 +59,14 @@ namespace ConsoleUserInt
public static string GetSingleState(CellState state) public static string GetSingleState(CellState state)
{ {
switch (state) switch (state)
{ {
case CellState.Empty: case CellState.Empty:
return " "; return " ";
case CellState.Mine: case CellState.Mine:
return "§"; return "§";
case CellState.Flag: case CellState.Flag:
...@@ -61,6 +74,7 @@ namespace ConsoleUserInt ...@@ -61,6 +74,7 @@ namespace ConsoleUserInt
case CellState.Hidden: case CellState.Hidden:
return "-"; return "-";
case CellState.Open: case CellState.Open:
return "O"; return "O";
default: default:
throw new InvalidEnumArgumentException("Unknown enum option!"); throw new InvalidEnumArgumentException("Unknown enum option!");
......
using System; using System;
using System.Runtime.Versioning;
using Game; using Game;
using GameEngine; using GameEngine;
namespace Engine namespace Engine
{ {
public class BoardDim public class BoardDim
{ {
private static CellState[,] Board { get; set; } public static CellState[,] Board { get; set; }
public int BoardWidth { get; } public int BoardWidth { get; }
public int BoardHeight { get; } public int BoardHeight { get; }
private static int[,] MineLoc { get; set; }
public bool mineHere { get; set; }
...@@ -38,20 +45,47 @@ namespace Engine ...@@ -38,20 +45,47 @@ namespace Engine
} }
public void Move(int posY, int posX) public void Move(int posY, int posX)
{ {
if (MineLoc[posY, posX] == 1)
{
Board[posY, posX] = CellState.Mine;
}
mineHere = Board[posY, posX] == (CellState) MineLoc[posY,posX];
if (Board[posY, posX] != CellState.Empty) if (Board[posY, posX] != CellState.Empty)
{ {
return; return;
} }
Board[posY, posX] = CellState.Open; Board[posY, posX] = CellState.Open;
} }
...@@ -63,63 +97,90 @@ namespace Engine ...@@ -63,63 +97,90 @@ namespace Engine
} }
public class Mines
{
}
public class Mines
{
public int[,] MineLoc { get; set; }
public int minePosY { get; }
public int minePosX { get; }
public int minePosY { get; set; }
public int minePosX { get; set; }
private static Random random = new Random(); private static Random random = new Random();
public static int[,] MinesSetter(int height, int width) public static int[,] MinesSetter(int height, int width)
{ {
int mineCount = 0; int mineCount = 0;
int numOfMines = height * width / 6; int numOfMines = height * width / 6;
//int[,] mineLoc = new int[width, height]; //int[,] mineLoc = new int[width, height];
int[,] mineLoc = new int[width, height]; MineLoc = new int[width, height];
{
do
{ {
int minePosY = random.Next(width); do
int minePosX = random.Next(height); {
int minePosY = random.Next(width);
int minePosX = random.Next(height);
// Make sure we haven't already set this position // Make sure we haven't already set this position
if (mineLoc[minePosY, minePosX] != 1) if (MineLoc[minePosY, minePosX] != 1)
{ {
mineLoc[minePosY, minePosX] = 1; MineLoc[minePosY, minePosX] = 1;
mineCount++; mineCount++;
} }
} while (mineCount <= numOfMines); } while (mineCount <= numOfMines);
}
Console.WriteLine($"There are {numOfMines} mines");
Console.WriteLine(MineLoc.Length);
/*foreach (var x in mineLoc)
{
Console.WriteLine(mineCount);
}
*/
return MineLoc;
} }
Console.WriteLine($"There are {numOfMines} mines");
Console.WriteLine(mineLoc.Length);
/*foreach (var x in mineLoc)
public int GetMineCount(int posY, int posX)
{ {
Console.WriteLine(mineCount); int count = 0;
} if (Board[posY-1, posX-1] == CellState.Mine)
*/ count++;
if (Board[posY, posX-1] == CellState.Mine)
count++;
if (Board[posY + 1, posX - 1] == CellState.Mine)
count++;
if (Board[posY + 1, posX] == CellState.Mine)
count++;
if (Board[posY + 1, posX + 1] == CellState.Mine)
count++;
if (Board[posY, posX+1] == CellState.Mine)
count++;
if (Board[posY-1, posX+1] == CellState.Mine)
count++;
if (Board[posY-1, posX] == CellState.Mine)
count++;
return count;
return mineLoc; }
} }
......
...@@ -32,17 +32,18 @@ namespace IDoMinesweeper ...@@ -32,17 +32,18 @@ namespace IDoMinesweeper
{ {
"1", new MenuItem() "1", new MenuItem()
{ {
Title = "Level 1", Title = "Play now",
CommandToExecute = TestGame CommandToExecute = TestGame
} }
}, },
{ /*{
"2", new MenuItem() "2", new MenuItem()
{ {
Title = "Level 2", Title = "Level 2",
CommandToExecute = OldTestGame CommandToExecute = OldTestGame
} }
}, },
*/
{ {
"3", new MenuItem() "3", new MenuItem()
...@@ -117,16 +118,51 @@ namespace IDoMinesweeper ...@@ -117,16 +118,51 @@ namespace IDoMinesweeper
return ""; return "";
} }
static string TestGame() static string TestGame()
{ {
var game = new BoardDim(_settings); var game = new BoardDim(_settings);
GameUI.PrintBoard(game); //GameUI.PrintBoard(game);
Mines.MinesSetter(_settings.BoardHeight, _settings.BoardWidth);
Console.WriteLine(); Console.WriteLine();
var done = false;
do
{
Console.Clear();
GameUI.PrintBoard(game);
BoardDim.Mines.MinesSetter(_settings.BoardHeight, _settings.BoardWidth);
var userXint = 0;
var userYint = 0;
var userCanceled = false;
(userYint, userCanceled) = GetUserIntInput("Enter Y coordinate", 1, 30, 0);
if (!userCanceled)
{
(userXint, userCanceled) = GetUserIntInput("Enter X coordinate", 1, 30, 0);
}
if (userYint > _settings.BoardHeight || userXint > _settings.BoardWidth)
{
Console.WriteLine("Out of Range");
}
if (userCanceled)
{
done = true;
}
else
{
game.Move(userYint - 1, userXint - 1);
}
} while (!done);
...@@ -189,25 +225,29 @@ namespace IDoMinesweeper ...@@ -189,25 +225,29 @@ namespace IDoMinesweeper
} }
static (int result, bool wasCanceled) GetUserIntInput(string prompt, int min, int max, public static (int result, bool wasCanceled) GetUserIntInput(string prompt, int min, int max,
int? cancelIntValue = null, string cancelStrValue = "") int? cancelIntValue = null, string cancelStrValue = "")
{ {
do do
{ {
Console.WriteLine(prompt); Console.WriteLine(prompt);
if (cancelIntValue.HasValue || !string.IsNullOrWhiteSpace(cancelStrValue)) if (cancelIntValue.HasValue || !string.IsNullOrWhiteSpace(cancelStrValue) )
{ {
Console.WriteLine($"To cancel input enter: {cancelIntValue}" + Console.WriteLine($"To cancel input enter: {cancelIntValue}" +
$"{(cancelIntValue.HasValue && !string.IsNullOrWhiteSpace(cancelStrValue) ? " or " : "")}" + $"{(cancelIntValue.HasValue && !string.IsNullOrWhiteSpace(cancelStrValue) ? " or " : "")}" +
$"{cancelStrValue}"); $"{cancelStrValue}");
} }
Console.Write(">"); Console.Write(">");
var consoleLine = Console.ReadLine(); var consoleLine = Console.ReadLine();
if (consoleLine == cancelStrValue) return (0, true); if (consoleLine == cancelStrValue) return (0, true);
if (int.TryParse(consoleLine, out var userInt)) if (int.TryParse(consoleLine, out var userInt) )
{ {
return userInt == cancelIntValue ? (userInt, true) : (userInt, false); return userInt == cancelIntValue ? (userInt, true) : (userInt, false);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment