コード例 #1
0
        public String Move(double angle, int energy)
        {
            int distance = energy / (this.Capacity / 100);


            //updateSelf();
            if (this._energy > energy)
            {
                for (int i = 1; i <= distance; i++)
                {
                    this.XCoordinate = Math.Round(this.XCoordinate + Math.Cos(angle * Math.PI / 180.0), 2);
                    this.YCoordinate = Math.Round(this.YCoordinate + Math.Sin(angle * Math.PI / 180.0), 2);
                    this.Energy     -= energy / distance;

                    System.Threading.Thread.Sleep(100);
                    Console.WriteLine(this.ToString());
                    ElasticSearchCommands.updateUser(this);
                }
            }
            else
            {
                Console.WriteLine("Not enough energy to move");
            }
            return(this.ToString());
        }
コード例 #2
0
 public static void UpdateEnergy()
 {
     while (true)
     {
         System.Threading.Thread.Sleep(1000);
         foreach (var ship in ElasticSearchCommands.searchAll().ToArray())
         {
             if (ship.Energy + 2 <= ship.Capacity)
             {
                 ship.Energy += 2;
                 ElasticSearchCommands.updateUser(ship);
             }
         }
     }
 }
コード例 #3
0
        public String Attack(Spaceship ship, int energy)
        {
            int beforeHealth = ship.Health;

            ship.Health -= energy;
            if (ship.Health <= 0)
            {
                ship.Health    = 0;
                this.Capacity += ship.Capacity;
            }

            ElasticSearchCommands.updateUser(ship);
            ElasticSearchCommands.updateUser(this);

            // update health and energy
            return("You just attacked the spaceship " + ship.Name + " . Damage caused: " + (double)ship.Health / beforeHealth * 100
                   + "% !\n");
        }