Implemented Highscore

This commit is contained in:
CreepyCrafter24 2019-11-10 17:31:09 +01:00
parent 4ae676e94e
commit 17808fbfc6
2 changed files with 37 additions and 35 deletions

View File

@ -5,6 +5,7 @@ using System.Media;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using static System.Console; using static System.Console;
using System.Collections.Generic;
//┌─┐ //┌─┐
//│ │ //│ │
@ -56,6 +57,7 @@ namespace testexetrisathlon
colors = new ConsoleColor[2] { BackgroundColor, ForegroundColor }; colors = new ConsoleColor[2] { BackgroundColor, ForegroundColor };
BackgroundColor = ConsoleColor.Red; BackgroundColor = ConsoleColor.Red;
ForegroundColor = ConsoleColor.Yellow; ForegroundColor = ConsoleColor.Yellow;
SetWindowSize(42, 29);
SetCursorPosition(0, 0); SetCursorPosition(0, 0);
Clear(); Clear();
#if (DEBUG) #if (DEBUG)
@ -79,22 +81,22 @@ namespace testexetrisathlon
{ {
SetCursorPosition(0, 1); SetCursorPosition(0, 1);
Write( 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" + " ▀█▀ ▀███▄ ▐███\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()); " testexetrisathlon v." + assembly.GetName().Version.ToString());
} }
void MainN(SoundPlayer intro, SoundPlayer inGame, SoundPlayer gameOver) void MainN(SoundPlayer intro, SoundPlayer inGame, SoundPlayer gameOver)
{ {
@ -113,19 +115,21 @@ namespace testexetrisathlon
gameOver.Stop(); gameOver.Stop();
intro.PlayLooping(); intro.PlayLooping();
DrawSymbol(); DrawSymbol();
SetCursorPosition(10, 18); SetCursorPosition(12, 18);
Write("Highscore: " + SettingsMan.HighScore.ToString());
SetCursorPosition(12, 20);
Write("Controls: Space"); Write("Controls: Space");
SetCursorPosition(11, 19); SetCursorPosition(13, 21);
Write("Up, Down, Right"); Write("Up, Down, Right");
SetCursorPosition(11, 20); SetCursorPosition(13, 22);
Write("Left"); Write("Left");
SetCursorPosition(10, 22); SetCursorPosition(12, 24);
Write("Press s to start"); Write("Press s to start");
SetCursorPosition(10, 23); SetCursorPosition(12, 25);
Write("Press x to exit"); Write("Press x to exit");
SetCursorPosition(10, 24); SetCursorPosition(12, 26);
Write("Press v for settings"); Write("Press v for settings");
SetCursorPosition(0, 26); SetCursorPosition(0, 28);
Write("Icon made by Freepik from www.flaticon.com"); Write("Icon made by Freepik from www.flaticon.com");
string tmp = ReadKey(true).KeyChar.ToString().ToLower(); string tmp = ReadKey(true).KeyChar.ToString().ToLower();
switch (tmp) switch (tmp)
@ -153,6 +157,8 @@ namespace testexetrisathlon
WriteLine("Score " + score); WriteLine("Score " + score);
SetCursorPosition(25, 2); SetCursorPosition(25, 2);
WriteLine("LinesCleared " + linesCleared); WriteLine("LinesCleared " + linesCleared);
SetCursorPosition(25, 4);
WriteLine("Highscore " + SettingsMan.HighScore);
nexttet = new Tetrominoe(); nexttet = new Tetrominoe();
tet = nexttet; tet = nexttet;
tet.Spawn(); tet.Spawn();
@ -162,6 +168,7 @@ namespace testexetrisathlon
state = GameState.gameOver; state = GameState.gameOver;
break; break;
case GameState.gameOver: case GameState.gameOver:
SettingsMan.HighScore = score;
gameOver.PlayLooping(); gameOver.PlayLooping();
string input = ""; string input = "";
while ((input != "y") && (input != "n")) while ((input != "y") && (input != "n"))
@ -251,7 +258,7 @@ namespace testexetrisathlon
isDropped = false; isDropped = false;
score += 10; score += 10;
} }
int j; for (j = 0; j < 10; j++) for (int j = 0; j < 10; j++)
{ {
if (droppedtetrominoeLocationGrid[0, j] == 1) if (droppedtetrominoeLocationGrid[0, j] == 1)
return; return;
@ -270,17 +277,12 @@ namespace testexetrisathlon
int combo = 0; int combo = 0;
for (int i = 0; i < 23; i++) for (int i = 0; i < 23; i++)
{ {
int j; for (j = 0; j < 10; j++) if (Enumerable.Range(0, 10).Where(s => droppedtetrominoeLocationGrid[i, s] == 0).Count() == 0)
{
if (droppedtetrominoeLocationGrid[i, j] == 0)
break;
}
if (j == 10)
{ {
linesCleared++; linesCleared++;
combo++; combo++;
Beep(400, 200); Beep(400, 200);
for (j = 0; j < 10; j++) for (int j = 0; j < 10; j++)
{ {
droppedtetrominoeLocationGrid[i, j] = 0; droppedtetrominoeLocationGrid[i, j] = 0;
} }

View File

@ -33,12 +33,12 @@ namespace testexetrisathlon
public Tetrominoe() public Tetrominoe()
{ {
shape = tetrominoes[Program.rnd.Next(0, tetrominoes.Count)]; shape = tetrominoes[Program.rnd.Next(0, tetrominoes.Count)];
for (int i = 0; i < 10; i++) for (int i = 0; i < 7; i++)
{ {
for (int j = 0; j < 7; j++) for (int j = 0; j < 2; j++)
{ {
SetCursorPosition(i + 23, j + 3); SetCursorPosition(i + 26, j + 6);
Write(" "); Write(Program.debug ? "X" : " ");
} }
} }
Program.DrawBorder(); Program.DrawBorder();
@ -48,7 +48,7 @@ namespace testexetrisathlon
{ {
if (shape[i, j] == 1) if (shape[i, j] == 1)
{ {
SetCursorPosition(30 - shape.GetLength(1) + (2 * j), i + 5); SetCursorPosition(30 - shape.GetLength(1) + (2 * j), i + 6);
Write(Program.sqr); Write(Program.sqr);
} }
} }