Advertisement
Guest User

C# Pattern Command test

a guest
Jun 18th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PatternTest
  4. {
  5.     interface ICommand { }
  6.    
  7.     class Move : ICommand
  8.     {
  9.         public int dx { get; set; }
  10.         public int dy { get; set; }
  11.     }
  12.  
  13.     class FullScreen : ICommand { }
  14.  
  15.     class Exit : ICommand { }
  16.  
  17.     class Program
  18.     {
  19.         static void Main(string[] args)
  20.         {
  21.  
  22.             int player_x = 0;
  23.             int player_y = 0;
  24.  
  25.             ICommand myCommand = new Move { dx = -1, dy = 0 };
  26.  
  27.             switch (myCommand) {
  28.                 case Move m:
  29.                     player_x += m.dx;
  30.                     player_y += m.dy;
  31.                     break;
  32.                 case FullScreen _:
  33.                     // toggle full screen
  34.                     break;
  35.                 case Exit _:
  36.                     // quit game nicely
  37.                     break;
  38.                    
  39.             }
  40.  
  41.             Console.WriteLine("Hello World!");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement