ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-05-06 [2차원배열]
    카테고리 없음 2020. 5. 6. 18:28
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    using System.ComponentModel;
     
    namespace Study_021
    {
        class APP
        {
            GameObject[,] tileMap;
            int[,] tileMap2;
     
            int totalRows = 5;
            int totalCols = 6;
     
            public APP()
            {
                this.Init();
                this.CreatetileMap();
     
     
                this.PrinttileMap();
     
                this.CreatetileMap2();
     
                this.PrinttileMap2();
     
            }
            private void Init()
            {
                this.tileMap2 = new int[this.totalRows, this.totalCols];
            }
     
            public void CreatetileMap()
            {
                this.tileMap = new GameObject[this.totalRows, this.totalCols];
     
                for (int row = 0; row < this.totalRows; row++)
                {
                    for (int col = 0; col < this.totalCols; col++)
                    {
                        var tile = new Tile(this.tileMap2[row, col]);
                        this.tileMap[row, col] = tile;
                    }
     
                }
     
            }
     
            public void CreatetileMap2()
            {
                var path = File.ReadAllText("./data/tilemap11.txt");
              
                var element = path.Split('\n');
                for (int row = 0; row < this.totalRows; row++)
                {
                    var element2 = element[row].Split(',');
                    for (int col = 0; col < this.totalCols; col++)
                    {
                        this.tileMap2[row, col] = int.Parse(element2[col]);
                    }
                }
            }
     
            public void PrinttileMap()
            {
                for (int row = 0; row < this.totalRows; row++)
                {
                    for (int col = 0; col < this.totalCols; col++)
                    {
                        var tile = (Tile)this.tileMap[row, col];
                        Console.Write("({0},{1}) {2}",row ,col ,tile);
                    }
                    Console.WriteLine();
                }
     
            }
     
            public void PrinttileMap2()
            {
                for (int row = 0; row < this.totalRows; row++)
                {
                    for (int col = 0; col < this.totalCols; col++)
                    {
                        Console.Write(this.tileMap2[row, col] + " ");
                    }
                    Console.WriteLine();
                }
     
            }
     
            public int[] ConvertIndexToPosition(int row, int col)
            {
                // 1, 0 -----> 0, -1 
                int[] rtnArr = new int[2];
                int x = col;
                int y = row;
                rtnArr[0= x;
                rtnArr[1= y * -1;
     
                return rtnArr;
            }
     
            public (int row, int col) ConvertPositionToIndex(int x, int y)
            {
                if (y < 0) y *= -1;
                return (row: y, col: x);
            }
     
            public Tuple<intint> ConvertPositionToIndex2(int x, int y)
            {
                if (y < 0) y *= -1;
                return Tuple.Create<intint>(y, x);
     
            }
     
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.IO;
    using System.Runtime.InteropServices;
     
    namespace Study_021
    {
        class Tile : GameObject
        {
            public int id;
     
            public Tile(int id)
            {
               this.id = id;
            }
     
     
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_021
    {
        class Character : GameObject
        {
            public int id;
            public string name;
     
            public Character(int id, string name)
            {
                this.id = id;
                this.name = name;
     
            }
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_021
    {
        class Vector2
        {
            int x;
            int y;
     
            public Vector2(int x, int y)
            {
                this.x = x;
                this.y = y;  
            }
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace Study_021
    {
        class GameObject
        {
            public int id;
            public string Name;
            public int x;
            public int y;
     
            public GameObject()
            {
             
     
            }
     
            //public static string ToString()
            //{
                
            //}
     
     
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

Designed by Tistory.