Advertisement
wingman007

SnakeOOPFinal_Controller

Oct 27th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using SnakeOOP1b.View;
  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.Controller
  9. {
  10.     public enum Direction { Left, Right, Up, Down};
  11.     class Controller
  12.     {
  13.         private SnakeOOP1b.View.View view;
  14.         private Snake snake;
  15.         private Input input;
  16.         private Timer timer;
  17.         private Direction direction;
  18.         public Controller(SnakeOOP1b.View.View view, Snake snake, Input input, Timer timer)
  19.         {
  20.             this.view = view;
  21.             this.snake = snake;
  22.             this.input = input;
  23.             this.timer = timer;
  24.             timer.Tick += GoAction;
  25.         }
  26.  
  27.         public void GoAction(object sender, EventArgs e)
  28.         {
  29.             if (input.IsKeyAvailable())
  30.             {
  31.                 ConsoleKeyInfo cki = input.GetKey();
  32.                 switch (cki.Key)
  33.                 {
  34.                     case ConsoleKey.RightArrow:
  35.                         direction = Direction.Right;
  36.                         break;
  37.                     case ConsoleKey.LeftArrow:
  38.                         direction = Direction.Left;
  39.                         break;
  40.                     case ConsoleKey.UpArrow:
  41.                         direction = Direction.Up;
  42.                         break;
  43.                     case ConsoleKey.DownArrow:
  44.                         direction = Direction.Down;
  45.                         break;
  46.                 }
  47.             }
  48.             snake.Move(direction);
  49.             view.Render(snake, direction);    
  50.         }
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement