Skip to content

Commit

Permalink
100 dpi version :
Browse files Browse the repository at this point in the history
- Redimensionnement des controls
- Mise en place de pictureBox à la place de labels
  • Loading branch information
Genjo15 committed Feb 26, 2013
1 parent 25df477 commit 54f4cb3
Show file tree
Hide file tree
Showing 13 changed files with 663 additions and 216 deletions.
16 changes: 9 additions & 7 deletions Snake/Fruit.cs
Expand Up @@ -14,7 +14,8 @@ public class Fruit
private int _X; // Position in X.
private int _Y; // Position in Y.
private const int _POINT = 5; // The points earned when item reached.
private const int _SIDE = 12; // Size of the panel side.
private int _SIDE; // Size of the panel side.
private Random _RandomNumber; // Random number.

#endregion

Expand All @@ -24,9 +25,10 @@ public class Fruit

public Fruit(int width, int height)
{
Random randomNumber = new Random(); // Initialize the generator of random.
_X = (_SIDE + 2) * (randomNumber.Next(width - _SIDE) / (_SIDE + 2)); // Set _X thanks to a generated number.
_Y = (_SIDE + 2) * (randomNumber.Next(height - _SIDE) / (_SIDE + 2)); // Set _Y thanks to another generated number.
_SIDE = width / 54 - 2; // Initialize dynamically the side of the fruit.
Random _RandomNumber = new Random(); // Initialize the generator of random.
_X = (_SIDE + 2) * (_RandomNumber.Next(width - _SIDE) / (_SIDE + 2)); // Set _X thanks to a generated number.
_Y = (_SIDE + 2) * (_RandomNumber.Next(height - _SIDE) / (_SIDE + 2)); // Set _Y thanks to another generated number.
}

#endregion
Expand All @@ -53,9 +55,9 @@ public Boolean IsReached(SnakePart snake)

public void MoveFruit(int width, int height, FullSnake fullSnake)
{
Random randomNumber = new Random(); // Initialize the generator of random.
_X = (_SIDE + 2) * (randomNumber.Next(width - _SIDE) / (_SIDE + 2)); // Set _X thanks to a generated number.
_Y = (_SIDE + 2) * (randomNumber.Next(height - _SIDE) / (_SIDE + 2)); // Set _Y thanks to another generated number.
_RandomNumber = new Random(); // Générate a new random number.
_X = (_SIDE + 2) * (_RandomNumber.Next(width - _SIDE) / (_SIDE + 2)); // Set _X thanks to a generated number.
_Y = (_SIDE + 2) * (_RandomNumber.Next(height - _SIDE) / (_SIDE + 2)); // Set _Y thanks to another generated number.

for (int i = 0; i < fullSnake.Get_SnakeSize(); i++) // Check each snake part.
{
Expand Down
24 changes: 12 additions & 12 deletions Snake/FullSnake.cs
Expand Up @@ -20,12 +20,12 @@ public class FullSnake

#region Constructor

public FullSnake()
public FullSnake(int width)
{
_Snake = new List<SnakePart>(); // Instanciate the list of snake parts.
_Snake.Add(new SnakePart()); // Add one part (the first one) of the snake to the list.
AddSnakePart(); // Then add two others parts (the game start with a snake composed of three parts).
AddSnakePart(); //
_Snake.Add(new SnakePart(width)); // Add one part (the first one) of the snake to the list.
AddSnakePart(width); // Then add two others parts (the game start with a snake composed of three parts).
AddSnakePart(width); //
}

#endregion
Expand All @@ -37,7 +37,7 @@ public FullSnake()
///////////////////////////////////////
// Method which update snake movement

public void UpdateSnake(int direction, int width, int height)
public void UpdateSnake(int direction, int width)
{
int i = 0;

Expand All @@ -46,14 +46,14 @@ public void UpdateSnake(int direction, int width, int height)
// If the element of the snake is the first one, move it by the direction defined by the event KeyDown.
if (element.Get_IsHead() == true)
{
element.UpdateSnakePart(direction, width, height);
element.UpdateSnakePart(direction);
i++;
}

// Else, if the element is not the head of the snake, move it by the last direction of the previous element.
else if (element.Get_IsHead() == false)
{
element.UpdateSnakePart(_Snake[i - 1].Get_LastDirection(), width, height);
element.UpdateSnakePart(_Snake[i - 1].Get_LastDirection());
i++;
}
}
Expand All @@ -62,18 +62,18 @@ public void UpdateSnake(int direction, int width, int height)
/////////////////////////////////////////////
// Method which add a part to the full snake

public void AddSnakePart()
public void AddSnakePart(int width)
{
int lastElementIndex = _Snake.Count - 1; // Compute the last element of the snake.

if (_Snake[lastElementIndex].Get_Direction() == 0) // If the last element moves up...
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X(), _Snake[lastElementIndex].Get_Y() + (_Snake[lastElementIndex].Get_SIDE() + 2), 0)); // ...then add a part just down on it.
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X(), _Snake[lastElementIndex].Get_Y() + (_Snake[lastElementIndex].Get_SIDE() + 2), 0, width)); // ...then add a part just down on it.
if (_Snake[lastElementIndex].Get_Direction() == 1) // If the last element moves right...
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X() - (_Snake[lastElementIndex].Get_SIDE() + 2), _Snake[lastElementIndex].Get_Y(), 1)); // ...then add a part just left on it.
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X() - (_Snake[lastElementIndex].Get_SIDE() + 2), _Snake[lastElementIndex].Get_Y(), 1, width)); // ...then add a part just left on it.
if (_Snake[lastElementIndex].Get_Direction() == 2) // If the last element moves down...
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X(), _Snake[lastElementIndex].Get_Y() - (_Snake[lastElementIndex].Get_SIDE() + 2), 2)); // ...then add a part just up on it.
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X(), _Snake[lastElementIndex].Get_Y() - (_Snake[lastElementIndex].Get_SIDE() + 2), 2, width)); // ...then add a part just up on it.
if (_Snake[lastElementIndex].Get_Direction() == 3) // If the last element moves left...
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X() + (_Snake[lastElementIndex].Get_SIDE() + 2), _Snake[lastElementIndex].Get_Y(), 3)); // ...then add a part just right on it.
_Snake.Add(new SnakePart(_Snake[lastElementIndex].Get_X() + (_Snake[lastElementIndex].Get_SIDE() + 2), _Snake[lastElementIndex].Get_Y(), 3, width)); // ...then add a part just right on it.
}

//////////////////////////////////////////////
Expand Down

0 comments on commit 54f4cb3

Please sign in to comment.