Advertisement
leogvozdkov

Csharp_medium5_go_speed

Oct 24th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4.  
  5.  
  6. namespace IMJunior
  7. {
  8.     class GameObject
  9.     {
  10.         public int x;
  11.         public int y;
  12.         public char visual;
  13.         public int speed;
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             Console.CursorVisible = false;
  21.  
  22.             GameObject go1 = new GameObject();
  23.             go1.x = 10;
  24.             go1.y = 10;
  25.             go1.visual = '#';
  26.             go1.speed = 10;
  27.  
  28.             GameObject go2 = new GameObject();
  29.             go2.x = 15;
  30.             go2.y = 25;
  31.             go2.visual = '$';
  32.             go2.speed = 1;
  33.  
  34.             GameObject[] gameObjects = { go1, go2 };
  35.  
  36.             while (true)
  37.             {
  38.                 foreach (GameObject go in gameObjects)
  39.                 {
  40.                     Draw(go);
  41.                     MoveRight(go);
  42.                 }
  43.                 System.Threading.Thread.Sleep(500);
  44.                 Console.Clear();
  45.             }
  46.  
  47.             //Console.SetCursorPosition(0, 50);
  48.         }
  49.  
  50.         static void Draw(GameObject gameObject)
  51.         {
  52.             Console.SetCursorPosition(gameObject.x, gameObject.y);
  53.             Console.Write(gameObject.visual);
  54.         }
  55.  
  56.         static void MoveRight(GameObject gameObject)
  57.         {
  58.             if (gameObject.x < Console.WindowWidth - 10)
  59.             {
  60.                 gameObject.x += gameObject.speed;
  61.             }
  62.         }
  63.  
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement