diff --git a/testexetrisathlon/Program.cs b/testexetrisathlon/Program.cs
index 0c9ee9d..a7ec021 100644
--- a/testexetrisathlon/Program.cs
+++ b/testexetrisathlon/Program.cs
@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Media;
using System.Reflection;
using static System.Console;
+using System.Runtime.InteropServices;
//┌─┐
//│ │
@@ -28,6 +29,11 @@ namespace testexetrisathlon
{
class Program
{
+ [DllImport("winmm.dll")]
+ static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
+
+ [DllImport("winmm.dll")]
+ static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
public static string sqr = "■";
public static int[,] grid = new int[23, 10];
public static int[,] droppedtetrominoeLocationGrid = new int[23, 10];
@@ -69,8 +75,31 @@ namespace testexetrisathlon
Clear();
}
enum GameState { exit, menu, game, gameOver }
+ void DrawSymbol()
+ {
+ SetCursorPosition(0, 1);
+ Write(
+ " ▀▀▀██████▄▄▄\r\n" +
+ " ▀▀▀████▄\r\n" +
+ " ▄███████▀ ▀███▄\r\n" +
+ " ▄███████▀ ▀███▄\r\n" +
+ " ▄████████ ███▄\r\n" +
+ " ██████████▄ ███▌\r\n" +
+ " ▀█████▀ ▀███▄ ▐███\r\n" +
+ " ▀█▀ ▀███▄ ▐███\r\n" +
+ " ▀███▄ ███▌\r\n" +
+ " ▄██▄ ▀███▄ ▐███\r\n" +
+ " ▄██████▄ ▀███▄███\r\n" +
+ " █████▀▀████▄▄ ▄█████\r\n" +
+ " ████▀ ▀▀█████▄▄▄▄█████████▄\r\n" +
+ " ▀▀ ▀▀██████▀▀ ▀▀██\r\n\r\n" +
+
+ " testexetrisathlon v." + assembly.GetName().Version.ToString());
+ }
void MainN(SoundPlayer intro, SoundPlayer inGame, SoundPlayer gameOver)
{
+ int NewVolume = (ushort.MaxValue / 10) * SettingsMan.Volume;
+ waveOutSetVolume(IntPtr.Zero, ((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
bool playing = true;
GameState state = GameState.menu;
try
@@ -83,36 +112,21 @@ namespace testexetrisathlon
Clear();
gameOver.Stop();
intro.PlayLooping();
- SetCursorPosition(0, 1);
- Write(
- " ▀▀▀██████▄▄▄\r\n" +
- " ▀▀▀████▄\r\n" +
- " ▄███████▀ ▀███▄\r\n" +
- " ▄███████▀ ▀███▄\r\n" +
- " ▄████████ ███▄\r\n" +
- " ██████████▄ ███▌\r\n" +
- " ▀█████▀ ▀███▄ ▐███\r\n" +
- " ▀█▀ ▀███▄ ▐███\r\n" +
- " ▀███▄ ███▌\r\n" +
- " ▄██▄ ▀███▄ ▐███\r\n" +
- " ▄██████▄ ▀███▄███\r\n" +
- " █████▀▀████▄▄ ▄█████\r\n" +
- " ████▀ ▀▀█████▄▄▄▄█████████▄\r\n" +
- " ▀▀ ▀▀██████▀▀ ▀▀██\r\n\r\n" +
-
- " testexetrisathlon v." + assembly.GetName().Version.ToString());
+ DrawSymbol();
SetCursorPosition(10, 18);
- WriteLine("Controls: Space");
+ Write("Controls: Space");
SetCursorPosition(11, 19);
- WriteLine("Up, Down, Right");
+ Write("Up, Down, Right");
SetCursorPosition(11, 20);
- WriteLine("Left");
+ Write("Left");
SetCursorPosition(10, 22);
- WriteLine("Press s to start");
+ Write("Press s to start");
SetCursorPosition(10, 23);
- WriteLine("Press x to exit");
+ Write("Press x to exit");
+ SetCursorPosition(10, 24);
+ Write("Press v for settings");
SetCursorPosition(0, 26);
- WriteLine("Icon made by Freepik from www.flaticon.com");
+ Write("Icon made by Freepik from www.flaticon.com");
string tmp = ReadKey(true).KeyChar.ToString().ToLower();
switch (tmp)
{
@@ -125,6 +139,30 @@ namespace testexetrisathlon
case "x":
state = GameState.exit;
break;
+ case "v":
+ Clear();
+ DrawSymbol();
+ bool barActive = true;
+ while (barActive)
+ {
+ SetCursorPosition(3, 20);
+ Write("Volume: " + new string('=', SettingsMan.Volume * 2) + "[" + SettingsMan.Volume.ToString("00") + "]" + new string('=', 20 - (SettingsMan.Volume * 2)));
+ switch (ReadKey().Key)
+ {
+ case ConsoleKey.LeftArrow:
+ SettingsMan.Volume--;
+ break;
+ case ConsoleKey.RightArrow:
+ SettingsMan.Volume++;
+ break;
+ case ConsoleKey.Enter:
+ barActive = false;
+ break;
+ }
+ NewVolume = (ushort.MaxValue / 10) * SettingsMan.Volume;
+ waveOutSetVolume(IntPtr.Zero, ((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
+ }
+ break;
}
break;
case GameState.game:
diff --git a/testexetrisathlon/SettingsMan.cs b/testexetrisathlon/SettingsMan.cs
new file mode 100644
index 0000000..93e8d6b
--- /dev/null
+++ b/testexetrisathlon/SettingsMan.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace testexetrisathlon
+{
+ static class SettingsMan
+ {
+ static XElement doc;
+ static string xmlfile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Save.xml";
+ public static int Volume
+ {
+ get {
+ if (doc == null)
+ Load();
+ return toRange(int.Parse(doc.Element("Save").Element("Volume").Value), 0, 10);
+ }
+ set {
+ doc.Element("Save").Element("Volume").Value = toRange(value, 0, 10).ToString();
+ Save();
+ }
+ }
+ public static int HighScore
+ {
+ get {
+ if (doc == null)
+ Load();
+ return int.Parse(doc.Element("Save").Element("HighScore").Value);
+ }
+ set {
+ doc.Element("Save").Element("HighScore").Value = value.ToString();
+ Save();
+ }
+ }
+ static void Save() => doc.Save(xmlfile);
+ static void Load()
+ {
+ if (!File.Exists(xmlfile))
+ new XElement("Save", new XElement("Volume", 10), new XElement("HighScore", 0)).Save(xmlfile);
+ doc = XDocument.Load(xmlfile).Root;
+ if (doc.Element("Save") == null)
+ doc.Add(new XElement("Save"));
+ if (doc.Element("Save").Element("Volume") == null)
+ doc.Element("Save").Add(new XElement("Volume", 10));
+ if (doc.Element("Save").Element("HighScore") == null)
+ doc.Element("Save").Add(new XElement("HighScore", 10));
+ }
+
+ static int toRange(int value, int rangeStart, int rangeEnd) => Math.Min(Math.Max(value, rangeStart), rangeEnd);
+ }
+}
diff --git a/testexetrisathlon/testexetrisathlon.csproj b/testexetrisathlon/testexetrisathlon.csproj
index 63f92e8..5e73d6c 100644
--- a/testexetrisathlon/testexetrisathlon.csproj
+++ b/testexetrisathlon/testexetrisathlon.csproj
@@ -71,6 +71,7 @@
+
@@ -83,6 +84,8 @@
+
+