Exemple #1
0
            }//地图文件读取(关卡数-地图)

            public char[,] PosRead(string[] levelmap)
            {
                List <char[]> charmap = new List <char[]>();

                char[,] mappos = new char[26, 26];
                string[] array = new string[levelmap.Length - 2];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = levelmap[i + 1];
                }

                int height = 0;

                foreach (var s in array)
                {
                    char[] a = new char[s.Length - 2];
                    for (int i = 0; i < a.Length; i++)
                    {
                        a[i] = s[i + 1];
                    }
                    charmap.Add(a); //char数组里面增加了一串横的坐标里的内容
                    int length = 0; //横坐标
                    for (length = 0; length < 24 && a.Length > length; length++)
                    {
                        mappos[height, length] = a[length];
                        if (a[length] == '#')
                        {
                            Wall wall = new Wall("□", 1001);
                            wall.SetPos(length, height);
                            Rogue.walls[MapPos(wall.x, wall.y)] = wall;
                        }
                        if (a[length] == 'o')
                        {
                            ElectricityDoor electricitydoor = new ElectricityDoor("×", 8);
                            electricitydoor.SetPos(length, height);
                            Rogue.electricitydoors[MapPos(electricitydoor.x, electricitydoor.y)] = electricitydoor;
                        }
                        if (a[length] == 'y')
                        {
                            Thorn thorn = new Thorn("◆", 5001);
                            thorn.SetPos(length, height);
                            Rogue.thorns[MapPos(thorn.x, thorn.y)] = thorn;
                        }
                        if (a[length] == 'w')
                        {
                            ElectricSwitch electricSwitch = new ElectricSwitch("※", 8);
                            electricSwitch.SetPos(length, height);
                            Rogue.electricSwitchs[MapPos(electricSwitch.x, electricSwitch.y)] = electricSwitch;
                        }
                        if (a[length] == 'u')
                        {
                            LongPole longPole = new LongPole("♂", 1);
                            longPole.SetPos(length, height);
                            Rogue.longpoles[MapPos(longPole.x, longPole.y)] = longPole;
                        }
                        if (a[length] == 'i')
                        {
                            Transfer transfer1 = new Transfer("¤", 1);
                            transfer1.SetPos(length, height);
                            Rogue.transfers[MapPos(transfer1.x, transfer1.y)] = transfer1;
                        }
                        if (a[length] == 'l')
                        {
                            Transfer transfer2 = new Transfer("§", 2);
                            transfer2.SetPos(length, height);
                            Rogue.transfers[MapPos(transfer2.x, transfer2.y)] = transfer2;
                        }
                        if (a[length] == ',')
                        {
                            Transfer transfer3 = new Transfer("◎", 1);
                            transfer3.SetPos(length, height);
                            Rogue.transfers[MapPos(transfer3.x, transfer3.y)] = transfer3;
                        }
                        if (a[length] == '.')
                        {
                            Transfer transfer4 = new Transfer("◎", 1);
                            transfer4.SetPos(length, height);
                            Rogue.transfers[MapPos(transfer4.x, transfer4.y)] = transfer4;
                        }
                        if (a[length] == 'p')
                        {
                            NPC oldman1 = new NPC("何炅", 1);
                            oldman1.SetPos(length, height);
                            Rogue.npcs[MapPos(oldman1.x, oldman1.y)] = oldman1;
                        }
                        if (a[length] == 'q')
                        {
                            NPC oldman2 = new NPC("恶魔", 2);
                            oldman2.SetPos(length, height);
                            Rogue.npcs[MapPos(oldman2.x, oldman2.y)] = oldman2;
                        }
                        if (a[length] == 'v')
                        {
                            NPC oldman3 = new NPC("撒贝宁", 3);
                            oldman3.SetPos(length, height);
                            Rogue.npcs[MapPos(oldman3.x, oldman3.y)] = oldman3;
                        }
                        if (a[length] == 'r')
                        {
                            Monster monster1 = new Monster("〓", 1, 5, 1);
                            monster1.SetPos(length, height);
                            Rogue.monsters[MapPos(monster1.x, monster1.y)] = monster1;
                        }
                        if (a[length] == '1')
                        {
                            Key key1 = new Key("Ⅰ", 1);
                            key1.SetPos(length, height);
                            Rogue.keys[MapPos(key1.x, key1.y)] = key1;
                        }
                        if (a[length] == '2')
                        {
                            Key key2 = new Key("Ⅱ", 2);
                            key2.SetPos(length, height);
                            Rogue.keys[MapPos(key2.x, key2.y)] = key2;
                        }
                        if (a[length] == '3')
                        {
                            Key key3 = new Key("Ⅲ", 3);
                            key3.SetPos(length, height);
                            Rogue.keys[MapPos(key3.x, key3.y)] = key3;
                        }
                        if (a[length] == '4')
                        {
                            Key key4 = new Key("Ⅳ", 4);
                            key4.SetPos(length, height);
                            Rogue.keys[MapPos(key4.x, key4.y)] = key4;
                        }
                        if (a[length] == '5')
                        {
                            Key key5 = new Key("Ⅴ", 5);
                            key5.SetPos(length, height);
                            Rogue.keys[MapPos(key5.x, key5.y)] = key5;
                        }
                        if (a[length] == '6')
                        {
                            Key key6 = new Key("Ⅵ", 6);
                            key6.SetPos(length, height);
                            Rogue.keys[MapPos(key6.x, key6.y)] = key6;
                        }
                        if (a[length] == '7')
                        {
                            Key key7 = new Key("Ⅶ", 7);
                            key7.SetPos(length, height);
                            Rogue.keys[MapPos(key7.x, key7.y)] = key7;
                        }
                        if (a[length] == 'a')
                        {
                            Door door1 = new Door("①", 1);
                            door1.SetPos(length, height);
                            Rogue.doors[MapPos(door1.x, door1.y)] = door1;
                        }
                        if (a[length] == 'b')
                        {
                            Door door2 = new Door("②", 2);
                            door2.SetPos(length, height);
                            Rogue.doors[MapPos(door2.x, door2.y)] = door2;
                        }
                        if (a[length] == 'c')
                        {
                            Door door3 = new Door("③", 3);
                            door3.SetPos(length, height);
                            Rogue.doors[MapPos(door3.x, door3.y)] = door3;
                        }
                        if (a[length] == 'd')
                        {
                            Door door4 = new Door("④", 4);
                            door4.SetPos(length, height);
                            Rogue.doors[MapPos(door4.x, door4.y)] = door4;
                        }
                        if (a[length] == 'e')
                        {
                            Door door5 = new Door("⑤", 5);
                            door5.SetPos(length, height);
                            Rogue.doors[MapPos(door5.x, door5.y)] = door5;
                        }
                        if (a[length] == 'f')
                        {
                            Door door6 = new Door("⑥", 6);
                            door6.SetPos(length, height);
                            Rogue.doors[MapPos(door6.x, door6.y)] = door6;
                        }
                        if (a[length] == 'g')
                        {
                            Door door7 = new Door("⑦", 7);
                            door7.SetPos(length, height);
                            Rogue.doors[MapPos(door7.x, door7.y)] = door7;
                        }
                        if (a[length] == 'h')
                        {
                            Monster monster10 = new Monster("★", 1, 5, 1);
                            monster10.SetPos(length, height);
                            Rogue.monsters[MapPos(monster10.x, monster10.y)] = monster10;
                        }
                        if (a[length] == 'j')
                        {
                            Monster monster11 = new Monster("☆", 1, 5, 1);
                            monster11.SetPos(length, height);
                            Rogue.monsters[MapPos(monster11.x, monster11.y)] = monster11;
                        }
                        if (a[length] == 'k')
                        {
                            Monster monster12 = new Monster("○", 1, 5, 1);
                            monster12.SetPos(length, height);
                            Rogue.monsters[MapPos(monster12.x, monster12.y)] = monster12;
                        }
                        if (a[length] == 't')
                        {
                            Monster monster13 = new Monster("●", 1, 5, 1);
                            monster13.SetPos(length, height);
                            Rogue.monsters[MapPos(monster13.x, monster13.y)] = monster13;
                        }
                        if (a[length] == 'm')
                        {
                            Monster monster14 = new Monster("◇", 1, 5, 1);
                            monster14.SetPos(length, height);
                            Rogue.monsters[MapPos(monster14.x, monster14.y)] = monster14;
                        }
                        if (a[length] == 'n')
                        {
                            Monster monster15 = new Monster("◆", 1, 5, 1);
                            monster15.SetPos(length, height);
                            Rogue.monsters[MapPos(monster15.x, monster15.y)] = monster15;
                        }
                    }
                    height++;
                }
                return(mappos);
            }
Exemple #2
0
        // 返回值: 是否需要刷新
        static bool MovePlayer()
        {
            ConsoleKeyInfo key = Console.ReadKey(true);

            int next_x = player.x;
            int next_y = player.y;

            if (key.Key == ConsoleKey.UpArrow)
            {
                next_y -= 1;
            }
            else if (key.Key == ConsoleKey.DownArrow)
            {
                next_y += 1;
            }
            else if (key.Key == ConsoleKey.LeftArrow)
            {
                next_x -= 1;
            }
            else if (key.Key == ConsoleKey.RightArrow)
            {
                next_x += 1;
            }
            else
            {
                return(true);
            }
            if (next_x < 0 || next_x >= map_width - 2 || next_y < 0 || next_y >= map_height - 2)
            {
                return(true);
            }
            int next_pos = MapPos(next_x, next_y);

            if (keys.ContainsKey(next_pos))
            {
                Key key1 = keys[next_pos];
                player.bag.Add(key1);
                string s;
                if (key1.OnTalk(player, out s))
                {
                    npcs.Remove(next_pos);
                    object o = key1.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                keys.Remove(next_pos);
            }
            else if (doors.ContainsKey(next_pos))
            {
                Door   door = doors[next_pos];
                string s;
                if (door.OnTalk(player, out s))
                {
                    //npcs.Remove(next_pos);
                    object o = door.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                for (int n = 0; n < player.bag.Count; n++)
                {
                    if (player.bag[n].id == doors[next_pos].id)
                    {
                        player.bag.RemoveAt(n);
                        doors.Remove(next_pos);
                        break;
                    }
                }
                return(false);
            }
            if (electricSwitchs.ContainsKey(next_pos))
            {
                ElectricSwitch electricSwitch = electricSwitchs[next_pos];
                player.bags.Add(electricSwitch);
                string s;
                if (electricSwitch.OnTalk(player, out s))
                {
                    npcs.Remove(next_pos);
                    object o = electricSwitch.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                electricSwitchs.Remove(next_pos);
            }
            else if (electricitydoors.ContainsKey(next_pos))
            {
                ElectricityDoor electricitydoor = electricitydoors[next_pos];
                string          s;
                if (electricitydoor.OnTalk(player, out s))
                {
                    //npcs.Remove(next_pos);
                    object o = electricitydoor.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                for (int n = 0; n < player.bags.Count; n++)
                {
                    if (player.bags[n].id == electricitydoors[next_pos].id)
                    {
                        electricSwitchs.Remove(next_pos); electricitydoors.Remove(next_pos);
                    }
                }
                return(false);
            }
            if (walls.ContainsKey(next_pos))
            {
                return(false);
            }
            else if (monsters.ContainsKey(next_pos))
            {
                Monster monster = monsters[next_pos];
                string  s;
                if (monster.OnTalk(player, out s))
                {
                    //npcs.Remove(next_pos);
                    object o = monster.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                game_over  = true;
                return(false);
            }
            else if (longpoles.ContainsKey(next_pos))
            {
                LongPole longPole = longpoles[next_pos];
                player.bagss.Add(longPole);
                string s;
                if (longPole.OnTalk(player, out s))
                {
                    object o = longPole.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                longpoles.Remove(next_pos);
                below_text = s;
                return(false);
            }
            if (transfers.ContainsKey(next_pos))
            {
                Transfer transfer = transfers[next_pos];
                string   s;
                if (transfer.OnTalk(player, out s))
                {
                    object o = transfer.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                if (transfers[next_pos].name == "¤")
                {
                    player.x = 21;
                    player.y = 23;
                }
                else if (transfers[next_pos].name == "§")
                {
                    player.x = 12;
                    player.y = 17;
                }
                else if (transfers[next_pos].name == "◎")
                {
                    player.x = 3;
                    player.y = 0;
                }
                return(false);
            }
            else if (npcs.ContainsKey(next_pos))
            {
                Key newkey = new Key("1", 1);
                player.bag.Add(newkey);
                NPC    npc = npcs[next_pos];
                string s;
                if (npc.OnTalk(player, out s))
                {
                    npcs.Remove(next_pos);
                    object o = npc.AfterDisappear();
                    if (o is Monster)
                    {
                        Monster m = o as Monster;
                        monsters[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
                //{ npcs.Remove(next_pos); }
                return(true);
            }
            else
            {
                int a, b;
                MapXY(next_pos, out a, out b);
                player.x = a;
                player.y = b;
            }

            return(true);
        }