mvaganov

Basic C# game starting point

Nov 16th, 2021 (edited)
974
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. public class MainClass {
  3.     public static void Main(string[] args) {
  4.         int width = 20, height = 15, x = 4, y = 5, running = 1;
  5.         while (running == 1) {
  6.             Console.SetCursorPosition(0,0);
  7.             for(int row = 0; row < height; ++row) {
  8.                 for(int col = 0; col < width; ++col) {
  9.                     if (row == y && col == x) {
  10.                         Console.Write("@");
  11.                     } else {
  12.                         Console.Write(".");
  13.                     }
  14.                 }
  15.                 Console.Write("\n");
  16.             }
  17.             ConsoleKeyInfo key = Console.ReadKey();
  18.             switch(key.Key) {
  19.                 case ConsoleKey.UpArrow:   --y; break;
  20.                 case ConsoleKey.LeftArrow: --x; break;
  21.                 case ConsoleKey.DownArrow: ++y; break;
  22.                 case ConsoleKey.RightArrow:++x; break;
  23.                 case ConsoleKey.Escape:    running = 0; break;
  24.             }
  25.         }
  26.     }
  27. }
Add Comment
Please, Sign In to add comment