Beispiel #1
0
 //Particle list method
 public static void ParticleList(Particles particles)
 {
     Clear();
     WriteLine("AVAILABLE PARTICLES" + "\n");
     foreach (Particle p in particles)
     {
         WriteLine(p.symbol + "   " + p.name);
     }
     WriteLine("\n" + "Press any key to return to the main menu");
     ReadKey();
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            //Particles object instantiation
            Particles particles = new Particles();

            //Introductory message
            WriteLine("WELCOME TO THE SUBATOMIC PARTICLE COLLISION SIMULATOR\n");
            Write("This program performs a simulation that predicts the possible outcomes of a collision between two fundamental subatomic particles by using the laws of conservation of relevant subatomic properties. Please press any key to access the main menu.");
            ReadKey();
            //Main menu
            #region
            //Loop to contain menu
            bool showMenu = true;
            while (showMenu)
            {
                showMenu = Menu.MainMenu(particles);
            }
            #endregion
        }
Beispiel #3
0
        //Main menu method
        public static bool MainMenu(Particles particles)
        {
            Clear();
            WriteLine("\n" + "MAIN MENU" + "\n");
            WriteLine("1. New collision");
            WriteLine("2. View list of available fundamental particles");
            WriteLine("3. Exit" + "\n");
            WriteLine("Please choose an option: ");
            int choice = 0;

            try
            {
                choice = Convert.ToInt32(ReadLine());
            }
            catch (Exception)
            {
                WriteLine("Invalid input. Please try again.");
                ReadKey();
            }

            switch (choice)
            {
            case 1:
                CollisionMenu.Collision(particles);
                return(true);

            case 2:
                //Display of particles to user
                WriteLine("AVAILABLE PARTICLES" + "\n");
                ParticleList(particles);
                return(true);

            case 3:
                return(false);

            default:
                WriteLine("Invalid choice. Please try again.");
                ReadKey();
                return(true);
            }
        }
Beispiel #4
0
        //Collision method
        public Particles CollideWith(Particle particle, Particles particles)
        {
            //Property totals for conservation laws
            var totalMass            = particle.mass + this.mass;
            var totalCharge          = particle.charge + this.charge;
            var totalBaryonNumber    = particle.baryonNumber + this.baryonNumber;
            var totalCharm           = particle.charm + this.charm;
            var totalStrangeness     = particle.strangeness + this.strangeness;
            var totalTopness         = particle.topness + this.topness;
            var totalBottomness      = particle.bottomness + this.bottomness;
            var totalLeptonElNumber  = particle.leptonElNumber + this.leptonElNumber;
            var totalLeptonMuNumber  = particle.leptonMuNumber + this.leptonMuNumber;
            var totalLeptonTauNumber = particle.leptonTauNumber + this.leptonTauNumber;

            //Result list
            var resultList = new List <Particle>(particles);

            //Loop to remove incompatible results
            foreach (Particle p in resultList.ToList())
            {
                if (p.mass != totalMass || p.charge != totalCharge || p.baryonNumber != totalBaryonNumber || p.charm != totalCharm || p.strangeness != totalStrangeness || p.topness != totalTopness || p.bottomness != totalBottomness || p.leptonElNumber != totalLeptonElNumber || p.leptonMuNumber != totalLeptonMuNumber || p.leptonTauNumber != totalLeptonTauNumber)
                {
                    resultList.Remove(p);
                }
            }

            //Loop to print remaining possible particles
            foreach (Particle p in resultList.ToList())
            {
                WriteLine("\n" + p.name + " is a possible resulting particle.");
                ReadKey();
            }
            if (resultList.Count == 0)
            {
                double energyRelease = totalMass * speedOfLight * speedOfLight;
                Write("\nThere are no possible particles generated by this collision, however, " + energyRelease + " Joules of energy is released.");
                ReadKey();
            }
            return(particles);
        }
Beispiel #5
0
        //Collision input validation method
        public static Particle InputValid(Particles particles)
        {
            string   userChoice = null;
            Particle result     = new Particle();
            bool     valid      = false;

            while (valid == false)
            {
                try
                {
                    userChoice = Convert.ToString(ReadLine());
                    valid      = true;
                }
                catch (Exception)
                {
                    WriteLine("Invalid input. Please try again.");
                    valid = false;
                    continue;
                }
                //Check that input matches existing particle
                foreach (Particle p in particles)
                {
                    if (userChoice.ToLower() == p.name.ToLower() || userChoice.ToLower() == p.symbol.ToLower())
                    {
                        valid  = true;
                        result = p;
                        goto success;
                    }
                    else
                    {
                        valid = false;
                    }
                }
                WriteLine("No matching particle found. Please try again.");
            }
success:
            return(result);
        }
Beispiel #6
0
        //Particle choice method
        public static void Collision(Particles particles)
        {
            Clear();
            WriteLine("\n" + "PARTICLE COLLISION SIMULATION" + "\n");

            //Assignment of first particle
            #region
            WriteLine("Please specify a particle using its full name or symbol as shown in the particles list (on the main menu): ");
            Particle particleOne = userInput(particles);
            #endregion

            //Assignment of second particle
            #region
            WriteLine("Please specify a second particle using its full name or symbol as shown in the list (on the main menu): ");
            Particle particleTwo = userInput(particles);
            #endregion

            WriteLine("Press any key to simulate your chosen collision between " + particleOne.name + " and " + particleTwo.name);
            ReadKey();

            //CollideWith method call
            particleOne.CollideWith(particleTwo, particles);
        }