Advertisement
wingman007

SnakeOOPFinal2b_View

Oct 28th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using SnakeOOP2b.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 SnakeOOP2b.View
  9. {
  10.     class View
  11.     {
  12.         public void Render(Snake snake, Direction direction)
  13.         {
  14.             Point segment;
  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.             // render snake
  33.             Console.Clear();
  34.             for (int i = 0; i < snake.body.Count; i++)
  35.             {
  36.                 segment = snake.body.ElementAt(i);
  37.                 Console.SetCursorPosition(segment.x, segment.y);
  38.                 if (i == snake.body.Count - 1)
  39.                 {
  40.                     Console.Write(symbol);
  41.                 }
  42.                 else
  43.                 {
  44.                     Console.Write("*");
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement