[내일 배움 캠프 Unity 4기] 04.24 TIL

김용준·2024년 4월 24일
0

내일배움캠프

목록 보기
3/47

Goals

  • Wireframe for personal project
  • Make main scene with the component

Tasks

Scene

As the project scheme can be organized with each scene. The each scene can be catagorized with below list

  • Start scene
    where the user have to insert the name of character

  • Main scene
    Through this scene, we can go any other scene.

  • Status
    The whole information of player are displayed on this scene; Stats of players' own properties and the bonus stats from the equipments.

  • Inventory
    When you buy items on the shop, the item with its short information can be seen in this scene
    If this project expanded to the dungeon, the item dropped from the monster also stored in here

  • Shop
    Player can buy equipments by the gold. I also applied the limiation of stocks


Questions & Try & Answer

Q. How does the 'Console.SetCursorPosition' work on the display?

T. Try below code snippet

Console.WriteLine("inital pos");

// to check the position with the value
for(int a=0; a<10; a++)
{
	Console.SetCursorPosition(a,a);
    Console.WriteLine("The left edge was moved to (" + a + "," + a + " )");
}


We can see the 'initial pos' were disappeared due to overlaps. Also the vertical number does not have same height with the width. When you tend to use this method, you should know this behaviour.

Q. How to align the text to the left,right and center?

A.

Align to the left and right is easily possible rather than center align. Just follow the below code snippet.

Console.WriteLine("중앙: {0}", CenterAlign("텍스트", 20)); // center
Console.WriteLine("좌측: {0,-20}", "텍스트"); // left
Console.WriteLine("우측: {0,20}", "텍스트"); // right

Before the explanation of the parameter, we should understand the structure of WriteLine. The WriteLine or Write create the pad which is invisible to user. But the concept can also be seen in Console.SetCursePosition(). That means the invisible pad created at the input position. And the string input is displayed on the pad. If you overlap the text by using WriteLine(), you can see the sliced text.
The argument 20 means the width of pad. and its sign means the direction which you want align. For instance, when we write the argument {0,50}, the pad which has 50 pt width was created and the first argument was aligned to right.

For the center align, we need the other method like below

public static string CenterAlign(string text, int width)
{
    return text.PadLeft((width - text.Length) / 2 + text.Length).PadRight(width);
}

This method modify the pad of the text. The left edge of pad is moved with the length of text and the width. And the right edge is expanded to the width

Fianally, we can see the result like

profile
꿈이큰개발자지망생

0개의 댓글