This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
LaptopSimulator2015/3g/3.cs

498 lines
38 KiB
C#
Raw Normal View History

using Base;
using LaptopSimulator2015;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LaptopSimulator2015.Goals
{
public class G3 : Goal
{
private Image _installer;
public string name => "DropBlox";
public Image icon
{
get {
if (_installer == null)
{
string __installer = "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURBVHic7d17tB51Ye7xZ2be2947iRAQkSpmqizl9CIKR4rQdaBFBFR0aK3WVkShKuqcg4CCVRd4tFUrIqevgkAgBLy3ZbiFJEBbPEtEPV5Qa1GpnWRvigG5B3Lb2e97/ph5ITvZl/cyM7+5fD9rsRLXIu/76Fru58lv3nfG6na7ApBvnuuPSdpnkX8mJDUlNeJf+/m9JG2XtCP+tZ/fPyXp4YX+CcL21jT+dwCQHIsBAJjjuX5D0vMluZJW7PLr/ppd7mNmEg5tq2aPgk2SNkgKd/l1KgjbOwzlAyqPAQCkyHN9W9KBml3uu/56gCTbTDrjOpLu1+xRsOuvk0HY7hjKBpQeAwBIiOf6+0r6fUm/F//6+5J+R8X723tebJX0M0k/if/5qaSfBGH7IaOpgJJgAAADio/tD9YzJd8r/OeazFUhv9YugyD+5x4uJwCDYQAAi/Bc/4WSjpR0lKQjJL1EUs1oKOxup6SfS7pL0rck3RmE7V+ZjQTkGwMA2IXn+jVJL9MzhX+kog/koXg2SbpT8SCQ9KMgbO80GwnIDwYAKs1z/WWK/lbfK/zDJY0bDYW0bJH0XT0zCO4KwvYTZiMB5jAAUCnxp/JfIekEScdLOkzV/RR+1XUkfV/SOklrJX2Pbx2gShg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Hiu/3JJl5rOAZjACABGcmncIaVV2gHguf4+ij7x3zKdBTCFEQAMraXomwH7mA6Sl
Stream s = new MemoryStream(Convert.FromBase64String(__installer));
_installer = Image.FromStream(s);
s.Close();
}
return _installer;
}
}
2019-09-19 18:51:31 +02:00
public int availableAfter => 0;
public int gameClock => 300;
public Panel desktopIcon { get; set; }
public int playableAfter => 4;
public string[] availableText
{
get {
switch (CultureInfo.CurrentUICulture.Name.Split('-')[0])
{
case "de":
return new string[] { "Dieses neue Spiel sieht unglaublich aus!", "Schaun' wir mal ob mein PC gut genug dafür ist..." };
default:
return new string[] { "My gosh, this new game will be so amazing!", "Lets see if my computer can handle it..." };
}
}
}
public string[] incompleteText
{
get {
switch (CultureInfo.CurrentUICulture.Name.Split('-')[0])
{
case "de":
return new string[] { "Scheinbar nicht.", "Mal sehen... ", "Ich brauche eine neue CPU, GPU und mehr RAM...", "Diese Programme sollten meinen PC kompatibel machen!" };
default:
return new string[] { "Doesn't seem like it.", "Lets see...", "I will need a new CPU, GPU and more RAM...", "These programs should make my PC compatible!" };
}
}
}
public string[] completeText
{
get {
switch (CultureInfo.CurrentUICulture.Name.Split('-')[0])
{
case "de":
return new string[] { "Ich sollte es jetzt nochmal versuchen..." };
default:
return new string[] { "I should try again now..." };
}
}
}
2019-09-26 22:24:45 +02:00
public Color backColor => Color.Black;
2019-09-29 11:23:07 +02:00
public string[] credits => new string[]{ "Testexetrisathlon Icon made by Freepik from www.flaticon.com" };
2019-10-05 17:49:56 +02:00
public bool isLowQuality => true;
2019-09-29 11:23:07 +02:00
public static int[,] grid = new int[23, 10];
public static int[,] droppedtetrominoeLocationGrid = new int[23, 10];
public static bool isDropped = false;
static Tetrominoe tet;
static Tetrominoe nexttet;
public static int linesCleared = 0, score = 0, level = 1;
public static Random rnd;
public void gameTick(GraphicsWrapper g, Panel minigamePanel, Timer minigameTimer, uint minigameTime)
{
try
{
Random random = new Random();
tet.Drop();
if (isDropped == true)
{
tet = nexttet;
nexttet = new Tetrominoe();
tet.Spawn();
isDropped = false;
score += 10;
}
int j; for (j = 0; j < 10; j++)
{
if (droppedtetrominoeLocationGrid[0, j] == 1)
Misc.closeGameWindow.Invoke();
}
Input();
ClearBlock();
}
catch (Exception ex) { if (ex.InnerException?.Message == "0717750f-3508-4bc2-841e-f3b077c676fe") Misc.closeGameWindow.Invoke(); else Console.WriteLine(ex.ToString()); }
}
public void initGame(Panel minigamePanel, Timer minigameTimer)
{
rnd = new Random();
grid = new int[23, 10];
droppedtetrominoeLocationGrid = new int[23, 10];
isDropped = false;
linesCleared = 0;
score = 0;
level = 1;
nexttet = new Tetrominoe();
tet = nexttet;
tet.Spawn();
nexttet = new Tetrominoe();
}
private static void ClearBlock()
{
int combo = 0;
for (int i = 0; i < 23; i++)
{
int j; for (j = 0; j < 10; j++)
{
if (droppedtetrominoeLocationGrid[i, j] == 0)
break;
}
if (j == 10)
{
linesCleared++;
combo++;
Console.Beep(400, 200);
for (j = 0; j < 10; j++)
{
droppedtetrominoeLocationGrid[i, j] = 0;
}
int[,] newdroppedtetrominoeLocationGrid = new int[23, 10];
for (int k = 1; k < i; k++)
{
for (int l = 0; l < 10; l++)
{
newdroppedtetrominoeLocationGrid[k + 1, l] = droppedtetrominoeLocationGrid[k, l];
}
}
for (int k = 1; k < i; k++)
{
for (int l = 0; l < 10; l++)
{
droppedtetrominoeLocationGrid[k, l] = 0;
}
}
for (int k = 0; k < 23; k++)
for (int l = 0; l < 10; l++)
if (newdroppedtetrominoeLocationGrid[k, l] == 1)
droppedtetrominoeLocationGrid[k, l] = 1;
}
}
score += (int)Math.Round(Math.Sqrt(Math.Max(combo * 50 - 50, 0)) * 5);
level = (int)Math.Round(Math.Sqrt(score * 0.01)) + 1;
}
private static void Input()
{
if (Base.Input.Left & !tet.isSomethingLeft())
{
for (int i = 0; i < 4; i++)
tet.location[i][1] -= 1;
tet.Update();
}
else if (Base.Input.Right & !tet.isSomethingRight())
{
for (int i = 0; i < 4; i++)
tet.location[i][1] += 1;
tet.Update();
}
if (Base.Input.Down)
tet.Drop();
if (Base.Input.Up)
for (; tet.isSomethingBelow() != true;)
tet.Drop();
if (Base.Input.Action)
{
tet.Rotate();
tet.Update();
}
}
public void draw(GraphicsWrapper g, Panel minigamePanel, Timer minigameTimer, uint minigameTime)
{
for (int y = 0; y < 23; ++y)
{
for (int x = 0; x < 10; x++)
{
if (grid[y, x] == 1 | droppedtetrominoeLocationGrid[y, x] == 1)
2019-09-26 22:24:45 +02:00
g.DrawRectangle(new RectangleF(x * 10, y * 10, 10, 10), Color.White, false, false);
}
2019-10-05 17:49:56 +02:00
g.DrawLine(new Point(0, (y + 1) * 10), new Point(10 * 10, (y + 1) * 10), Color.DarkGray, 1, false);
}
for (int x = 0; x < 10; x++)
{
2019-10-05 17:49:56 +02:00
g.DrawLine(new Point((x + 1) * 10, 0), new Point((x + 1) * 10, 23 * 10), Color.DarkGray, 1, false);
}
2019-09-26 22:24:45 +02:00
g.DrawSizedString("Level " + level, 10, new PointF(150, 10), Brushes.White, false);
g.DrawSizedString("Score " + score, 10, new PointF(150, 30), Brushes.White, false);
g.DrawSizedString("LinesCleared " + linesCleared, 10, new PointF(150, 50), Brushes.White, false);
}
public class Tetrominoe
{
public static int[,] I = new int[1, 4] { { 1, 1, 1, 1 } };
public static int[,] O = new int[2, 2] { { 1, 1 },
{ 1, 1 } };
public static int[,] T = new int[2, 3] { { 0, 1, 0 },
{ 1, 1, 1 } };
public static int[,] S = new int[2, 3] { { 0, 1, 1 },
{ 1, 1, 0 } };
public static int[,] Z = new int[2, 3] { { 1, 1, 0 },
{ 0, 1, 1 } };
public static int[,] J = new int[2, 3] { { 1, 0, 0 },
{ 1, 1, 1 } };
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()
{
shape = tetrominoes[rnd.Next(0, tetrominoes.Count)];
}
public void Spawn()
{
for (int i = 0; i < shape.GetLength(0); i++)
{
for (int j = 0; j < shape.GetLength(1); j++)
{
if (shape[i, j] == 1)
{
location.Add(new int[] { i, (10 - shape.GetLength(1)) / 2 + j });
}
}
}
Update();
}
public void Drop()
{
if (isSomethingBelow())
{
for (int i = 0; i < 4; i++)
{
droppedtetrominoeLocationGrid[location[i][0], location[i][1]] = 1;
}
isDropped = true;
Console.Beep(800, 200);
}
else
{
for (int numCount = 0; numCount < 4; numCount++)
{
location[numCount][0] += 1;
}
Update();
}
}
public void Rotate()
{
List<int[]> templocation = new List<int[]>();
for (int i = 0; i < shape.GetLength(0); i++)
{
for (int j = 0; j < shape.GetLength(1); j++)
{
if (shape[i, j] == 1)
{
templocation.Add(new int[] { i, (10 - shape.GetLength(1)) / 2 + j });
}
}
}
if (shape == tetrominoes[0])
{
for (int i = 0; i < location.Count; i++)
{
templocation[i] = TransformMatrix(location[i], location[2]);
}
}
else if (shape == tetrominoes[3])
{
for (int i = 0; i < location.Count; i++)
{
templocation[i] = TransformMatrix(location[i], location[3]);
}
}
else if (shape == tetrominoes[1])
return;
else
{
for (int i = 0; i < location.Count; i++)
{
templocation[i] = TransformMatrix(location[i], location[2]);
}
}
for (int count = 0; isOverlayLeft(templocation) != false | isOverlayRight(templocation) != false | isOverlayBelow(templocation) != false; count++)
{
if (isOverlayLeft(templocation) == true)
{
for (int i = 0; i < location.Count; i++)
{
templocation[i][1] += 1;
}
}
if (isOverlayRight(templocation) == true)
{
for (int i = 0; i < location.Count; i++)
{
templocation[i][1] -= 1;
}
}
if (isOverlayBelow(templocation) == true)
{
for (int i = 0; i < location.Count; i++)
{
templocation[i][0] -= 1;
}
}
if (count == 3)
{
return;
}
}
location = templocation;
}
public bool notFalse(bool? inp) => (inp ?? true);
public int[] TransformMatrix(int[] coord, int[] axis) => new int[] { axis[0] - axis[1] + coord[1], axis[0] + axis[1] - coord[0] };
public bool isSomethingBelow()
{
for (int i = 0; i < 4; i++)
{
if (location[i][0] + 1 >= 23)
return true;
if (location[i][0] + 1 < 23 & droppedtetrominoeLocationGrid[location[i][0] + 1, location[i][1]] == 1)
return true;
}
return false;
}
public bool? isOverlayBelow(List<int[]> location)
{
List<int> ycoords = new List<int>();
for (int i = 0; i < 4; i++)
{
ycoords.Add(location[i][0]);
if (location[i][0] >= 23)
return true;
if (location[i][0] < 0 | location[i][1] < 0 | location[i][1] > 9)
return null;
}
for (int i = 0; i < 4; i++)
{
if (ycoords.Max() - ycoords.Min() == 3)
{
if ((ycoords.Max() == location[i][0] | ycoords.Max() - 1 == location[i][0]) & (droppedtetrominoeLocationGrid[location[i][0], location[i][1]] == 1))
{
return true;
}
}
else
{
if ((ycoords.Max() == location[i][0]) & (droppedtetrominoeLocationGrid[location[i][0], location[i][1]] == 1))
{
return true;
}
}
}
return false;
}
public bool isSomethingLeft()
{
for (int i = 0; i < 4; i++)
{
if (location[i][1] == 0)
return true;
else if (droppedtetrominoeLocationGrid[location[i][0], location[i][1] - 1] == 1)
return true;
}
return false;
}
public bool? isOverlayLeft(List<int[]> location)
{
List<int> xcoords = new List<int>();
for (int i = 0; i < 4; i++)
{
xcoords.Add(location[i][1]);
if (location[i][1] < 0)
return true;
if (location[i][1] > 9)
return false;
if (location[i][0] >= 23 | location[i][0] < 0)
return null;
}
for (int i = 0; i < 4; i++)
{
if (xcoords.Max() - xcoords.Min() == 3)
{
if (xcoords.Min() == location[i][1] | xcoords.Min() + 1 == location[i][1])
{
if (droppedtetrominoeLocationGrid[location[i][0], location[i][1]] == 1)
{
return true;
}
}
}
else
{
if (xcoords.Min() == location[i][1])
{
if (droppedtetrominoeLocationGrid[location[i][0], location[i][1]] == 1)
{
return true;
}
}
}
}
return false;
}
public bool isSomethingRight()
{
for (int i = 0; i < 4; i++)
{
if (location[i][1] == 9)
return true;
else if (droppedtetrominoeLocationGrid[location[i][0], location[i][1] + 1] == 1)
return true;
}
return false;
}
public bool? isOverlayRight(List<int[]> location)
{
List<int> xcoords = new List<int>();
for (int i = 0; i < 4; i++)
{
xcoords.Add(location[i][1]);
if (location[i][1] > 9)
return true;
if (location[i][1] < 0)
return false;
if (location[i][0] >= 23 | location[i][0] < 0)
return null;
}
for (int i = 0; i < 4; i++)
{
if (xcoords.Max() - xcoords.Min() == 3)
{
if ((xcoords.Max() == location[i][1] | xcoords.Max() - 1 == location[i][1]) & droppedtetrominoeLocationGrid[location[i][0], location[i][1]] == 1)
{
return true;
}
}
else
{
if (xcoords.Max() == location[i][1] & droppedtetrominoeLocationGrid[location[i][0], location[i][1]] == 1)
{
return true;
}
}
}
return false;
}
public void Update()
{
for (int i = 0; i < 23; i++)
{
for (int j = 0; j < 10; j++)
{
grid[i, j] = 0;
}
}
for (int i = 0; i < 4; i++)
{
grid[location[i][0], location[i][1]] = 1;
}
}
}
}
}