Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
85
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. namespace M5_1
  6.  
  7. {
  8.  
  9.     class GameObject
  10.     {
  11.         public int x;
  12.         public int y;
  13.         public char visual;
  14.         public int speed;
  15.     }
  16.  
  17.     class Program
  18.     {
  19.         static void Main(string[] args)
  20.         {
  21.             Console.CursorVisible = false;
  22.  
  23.             GameObject go1 = new GameObject();
  24.             go1.x = 10;
  25.             go1.y = 10;
  26.             go1.visual = '#';
  27.             go1.speed = 2;
  28.  
  29.             GameObject go2 = new GameObject();
  30.             go2.x = 15;
  31.             go2.y = 25;
  32.             go2.visual = '$';
  33.             go2.speed = 5;
  34.  
  35.             GameObject[] gameObjects = { go1, go2 };
  36.  
  37.             while (true)
  38.             {
  39.                 foreach (GameObject go in gameObjects)
  40.                 {
  41.                     Draw(go);
  42.                     MoveRight(go);
  43.                 }
  44.                 System.Threading.Thread.Sleep(500);
  45.                 Console.Clear();
  46.             }
  47.  
  48.             Console.SetCursorPosition(0, 50);
  49.         }
  50.  
  51.         static void Draw(GameObject gameObject)
  52.         {
  53.             Console.SetCursorPosition(gameObject.x, gameObject.y);
  54.             Console.Write(gameObject.visual);
  55.         }
  56.  
  57.         static void MoveRight(GameObject gameObject)
  58.         {
  59.             if (gameObject.x < Console.WindowWidth - 10)
  60.             {
  61.                 gameObject.x += gameObject.speed;
  62.             }
  63.         }
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement