Exemple #1
0
        // 返回值: 是否需要刷新
        static bool MovePlayer()//移动玩家
        {
            ConsoleKeyInfo key = Console.ReadKey();

            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 || next_y < 0 || next_y >= map_height)
            {
                return(true);
            }
            int next_pos = MapPos(next_x, next_y);

            if (moneys.ContainsKey(next_pos))//如果遇到金币
            {
                Money money = moneys[next_pos];
                below_text    = "捡到 " + money.money + " 颗金币。";
                player.money += money.money;
                moneys.Remove(next_pos);
            }
            else if (loutis_d.ContainsKey(next_pos))//如果遇到往下走的楼梯
            {
                Rogue.monsters.Clear();
                Rogue.walls.Clear();
                Rogue.yaoshis.Clear();
                Rogue.doors.Clear();
                Rogue.trap2s.Clear();
                Rogue.traps.Clear();
                Rogue.loutis_u.Clear();
                Map_save();
                DrawOther();
            }

            else if (yaoshis.ContainsKey(next_pos))
            {
                Yaoshi yaoshi = yaoshis[next_pos];
                below_text     = "捡到一把钥匙";
                player.yaoshi += 1;
                yaoshis.Remove(next_pos);
            }
            else if (doors.ContainsKey(next_pos))
            {
                if (player.yaoshi >= 1)
                {
                    Door door = doors[next_pos];
                    below_text     = "门打开了";
                    player.yaoshi -= 1;
                    doors.Remove(next_pos);
                }
                else
                {
                    below_text = "寻找一把钥匙,方可打开此门";
                }
            }
            else if (monsters.ContainsKey(next_pos))//如果遇到怪兽
            {
                Monster monster = monsters[next_pos];
                string  info;
                int     result = player.Attack(monster, out info);
                below_text = info;
                if (result == -1)
                {
                    GameOver();
                    return(true);
                }
                else if (result == 1)
                {
                    bool ret = onMonsterDead(monster);
                    if (ret)
                    {
                        below_text += "怪物死亡。";
                        player.AddExp(monster.level);
                        monsters.Remove(next_pos);
                    }
                }
            }
            else if (npcs.ContainsKey(next_pos))//如果遇到NPC
            {
                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;
            }
            else if (walls.ContainsKey(next_pos))//如果遇到墙
            {
            }
            else if (trap2s.ContainsKey(next_pos))//如果遇到陷阱2
            {
                Trap trap = trap2s[next_pos];
                trap2s.Remove(next_pos);
                Rogue.AddMonster(11, 8, 4);
                Rogue.AddMonster(12, 8, 4);
                Rogue.AddMonster(13, 8, 4);
            }
            else if (traps.ContainsKey(next_pos))//如果遇到陷阱
            {
                Trap trap1 = traps[next_pos];
                traps.Remove(next_pos);

                player.x = 15;
                player.y = 0;
            }
            else if (equipments.ContainsKey(next_pos))//如果遇到装备
            {
                Equipment equipment = equipments[next_pos];
                equipments.Remove(next_pos);
                player.AddAtk(100);
                object o = equipment.AfterDisappear();
                if (o is Trap)
                {
                    Trap m = o as Trap;
                    traps[MapPos(m.x, m.y)] = m;
                }
            }
            else if (princess.ContainsKey(next_pos))//如果遇到公主
            {
                Base_Princess princess1 = princess[next_pos];
                string        s;
                if (princess1.OnTalk(player, out s))
                {
                    princess.Remove(next_pos);
                    object o = princess1.AfterDisappear();
                    if (o is NPC)
                    {
                        NPC m = o as NPC;
                        npcs[MapPos(m.x, m.y)] = m;
                    }
                }
                below_text = s;
            }

            else
            {
                MapXY(next_pos, out player.x, out player.y);
            }
            // 玩家行动结束


            // 所有怪物行动
            List <int> remove_keys = new List <int>();
            Dictionary <int, Monster> new_monsters = new Dictionary <int, Monster>();

            foreach (var pair in monsters)
            {
                int new_pos = MonsterMove(pair.Value);
                if (new_pos != pair.Key)
                {
                    // 更新Key
                    remove_keys.Add(pair.Key);
                    new_monsters[new_pos] = pair.Value;
                }
            }

            for (int i = 0; i < remove_keys.Count(); ++i)
            {
                monsters.Remove(remove_keys[i]);
            }
            foreach (var new_pair in new_monsters)
            {
                monsters[new_pair.Key] = new_pair.Value;
            }

            return(true);
        }
Exemple #2
0
 public void descend()
 {
     current.detach(player);
     if (depth + 1 >= Levels.Count)
     {
         Level level = new Level(MapGenerater.MapGen(current.width, current.height, 100));
         Levels.Add(level);
         level.world = this;
         //Add items
         for (int i = 0; i < 15; i++)
         {
             while (true)
             {
                 int x = random.Next(0, level.width), y = random.Next(0, level.height);
                 if (current.isMove(x, y))
                 {
                     Item item = Item.createItem();
                     if (random.Next(100) < 30)
                     {
                         item.set(Item.Flags.Cursed);
                     }
                     else if (random.Next(100) < 30)
                     {
                         item.set(Item.Flags.Blessed);
                     }
                     item.pos = new System.Drawing.Point(x, y);
                     current.attach(item);
                     break;
                 }
             }
         }
         while (true)
         {
             if (random.Next(100) > 25)
             {
                 break;
             }
             while (true)
             {
                 int x = random.Next(0, level.width), y = random.Next(0, level.height);
                 if (level.isMove(x, y) && level.atTrap(new System.Drawing.Point(x, y)) == null)
                 {
                     Trap trap = Trap.Generate();
                     trap.pos = new System.Drawing.Point(x, y);
                     level.attach(trap);
                     break;
                 }
             }
         }
     }
     depth++;
     fov.load(current);
     for (int x = current.width - 1; x >= 0; x--)
     {
         for (int y = current.height - 1; y >= 0; y--)
         {
             if (current.isMove(x, y))
             {
                 player.pos.X = x;
                 player.pos.Y = y;
                 current.attach(player);
                 return;
             }
         }
     }
 }
Exemple #3
0
        static void Map_save()
        {
            FileStream   fs   = new FileStream("../../map2.txt", FileMode.Open, FileAccess.Read);
            StreamReader read = new StreamReader(fs, Encoding.Default);
            string       strReadline;
            int          y = 0;

            while ((strReadline = read.ReadLine()) != null)
            {
                Console.WriteLine(strReadline);
                for (int x = 0; x < strReadline.Length; ++x)
                {
                    if (strReadline[x] == '#')
                    {
                        Walls wall = new Walls();
                        wall.SetPos(x, y);
                        Rogue.walls[MapPos(wall.x, wall.y)] = wall;
                    }
                    if (strReadline[x] == '$')
                    {
                        Money monry = new Money(100);
                        monry.SetPos(x, y);
                        Rogue.moneys [MapPos(monry.x, monry.y)] = monry;
                    }
                    if (strReadline[x] == '!')
                    {
                        Rogue.AddMonster(x, y, 1);
                    }
                    if (strReadline[x] == '8')
                    {
                        Rogue.AddMonster(x, y, 160, 100);
                    }
                    if (strReadline[x] == '%')
                    {
                        Yaoshi yaoshi = new Yaoshi();
                        yaoshi.SetPos(x, y);
                        Rogue.yaoshis[MapPos(yaoshi.x, yaoshi.y)] = yaoshi;
                    }
                    if (strReadline[x] == '=')
                    {
                        Door door = new Door();
                        door.SetPos(x, y);
                        Rogue.doors[MapPos(door.x, door.y)] = door;
                    }
                    if (strReadline[x] == '^')
                    {
                        Trap trap = new Trap();
                        trap.SetPos(x, y);
                        Rogue.traps[MapPos(trap.x, trap.y)] = trap;
                    }
                    if (strReadline[x] == '*')
                    {
                        Trap trap = new Trap();
                        trap.SetPos(x, y);
                        Rogue.trap2s[MapPos(trap.x, trap.y)] = trap;
                    }
                    if (strReadline[x] == '@')
                    {
                        OldMan oldman = new OldMan("公主", 101);
                        oldman.SetPos(x, y);
                        Rogue.npcs[MapPos(oldman.x, oldman.y)] = oldman;
                    }
                    if (strReadline[x] == '&')
                    {
                        Merchant merchant2 = new Merchant("商人", 200);
                        merchant2.SetPos(x, y);
                        Rogue.npcs[MapPos(merchant2.x, merchant2.y)] = merchant2;
                    }
                }
                y += 1;
                // strReadline即为按照行读取的字符串
            }

            /*Guanka guanka1 = new Guanka(Rogue.monsters, Rogue.npcs, Rogue.walls, Rogue.equipments, Rogue.princess, Rogue.traps, Rogue.doors, Rogue.yaoshis
             * , Rogue.trap2s, Rogue.loutis_d, Rogue.loutis_u);*/
        }