C#

2048

송현호 2023. 7. 25. 12:52

Starcraft.exe
0.01MB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Starcraft
{
    internal class App
    {
        //생성자
        public App()
        {
            Board board = new Board();
            Console.WriteLine(board);
            while (true)
            {
                var info = Console.ReadKey();
                if(info.Key == ConsoleKey.LeftArrow)
                {
                    board.Left();
                    for (int i = 0; i < board.size.Length; i++)
                    {
                        Console.Write("{0} ", board.size[i]);
                    }
                }
                if (info.Key == ConsoleKey.RightArrow)
                {
                    board.Right();
                    for (int i = 0; i < board.size.Length; i++)
                    {
                        Console.Write("{0} ", board.size[i]);
                    }
                }
                //if (info.Key == ConsoleKey.UpArrow)
                //{
                //    Console.WriteLine("qd");
                //}
                //if (info.Key == ConsoleKey.DownArrow)
                //{
                //    Console.WriteLine("wd");
                //}
            }
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;

namespace Starcraft
{

    internal class Board
    {
        public int[] size;
        public Board()
        {
            int[] size = new int[4];
            this.size = size;
            Random random = new Random();
            int Index = random.Next(size.Length);
            this.size[Index] = (random.Next(1,3))*2;
            for(int i=0; i<size.Length; i++)
            {
                Console.Write("{0} ",size[i]);
            }
        }

        public void Left()
        {
            for(int i =0; i < size.Length; i++)
            {
                if (size[i] != 0)
                {
                    if (size[i] == size[0])
                    {

                    }

                    else
                    {
                        size[0] = size[i];
                        size[i] = 0;
                    }
                }
                else
                {

                }
            }
        }

        public void Right()
        {
            for (int i = 0; i < size.Length; i++)
            {
                if (size[i] != 0)
                {
                    if (size[i] == size[size.Length-1])
                    {

                    }

                    else
                    {
                        size[size.Length-1] = size[i];
                        size[i] = 0;
                    }
                }
                else
                {

                }
            }
        }

        //public Up()
        //{

        //}

        //public Down()
        //{

        //}
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Starcraft
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //new키워드 : App클래스의 인스턴스 생성하고 생성자를 호출함
            new App();
        }
    }
}

 

'C#' 카테고리의 다른 글

몬스터 아이템 드랍  (0) 2023.07.26
2차원 배열  (0) 2023.07.25
인벤토리1  (0) 2023.07.24
마린 메딕  (0) 2023.07.24
마린 vs 저글링  (0) 2023.07.21