Ejemplo n.º 1
0
        public List <Block> LoadMapData(string path)
        {
            string[]     mapData   = File.ReadAllLines(path);
            List <Block> mapBlocks = new List <Block>();

            for (int i = 0; i < mapData.Length; i++)
            {
                char[] curLine = mapData[i].ToCharArray();
                for (int j = 0; j < curLine.Length; j++)
                {
                    Pos   pos             = new Pos((j * 2 + 2), i + 1); // RowCol->X,Y
                    Block tempCreateBlock = new Block();
                    switch (curLine[j])
                    {
                    case '■':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Wall);
                        mapBlocks.Add(tempCreateBlock);
                        break;

                    case '★':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Door);
                        mapBlocks.Add(tempCreateBlock);
                        break;

                    case '▲':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Box);
                        mapBlocks.Add(tempCreateBlock);
                        break;

                    case ' ':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Null);
                        mapBlocks.Add(tempCreateBlock);
                        break;

                    case '□':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Door);
                        mapBlocks.Add(tempCreateBlock);
                        break;

                    case '\n':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Turn);
                        mapBlocks.Add(tempCreateBlock);
                        break;

                    case '⊙':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Monster);
                        mapBlocks.Add(tempCreateBlock);
                        tempCreateBlock.npc = LoadController.Instance.RollMonster();                                //return a monster
                        break;

                    case '¤':
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.Item);
                        mapBlocks.Add(tempCreateBlock);
                        tempCreateBlock.item = new Item();
                        break;
                    }
                    if (curLine[j] >= 'ァ' && curLine[j] <= 'ヶ')
                    {
                        tempCreateBlock = new Block(pos, curLine[j], BlockType.NPC);
                        mapBlocks.Add(tempCreateBlock);
                        //TODO Roll a NPC from Manager.
                        tempCreateBlock.npc = LoadController.Instance.RollNPC();                        //return a NPC
                    }
                }
            }
            return(mapBlocks);
        }
Ejemplo n.º 2
0
        public void CheckBlock(Pos nextPos)
        {
            index = (nextPos.y - 1) * 10 + (nextPos.x - 2) / 2;
            //kinds of Block Check and effect.
            if (map[index].style == ' ' && map[index].type != BlockType.Player)
            {
                //change display
                Console.SetCursorPosition(chrBlock[pointer].pos.x, chrBlock[pointer].pos.y);
                Console.Write(' ');
                Console.SetCursorPosition(nextPos.x, nextPos.y);
                Console.Write(chrBlock[pointer].style);

                //change style
                map[Pos2Index(chrBlock[pointer].pos)].type = BlockType.Null;                //former->null
                chrBlock[pointer].pos = nextPos;
                map[Pos2Index(chrBlock[pointer].pos)].type = BlockType.Player;              //latter->NPC
            }
            if (map[index].style == '▲')
            {
                //controller.OpenPanel()
            }
            if (map[index].style == '¤')
            {
                ConsoleKey cur_key = Console.ReadKey(true).Key;
                if (cur_key == ConsoleKey.Enter)
                {
                    controller.OpenPanel(new DescripPanel("I n f o ", new Pos(10, 10), new Size(10, 4), "获得了物品" + map[index].item.name));
                    chrBlock[pointer].npc.bag.Add(map[index].item);
                }
                map[index].style = ' ';
                map[index].type  = BlockType.Null;
            }
            if (map[index].style == '⊙')
            {
                ConsoleKey cur_key = Console.ReadKey(true).Key;
                if (cur_key == ConsoleKey.Enter)
                {
                    //Create a FightPanel with current Player-info
                    Fight curFight = new Fight();
                    {
                        //init Team
                        foreach (Block curBlock in teamDict[pointer])
                        {
                            curFight.playerTeam.Add(curBlock.npc);
                        }
                        //init Monster
                        curFight.hostile = map[index].npc;                        //default test
                    }
                    controller.OpenPanel(new FightPanel("F i g h t ", new Pos(0, 0), new Size(45, 30), curFight));
                }
            }
            if (map[index].type == BlockType.NPC)
            {
                ConsoleKey cur_key = Console.ReadKey(true).Key;
                if (cur_key == ConsoleKey.Enter)
                {
                    if (teamDict[pointer].Count < 3)
                    {
                        //Create a MessagePanel with current Player-info
                        DescripPanel Info = new DescripPanel("I n f o ", new Pos(10, 10), new Size(10, 4), map[index].npc.name + "加入了队伍");
                        controller.OpenPanel(Info);
                        //updata team-info
                        teamDict[pointer].Add(new Block(map[index]));

                        //update block-info
                        map[index].style = ' ';
                        map[index].type  = BlockType.Null;
                        map[index].npc   = null;

                        UpdateOptions();
                        controller.OnlyDrawTopPanel();
                    }
                    else
                    {
                        DescripPanel Info = new DescripPanel("I n f o ", new Pos(10, 10), new Size(10, 4), "队伍已满");
                        controller.OpenPanel(Info);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override int OperateOption()
        {
            if (!isTop)
            {
                return(-1);
            }
            ConsoleKey cur_key = Console.ReadKey(true).Key;

            switch (cur_key)
            {
            //pointer in this Class equals chr's index
            case ConsoleKey.Tab:
                if (pointer < chrBlock.Count - 1)
                {
                    pointer++;
                }
                else
                {
                    pointer = 0;
                }
                break;

            case ConsoleKey.T:
                controller.OpenPanel(new TeamPanel("T e a m ", new Pos(10, 10), new Size(23, 6), this));
                break;

            case ConsoleKey.W:
                Pos posW = new Pos(chrBlock[pointer].pos.x, chrBlock[pointer].pos.y - 1);
                CheckBlock(posW);
                Console.SetCursorPosition(80, 3);
                Console.Write(chrBlock[pointer].pos.x.ToString() + "," + chrBlock[pointer].pos.y.ToString() + "  ");
                foreach (Block i in map)
                {
                    if (i.style == '★')
                    {
                        Console.SetCursorPosition(80, 4);
                        Console.Write(i.pos.x.ToString() + "," + i.pos.y.ToString());
                    }
                }
                break;

            case ConsoleKey.S:
                Pos posS = new Pos(chrBlock[pointer].pos.x, chrBlock[pointer].pos.y + 1);
                CheckBlock(posS);
                Console.SetCursorPosition(80, 3);
                Console.Write(chrBlock[pointer].pos.x.ToString() + "," + chrBlock[pointer].pos.y.ToString() + "  ");
                break;

            case ConsoleKey.A:
                Pos posA = new Pos(chrBlock[pointer].pos.x - 2, chrBlock[pointer].pos.y);
                CheckBlock(posA);
                Console.SetCursorPosition(80, 3);
                Console.Write(chrBlock[pointer].pos.x.ToString() + "," + chrBlock[pointer].pos.y.ToString() + "  ");
                break;

            case ConsoleKey.D:
                Pos posD = new Pos(chrBlock[pointer].pos.x + 2, chrBlock[pointer].pos.y);
                CheckBlock(posD);
                //Console.SetCursorPosition(80 , 3);
                //Console.Write(chrBlock[pointer].pos.x.ToString() + "," + chrBlock[pointer].pos.y.ToString() + "  ");
                break;

            case ConsoleKey.Escape:
                ResetOutputStyle();
                controller.OpenPanel(new GlobalStaticPanel(PanelType.Menu));
                break;
            }
            return(-1);
        }
Ejemplo n.º 4
0
 public int Pos2Index(Pos pos)
 {
     return((pos.y - 1) * 10 + (pos.x - 2) / 2);
 }
Ejemplo n.º 5
0
 public Pos(Pos pos)
 {
     x = pos.x;
     y = pos.y;
 }