コード例 #1
0
ファイル: Form1.cs プロジェクト: chromos33/DnDBattleSim
        public Form1()
        {
            InitializeComponent();
            Random randomizer = new Random();


            BattleField Battlefield = new BattleField(randomizer,4);
            Character ally = new Character();
            ally.Name = "ally";
            Character ally2 = new Character();
            ally.Name = "ally";
            Character ally3 = new Character();
            ally.Name = "ally";
            Character enemy = new Character();
            enemy.Name = "enemy";
            
            Battlefield.addCharacter(ally,3,2);
            //Battlefield.addCharacter(ally2, 6, 4);
            //Battlefield.addCharacter(ally3, 6, 5);
            Battlefield.addCharacter(enemy,1,3);
            goal.Text = enemy.getPoint().X + "/" + enemy.getPoint().Y;
            start.Text = ally.getPoint().X + "/" + ally.getPoint().Y;
            string msg = "";
            foreach (Character chara in Battlefield.getCharacters())
            {
                msg += chara.Name + " x: " + chara.getPoint().X + " y:" + chara.getPoint().Y + System.Environment.NewLine;
            }
            List<DnDBattleSim.Classes.SubClasses.Point> resultmove = ally.MoveTo(enemy.getPoint());
            foreach(DnDBattleSim.Classes.SubClasses.Point point in resultmove)
            {
                StepList.Items.Add(point.X + "//" + point.Y);
            }
        }
コード例 #2
0
ファイル: BattleField.cs プロジェクト: chromos33/DnDBattleSim
 public void addCharacter(Character character,int _x = -1, int _y = -1)
 {
     if(_x ==-1 && _y==-1)
     {
         if (Characters.Count > 0)
         {
             bool positionoccupied = false;
             Point position = null;
             while (true)
             {
                 position = MapConfig.ElementAt(randomenerator.Next(MapConfig.Count));
                 foreach (Character Character in Characters)
                 {
                     if (Character.isOccupied(position))
                     {
                         positionoccupied = true;
                     }
                 }
                 if (!positionoccupied)
                 {
                     break;
                 }
             }
             character.setPosition(position);
             character.setBattlefield(this);
             Characters.Add(character);
         }
         else
         {
             character.setPosition(MapConfig.ElementAt(randomenerator.Next(MapConfig.Count)));
             character.setBattlefield(this);
             Characters.Add(character);
         }
     }
     else
     {
         Point pos = new Point(_x, _y);
         character.setPosition(pos);
         character.setBattlefield(this);
         Characters.Add(character);
     }
     
 }