Advertisement
Guest User

SnakeObject

a guest
Mar 5th, 2012
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6.  
  7. namespace SnakeV2
  8. {
  9.     public class SnakeObject
  10.     {
  11.         public List<Point> Body;
  12.         public Point Head;
  13.         public char[] dirArrow = { '<', '>', '^', 'V' };
  14.         public Direction Dir;
  15.  
  16.         public SnakeObject(int firstCreation)
  17.         {
  18.             Body = new List<Point>();
  19.  
  20.             for (int i = 0; i < firstCreation; i++)
  21.                 Body.Add(new Point(0, i));
  22.         }
  23.  
  24.         public void Update()
  25.         {
  26.             Body.RemoveAt(0);
  27.             Body.Add(Head);
  28.         }
  29.  
  30.         public void Draw()
  31.         {
  32.             for (int i = 0; i < Body.Count - 1; i++)
  33.             {
  34.                 Console.SetCursorPosition(Body[i].Y, Body[i].X);
  35.                 Console.Write('*');
  36.             }
  37.  
  38.             Console.SetCursorPosition(Head.Y, Head.X);
  39.             Console.Write(dirArrow[(int)Dir]);
  40.         }
  41.  
  42.         public Point GetHeadPoint()
  43.         {
  44.             return new Point(Body.Last().X, Body.Last().Y);
  45.         }
  46.  
  47.         public void Grow()
  48.         {
  49.             Body.Add(new Point(0, 0));
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement