Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace test
- {
- enum eDir
- {
- None,
- Left,
- Top,
- Right,
- Bottom,
- }
- enum eItem
- {
- PowerUp,
- DefenceUp,
- HpUp,
- None,
- }
- enum Stage
- {
- stage1, //0
- stage2, //1
- stage3, //2
- }
- enum Tile
- {
- blank, //0
- wall, //1
- Player, //2
- enemy, //3
- Item_P, //4
- Item_D, //5
- Item_H, //6
- PotalIn, //7
- PotalOut, //8
- Fire, //9
- Water, //10
- Blood, //11
- }
- class Map
- {
- public int x;
- public int y;
- int temp_x;
- int temp_y;
- public Map()
- {
- }
- public int[,] m_MapData = new int[20, 40] //y , x
- // x는 좌표에서는 횡의 값
- // y는 열의값
- {
- {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
- {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},
- {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},
- {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},
- {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},
- {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},
- {1,0,0,0,0,0,0,0,0,3,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},
- {1,0,0,0,0,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1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- };
- public void MapUpdate(Hero a_hero, Monster a_Monster, eDir a_eDir)
- {
- m_MapData[a_Monster.y, a_Monster.x] = (int)Tile.enemy;
- // x는 좌표에서는 횡의 값
- // y는 열의값
- x = a_hero.x;
- y = a_hero.y;
- temp_x = x;
- temp_y = y;
- // 이동할곳 판별
- switch (a_eDir)
- {
- case eDir.Left: { temp_x = x; x -= 1; } break; //열
- case eDir.Right: { temp_x = x; x += 1; } break; //열
- case eDir.Top: { temp_y = y; y -= 1; } break; //횡
- case eDir.Bottom: { temp_y = y; y += 1; } break; //횡
- default: Console.WriteLine("arg error"); break;
- }
- //히어로 맵 업데이트
- if (m_MapData[y, x] != (int)Tile.wall) //벽이 아니면 실행
- {
- //기본이동
- if (m_MapData[y, x] == (int)Tile.blank)
- {
- m_MapData[temp_y, temp_x] = (int)Tile.blank; //지나온자리 블랭크
- m_MapData[y, x] = (int)Tile.Player; //새로운자리로 플레이어 타일변경
- a_hero.x = x; //히어로에 좌표값 찍어주느거
- a_hero.y = y;
- }
- else if (m_MapData[y, x] == (int)Tile.PotalIn)
- {
- int tempX;
- int tempY;
- m_MapData[temp_y, temp_x] = (int)Tile.blank;
- m_MapData[y, x] = (int)Tile.PotalOut;
- tempX = x;
- tempY = y;
- for (int i = 0; i < 20; i++)
- {
- for (int j = 0; j < 40; j++)
- {
- if (m_MapData[i, j] == 8)
- {
- if (i == tempY && j == tempX) continue; //방금 바꾼 포탈은 제외.
- x = j; y = i;
- continue;
- }
- }
- }
- m_MapData[y, x] = (int)Tile.PotalIn;
- m_MapData[y + 1, x] = (int)Tile.Player;
- a_hero.x = x; //히어로에 좌표값 찍어주느거
- a_hero.y = y + 1;
- }
- else if (m_MapData[y, x] == (int)Tile.enemy)
- {
- int eDamage = a_Monster.pow - a_hero.def;
- a_hero.hp -= eDamage;
- }
- }
- }
- public void Render()
- {
- Console.Clear();
- for (int h = 0; h < 20; h++)
- {
- for (int w = 0; w < 40; w++)
- {
- Tile temp = (Tile)m_MapData[h, w];
- switch (temp)
- {
- case Tile.blank:
- Console.Write("▨");
- break;
- case Tile.wall:
- Console.Write("▥");
- break;
- case Tile.Player:
- Console.Write("◎");
- break;
- case Tile.enemy:
- Console.Write("◇");
- break;
- case Tile.Item_P:
- Console.Write("㉬");
- break;
- case Tile.Item_D:
- Console.Write("㉢");
- break;
- case Tile.Item_H:
- Console.Write("♡");
- break;
- case Tile.PotalIn:
- Console.Write("◐");
- break;
- case Tile.PotalOut:
- Console.Write("◑");
- break;
- case Tile.Fire:
- Console.Write("♨");
- break;
- case Tile.Water:
- Console.Write("▩");
- break;
- case Tile.Blood:
- Console.Write("ゃ");
- break;
- default:
- break;
- }
- }
- Console.WriteLine();
- }
- }
- public void StageSelcet()
- {
- }
- }
- //-----------------------------------------------------히어로 시작-------------------------------------
- class Hero
- {
- public int x;
- public int y;
- public int hp;
- public int pow;
- public int def;
- public Tile eHero;
- public Hero(int _x, int _y,
- int _hp, int _pow, int _def)
- {
- x = _x; y = _y;
- hp = _hp; pow = _pow; def = _def;
- }
- public void Update()
- {
- }
- }
- //-----------------------------------------------------몬스터 시작------------------------------------------
- class Monster
- {
- public int x;
- public int y;
- public int hp;
- public int pow;
- public int def;
- public Tile eMonster;
- public Monster(int _x, int _y, int _hp, int _pow, int _def)
- {
- x = _x; y = _y;
- hp = _hp; pow = _pow; def = _def;
- }
- public void Update()
- {
- }
- }
- //-----------------------------------------------------아이템 시작----------------------------------------------------
- class Item
- {
- public int x;
- public int y;
- public int Count = 0;
- public eItem eItem;
- public Item(int _x, int _y, eItem _item)
- {
- x = _x; y = _y;
- eItem = _item;
- }
- public void Update(Hero aHero)
- {
- if (aHero.x == x || aHero.y == y)
- {
- Count++;
- }
- }
- }
- //------------------------------------------------메인---------------------------------------------------
- class Program
- {
- static void Main(string[] args)
- {
- Map map = new Map();
- Hero hero = new Hero(5, 5, 100, 20, 10);
- Monster monster = new Monster(10, 10, 100, 20, 10);
- int GameCount = 0;
- while (true)
- {
- //초기 실행 // 키입력이 없을시 화면에 아무것도 출력안되는거 방지
- if (GameCount == 0)
- {
- map.Render();
- GameCount++;
- }
- eDir eDir = eDir.None;
- var k = Console.ReadKey();
- // 좌우
- if (k.Key == ConsoleKey.LeftArrow ||
- k.Key == ConsoleKey.A)
- {
- eDir = eDir.Left;
- }
- else if (k.Key == ConsoleKey.RightArrow ||
- k.Key == ConsoleKey.D)
- {
- eDir = eDir.Right;
- }
- // 위아래
- if (k.Key == ConsoleKey.DownArrow ||
- k.Key == ConsoleKey.S)
- {
- eDir = eDir.Bottom;
- }
- else if (k.Key == ConsoleKey.UpArrow ||
- k.Key == ConsoleKey.W)
- {
- eDir = eDir.Top;
- }
- //업데이트
- if (eDir != eDir.None)
- {
- map.MapUpdate(hero, monster, eDir);
- }
- //랜더
- map.Render();
- Console.Write($"히어로좌표{hero.y},{hero.x}");
- // 종료
- if (k.Key == ConsoleKey.Q)
- {
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement