Esempio n. 1
0
        // technically we can even subscribe to delegate-typed members without events
        // at all but it is more limited

        // return true if success, false if failure
        public bool Play()
        {
            Console.WriteLine("Playing Movie.");
            // wait for 3 seconds
            Thread.Sleep(3000);

            // firing the MovieFinished event
            // null-check because if there are zero subscribers,
            // that is a null reference exception
            //if (MovieFinished != null)
            //{
            //    MovieFinished();
            //}
            MovieFinished?.Invoke();
            // this will call not just one function, but all event subscribers.

            // ?. is a special operator called the null-coalescing operator
            // If the thing to the left is null, it simply returns null.
            // if the thing to the left is NOT null, it will behave like . (dot)

            // ?? is the null-coalescing operator
            // a ?? b, that means, return a, unless it's null, in which case return b.

            // When we fire the event, we provide all parrameters that the event
            // says its handlers needs
            DiscEjected?.Invoke(CurrentMovie.ToString());
            return(true);
        }
Esempio n. 2
0
        //technically we can even subscribe to delegate-typed members
        //  without events at all, but it's a bit more limited

        //return true if success, false if failure
        public bool Play()
        {
            //wait for 3 seconds
            Thread.Sleep(3000);

            //firing the MovieFinished event
            //must null-check because if there are zero subscribers,
            //  that's a nullreferenceexception

            //if (MovieFinished != null)
            //{
            //    if (MovieFinished != null)
            //        MovieFinished();
            //}

            MovieFinished?.Invoke();
            //this will call not just one function but all event subscribers

            //?. is a special operator called the null-coalescing operator
            //if the thing to the left of it is null, it simply returns null
            //if the thing to the left is NOT null, it will behave like .(dot)

            //?? is the null-coalescing operator
            //a ?? b, means return a unless it's null, in which case return b

            //when we fire the event, we provide all parameters that the event
            //  says its handlers need
            DiscEjected?.Invoke(CurrentMovie.ToString());

            return(false);
        }
Esempio n. 3
0
        // technically we can even subscribe to delegate typed members without events at all
        // but it's a bit more limited

        // return true if success, false if failure
        public bool Play()
        {
            // wait 3 secs
            Thread.Sleep(3000);

            // firing the Moviefinished event
            // must null check because there are 0 subscribers
            // nullReferenceException
            //if (MovieFinished is null)
            //{
            //    MovieFinished();
            //}

            // firing the MovieFinished Event
            MovieFinished?.Invoke();
            // will not just call one fn, but all event subscribers
            // `?.` is a special operator called the null coalescing operator
            // if the thing to left is null, it returns null
            // if thing to the left is not null, will behave like .

            // `??` is the null coalescing operator
            // a ?? b, means return a, unless it's null, in which case returns b

            // when we fire the event, we provide all the params that the event says it needs
            DiscEjected?.Invoke(CurrentMovie.ToString());
            return(true);
        }
Esempio n. 4
0
        public void PlayMovie()
        {
            Console.WriteLine($"Play movie {CurrentMovie}");
            Thread.Sleep(3000);

            //Fire event
            MovieFinished?.Invoke();
        }
Esempio n. 5
0
      internal static void PlayMovie(Stream file, MovieFinished OnMovieFinished)
      {
         MovieGameScreen movieGS = new MovieGameScreen();
         movieGS.OnMovieFinished = OnMovieFinished;
         movieGS.PlayMovie(file);

         MainGame.WinWarGame.SetNextGameScreen(movieGS);
      }
Esempio n. 6
0
        // will return true if success, false if not
        public bool Play()
        {
            Thread.Sleep(3000);

            MovieFinished?.Invoke();

            return(false);
        }
Esempio n. 7
0
        internal static void PlayMovie(Stream file, MovieFinished OnMovieFinished)
        {
            MovieGameScreen movieGS = new MovieGameScreen();

            movieGS.OnMovieFinished = OnMovieFinished;
            movieGS.PlayMovie(file);

            MainGame.WinWarGame.SetNextGameScreen(movieGS);
        }
Esempio n. 8
0
      internal async static void PlayMovie(string moviename, MovieFinished OnMovieFinished)
      {
         Stream resultFile = await WinWarCS.Platform.IO.OpenContentFile (Path.Combine ("Assets" + Platform.IO.DirectorySeparatorChar + "Data", moviename));
         if (resultFile == null)
            // TODO: Log error
            return;

         PlayMovie(resultFile, OnMovieFinished);
      }
Esempio n. 9
0
        public void PlayMovie()
        {
            Console.WriteLine($"Playing movie {CurrentMovie}");

            Thread.Sleep(3000);
            //if (MovieFinished != null)
            //{
            //    MovieFinished();
            //}
            MovieFinished?.Invoke();
        }
Esempio n. 10
0
        internal async static void PlayMovie(string moviename, MovieFinished OnMovieFinished)
        {
            Stream resultFile = await MainGame.AssetProvider.OpenContentFile(Path.Combine("Assets" + MainGame.AssetProvider.DirectorySeparatorChar + "Data", moviename));

            if (resultFile == null)
            {
                // TODO: Log error
                return;
            }

            PlayMovie(resultFile, OnMovieFinished);
        }
Esempio n. 11
0
        public void PlayMovie()
        {
            Console.WriteLine($"Playing movie {CurrentMovie}");

            Thread.Sleep(3000);

            //fire the event (syntax looks just like calling a method)
            //what it effectively does is call all subscribing delegates

            //weird issue - if there are no subscribers, the event is kind of "null"

            /*if(MovieFinished != null)
             *  MovieFinished(CurrentMovie);*/
            MovieFinished?.Invoke(CurrentMovie); //does same thing as above code - do nothing if no subscribers

            //when you invoke the event, you have to pass the name of the event
        }
Esempio n. 12
0
        public void PlayMovie()
        {
            Console.WriteLine($"Playing movie {CurrentMovie}");

            Thread.Sleep(3000); // wait for 3 seconds

            // fire the event. (the syntax looks just like calling a method)
            // what it effectively does is call all the subscribing delegates

            // weird issue - if there are no subscribers, the event is kind of "null"
            //if (MovieFinished != null)
            //{
            //    MovieFinished(CurrentMovie);
            //}
            MovieFinished?.Invoke(CurrentMovie); // does same thing as above code - do nothing if no subscribers

            // when you invoke the event, you have ot pass it the parameters the handlers want
        }
Esempio n. 13
0
        // technically we can subscribe to delegate-typed members without events at all
        // but it's a bit more limited

        //return true if success, false if failure
        public bool Play()
        {
            //wait for 3 seconds
            Thread.Sleep(3000);

            // Firing the MovieFinished event
            // MovieFinished();
            // this will call not just one function, but all event subscribers.

            MovieFinished?.Invoke();
            // ?. is a special operator called the null-coalescing operator
            // if the thing to the left of it is null, it simply returns null.
            // if the thing to the left is not null, it will behave like .

            // when we fire the event, we provide all parameters that the event
            // needs
            DiscEjected?.Invoke(CurrentMovie.ToString());
            return(true);
        }
Esempio n. 14
0
        public void PlayMovie()
        {
            Console.WriteLine($"Playering {CurrentMovie}");

            //Mmovie plays... placeholder code here
            Thread.Sleep(3000); //wait for 3 seconds

            //fire the event. (the syntax looks just like calling a method)
            //what is effectively does is call all the subscribing delegates

            //if there are no subscribers, the event is null.
            //if (MovieFinished != null)
            //{
            //    MovieFinished();
            //}

            //better way

            MovieFinished?.Invoke(); // better, modern: do nothing if no subscribers...
        }
Esempio n. 15
0
        public bool Play()
        {
            Thread.Sleep(3000);

            // fire event
            //if (MovieFinished != null)
            //{
            //    MovieFinished();
            //}
            // ?. is a special operator called the null-coalescing operator
            // if the thing to the left of it is null, it simply returns null.
            // if the thing to the left is not null, it will behave like .

            // ?? is the null-coalescing operator
            // a ?? b, that means, return a, unless it's null, in which case return b.

            MovieFinished?.Invoke();
            // this calls all event subscribers

            DiscEjected?.Invoke(CurrentMovie.ToString());
            return(true);
        }