Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
53X Again 13!
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Jul 19, 2020
1 parent d3b57da commit 10f9e20
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 133 deletions.
299 changes: 168 additions & 131 deletions Snake/Game.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Threading.Tasks;

Expand All @@ -13,7 +14,7 @@ public partial class Game : Form
int[] Locations2 = new int[999999];
int Queue, Queue2/*, Queue3*/, T1, T2, Measurement2 = 0;

int Measurement = 555;
int Measurement = 111;
int Growth = 5;
bool Apple = false;
bool Continue = true;
Expand All @@ -33,7 +34,7 @@ public Game()
private void Game_Load(object sender, EventArgs e)
{
Measurement2 = Measurement;
Game_Start();
Game_Restart();
}

private void Game_Start()
Expand Down Expand Up @@ -69,6 +70,7 @@ private void Game_Restart()
T2 = 0;
Array.Clear(Locations1, 0, 999999);
Array.Clear(Locations2, 0, 999999);
Direct = Direction.Right;
Gaming.Enabled = true;
Continue = true;
}
Expand All @@ -78,7 +80,7 @@ private enum Direction
Up, Down, Left, Right
}

private void Drawing(int AX, int AY)
private void Tail_Draw(int AX, int AY)
{
Pen Pencil = new Pen(Color.Black, 5);
Graphics Graph = null;
Expand All @@ -89,7 +91,7 @@ private void Drawing(int AX, int AY)
Graph.DrawRectangle(Pencil, new Rectangle(Locations1[Queue2], Locations2[Queue2], 10, 10));
Graph.FillRectangle(Colored, Locations1[Queue2], Locations2[Queue2], 10, 10);
if (AX == Locations1[Queue2] && AY == Locations2[Queue2])
AppleEat(AX, AY);
Apple_Eat(AX, AY);
Queue2++;
}
Pencil.Dispose();
Expand All @@ -101,7 +103,7 @@ private void Drawing(int AX, int AY)
Queue2 = Queue;
}

private void AppleEat(int AX, int AY)
private void Apple_Eat(int AX, int AY)
{
Apple = false;
Measurement += Growth;
Expand All @@ -116,118 +118,179 @@ private void AppleEat(int AX, int AY)
Colored.Dispose();
}

private void Gaming_Tick(object sender, EventArgs e)
private void Apple_Control(object AC)
{
if (Continue)
if (!Apple)
{
Apple = true;
AX = RNDM.Next(50, VWidth - 50);
AY = RNDM.Next(50, VHeight - 50);
Pen Pencil = new Pen(Color.Red, 5);
Graphics Graph = null;
Graph = CreateGraphics();
SolidBrush Colored = new SolidBrush(Color.Red);
Graph.DrawRectangle(Pencil, new Rectangle(AX, AY, 10, 10));
Graph.FillRectangle(Colored, AX, AY, 10, 10);
Pencil.Dispose();
Graph.Dispose();
Colored.Dispose();
}
else
{
X = Width2;
Y = Height2;
Pen Pencil = new Pen(Color.Red, 5);
Graphics Graph = null;
Graph = CreateGraphics();
SolidBrush Colored = new SolidBrush(Color.Red);
Graph.DrawRectangle(Pencil, new Rectangle(AX, AY, 10, 10));
Graph.FillRectangle(Colored, AX, AY, 10, 10);
Pencil.Dispose();
Graph.Dispose();
}
}

switch (Direct)
{
case Direction.Up:
if (Height2 <= 1)
Height2 = VHeight - 13;
else
Height2 -= 10;
break;
case Direction.Down:
if (Height2 >= VHeight - 12)
Height2 = 2;
else
Height2 += 10;
break;
case Direction.Left:
if (Width2 <= 1)
Width2 = VWidth - 13;
else
Width2 -= 10;
break;
case Direction.Right:
if (Width2 >= VWidth - 12)
Width2 = 2;
else
Width2 += 10;
break;
}
Drawing(X, Y);
SnakeHead.Location = new Point(Width2, Height2);
private void Apple_Look(object AL)
{
if (Width2 == AX && Height2 == AY)
Apple_Eat(AX, AY);
else
{
FX = Width2 - AX;
FY = Height2 - AY;
if (Math.Abs(FX) >= 0 && Math.Abs(FX) <= 8 && Math.Abs(FY) >= 0 && Math.Abs(FY) <= 8)
Apple_Eat(AX, AY);
}
}

if (X != Width2 || Y != Height2)
{
Locations1[Queue] = X;
Locations2[Queue] = Y;
Queue++;
}
private void Snake_Move()
{
X = Width2;
Y = Height2;

if (!Apple)
{
Apple = true;
AX = RNDM.Next(50, VWidth - 50);
AY = RNDM.Next(50, VHeight - 50);
Pen Pencil = new Pen(Color.Red, 5);
Graphics Graph = null;
Graph = CreateGraphics();
SolidBrush Colored = new SolidBrush(Color.Red);
Graph.DrawRectangle(Pencil, new Rectangle(AX, AY, 10, 10));
Graph.FillRectangle(Colored, AX, AY, 10, 10);
Pencil.Dispose();
Graph.Dispose();
Colored.Dispose();
}
else
{
Pen Pencil = new Pen(Color.Red, 5);
Graphics Graph = null;
Graph = CreateGraphics();
SolidBrush Colored = new SolidBrush(Color.Red);
Graph.DrawRectangle(Pencil, new Rectangle(AX, AY, 10, 10));
Graph.FillRectangle(Colored, AX, AY, 10, 10);
Pencil.Dispose();
Graph.Dispose();
}
switch (Direct)
{
case Direction.Up:
if (Height2 <= 1)
Height2 = VHeight - 13;
else
Height2 -= 10;
break;
case Direction.Down:
if (Height2 >= VHeight - 12)
Height2 = 2;
else
Height2 += 10;
break;
case Direction.Left:
if (Width2 <= 1)
Width2 = VWidth - 13;
else
Width2 -= 10;
break;
case Direction.Right:
if (Width2 >= VWidth - 12)
Width2 = 2;
else
Width2 += 10;
break;
}
Tail_Draw(X, Y);
SnakeHead.Location = new Point(Width2, Height2);

if (Queue >= Measurement)
{
Queue2 = Queue - Measurement;
Pen Pencil = new Pen(Color.White, 5);
Graphics Graph = null;
Graph = CreateGraphics();
SolidBrush Colored = new SolidBrush(Color.White);
Graph.DrawRectangle(Pencil, new Rectangle(Locations1[Queue2], Locations2[Queue2], 10, 10));
Graph.FillRectangle(Colored, Locations1[Queue2], Locations2[Queue2], 10, 10);
Pencil.Dispose();
Graph.Dispose();
Colored.Dispose();
/*Array.Clear(Locations1, 0, Queue2 + 1);
Array.Clear(Locations2, 0, Queue2 + 1);*/
Locations1[Queue2] = 999999;
Locations2[Queue2] = 999999;
}
if (X != Width2 || Y != Height2)
{
Locations1[Queue] = X;
Locations2[Queue] = Y;
Queue++;
}
}

if (Width2 == AX && Height2 == AY)
AppleEat(AX, AY);
else
private void Snake_Tail(object ST)
{
if (Queue >= Measurement)
{
Queue2 = Queue - Measurement;
Pen Pencil = new Pen(Color.White, 5);
Graphics Graph = null;
Graph = CreateGraphics();
SolidBrush Colored = new SolidBrush(Color.White);
Graph.DrawRectangle(Pencil, new Rectangle(Locations1[Queue2], Locations2[Queue2], 10, 10));
Graph.FillRectangle(Colored, Locations1[Queue2], Locations2[Queue2], 10, 10);
Pencil.Dispose();
Graph.Dispose();
Colored.Dispose();
/*Array.Clear(Locations1, 0, Queue2 + 1);
Array.Clear(Locations2, 0, Queue2 + 1);*/
Locations1[Queue2] = 999999;
Locations2[Queue2] = 999999;
}
}

private void Time_Plus(object TP)
{
T2 += 50;
if (T2 >= 1000)
{
T1++;
T2 = 0;
}
}

private void Label_Write(object LW)
{
InfoLabel.Text = "X = " + Width2 + " - FX = " + Math.Abs(FX) + "\n" + "Y = " + Height2 + " - FY = " + Math.Abs(FY);
StateLabel.Text = "Measurement = " + Measurement + "\n" + "Time = " + T1 + "." + T2 + " Second";

InfoLabel.SendToBack();
StateLabel.SendToBack();
SnakeHead.BringToFront();
}

private void Death_Control()
{
Parallel.For(0, Queue, i =>
{
FX2 = Locations1[i] - Width2;
FY2 = Locations2[i] - Height2;
if (Math.Abs(FX2) >= 0 && Math.Abs(FX2) <= 8 && Math.Abs(FY2) >= 0 && Math.Abs(FY2) <= 8)
{
FX = Width2 - AX;
FY = Height2 - AY;
if (Math.Abs(FX) >= 0 && Math.Abs(FX) <= 8 && Math.Abs(FY) >= 0 && Math.Abs(FY) <= 8)
AppleEat(AX, AY);
Gaming.Enabled = false;
Continue = false;
Game_Restart();
}
});

T2 += 50;
if (T2 >= 1000)
/*
Queue3 = 0;
while (Queue3 != Queue)
{
T1++;
T2 = 0;
FX2 = Locations1[Queue3] - Width2;
FY2 = Locations2[Queue3] - Height2;
if (Math.Abs(FX2) >= 0 && Math.Abs(FX2) <= 8 && Math.Abs(FY2) >= 0 && Math.Abs(FY2) <= 8)
{
Gaming.Enabled = false;
Continue = false;
Game_Restart();
}
Queue3++;
}
*/
}

InfoLabel.Text = "X = " + Width2 + " - FX = " + Math.Abs(FX) + "\n" + "Y = " + Height2 + " - FY = " + Math.Abs(FY);
StateLabel.Text = "Measurement = " + Measurement + "\n" + "Time = " + T1 + "." + T2 + " Second";

InfoLabel.SendToBack();
StateLabel.SendToBack();
SnakeHead.BringToFront();
private void Gaming_Tick(object sender, EventArgs e)
{
if (Continue)
{
Snake_Move();

ThreadPool.QueueUserWorkItem(new WaitCallback(Apple_Control));

ThreadPool.QueueUserWorkItem(new WaitCallback(Snake_Tail));

ThreadPool.QueueUserWorkItem(new WaitCallback(Apple_Look));

ThreadPool.QueueUserWorkItem(new WaitCallback(Time_Plus));

ThreadPool.QueueUserWorkItem(new WaitCallback(Label_Write));
}
}

Expand Down Expand Up @@ -272,33 +335,7 @@ private void Death_Tick(object sender, EventArgs e)
{
PauseLabel.Visible = false;

Parallel.For(0, Queue, i =>
{
FX2 = Locations1[i] - Width2;
FY2 = Locations2[i] - Height2;
if (Math.Abs(FX2) >= 0 && Math.Abs(FX2) <= 8 && Math.Abs(FY2) >= 0 && Math.Abs(FY2) <= 8)
{
Gaming.Enabled = false;
Continue = false;
Game_Restart();
}
});

/*
Queue3 = 0;
while (Queue3 != Queue)
{
FX2 = Locations1[Queue3] - Width2;
FY2 = Locations2[Queue3] - Height2;
if (Math.Abs(FX2) >= 0 && Math.Abs(FX2) <= 8 && Math.Abs(FY2) >= 0 && Math.Abs(FY2) <= 8)
{
Gaming.Enabled = false;
Continue = false;
Game_Restart();
}
Queue3++;
}
*/
Death_Control();
}
else
{
Expand Down
Loading

0 comments on commit 10f9e20

Please sign in to comment.