using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
internal class Hero
{
private string nickname;
private Vector2 position;
private int id;
private int[,] playerMap;
//생성자
public Hero(int id ,string nickname)
{
this.id = id;
this.nickname = nickname;
}
public void Init(int[,]playerMap ,Vector2 position)
{
this.playerMap = playerMap;
this.position = position;
}
public void PrintPosition()
{
Console.WriteLine("좌표:{0}", this.position.ToString());
}
//플레이어맵을 출력
public void PrintPlayerMap()
{
for(int i = 0; i < this.playerMap.GetLength(0); i++)
{
for(int j = 0; j < this.playerMap.GetLength(1); j++)
{
Console.Write("[{0},{1}]:{2}", i, j, this.playerMap[i, j]);
}
Console.WriteLine();
}
}
}
}
namespace LearnDotnet
{
internal class App
{
int[,] playerMap = new int[3, 3];
public App()
{
Hero hero = new Hero(100, "홍길동");
hero.Init(playerMap, new Vector2(1, 2));
hero.PrintPosition();
hero.PrintPlayerMap();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
internal class Utils
{
public static Vector2 ConvertPosition2Indices(Vector2 position)
{
return new Vector2(position.y, position.x);
}
public static Vector2 ConvertIndices2Position(Vector2 indices)
{
return new Vector2(indices.y, indices.x);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
//구조체: 값형식
//기본생성자 못씀
//
internal struct Vector2
{
public int x;
public int y;
//생성자
public Vector2(int x, int y)
{
this.x = x;
this.y = y;
}
//부모클래스의 virtual 맴버메서드 재정의
public override string ToString()
{
return string.Format("({0},{1})", this.x, this.y);
//return $"({this.x},{this.y})";
}
}
}
배열 그림 그려보기
인벤토리는 클래스 그려보기
앞에서 보여지는 거랑 뒤에 있는 좌표랑 동일시
'C#프로그래밍' 카테고리의 다른 글
딕셔너리 두개 만들기 (0) | 2023.07.26 |
---|---|
7월 25일 복습 (0) | 2023.07.25 |
이차원 배열 맵 캐릭터 움직이기 (0) | 2023.07.25 |
인벤토리 연습 2 (0) | 2023.07.25 |
배열 복습 (0) | 2023.07.25 |