교육받는 곳에서 자리를 바꾸기위해 뽑기함이 필요했는데, 코딩복습도 할겸 자동으로 이름을 섞어주는 프로그램을 코딩해봤다.
뽑기가아닌, 자동으로 섞어버리는걸 만들어버렸는데, 뭐 그거나 그거나 똑같다고 생각한다ㅎㅎ
-----------------------------------------------------------------------------------------------------------------------------------
App.Class
더보기
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Newtonsoft.Json;
namespace RandomMachine
{
class App
{
DataManager dataManager;
Random rand;
SeatInfo seatInfo;
List<string> peopleList;
public App()
{
this.Init();
dataManager.LoadData();
Console.WriteLine("자리를 섞으시려면 엔터를 입력하세요.");
Console.ReadLine();
this.GetMySeat();
//this.SeatOfPrint();
this.SeatOfPrint();
Console.ReadLine();
}
public void Init()
{
this.dataManager = DataManager.GetInstance();
this.rand = new Random();
this.peopleList = new List<string>();
this.seatInfo = new SeatInfo();
}
public void GetMySeat()
{
for (int i = 0; i < this.dataManager.GetDicLangth(); i++)
{
}
this.SuffleSeat(this.peopleList);
}
public void SuffleSeat(List<string> list)
{
int randominx1 = 0;
int randominx2 = 0;
int SeatNum = 0;
string temp = null;
{
temp = list[randominx1];
list[randominx1] = list[randominx2];
list[randominx2] = temp;
}
foreach (var element in list)
{
SeatNum++;
}
foreach (var pair in this.seatInfo.dicSeatInfo)
{
}
this.SaveToLocal(this.seatInfo);
}
public void SaveToLocal(SeatInfo info)
{
File.WriteAllText("./data/random_seat_result.json",JsonConvert.SerializeObject(info.dicSeatInfo));
}
public void SeatOfPrint()
{
Console.WriteLine("=====================================좌석배치표========================================");
Console.Write("[ 1 ] [ 2 ] [ 3 ] [ 4 ]\t\t");
Console.WriteLine("[ 5 ] [ 6 ] [ 7 ] [ 8 ]");
Console.Write(" [ 9 ] [ 10 ]\t\t");
Console.WriteLine("[ 11 ] [ 12 ] [ 13 ] [ 14 ]");
Console.Write(" \t\t");
Console.WriteLine("[ 15 ] [ 16 ] ");
Console.WriteLine("=======================================================================================");
}
}
}
|
DataManager.Class
더보기
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Newtonsoft.Json;
namespace RandomMachine
{
class DataManager
{
private static DataManager instance;
private Dictionary<int, NameData> dicNameData;
private DataManager()
{
this.Init();
}
public static DataManager GetInstance()
{
if (instance == null)
{
instance = new DataManager();
}
return DataManager.instance;
}
public void Init()
{
this.dicNameData = new Dictionary<int, NameData>();
}
public void LoadData()
{
this.dicNameData = (JsonConvert.DeserializeObject<NameData[]>
(File.ReadAllText(NAME_DATA_PATH))).ToDictionary(x => x.id, x => x);
}
public NameData GetNameById(int id)
{
return this.dicNameData[id];
}
public int GetDicLangth()
{
}
}
}
|
NameData.Class
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RandomMachine
{
class NameData
{
public int id;
public string name;
}
}
|
SeatInfo.Class
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RandomMachine
{
class SeatInfo
{
public Dictionary<string, string> dicSeatInfo;
public SeatInfo()
{
this.dicSeatInfo = new Dictionary<string, string>();
}
}
}
|
'C# > 복습' 카테고리의 다른 글
2020-05-25 LINQ의 기본 (0) | 2020.05.25 |
---|---|
2020-05-17 델리게이트, 선언방법, 활용법, 이벤트 (1) | 2020.05.17 |
2020-04-30 삼항연산자, Null병합연산자, 연산자 우선순위 (0) | 2020.04.30 |
2020-04-28 저장 예제만들어 복습 (0) | 2020.04.29 |
2020-04-25 업적 시스템 복습(2) && 생각정리 (0) | 2020.04.25 |