Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. namespace test
  9. {
  10. enum eDir
  11. {
  12. None,
  13. Left,
  14. Top,
  15. Right,
  16. Bottom,
  17. }
  18.  
  19. enum eItem
  20. {
  21. PowerUp,
  22. DefenceUp,
  23. HpUp,
  24. None,
  25. }
  26. enum Stage
  27. {
  28. stage1, //0
  29. stage2, //1
  30. stage3, //2
  31. }
  32. enum Tile
  33. {
  34. blank, //0
  35. wall, //1
  36. Player, //2
  37. enemy, //3
  38. Item_P, //4
  39. Item_D, //5
  40. Item_H, //6
  41. PotalIn, //7
  42. PotalOut, //8
  43. Fire, //9
  44. Water, //10
  45. Blood, //11
  46. }
  47. class Map
  48. {
  49.  
  50. public int x;
  51. public int y;
  52. int temp_x;
  53. int temp_y;
  54. public Map()
  55. {
  56.  
  57. }
  58. public int[,] m_MapData = new int[20, 40] //y , x
  59. // x는 좌표에서는 횡의 값
  60. // y는 열의값
  61.  
  62. {
  63. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, //1
  64. {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  65. {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  66. {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  67. {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,1},
  80. {1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  81. {1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
  82. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  83.  
  84. };
  85.  
  86. public void MapUpdate(Hero a_hero, Monster a_Monster, eDir a_eDir)
  87. {
  88. m_MapData[a_Monster.y, a_Monster.x] = (int)Tile.enemy;
  89.  
  90. // x는 좌표에서는 횡의 값
  91. // y는 열의값
  92. x = a_hero.x;
  93. y = a_hero.y;
  94. temp_x = x;
  95. temp_y = y;
  96.  
  97. // 이동할곳 판별
  98. switch (a_eDir)
  99. {
  100. case eDir.Left: { temp_x = x; x -= 1; } break; //열
  101. case eDir.Right: { temp_x = x; x += 1; } break; //열
  102. case eDir.Top: { temp_y = y; y -= 1; } break; //횡
  103. case eDir.Bottom: { temp_y = y; y += 1; } break; //횡
  104. default: Console.WriteLine("arg error"); break;
  105. }
  106.  
  107. //히어로 맵 업데이트
  108.  
  109. if (m_MapData[y, x] != (int)Tile.wall) //벽이 아니면 실행
  110. {
  111. //기본이동
  112. if (m_MapData[y, x] == (int)Tile.blank)
  113. {
  114. m_MapData[temp_y, temp_x] = (int)Tile.blank; //지나온자리 블랭크
  115. m_MapData[y, x] = (int)Tile.Player; //새로운자리로 플레이어 타일변경
  116. a_hero.x = x; //히어로에 좌표값 찍어주느거
  117. a_hero.y = y;
  118. }
  119.  
  120. else if (m_MapData[y, x] == (int)Tile.PotalIn)
  121. {
  122.  
  123. int tempX;
  124. int tempY;
  125. m_MapData[temp_y, temp_x] = (int)Tile.blank;
  126. m_MapData[y, x] = (int)Tile.PotalOut;
  127. tempX = x;
  128. tempY = y;
  129.  
  130. for (int i = 0; i < 20; i++)
  131. {
  132. for (int j = 0; j < 40; j++)
  133. {
  134. if (m_MapData[i, j] == 8)
  135. {
  136. if (i == tempY && j == tempX) continue; //방금 바꾼 포탈은 제외.
  137.  
  138. x = j; y = i;
  139. continue;
  140. }
  141. }
  142. }
  143.  
  144. m_MapData[y, x] = (int)Tile.PotalIn;
  145. m_MapData[y + 1, x] = (int)Tile.Player;
  146. a_hero.x = x; //히어로에 좌표값 찍어주느거
  147. a_hero.y = y + 1;
  148. }
  149. else if (m_MapData[y, x] == (int)Tile.enemy)
  150. {
  151. int eDamage = a_Monster.pow - a_hero.def;
  152. a_hero.hp -= eDamage;
  153. }
  154.  
  155.  
  156.  
  157. }
  158. }
  159.  
  160. public void Render()
  161. {
  162. Console.Clear();
  163. for (int h = 0; h < 20; h++)
  164. {
  165. for (int w = 0; w < 40; w++)
  166. {
  167. Tile temp = (Tile)m_MapData[h, w];
  168. switch (temp)
  169. {
  170. case Tile.blank:
  171. Console.Write("▨");
  172. break;
  173. case Tile.wall:
  174. Console.Write("▥");
  175. break;
  176. case Tile.Player:
  177. Console.Write("◎");
  178. break;
  179. case Tile.enemy:
  180. Console.Write("◇");
  181. break;
  182. case Tile.Item_P:
  183. Console.Write("㉬");
  184. break;
  185. case Tile.Item_D:
  186. Console.Write("㉢");
  187. break;
  188. case Tile.Item_H:
  189. Console.Write("♡");
  190. break;
  191. case Tile.PotalIn:
  192. Console.Write("◐");
  193. break;
  194. case Tile.PotalOut:
  195. Console.Write("◑");
  196. break;
  197. case Tile.Fire:
  198. Console.Write("♨");
  199. break;
  200. case Tile.Water:
  201. Console.Write("▩");
  202. break;
  203. case Tile.Blood:
  204. Console.Write("ゃ");
  205. break;
  206. default:
  207. break;
  208. }
  209. }
  210. Console.WriteLine();
  211. }
  212. }
  213. public void StageSelcet()
  214. {
  215.  
  216. }
  217.  
  218. }
  219. //-----------------------------------------------------히어로 시작-------------------------------------
  220. class Hero
  221. {
  222. public int x;
  223. public int y;
  224. public int hp;
  225. public int pow;
  226. public int def;
  227. public Tile eHero;
  228.  
  229. public Hero(int _x, int _y,
  230. int _hp, int _pow, int _def)
  231. {
  232. x = _x; y = _y;
  233. hp = _hp; pow = _pow; def = _def;
  234. }
  235.  
  236.  
  237. public void Update()
  238. {
  239.  
  240. }
  241. }
  242. //-----------------------------------------------------몬스터 시작------------------------------------------
  243. class Monster
  244. {
  245. public int x;
  246. public int y;
  247. public int hp;
  248. public int pow;
  249. public int def;
  250. public Tile eMonster;
  251.  
  252.  
  253. public Monster(int _x, int _y, int _hp, int _pow, int _def)
  254. {
  255. x = _x; y = _y;
  256. hp = _hp; pow = _pow; def = _def;
  257. }
  258.  
  259. public void Update()
  260. {
  261.  
  262. }
  263.  
  264. }
  265. //-----------------------------------------------------아이템 시작----------------------------------------------------
  266. class Item
  267. {
  268. public int x;
  269. public int y;
  270. public int Count = 0;
  271. public eItem eItem;
  272.  
  273. public Item(int _x, int _y, eItem _item)
  274. {
  275. x = _x; y = _y;
  276. eItem = _item;
  277. }
  278.  
  279. public void Update(Hero aHero)
  280. {
  281. if (aHero.x == x || aHero.y == y)
  282. {
  283. Count++;
  284.  
  285. }
  286. }
  287. }
  288. //------------------------------------------------메인---------------------------------------------------
  289. class Program
  290. {
  291. static void Main(string[] args)
  292. {
  293. Map map = new Map();
  294. Hero hero = new Hero(5, 5, 100, 20, 10);
  295. Monster monster = new Monster(10, 10, 100, 20, 10);
  296. int GameCount = 0;
  297. while (true)
  298. {
  299.  
  300. //초기 실행 // 키입력이 없을시 화면에 아무것도 출력안되는거 방지
  301. if (GameCount == 0)
  302. {
  303. map.Render();
  304. GameCount++;
  305. }
  306.  
  307. eDir eDir = eDir.None;
  308. var k = Console.ReadKey();
  309.  
  310.  
  311. // 좌우
  312. if (k.Key == ConsoleKey.LeftArrow ||
  313. k.Key == ConsoleKey.A)
  314. {
  315. eDir = eDir.Left;
  316. }
  317. else if (k.Key == ConsoleKey.RightArrow ||
  318. k.Key == ConsoleKey.D)
  319. {
  320. eDir = eDir.Right;
  321. }
  322.  
  323. // 위아래
  324. if (k.Key == ConsoleKey.DownArrow ||
  325. k.Key == ConsoleKey.S)
  326. {
  327. eDir = eDir.Bottom;
  328. }
  329. else if (k.Key == ConsoleKey.UpArrow ||
  330. k.Key == ConsoleKey.W)
  331. {
  332. eDir = eDir.Top;
  333. }
  334.  
  335. //업데이트
  336.  
  337. if (eDir != eDir.None)
  338. {
  339. map.MapUpdate(hero, monster, eDir);
  340.  
  341. }
  342.  
  343. //랜더
  344. map.Render();
  345. Console.Write($"히어로좌표{hero.y},{hero.x}");
  346.  
  347. // 종료
  348. if (k.Key == ConsoleKey.Q)
  349. {
  350. break;
  351. }
  352.  
  353. }
  354.  
  355. }
  356. }
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement