Advertisement
wingman007

SnakeOOPFinal_View

Oct 27th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using SnakeOOP1b.Controller;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SnakeOOP1b.View
  9. {
  10.     class View
  11.     {
  12.         public void Render(Snake snake, Direction direction)
  13.         {
  14.             Point segment = new Point(0,0);
  15.             char symbol = '>';
  16.             switch (direction)
  17.             {
  18.                 case Direction.Right:
  19.                     symbol = '>';
  20.                     break;
  21.                 case Direction.Left:
  22.                     symbol = '<';
  23.                     break;
  24.                 case Direction.Up:
  25.                     symbol = '^';
  26.                     break;
  27.                 case Direction.Down:
  28.                     symbol = 'V';
  29.                     break;
  30.             }
  31.  
  32.             Console.Clear();
  33.             // render snake
  34.             Console.Clear();
  35.             for (int i = 0; i < snake.body.Count; i++)
  36.             {
  37.                 segment = snake.body.ElementAt(i);
  38.                 Console.SetCursorPosition(segment.x, segment.y);
  39.                 if (i == snake.body.Count - 1)
  40.                 {
  41.                     Console.Write(symbol);
  42.                 }
  43.                 else
  44.                 {
  45.                     Console.Write("*");
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement