• Home
  • About
    • Hanna's Blog photo

      Hanna's Blog

      I wanna be a global developer.

    • Learn More
    • Email
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[C#] Bullet Map

22 Dec 2020

Reading time ~1 minute

Reference by [C#과 유니티로 만드는 MMORPG 게임 개발 시리즈] Part2: 자료구조와 알고리즘

Code

  using System;

  namespace Bullet_Map
  {
    class Program
    {
      class Map
      {
        int[,] tiles = {
          { 1, 1, 1, 1, 1},
          { 1, 0, 0, 0, 1},
          { 1, 0, 0, 0, 1},
          { 1, 0, 0, 0, 1},
          { 1, 1, 1, 1, 1},
        };

        public void Render()
        {
          ConsoleColor defaultColor = Console.ForegroundColor;

          for (int y = 0; y < tiles.GetLength(1); y++)
          {
            for (int x = 0; x < tiles.GetLength(0); x++)
            {
              if (tiles[y, x] == 1)
                Console.ForegroundColor = ConsoleColor.Red;
              else
                Console.ForegroundColor = ConsoleColor.Green;
              Console.Write('\u25cf');
            }
            Console.WriteLine();
          }

          Console.ForegroundColor = defaultColor;
        }
      }
      
      static void Main(string[] args)
      {
        Map map = new Map();
        map.Render();
      }
    }
  }

Multidimensional Arrays

  • An array of more than two dimensions
  • Has another array as an array element
  int[,] tiles = {
          { 1, 1, 1, 1, 1},
          { 1, 0, 0, 0, 1},
          { 1, 0, 0, 0, 1},
          { 1, 0, 0, 0, 1},
          { 1, 1, 1, 1, 1},
        };

ConsoleColor

  • ConsoleColor
    • Specifies a constant that defines the foreground and background colors of the console
  ConsoleColor defaultColor = Console.ForegroundColor;
  ...
  Console.ForegroundColor = ConsoleColor.Red;
  • Console.ForegroundColor
    • Gets or sets the foreground color of the console
  ConsoleColor defaultColor = Console.ForegroundColor;

Result

C# Bullet Map

Download



C#Game Share Tweet +1