Add alternative soundtrack and rework some stuff
This commit is contained in:
parent
8e0037aba8
commit
ee11ee4456
|
@ -1,10 +1,9 @@
|
||||||
#Soundtrack data
|
#Soundtrack data
|
||||||
Soundtrack.aup
|
testexetrisathlon/*.wav
|
||||||
Soundtrack_data/*
|
|
||||||
|
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/csharp,visualstudio
|
# Created by https://www.gitignore.io/api/rider,csharp,visualstudio
|
||||||
# Edit at https://www.gitignore.io/?templates=csharp,visualstudio
|
# Edit at https://www.gitignore.io/?templates=rider,csharp,visualstudio
|
||||||
|
|
||||||
### Csharp ###
|
### Csharp ###
|
||||||
## Ignore Visual Studio temporary files, build results, and
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
@ -77,7 +76,6 @@ StyleCopReport.xml
|
||||||
*_p.c
|
*_p.c
|
||||||
*_h.h
|
*_h.h
|
||||||
*.ilk
|
*.ilk
|
||||||
*.meta
|
|
||||||
*.obj
|
*.obj
|
||||||
*.iobj
|
*.iobj
|
||||||
*.pch
|
*.pch
|
||||||
|
@ -357,6 +355,76 @@ healthchecksdb
|
||||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
MigrationBackup/
|
MigrationBackup/
|
||||||
|
|
||||||
|
### Rider ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
### VisualStudio ###
|
### VisualStudio ###
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
|
@ -513,4 +581,4 @@ MigrationBackup/
|
||||||
|
|
||||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
|
||||||
# End of https://www.gitignore.io/api/csharp,visualstudio
|
# End of https://www.gitignore.io/api/rider,csharp,visualstudio
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectNotificationSettings">
|
||||||
|
<option name="askShowProject" value="false" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ContentModelUserStore">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.testexetrisathlon/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.testexetrisathlon/riderModule.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RiderProjectSettingsUpdater">
|
||||||
|
<option name="vcsConfiguration" value="1" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="RIDER_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$/../.." />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,51 @@
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
import wave
|
||||||
|
import youtube_dl
|
||||||
|
|
||||||
|
|
||||||
|
os.chdir("testexetrisathlon")
|
||||||
|
|
||||||
|
def dl_vid(url, outfile):
|
||||||
|
ydl_opts = {
|
||||||
|
'outtmpl': outfile,
|
||||||
|
'noplaylist': True,
|
||||||
|
'continue_dl': True,
|
||||||
|
'postprocessors': [{
|
||||||
|
'key': 'FFmpegExtractAudio',
|
||||||
|
'preferredcodec': 'wav' }]
|
||||||
|
}
|
||||||
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
ydl.download([url])
|
||||||
|
|
||||||
|
def merge_vids(infiles, outfile):
|
||||||
|
data= []
|
||||||
|
for infile in infiles:
|
||||||
|
w = wave.open(infile + ".wav", 'rb')
|
||||||
|
data.append( [w.getparams(), w.readframes(w.getnframes())] )
|
||||||
|
w.close()
|
||||||
|
os.remove(infile + ".wav")
|
||||||
|
|
||||||
|
output = wave.open(outfile + ".wav", 'wb')
|
||||||
|
output.setparams(data[0][0])
|
||||||
|
output.writeframes(data[0][1])
|
||||||
|
output.writeframes(data[1][1])
|
||||||
|
output.close()
|
||||||
|
|
||||||
|
if not os.path.isfile("Intro.wav"):
|
||||||
|
dl_vid("https://youtu.be/U06jlgpMtQs", "Intro")
|
||||||
|
|
||||||
|
if not os.path.isfile("InGame1.wav"):
|
||||||
|
dl_vid("https://youtu.be/hueJrl83sOQ", "st1")
|
||||||
|
dl_vid("https://youtu.be/7gSS4h47rLU", "st2")
|
||||||
|
dl_vid("https://youtu.be/NDjDgvXlfVw", "st3")
|
||||||
|
merge_vids(["st1", "st2", "st3"], "InGame1")
|
||||||
|
|
||||||
|
if not os.path.isfile("InGame2.wav"):
|
||||||
|
dl_vid("https://youtu.be/umEDct4BoGc", "st1")
|
||||||
|
dl_vid("https://youtu.be/NVpjt9gHlDw", "st2")
|
||||||
|
dl_vid("https://youtu.be/zgKazTrhXmI", "st3")
|
||||||
|
merge_vids(["st1", "st2", "st3"], "InGame2")
|
||||||
|
|
||||||
|
if not os.path.isfile("GameOver.wav"):
|
||||||
|
dl_vid("https://youtu.be/J_3Zad-e9f4", "GameOver")
|
|
@ -0,0 +1,8 @@
|
||||||
|
import pkg_resources
|
||||||
|
from subprocess import call
|
||||||
|
|
||||||
|
|
||||||
|
packages = [dist.project_name for dist in pkg_resources.working_set]
|
||||||
|
if not "youtube-dl" in packages:
|
||||||
|
packages += ["youtube-dl"]
|
||||||
|
call("pip install --upgrade " + ' '.join(packages), shell=True)
|
|
@ -1 +1,3 @@
|
||||||
# testexetrisathlon
|
# testexetrisathlon
|
||||||
|
To download the files required for building, just run DownloadData.py
|
||||||
|
If you don't have youtube-dl installed (or it is outdated), just run DownloadDataDepsInstall.py
|
|
@ -0,0 +1,5 @@
|
||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Freepik/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=testexetrisathlon/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tetrominoe/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=winmm/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
#define WINDOWS
|
||||||
using System.Linq;
|
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Media;
|
using System.Media;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -27,95 +29,74 @@ using static System.Console;
|
||||||
|
|
||||||
namespace testexetrisathlon
|
namespace testexetrisathlon
|
||||||
{
|
{
|
||||||
class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
public const string Sqr = "■";
|
||||||
|
public static int[,] Grid = new int[23, 10];
|
||||||
|
public static int[,] DroppedTetrominoeLocationGrid = new int[23, 10];
|
||||||
|
private static Stopwatch _dropTimer = new Stopwatch();
|
||||||
|
private static int _dropTime;
|
||||||
|
private static int _dropRate = 300;
|
||||||
|
public static bool IsDropped;
|
||||||
|
private static Tetrominoe _tet;
|
||||||
|
private static Tetrominoe _nextTet;
|
||||||
|
private static ConsoleKeyInfo _key;
|
||||||
|
private static bool _isKeyPressed;
|
||||||
|
private static int _linesCleared;
|
||||||
|
private static int _score;
|
||||||
|
private static int _level = 1;
|
||||||
|
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
|
||||||
|
private static readonly ConsoleColor[] Colors = {BackgroundColor, ForegroundColor};
|
||||||
|
public static bool Debug;
|
||||||
|
public static readonly Random Rnd = new Random();
|
||||||
|
private static readonly SoundPlayer Intro =
|
||||||
|
new SoundPlayer(Assembly.GetManifestResourceStream("testexetrisathlon.Intro.wav"));
|
||||||
|
private static readonly SoundPlayer InGame1 =
|
||||||
|
new SoundPlayer(Assembly.GetManifestResourceStream("testexetrisathlon.InGame1.wav"));
|
||||||
|
private static readonly SoundPlayer InGame2 =
|
||||||
|
new SoundPlayer(Assembly.GetManifestResourceStream("testexetrisathlon.InGame2.wav"));
|
||||||
|
private static readonly SoundPlayer GameOver =
|
||||||
|
new SoundPlayer(Assembly.GetManifestResourceStream("testexetrisathlon.GameOver.wav"));
|
||||||
|
private static SoundPlayer _inGame = SettingsMan.UsingAltTrack ? InGame2 : InGame1;
|
||||||
|
#if WINDOWS
|
||||||
[DllImport("winmm.dll")]
|
[DllImport("winmm.dll")]
|
||||||
static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
|
private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
|
||||||
|
#endif
|
||||||
|
|
||||||
[DllImport("winmm.dll")]
|
#if DEBUG
|
||||||
static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
|
private static void Main()
|
||||||
public static string sqr = "■";
|
|
||||||
public static int[,] grid = new int[23, 10];
|
|
||||||
public static int[,] droppedtetrominoeLocationGrid = new int[23, 10];
|
|
||||||
public static Stopwatch dropTimer = new Stopwatch();
|
|
||||||
public static Stopwatch inputTimer = new Stopwatch();
|
|
||||||
public static int dropTime, dropRate = 300;
|
|
||||||
public static bool isDropped = false;
|
|
||||||
static Tetrominoe tet;
|
|
||||||
static Tetrominoe nexttet;
|
|
||||||
public static ConsoleKeyInfo key;
|
|
||||||
public static bool isKeyPressed = false;
|
|
||||||
public static int linesCleared = 0, score = 0, level = 1;
|
|
||||||
static readonly Assembly assembly = Assembly.GetExecutingAssembly();
|
|
||||||
static ConsoleColor[] colors;
|
|
||||||
public static bool debug;
|
|
||||||
public static Random rnd;
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
{
|
||||||
rnd = new Random();
|
Debug = true;
|
||||||
colors = new ConsoleColor[2] { BackgroundColor, ForegroundColor };
|
#else
|
||||||
|
private static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Debug = args.Contains("debug");
|
||||||
|
#endif
|
||||||
BackgroundColor = ConsoleColor.Red;
|
BackgroundColor = ConsoleColor.Red;
|
||||||
ForegroundColor = ConsoleColor.Yellow;
|
ForegroundColor = ConsoleColor.Yellow;
|
||||||
SetWindowSize(42, 29);
|
SetWindowSize(42, 29);
|
||||||
SetCursorPosition(0, 0);
|
SetCursorPosition(0, 0);
|
||||||
Clear();
|
Clear();
|
||||||
#if (DEBUG)
|
if (Debug)
|
||||||
debug = true;
|
|
||||||
#else
|
|
||||||
debug = args.Contains("debug");
|
|
||||||
#endif
|
|
||||||
if (debug)
|
|
||||||
SetWindowSize(50, 40);
|
SetWindowSize(50, 40);
|
||||||
new Program().MainN(
|
#if WINDOWS
|
||||||
new SoundPlayer(assembly.GetManifestResourceStream("testexetrisathlon.Intro.wav")),
|
int newVolume = (ushort.MaxValue / 10) * SettingsMan.Volume;
|
||||||
new SoundPlayer(assembly.GetManifestResourceStream("testexetrisathlon.InGame.wav")),
|
waveOutSetVolume(IntPtr.Zero, ((uint) newVolume & 0x0000ffff) | ((uint) newVolume << 16));
|
||||||
new SoundPlayer(assembly.GetManifestResourceStream("testexetrisathlon.GameOver.wav")));
|
#endif
|
||||||
BackgroundColor = colors[0];
|
|
||||||
ForegroundColor = colors[1];
|
|
||||||
SetCursorPosition(0, 0);
|
|
||||||
Clear();
|
|
||||||
}
|
|
||||||
enum GameState { exit, menu, game, gameOver }
|
|
||||||
static 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;
|
bool playing = true;
|
||||||
GameState state = GameState.menu;
|
GameState state = GameState.Menu;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (playing)
|
while (playing)
|
||||||
{
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case GameState.menu:
|
case GameState.Menu:
|
||||||
Clear();
|
Clear();
|
||||||
gameOver.Stop();
|
GameOver.Stop();
|
||||||
intro.PlayLooping();
|
Intro.PlayLooping();
|
||||||
DrawSymbol();
|
DrawSymbol();
|
||||||
SetCursorPosition(12, 18);
|
SetCursorPosition(12, 18);
|
||||||
Write("Highscore: " + SettingsMan.HighScore.ToString());
|
Write("HighScore: " + SettingsMan.HighScore);
|
||||||
SetCursorPosition(12, 20);
|
SetCursorPosition(12, 20);
|
||||||
Write("Controls: Space");
|
Write("Controls: Space");
|
||||||
SetCursorPosition(13, 21);
|
SetCursorPosition(13, 21);
|
||||||
|
@ -134,43 +115,43 @@ namespace testexetrisathlon
|
||||||
switch (tmp)
|
switch (tmp)
|
||||||
{
|
{
|
||||||
case "s":
|
case "s":
|
||||||
intro.Stop();
|
Intro.Stop();
|
||||||
state = GameState.game;
|
state = GameState.Game;
|
||||||
Clear();
|
Clear();
|
||||||
DrawBorder();
|
DrawBorder();
|
||||||
break;
|
break;
|
||||||
case "x":
|
case "x":
|
||||||
state = GameState.exit;
|
state = GameState.Exit;
|
||||||
break;
|
break;
|
||||||
case "v":
|
case "v":
|
||||||
VolumeSlider();
|
SettingsMenu();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GameState.game:
|
case GameState.Game:
|
||||||
inGame.PlayLooping();
|
_inGame.PlayLooping();
|
||||||
dropTimer.Start();
|
_dropTimer.Start();
|
||||||
SetCursorPosition(25, 0);
|
SetCursorPosition(25, 0);
|
||||||
WriteLine("Level " + level);
|
WriteLine("Level " + _level);
|
||||||
SetCursorPosition(25, 1);
|
SetCursorPosition(25, 1);
|
||||||
WriteLine("Score " + score + "/" + (Math.Pow(level, 2) * 100).ToString());
|
WriteLine("Score " + _score + "/" + (Math.Pow(_level, 2) * 100));
|
||||||
SetCursorPosition(25, 2);
|
SetCursorPosition(25, 2);
|
||||||
WriteLine("LinesCleared " + linesCleared);
|
WriteLine("LinesCleared " + _linesCleared);
|
||||||
SetCursorPosition(25, 4);
|
SetCursorPosition(25, 4);
|
||||||
WriteLine("Highscore " + SettingsMan.HighScore);
|
WriteLine("HighScore " + SettingsMan.HighScore);
|
||||||
nexttet = new Tetrominoe();
|
_nextTet = new Tetrominoe();
|
||||||
tet = nexttet;
|
_tet = _nextTet;
|
||||||
tet.Spawn();
|
_tet.Spawn();
|
||||||
nexttet = new Tetrominoe();
|
_nextTet = new Tetrominoe();
|
||||||
Update();
|
Update();
|
||||||
inGame.Stop();
|
_inGame.Stop();
|
||||||
state = GameState.gameOver;
|
state = GameState.GameOver;
|
||||||
break;
|
break;
|
||||||
case GameState.gameOver:
|
case GameState.GameOver:
|
||||||
SettingsMan.HighScore = score;
|
SettingsMan.HighScore = _score;
|
||||||
gameOver.PlayLooping();
|
GameOver.PlayLooping();
|
||||||
string input = "";
|
string input = "";
|
||||||
while ((input != "y") && (input != "n"))
|
while (input != "y" && input != "n")
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
DrawBorder();
|
DrawBorder();
|
||||||
|
@ -182,87 +163,148 @@ namespace testexetrisathlon
|
||||||
WriteLine("├───────────────────┤");
|
WriteLine("├───────────────────┤");
|
||||||
input = ReadKey().KeyChar.ToString().ToLower();
|
input = ReadKey().KeyChar.ToString().ToLower();
|
||||||
}
|
}
|
||||||
grid = new int[23, 10];
|
Grid = new int[23, 10];
|
||||||
droppedtetrominoeLocationGrid = new int[23, 10];
|
DroppedTetrominoeLocationGrid = new int[23, 10];
|
||||||
dropTimer = new Stopwatch();
|
_dropTimer = new Stopwatch();
|
||||||
inputTimer = new Stopwatch();
|
_dropRate = 300;
|
||||||
dropRate = 300;
|
IsDropped = false;
|
||||||
isDropped = false;
|
_isKeyPressed = false;
|
||||||
isKeyPressed = false;
|
_linesCleared = 0;
|
||||||
linesCleared = 0;
|
_score = 0;
|
||||||
score = 0;
|
_level = 1;
|
||||||
level = 1;
|
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
Clear();
|
Clear();
|
||||||
DrawBorder();
|
DrawBorder();
|
||||||
if (input == "y")
|
state = input == "y" ? GameState.Game : GameState.Menu;
|
||||||
state = GameState.game;
|
|
||||||
else
|
|
||||||
state = GameState.menu;
|
|
||||||
break;
|
break;
|
||||||
default:
|
case GameState.Exit:
|
||||||
playing = false;
|
playing = false;
|
||||||
break;
|
break;
|
||||||
|
default: throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
intro.Dispose();
|
Intro.Dispose();
|
||||||
inGame.Dispose();
|
InGame1.Dispose();
|
||||||
gameOver.Dispose();
|
InGame2.Dispose();
|
||||||
|
GameOver.Dispose();
|
||||||
}
|
}
|
||||||
|
BackgroundColor = Colors[0];
|
||||||
|
ForegroundColor = Colors[1];
|
||||||
|
SetCursorPosition(0, 0);
|
||||||
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VolumeSlider()
|
private static 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SettingsMenu()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
DrawSymbol();
|
DrawSymbol();
|
||||||
|
#if !WINDOWS
|
||||||
|
SetCursorPosition(2, 19);
|
||||||
|
Write("Volume is not supported in this build!");
|
||||||
|
#endif
|
||||||
bool barActive = true;
|
bool barActive = true;
|
||||||
|
int currentSetting = 0;
|
||||||
while (barActive)
|
while (barActive)
|
||||||
{
|
{
|
||||||
|
bool curr = SettingsMan.UsingAltTrack;
|
||||||
SetCursorPosition(3, 20);
|
SetCursorPosition(3, 20);
|
||||||
Write("Volume: " + new string('=', SettingsMan.Volume * 2) + "[" + SettingsMan.Volume.ToString("00") + "]" + new string('=', 20 - (SettingsMan.Volume * 2)));
|
ForegroundColor = currentSetting == 0 ? ConsoleColor.White : ConsoleColor.Yellow;
|
||||||
switch (ReadKey().Key)
|
Write("Volume: " + new string('=', SettingsMan.Volume * 2) + "[" + SettingsMan.Volume.ToString("00") +
|
||||||
|
"]" + new string('=', 20 - (SettingsMan.Volume * 2)));
|
||||||
|
SetCursorPosition(5, 22);
|
||||||
|
ForegroundColor = currentSetting == 1 ? ConsoleColor.White : ConsoleColor.Yellow;
|
||||||
|
Write($"{(curr ? " Using" : "Not using")} alternative soundtrack ");
|
||||||
|
ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
switch (currentSetting)
|
||||||
{
|
{
|
||||||
case ConsoleKey.LeftArrow:
|
case 0:
|
||||||
SettingsMan.Volume--;
|
switch (ReadKey().Key)
|
||||||
|
{
|
||||||
|
case ConsoleKey.LeftArrow:
|
||||||
|
SettingsMan.Volume--;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.RightArrow:
|
||||||
|
SettingsMan.Volume++;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.Enter:
|
||||||
|
barActive = false;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.Tab:
|
||||||
|
currentSetting = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ConsoleKey.RightArrow:
|
case 1:
|
||||||
SettingsMan.Volume++;
|
switch (ReadKey().Key)
|
||||||
break;
|
{
|
||||||
case ConsoleKey.Enter:
|
case ConsoleKey.LeftArrow:
|
||||||
barActive = false;
|
case ConsoleKey.RightArrow:
|
||||||
|
case ConsoleKey.Spacebar:
|
||||||
|
SettingsMan.UsingAltTrack = !curr;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.Enter:
|
||||||
|
barActive = false;
|
||||||
|
break;
|
||||||
|
case ConsoleKey.Tab:
|
||||||
|
currentSetting = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int NewVolume = (ushort.MaxValue / 10) * SettingsMan.Volume;
|
#if WINDOWS
|
||||||
waveOutSetVolume(IntPtr.Zero, ((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
|
int newVolume = (ushort.MaxValue / 10) * SettingsMan.Volume;
|
||||||
|
waveOutSetVolume(IntPtr.Zero, ((uint) newVolume & 0x0000ffff) | ((uint) newVolume << 16));
|
||||||
|
#endif
|
||||||
|
_inGame = SettingsMan.UsingAltTrack ? InGame2 : InGame1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Update()
|
private static void Update()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
dropTime = (int)dropTimer.ElapsedMilliseconds;
|
_dropTime = (int) _dropTimer.ElapsedMilliseconds;
|
||||||
if (dropTime > dropRate)
|
if (_dropTime > _dropRate)
|
||||||
{
|
{
|
||||||
dropTime = 0; dropTimer.Restart(); tet.Drop();
|
_dropTime = 0;
|
||||||
|
_dropTimer.Restart();
|
||||||
|
_tet.Drop();
|
||||||
}
|
}
|
||||||
if (isDropped == true)
|
if (IsDropped)
|
||||||
{
|
{
|
||||||
tet = nexttet;
|
_tet = _nextTet;
|
||||||
nexttet = new Tetrominoe();
|
_nextTet = new Tetrominoe();
|
||||||
tet.Spawn();
|
_tet.Spawn();
|
||||||
isDropped = false;
|
IsDropped = false;
|
||||||
score += 10;
|
_score += 10;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < 10; j++)
|
for (int j = 0; j < 10; j++)
|
||||||
{
|
if (DroppedTetrominoeLocationGrid[0, j] == 1)
|
||||||
if (droppedtetrominoeLocationGrid[0, j] == 1)
|
|
||||||
return;
|
return;
|
||||||
}
|
if (Debug)
|
||||||
if (debug)
|
|
||||||
{
|
{
|
||||||
SetCursorPosition(0, 25);
|
SetCursorPosition(0, 25);
|
||||||
WriteLine("!DEBUG MODE ENABLED!");
|
WriteLine("!DEBUG MODE ENABLED!");
|
||||||
|
@ -271,100 +313,89 @@ namespace testexetrisathlon
|
||||||
ClearBlock();
|
ClearBlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void ClearBlock()
|
|
||||||
|
private static void ClearBlock()
|
||||||
{
|
{
|
||||||
int combo = 0;
|
int combo = 0;
|
||||||
for (int i = 0; i < 23; i++)
|
for (int i = 0; i < 23; i++)
|
||||||
{
|
if (Enumerable.Range(0, 10).All(s => DroppedTetrominoeLocationGrid[i, s] != 0))
|
||||||
if (Enumerable.Range(0, 10).Where(s => droppedtetrominoeLocationGrid[i, s] == 0).Count() == 0)
|
|
||||||
{
|
{
|
||||||
linesCleared++;
|
_linesCleared++;
|
||||||
combo++;
|
combo++;
|
||||||
Beep(400, 200);
|
Beep(400, 200);
|
||||||
for (int j = 0; j < 10; j++)
|
for (int j = 0; j < 10; j++) DroppedTetrominoeLocationGrid[i, j] = 0;
|
||||||
{
|
int[,] newDroppedTetrominoeLocationGrid = new int[23, 10];
|
||||||
droppedtetrominoeLocationGrid[i, j] = 0;
|
|
||||||
}
|
|
||||||
int[,] newdroppedtetrominoeLocationGrid = new int[23, 10];
|
|
||||||
for (int k = 1; k < i; k++)
|
for (int k = 1; k < i; k++)
|
||||||
{
|
for (int l = 0; l < 10; l++)
|
||||||
for (int l = 0; l < 10; l++)
|
newDroppedTetrominoeLocationGrid[k + 1, l] = DroppedTetrominoeLocationGrid[k, l];
|
||||||
{
|
|
||||||
newdroppedtetrominoeLocationGrid[k + 1, l] = droppedtetrominoeLocationGrid[k, l];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int k = 1; k < i; k++)
|
for (int k = 1; k < i; k++)
|
||||||
{
|
for (int l = 0; l < 10; l++)
|
||||||
for (int l = 0; l < 10; l++)
|
DroppedTetrominoeLocationGrid[k, l] = 0;
|
||||||
{
|
|
||||||
droppedtetrominoeLocationGrid[k, l] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int k = 0; k < 23; k++)
|
for (int k = 0; k < 23; k++)
|
||||||
for (int l = 0; l < 10; l++)
|
for (int l = 0; l < 10; l++)
|
||||||
if (newdroppedtetrominoeLocationGrid[k, l] == 1)
|
if (newDroppedTetrominoeLocationGrid[k, l] == 1)
|
||||||
droppedtetrominoeLocationGrid[k, l] = 1;
|
DroppedTetrominoeLocationGrid[k, l] = 1;
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
_score += (int) Math.Round(Math.Sqrt(Math.Max((combo * 50) - 50, 0)) * 5);
|
||||||
score += (int)Math.Round(Math.Sqrt(Math.Max((combo * 50) - 50, 0)) * 5);
|
_level = (int) Math.Round(Math.Sqrt(_score * 0.01)) + 1;
|
||||||
level = (int)Math.Round(Math.Sqrt(score * 0.01)) + 1;
|
_dropRate = 300 - (22 * _level);
|
||||||
dropRate = 300 - (22 * level);
|
|
||||||
}
|
}
|
||||||
static void Input()
|
|
||||||
|
private static void Input()
|
||||||
{
|
{
|
||||||
isKeyPressed = KeyAvailable;
|
_isKeyPressed = KeyAvailable;
|
||||||
SetCursorPosition(0, 24);
|
SetCursorPosition(0, 24);
|
||||||
if (isKeyPressed)
|
if (_isKeyPressed)
|
||||||
key = ReadKey();
|
_key = ReadKey();
|
||||||
if (key.Key == ConsoleKey.LeftArrow & !tet.isSomethingLeft() & isKeyPressed)
|
if ((_key.Key == ConsoleKey.LeftArrow) & !_tet.IsSomethingLeft() & _isKeyPressed)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
tet.location[i][1] -= 1;
|
_tet.Location[i][1] -= 1;
|
||||||
tet.Update();
|
_tet.Update();
|
||||||
}
|
}
|
||||||
else if (key.Key == ConsoleKey.RightArrow & !tet.isSomethingRight() & isKeyPressed)
|
else if ((_key.Key == ConsoleKey.RightArrow) & !_tet.IsSomethingRight() & _isKeyPressed)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
tet.location[i][1] += 1;
|
_tet.Location[i][1] += 1;
|
||||||
tet.Update();
|
_tet.Update();
|
||||||
}
|
}
|
||||||
if (key.Key == ConsoleKey.DownArrow & isKeyPressed)
|
if ((_key.Key == ConsoleKey.DownArrow) & _isKeyPressed)
|
||||||
tet.Drop();
|
_tet.Drop();
|
||||||
if (key.Key == ConsoleKey.UpArrow & isKeyPressed)
|
if ((_key.Key == ConsoleKey.UpArrow) & _isKeyPressed)
|
||||||
for (; tet.isSomethingBelow!= true;)
|
for (; _tet.IsSomethingBelow != true;)
|
||||||
tet.Drop();
|
_tet.Drop();
|
||||||
if (key.Key == ConsoleKey.Spacebar & isKeyPressed)
|
if ((_key.Key == ConsoleKey.Spacebar) & _isKeyPressed)
|
||||||
{
|
{
|
||||||
tet.Rotate();
|
_tet.Rotate();
|
||||||
tet.Update();
|
_tet.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw()
|
public static void Draw()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 23; ++i)
|
for (int i = 0; i < 23; ++i)
|
||||||
|
for (int j = 0; j < 10; j++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 10; j++)
|
SetCursorPosition((2 * j) + 1, i);
|
||||||
|
if ((Grid[i, j] == 1) | (DroppedTetrominoeLocationGrid[i, j] == 1))
|
||||||
{
|
{
|
||||||
SetCursorPosition((2 * j) + 1, i);
|
SetCursorPosition((2 * j) + 1, i);
|
||||||
if (grid[i, j] == 1 | droppedtetrominoeLocationGrid[i, j] == 1)
|
Write(Sqr);
|
||||||
{
|
}
|
||||||
SetCursorPosition((2 * j) + 1, i);
|
else
|
||||||
Write(sqr);
|
{
|
||||||
}
|
Write(" ");
|
||||||
else
|
|
||||||
{
|
|
||||||
Write(" ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetCursorPosition(25, 0);
|
SetCursorPosition(25, 0);
|
||||||
WriteLine("Level " + level);
|
WriteLine("Level " + _level);
|
||||||
SetCursorPosition(25, 1);
|
SetCursorPosition(25, 1);
|
||||||
WriteLine("Score " + score + "/" + (Math.Pow(level, 2) * 100).ToString());
|
WriteLine("Score " + _score + "/" + (Math.Pow(_level, 2) * 100));
|
||||||
SetCursorPosition(25, 2);
|
SetCursorPosition(25, 2);
|
||||||
WriteLine("LinesCleared " + linesCleared);
|
WriteLine("LinesCleared " + _linesCleared);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DrawBorder()
|
public static void DrawBorder()
|
||||||
{
|
{
|
||||||
for (int lengthCount = 0; lengthCount <= 22; lengthCount++)
|
for (int lengthCount = 0; lengthCount <= 22; lengthCount++)
|
||||||
|
@ -376,11 +407,16 @@ namespace testexetrisathlon
|
||||||
}
|
}
|
||||||
SetCursorPosition(0, 23);
|
SetCursorPosition(0, 23);
|
||||||
Write("└");
|
Write("└");
|
||||||
for (int widthCount = 0; widthCount <= 18; widthCount++)
|
for (int widthCount = 0; widthCount <= 18; widthCount++) Write("─");
|
||||||
{
|
|
||||||
Write("─");
|
|
||||||
}
|
|
||||||
Write("┘");
|
Write("┘");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum GameState
|
||||||
|
{
|
||||||
|
Exit,
|
||||||
|
Menu,
|
||||||
|
Game,
|
||||||
|
GameOver
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
// Information about this assembly is defined by the following attributes.
|
// Information about this assembly is defined by the following attributes.
|
||||||
// Change them to the values specific to your project.
|
// Change them to the values specific to your project.
|
||||||
|
@ -23,4 +22,4 @@ using System.Runtime.CompilerServices;
|
||||||
// if desired. See the Mono documentation for more information about signing.
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
//[assembly: AssemblyDelaySign(false)]
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
//[assembly: AssemblyKeyFile("")]
|
//[assembly: AssemblyKeyFile("")]
|
|
@ -1,56 +1,65 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace testexetrisathlon
|
namespace testexetrisathlon
|
||||||
{
|
{
|
||||||
static class SettingsMan
|
internal static class SettingsMan
|
||||||
{
|
{
|
||||||
static XElement doc;
|
private static readonly string XmlFile =
|
||||||
static string xmlfile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Save.xml";
|
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Save.xml");
|
||||||
|
|
||||||
public static int Volume
|
public static int Volume
|
||||||
{
|
{
|
||||||
get {
|
get => ToRange(int.Parse(Load().Element("Volume").Value), 0, 10);
|
||||||
if (doc == null)
|
set
|
||||||
Load();
|
{
|
||||||
return toRange(int.Parse(doc.Element("Save").Element("Volume").Value), 0, 10);
|
XElement doc = Load();
|
||||||
|
doc.Element("Volume").Value = ToRange(value, 0, 10).ToString();
|
||||||
|
doc.Save();
|
||||||
}
|
}
|
||||||
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);
|
public static int HighScore
|
||||||
|
{
|
||||||
|
get => int.Parse(Load().Element("HighScore").Value);
|
||||||
|
set
|
||||||
|
{
|
||||||
|
XElement doc = Load();
|
||||||
|
doc.Element("HighScore").Value = value.ToString();
|
||||||
|
doc.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool UsingAltTrack
|
||||||
|
{
|
||||||
|
get => bool.Parse(Load().Element("AltTrack").Value);
|
||||||
|
set
|
||||||
|
{
|
||||||
|
XElement doc = Load();
|
||||||
|
doc.Element("AltTrack").Value = value.ToString();
|
||||||
|
doc.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Save(this XElement doc) => doc.Save(XmlFile);
|
||||||
|
|
||||||
|
private static XElement Load()
|
||||||
|
{
|
||||||
|
if (!File.Exists(XmlFile))
|
||||||
|
new XElement("Save").Save(XmlFile);
|
||||||
|
XElement doc = XDocument.Load(XmlFile).Root;
|
||||||
|
if (doc.Element("Volume") == null)
|
||||||
|
doc.Add(new XElement("Volume", 10));
|
||||||
|
if (doc.Element("HighScore") == null)
|
||||||
|
doc.Add(new XElement("HighScore", 10));
|
||||||
|
if (doc.Element("AltTrack") == null)
|
||||||
|
doc.Add(new XElement("AltTrack", false));
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int ToRange(int value, int rangeStart, int rangeEnd) =>
|
||||||
|
Math.Min(Math.Max(value, rangeStart), rangeEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,184 +1,202 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security;
|
|
||||||
using static System.Console;
|
using static System.Console;
|
||||||
#pragma warning disable IDE1006
|
|
||||||
namespace testexetrisathlon
|
namespace testexetrisathlon
|
||||||
{
|
{
|
||||||
public class Tetrominoe
|
public class Tetrominoe
|
||||||
{
|
{
|
||||||
public static int[,] I = new int[1, 4] { { 1, 1, 1, 1 } };
|
private static readonly int[,] I = {{1, 1, 1, 1}};
|
||||||
|
|
||||||
public static int[,] O = new int[2, 2] { { 1, 1 },
|
private static readonly int[,] O =
|
||||||
{ 1, 1 } };
|
{
|
||||||
|
{1, 1},
|
||||||
|
{1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
public static int[,] T = new int[2, 3] { { 0, 1, 0 },
|
private static readonly int[,] T =
|
||||||
{ 1, 1, 1 } };
|
{
|
||||||
|
{0, 1, 0},
|
||||||
|
{1, 1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
public static int[,] S = new int[2, 3] { { 0, 1, 1 },
|
private static readonly int[,] S =
|
||||||
{ 1, 1, 0 } };
|
{
|
||||||
|
{0, 1, 1},
|
||||||
|
{1, 1, 0}
|
||||||
|
};
|
||||||
|
|
||||||
public static int[,] Z = new int[2, 3] { { 1, 1, 0 },
|
private static readonly int[,] Z =
|
||||||
{ 0, 1, 1 } };
|
{
|
||||||
|
{1, 1, 0},
|
||||||
|
{0, 1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
public static int[,] J = new int[2, 3] { { 1, 0, 0 },
|
private static readonly int[,] J =
|
||||||
{ 1, 1, 1 } };
|
{
|
||||||
|
{1, 0, 0},
|
||||||
|
{1, 1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly int[,] L =
|
||||||
|
{
|
||||||
|
{0, 0, 1},
|
||||||
|
{1, 1, 1}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly List<int[,]> TetrominoeList = new List<int[,]> {I, O, T, S, Z, J, L};
|
||||||
|
private readonly int[,] _shape;
|
||||||
|
public List<int[]> Location = new List<int[]>();
|
||||||
|
|
||||||
public static int[,] L = new int[2, 3] { { 0, 0, 1 },
|
|
||||||
{ 1, 1, 1 } };
|
|
||||||
public static List<int[,]> tetrominoes = new List<int[,]>() { I, O, T, S, Z, J, L };
|
|
||||||
private readonly int[,] shape;
|
|
||||||
public List<int[]> location = new List<int[]>();
|
|
||||||
public Tetrominoe()
|
public Tetrominoe()
|
||||||
{
|
{
|
||||||
shape = tetrominoes[Program.rnd.Next(0, tetrominoes.Count)];
|
_shape = TetrominoeList[Program.Rnd.Next(0, TetrominoeList.Count)];
|
||||||
for (int i = 0; i < 7; i++)
|
for (int i = 0; i < 7; i++)
|
||||||
|
for (int j = 0; j < 2; j++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 2; j++)
|
SetCursorPosition(i + 26, j + 6);
|
||||||
{
|
Write(Program.Debug ? "X" : " ");
|
||||||
SetCursorPosition(i + 26, j + 6);
|
|
||||||
Write(Program.debug ? "X" : " ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Program.DrawBorder();
|
Program.DrawBorder();
|
||||||
for (int i = 0; i < shape.GetLength(0); i++)
|
for (int i = 0; i < _shape.GetLength(0); i++)
|
||||||
{
|
for (int j = 0; j < _shape.GetLength(1); j++)
|
||||||
for (int j = 0; j < shape.GetLength(1); j++)
|
if (_shape[i, j] == 1)
|
||||||
{
|
{
|
||||||
if (shape[i, j] == 1)
|
SetCursorPosition((30 - _shape.GetLength(1)) + (2 * j), i + 6);
|
||||||
{
|
Write(Program.Sqr);
|
||||||
SetCursorPosition(30 - shape.GetLength(1) + (2 * j), i + 6);
|
|
||||||
Write(Program.sqr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsSomethingBelow => Location.Any(s => s[0] + 1 >= 23 || (s[0] + 1 < 23) &
|
||||||
|
(Program.DroppedTetrominoeLocationGrid[s[0] + 1, s[1]] == 1));
|
||||||
|
|
||||||
public void Spawn()
|
public void Spawn()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < shape.GetLength(0); i++)
|
for (int i = 0; i < _shape.GetLength(0); i++)
|
||||||
{
|
for (int j = 0; j < _shape.GetLength(1); j++)
|
||||||
for (int j = 0; j < shape.GetLength(1); j++)
|
if (_shape[i, j] == 1)
|
||||||
{
|
Location.Add(new[] {i, (5 - (_shape.GetLength(1) / 2)) + j});
|
||||||
if (shape[i, j] == 1)
|
|
||||||
{
|
|
||||||
location.Add(new int[] { i, 5 - (shape.GetLength(1) / 2) + j });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Drop()
|
public void Drop()
|
||||||
{
|
{
|
||||||
if (isSomethingBelow)
|
if (IsSomethingBelow)
|
||||||
{
|
{
|
||||||
location.ForEach(s => Program.droppedtetrominoeLocationGrid[s[0], s[1]] = 1);
|
Location.ForEach(s => Program.DroppedTetrominoeLocationGrid[s[0], s[1]] = 1);
|
||||||
Program.isDropped = true;
|
Program.IsDropped = true;
|
||||||
Beep(800, 200);
|
Beep(800, 200);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
location.ForEach(s => s[0]++);
|
Location.ForEach(s => s[0]++);
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Rotate()
|
public void Rotate()
|
||||||
{
|
{
|
||||||
List<int[]> templocation = new List<int[]>();
|
List<int[]> tempLocation = new List<int[]>();
|
||||||
for (int i = 0; i < shape.GetLength(0); i++)
|
for (int i = 0; i < _shape.GetLength(0); i++)
|
||||||
{
|
for (int j = 0; j < _shape.GetLength(1); j++)
|
||||||
for (int j = 0; j < shape.GetLength(1); j++)
|
if (_shape[i, j] == 1)
|
||||||
{
|
tempLocation.Add(new[] {i, ((10 - _shape.GetLength(1)) / 2) + j});
|
||||||
if (shape[i, j] == 1)
|
if (_shape == TetrominoeList[1])
|
||||||
{
|
|
||||||
templocation.Add(new int[] { i, ((10 - shape.GetLength(1)) / 2) + j });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shape == tetrominoes[1])
|
|
||||||
return;
|
return;
|
||||||
for (int i = 0; i < location.Count; i++)
|
for (int i = 0; i < Location.Count; i++)
|
||||||
templocation[i] = TransformMatrix(location[i], location[(shape == tetrominoes[3]) ? 3 : 2]);
|
tempLocation[i] = TransformMatrix(Location[i], Location[_shape == TetrominoeList[3] ? 3 : 2]);
|
||||||
for (int count = 0; isOverlayLeft(templocation) != false | isOverlayRight(templocation) != false | isOverlayBelow(templocation) != false; count++)
|
for (int count = 0;
|
||||||
|
(IsOverlayLeft(tempLocation) != false) | (IsOverlayRight(tempLocation) != false) |
|
||||||
|
(IsOverlayBelow(tempLocation) != false);
|
||||||
|
count++)
|
||||||
{
|
{
|
||||||
if (isOverlayLeft(templocation) == true)
|
if (IsOverlayLeft(tempLocation) == true)
|
||||||
for (int i = 0; i < location.Count; i++)
|
for (int i = 0; i < Location.Count; i++)
|
||||||
templocation[i][1]++;
|
tempLocation[i][1]++;
|
||||||
if (isOverlayRight(templocation) == true)
|
if (IsOverlayRight(tempLocation) == true)
|
||||||
for (int i = 0; i < location.Count; i++)
|
for (int i = 0; i < Location.Count; i++)
|
||||||
templocation[i][1]--;
|
tempLocation[i][1]--;
|
||||||
if (isOverlayBelow(templocation) == true)
|
if (IsOverlayBelow(tempLocation) == true)
|
||||||
for (int i = 0; i < location.Count; i++)
|
for (int i = 0; i < Location.Count; i++)
|
||||||
templocation[i][0]--;
|
tempLocation[i][0]--;
|
||||||
if (count == 3)
|
if (count == 3)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
location = templocation;
|
Location = tempLocation;
|
||||||
}
|
}
|
||||||
public static int[] TransformMatrix(int[] coord, int[] axis) => new int[] { axis[0] - axis[1] + coord[1], axis[0] + axis[1] - coord[0] };
|
|
||||||
public bool isSomethingBelow => location.Where(s => s[0] + 1 >= 23 || s[0] + 1 < 23 & Program.droppedtetrominoeLocationGrid[s[0] + 1, s[1]] == 1).Count() > 0;
|
private static int[] TransformMatrix(IReadOnlyList<int> coords, IReadOnlyList<int> axis) =>
|
||||||
public static bool? isOverlayBelow(List<int[]> location)
|
new[] {(axis[0] - axis[1]) + coords[1], (axis[0] + axis[1]) - coords[0]};
|
||||||
|
|
||||||
|
private static bool? IsOverlayBelow(IReadOnlyList<int[]> location)
|
||||||
{
|
{
|
||||||
List<int> ycoords = new List<int>();
|
List<int> yCoords = new List<int>();
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
ycoords.Add(location[i][0]);
|
yCoords.Add(location[i][0]);
|
||||||
if (location[i][0] >= 23)
|
if (location[i][0] >= 23)
|
||||||
return true;
|
return true;
|
||||||
if (location[i][0] < 0 | location[i][1] < 0 | location[i][1] > 9)
|
if ((location[i][0] < 0) | (location[i][1] < 0) | (location[i][1] > 9))
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return location.Where(s => (ycoords.Max() - ycoords.Min() == 3) ?
|
return location.Any(s =>
|
||||||
((ycoords.Max() == s[0] | ycoords.Max() - 1 == s[0]) & (Program.droppedtetrominoeLocationGrid[s[0], s[1]] == 1)) :
|
yCoords.Max() - yCoords.Min() == 3
|
||||||
((ycoords.Max() == s[0]) & (Program.droppedtetrominoeLocationGrid[s[0], s[1]] == 1))).Count() > 0;
|
? ((yCoords.Max() == s[0]) | (yCoords.Max() - 1 == s[0])) &
|
||||||
|
(Program.DroppedTetrominoeLocationGrid[s[0], s[1]] == 1)
|
||||||
|
: (yCoords.Max() == s[0]) & (Program.DroppedTetrominoeLocationGrid[s[0], s[1]] == 1));
|
||||||
}
|
}
|
||||||
public bool isSomethingLeft() => location.Where(s => s[1] == 0 || Program.droppedtetrominoeLocationGrid[s[0], s[1] - 1] == 1).Count() > 0;
|
|
||||||
public static bool? isOverlayLeft(List<int[]> location)
|
public bool IsSomethingLeft() =>
|
||||||
|
Location.Any(s => s[1] == 0 || Program.DroppedTetrominoeLocationGrid[s[0], s[1] - 1] == 1);
|
||||||
|
|
||||||
|
private static bool? IsOverlayLeft(IReadOnlyList<int[]> location)
|
||||||
{
|
{
|
||||||
List<int> xcoords = new List<int>();
|
List<int> xCoords = new List<int>();
|
||||||
xcoords.AddRange(location.Select(s => s[1]));
|
xCoords.AddRange(location.Select(s => s[1]));
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
if (location[i][1] < 0)
|
if (location[i][1] < 0)
|
||||||
return true;
|
return true;
|
||||||
if (location[i][1] > 9)
|
if (location[i][1] > 9)
|
||||||
return false;
|
return false;
|
||||||
if (location[i][0] >= 23 | location[i][0] < 0)
|
if ((location[i][0] >= 23) | (location[i][0] < 0))
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return location.Where(s => (xcoords.Max() - xcoords.Min() == 3) ?
|
return location.Any(s => xCoords.Max() - xCoords.Min() == 3
|
||||||
(xcoords.Min() == s[1] | xcoords.Min() + 1 == s[1] && Program.droppedtetrominoeLocationGrid[s[0], s[1]] == 1) :
|
? (xCoords.Min() == s[1]) | (xCoords.Min() + 1 == s[1]) &&
|
||||||
(xcoords.Min() == s[1] && Program.droppedtetrominoeLocationGrid[s[0], s[1]] == 1)).Count() > 0;
|
Program.DroppedTetrominoeLocationGrid[s[0], s[1]] == 1
|
||||||
|
: xCoords.Min() == s[1] && Program.DroppedTetrominoeLocationGrid[s[0], s[1]] == 1);
|
||||||
}
|
}
|
||||||
public bool isSomethingRight() => location.Where(s => s[1] == 9 || Program.droppedtetrominoeLocationGrid[s[0], s[1] + 1] == 1).Count() > 0;
|
|
||||||
public static bool? isOverlayRight(List<int[]> location)
|
public bool IsSomethingRight() =>
|
||||||
|
Location.Any(s => s[1] == 9 || Program.DroppedTetrominoeLocationGrid[s[0], s[1] + 1] == 1);
|
||||||
|
|
||||||
|
private static bool? IsOverlayRight(IReadOnlyList<int[]> location)
|
||||||
{
|
{
|
||||||
List<int> xcoords = new List<int>();
|
List<int> xCoords = new List<int>();
|
||||||
xcoords.AddRange(location.Select(s => s[1]));
|
xCoords.AddRange(location.Select(s => s[1]));
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
if (location[i][1] > 9)
|
if (location[i][1] > 9)
|
||||||
return true;
|
return true;
|
||||||
if (location[i][1] < 0)
|
if (location[i][1] < 0)
|
||||||
return false;
|
return false;
|
||||||
if (location[i][0] >= 23 | location[i][0] < 0)
|
if ((location[i][0] >= 23) | (location[i][0] < 0))
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return location.Where(s => (xcoords.Max() - xcoords.Min() == 3) ?
|
return location.Any(s => xCoords.Max() - xCoords.Min() == 3
|
||||||
((xcoords.Max() == s[1] | xcoords.Max() - 1 == s[1]) & Program.droppedtetrominoeLocationGrid[s[0], s[1]] == 1) :
|
? ((xCoords.Max() == s[1]) | (xCoords.Max() - 1 == s[1])) &
|
||||||
(xcoords.Max() == s[1] & Program.droppedtetrominoeLocationGrid[s[0], s[1]] == 1)).Count() > 0;
|
(Program.DroppedTetrominoeLocationGrid[s[0], s[1]] == 1)
|
||||||
|
: (xCoords.Max() == s[1]) & (Program.DroppedTetrominoeLocationGrid[s[0], s[1]] == 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 23; i++)
|
for (int i = 0; i < 23; i++)
|
||||||
{
|
for (int j = 0; j < 10; j++)
|
||||||
for (int j = 0; j < 10; j++)
|
Program.Grid[i, j] = 0;
|
||||||
{
|
Location.ForEach(s => Program.Grid[s[0], s[1]] = 1);
|
||||||
Program.grid[i, j] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
location.ForEach(s => Program.grid[s[0], s[1]] = 1);
|
|
||||||
Program.Draw();
|
Program.Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
|
|
|
@ -9,6 +9,8 @@
|
||||||
<AssemblyName>testexetrisathlon</AssemblyName>
|
<AssemblyName>testexetrisathlon</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
|
<LangVersion>8</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -75,11 +77,6 @@
|
||||||
<Compile Include="Tetrominoe.cs" />
|
<Compile Include="Tetrominoe.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Include="GameOver.wav" />
|
|
||||||
<EmbeddedResource Include="InGame.wav" />
|
|
||||||
<EmbeddedResource Include="Intro.wav" />
|
<EmbeddedResource Include="Intro.wav" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -88,6 +85,9 @@
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="GameOver.wav" />
|
||||||
|
<EmbeddedResource Include="InGame1.wav" />
|
||||||
|
<EmbeddedResource Include="InGame2.wav" />
|
||||||
<Content Include="tetris_yUxH6t_256px.ico" />
|
<Content Include="tetris_yUxH6t_256px.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "testexetrisathlon", "testexetrisathlon.csproj", "{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Release|x86.Build.0 = Release|x86
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{6B0BD176-D6E3-49F5-8CA1-AE5F1535AC59}.Release|x64.Build.0 = Release|x64
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
Reference in New Issue