Advertisement
Guest User

SnakeGame, by D4N93R

a guest
Sep 10th, 2010
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Drawing;
  5.  
  6. namespace Nexus.Games.Snake.ComponentModel
  7. {
  8.     public abstract class SnakeBase
  9.     {
  10.         Queue<Point> m_snakePoints = new Queue<Point>(6);
  11.         private Direction m_direction = Direction.Down;
  12.         private int m_growTendence = 0;
  13.         public bool IsDirectionChanged = false;
  14.         public Direction Direction
  15.         {
  16.             get { return m_direction; }
  17.             set
  18.             {
  19.                 if (!IsDirectionChanged)
  20.                 {
  21.                     if (m_direction == Direction.Up && value != Direction.Down)
  22.                         m_direction = value;
  23.                     if (m_direction == Direction.Down && value != Direction.Up)
  24.                         m_direction = value;
  25.                     if (m_direction == Direction.Left && value != Direction.Right)
  26.                         m_direction = value;
  27.                     if (m_direction == Direction.Right && value != Direction.Left)
  28.                         m_direction = value;
  29.                     IsDirectionChanged = true;
  30.                 }
  31.             }
  32.         }
  33.  
  34.         private Board m_ownerBoard;
  35.         public int length
  36.         {
  37.             get { return m_snakePoints.Count; }
  38.         }
  39.         public Board OwnerBoard
  40.         {
  41.             get { return m_ownerBoard; }
  42.             set { m_ownerBoard = value; }
  43.         }
  44.         public Queue<Point> SnakePoints
  45.         {
  46.             get { return m_snakePoints; }
  47.         }
  48.         public SnakeBase(Board owner)
  49.         {
  50.             m_ownerBoard = owner;
  51.         }
  52.         public SnakeBase() { }
  53.         internal abstract int[,] GetArray();
  54.  
  55.         internal virtual void Move()
  56.         {
  57.  
  58.  
  59.         }
  60.  
  61.         internal virtual void RestartPosition(int length)
  62.         {
  63.             RestartPosition(length, false);
  64.         }
  65.         public virtual void RestartPosition(int length, bool isEvil)
  66.         {
  67.             m_growTendence = 0;
  68.             int centerX = m_ownerBoard.BoardSize - 1;
  69.             int centerY = m_ownerBoard.BoardSize - 1;
  70.  
  71.             if (isEvil)
  72.             {
  73.                 int randNumber = new Random(DateTime.Now.Millisecond).Next(0, m_ownerBoard.BoardSize - 1);
  74.  
  75.                 if (randNumber % 2 == 0)
  76.                 {
  77.                     centerX = randNumber;
  78.                     centerY = 0;
  79.                     m_snakePoints.Clear();
  80.                     for (int i = 0; i < length; i++)
  81.                     {
  82.                         m_snakePoints.Enqueue(new Point(centerX, (-length) + i + 1));
  83.                         centerY--;
  84.                     }
  85.                 }
  86.                 else
  87.                 {
  88.                     centerX = 0;
  89.                     centerY = randNumber;
  90.                     m_snakePoints.Clear();
  91.                     for (int i = 0; i < length; i++)
  92.                     {
  93.                         m_snakePoints.Enqueue(new Point((-length) + i + 1, centerY));
  94.                         centerY--;
  95.                     }
  96.                 }
  97.             }
  98.             Direction = Direction.Down;
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement