Commit f9134b81 by adbaga

better

parent 2c9d0a76
......@@ -2,9 +2,6 @@
<project version="4">
<component name="ChangeListManager">
<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$/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" />
......@@ -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.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$/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/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/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$/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/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/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/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.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.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/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>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -75,8 +63,8 @@
<option value="$PROJECT_DIR$/Game/GameSettings.cs" />
<option value="$PROJECT_DIR$/Game/GameConfigHandler.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$/ConsoleUserInt/GameUI.cs" />
<option value="$PROJECT_DIR$/Game/Engine.cs" />
</list>
</option>
......@@ -144,7 +132,7 @@
<workItem from="1571052402368" duration="4070000" />
<workItem from="1571651125428" duration="10380000" />
<workItem from="1571827801729" duration="8314000" />
<workItem from="1571984846202" duration="21683000" />
<workItem from="1571984846202" duration="33205000" />
</task>
<task id="LOCAL-00001" summary="yes">
<created>1570973690674</created>
......@@ -188,7 +176,21 @@
<option name="project" value="LOCAL" />
<updated>1572070201697</updated>
</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 />
</component>
<component name="TypeScriptGeneratedFilesManager">
......
......@@ -8,12 +8,21 @@ namespace ConsoleUserInt
{
public static class GameUI
{
private static readonly string _verticalSeparator = "┇";
private static readonly string _horizontalSeparator = "-";
private static readonly string _centerSeparator = "◉";
public static void PrintBoard(Engine.BoardDim game)
{
var g = new Engine.BoardDim.Mines();
// g.GetMineCount();
var board = game.GetBoard();
for (int yIndex = 0; yIndex < game.BoardHeight; yIndex++)
{
......@@ -50,6 +59,10 @@ namespace ConsoleUserInt
public static string GetSingleState(CellState state)
{
switch (state)
{
case CellState.Empty:
......@@ -61,6 +74,7 @@ namespace ConsoleUserInt
case CellState.Hidden:
return "-";
case CellState.Open:
return "O";
default:
throw new InvalidEnumArgumentException("Unknown enum option!");
......
using System;
using System.Runtime.Versioning;
using Game;
using GameEngine;
namespace Engine
{
public class BoardDim
{
private static CellState[,] Board { get; set; }
public static CellState[,] Board { get; set; }
public int BoardWidth { get; }
public int BoardHeight { get; }
private static int[,] MineLoc { get; set; }
public bool mineHere { get; set; }
......@@ -40,44 +47,63 @@ namespace Engine
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)
{
return;
}
Board[posY, posX] = CellState.Open;
}
public CellState[,] GetBoard()
{
var result = new CellState[BoardHeight, BoardWidth];
Array.Copy(Board, result, Board.Length);
return result;
}
public CellState[,] GetBoard()
{
var result = new CellState[BoardHeight, BoardWidth];
Array.Copy(Board, result, Board.Length);
return result;
}
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();
......@@ -90,7 +116,7 @@ namespace Engine
int[,] mineLoc = new int[width, height];
MineLoc = new int[width, height];
{
do
{
......@@ -99,9 +125,9 @@ namespace Engine
// 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++;
}
......@@ -109,18 +135,53 @@ namespace Engine
} while (mineCount <= numOfMines);
}
Console.WriteLine($"There are {numOfMines} mines");
Console.WriteLine(mineLoc.Length);
Console.WriteLine(MineLoc.Length);
/*foreach (var x in mineLoc)
{
Console.WriteLine(mineCount);
}
*/
return mineLoc;
return MineLoc;
}
public int GetMineCount(int posY, int posX)
{
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;
}
}
......
......@@ -32,17 +32,18 @@ namespace IDoMinesweeper
{
"1", new MenuItem()
{
Title = "Level 1",
Title = "Play now",
CommandToExecute = TestGame
}
},
{
/*{
"2", new MenuItem()
{
Title = "Level 2",
CommandToExecute = OldTestGame
}
},
*/
{
"3", new MenuItem()
......@@ -119,15 +120,50 @@ namespace IDoMinesweeper
static string TestGame()
{
var game = new BoardDim(_settings);
GameUI.PrintBoard(game);
Mines.MinesSetter(_settings.BoardHeight, _settings.BoardWidth);
//GameUI.PrintBoard(game);
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);
return "GAME OVER!!";
......@@ -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 = "")
{
do
{
Console.WriteLine(prompt);
if (cancelIntValue.HasValue || !string.IsNullOrWhiteSpace(cancelStrValue))
if (cancelIntValue.HasValue || !string.IsNullOrWhiteSpace(cancelStrValue) )
{
Console.WriteLine($"To cancel input enter: {cancelIntValue}" +
$"{(cancelIntValue.HasValue && !string.IsNullOrWhiteSpace(cancelStrValue) ? " or " : "")}" +
$"{cancelStrValue}");
}
Console.Write(">");
var consoleLine = Console.ReadLine();
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);
}
......
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