Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing;
- namespace Nexus.Games.Snake.ComponentModel
- {
- public abstract class SnakeBase
- {
- Queue<Point> m_snakePoints = new Queue<Point>(6);
- private Direction m_direction = Direction.Down;
- private int m_growTendence = 0;
- public bool IsDirectionChanged = false;
- public Direction Direction
- {
- get { return m_direction; }
- set
- {
- if (!IsDirectionChanged)
- {
- if (m_direction == Direction.Up && value != Direction.Down)
- m_direction = value;
- if (m_direction == Direction.Down && value != Direction.Up)
- m_direction = value;
- if (m_direction == Direction.Left && value != Direction.Right)
- m_direction = value;
- if (m_direction == Direction.Right && value != Direction.Left)
- m_direction = value;
- IsDirectionChanged = true;
- }
- }
- }
- private Board m_ownerBoard;
- public int length
- {
- get { return m_snakePoints.Count; }
- }
- public Board OwnerBoard
- {
- get { return m_ownerBoard; }
- set { m_ownerBoard = value; }
- }
- public Queue<Point> SnakePoints
- {
- get { return m_snakePoints; }
- }
- public SnakeBase(Board owner)
- {
- m_ownerBoard = owner;
- }
- public SnakeBase() { }
- internal abstract int[,] GetArray();
- internal virtual void Move()
- {
- }
- internal virtual void RestartPosition(int length)
- {
- RestartPosition(length, false);
- }
- public virtual void RestartPosition(int length, bool isEvil)
- {
- m_growTendence = 0;
- int centerX = m_ownerBoard.BoardSize - 1;
- int centerY = m_ownerBoard.BoardSize - 1;
- if (isEvil)
- {
- int randNumber = new Random(DateTime.Now.Millisecond).Next(0, m_ownerBoard.BoardSize - 1);
- if (randNumber % 2 == 0)
- {
- centerX = randNumber;
- centerY = 0;
- m_snakePoints.Clear();
- for (int i = 0; i < length; i++)
- {
- m_snakePoints.Enqueue(new Point(centerX, (-length) + i + 1));
- centerY--;
- }
- }
- else
- {
- centerX = 0;
- centerY = randNumber;
- m_snakePoints.Clear();
- for (int i = 0; i < length; i++)
- {
- m_snakePoints.Enqueue(new Point((-length) + i + 1, centerY));
- centerY--;
- }
- }
- }
- Direction = Direction.Down;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement