Ejemplo n.º 1
0
        public override void Attach()
        {
            base.Attach();


            InitOnceOKTransition.Subscribe(_ => {
                if (CurrentState.Value == State.InitOnce)
                {
                    CurrentState.Value = State.Init;
                }
            }).AddTo(this.baseAttachDisposables);

            InitOKTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Init)
                {
                    CurrentState.Value = State.Ready;
                }
            }).AddTo(this.baseAttachDisposables);

            StartTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Ready)
                {
                    CurrentState.Value = State.Running;
                }
            }).AddTo(this.baseAttachDisposables);

            RestartTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Ready)
                {
                    CurrentState.Value = State.Init;
                }
                else if (CurrentState.Value == State.Pause)
                {
                    CurrentState.Value = State.Init;
                }
                else if (CurrentState.Value == State.Win)
                {
                    CurrentState.Value = State.Init;
                }
                else if (CurrentState.Value == State.Lose)
                {
                    CurrentState.Value = State.Init;
                }
            }).AddTo(this.baseAttachDisposables);

            PauseTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Ready)
                {
                    CurrentState.Value = State.Pause;
                }
                else if (CurrentState.Value == State.Running)
                {
                    CurrentState.Value = State.Pause;
                }
            }).AddTo(this.baseAttachDisposables);

            ResumeTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Pause)
                {
                    CurrentState.Value = State.Running;
                }
            }).AddTo(this.baseAttachDisposables);

            ResumeToReadyTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Pause)
                {
                    CurrentState.Value = State.Ready;
                }
            }).AddTo(this.baseAttachDisposables);

            WinTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Running)
                {
                    CurrentState.Value = State.Win;
                }
            }).AddTo(this.baseAttachDisposables);

            LoseTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Running)
                {
                    CurrentState.Value = State.Lose;
                }
            }).AddTo(this.baseAttachDisposables);

            FinishTransition.Subscribe(_ => {
                if (CurrentState.Value == State.Pause)
                {
                    CurrentState.Value = State.End;
                }
                else if (CurrentState.Value == State.Win)
                {
                    CurrentState.Value = State.End;
                }
                else if (CurrentState.Value == State.Lose)
                {
                    CurrentState.Value = State.End;
                }
            }).AddTo(this.baseAttachDisposables);
        }
    public static void StartRegular()
    {
#if false
        GameHost.Instance.Screen = new BackdropConsole(Width, Height, new Backdrop(), () => new Common.XY(0.5, 0.5));
        return;
#endif
        //var files = Directory.GetFiles($"{AppDomain.CurrentDomain.BaseDirectory}save", "*.trl");
        //SaveGame.Deserialize(File.ReadAllText(files.First()));

        var poster = new ColorImage(ASECIILoader.DeserializeObject <Dictionary <(int, int), TileValue> >(File.ReadAllText(cover)));

        var title      = new TitleScreen(Width, Height, GenerateIntroSystem());
        var titleSlide = new TitleSlideOpening(title)
        {
            IsFocused = true
        };

        var splashBack       = new ColorImage(ASECIILoader.DeserializeObject <Dictionary <(int, int), TileValue> >(File.ReadAllText(splash)));
        var splashBackground = new DisplayImage(Width / 2, Height / 2, splashBack, new Point())
        {
            FontSize = title.FontSize * 2
        };

        int        index     = 0;
        KeyConsole container = null;
        container = new KeyConsole(Width, Height, (k) => {
            if (k.IsKeyPressed(Keys.Enter))
            {
                switch (index)
                {
                case 1: {
                    container.Children.Clear();
                    Console c = new(Width, Height);
                    container.Children.Add(c);
                    ShowOpening(c);
                    break;
                }

                case 2: {
                    container.Children.Clear();
                    Console c = new(Width, Height);
                    container.Children.Add(c);
                    ShowPoster(c);
                    break;
                }

                case 3:
                default:
                    ShowTitle();
                    break;
                }
            }
        })
        {
            IsFocused = true, UseKeyboard = true,
        };
        container.Children.Add(splashBackground);

        GameHost.Instance.Screen = container;

#if DEBUG
        ShowTitle();
        //title.QuickStart();
        //title.StartSurvival();
#else
        ShowSplash();
#endif

        void ShowSplash()
        {
            //var p = Path.GetFullPath(theme);
            //MediaPlayer.Play(Song.FromUri(p, new(p)));

            index = 1;
            SplashScreen c = null;

            c = new SplashScreen(() => ShowCrawl(c));
            container.Children.Add(c);
        }

        void ShowCrawl(Console prev)
        {
            SimpleCrawl c = null;
            string      s = "Presents...";

            c = new SimpleCrawl(s, () => {
                ShowPause(prev);
            })
            {
                Position = new Point(prev.Width / 4 - s.Length / 2 + 1, 13), FontSize = prev.FontSize * 2
            };
            prev.Children.Add(c);
        }

        void ShowPause(Console prev)
        {
            Console c = null;

            c = new PauseTransition(Width, Height, 1, prev, () => ShowFade(c));

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        void ShowFade(Console prev)
        {
            Console c = null;

            c = new FadeOut(prev, () => ShowOpening(c), 1);

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        void ShowOpening(Console prev)
        {
            index = 2;
            prev.Parent.Children.Remove(splashBackground);

            Console c = null;

            c = new SimpleCrawl(
                @"                  
A reimagining of...
                    
      Transcendence  
 by George Moromisato
                    
And the vision that was
more than just a dream...
                    ".Replace("\r", null), () => ShowFade2(c))
            {
                Position = new Point(4, 4),
                FontSize = title.FontSize * 3
            };

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        /*
         * void ShowPause2(Console prev) {
         *  Console c = null;
         *  c = new PauseTransition(Width, Height, 1, prev, () => ShowFade2(c));
         *
         *  prev.Parent.Children.Add(c);
         *  prev.Parent.Children.Remove(prev);
         * }
         */
        void ShowFade2(Console prev)
        {
            Console c = null;

            c = new FadeOut(prev, () => ShowPause2(c), 1);

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        void ShowPause2(Console prev)
        {
            Console c = null;

            c = new PauseTransition(Width, Height, 1, prev, () => ShowPoster(c));

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        void ShowPoster(Console prev)
        {
            index = 3;
            var display = new DisplayImage(poster.Size.X, poster.Size.Y, poster,
                                           new Point(Width / 2 - poster.Size.X / 2 + 4, -5))
            {
                FontSize = title.FontSize * 3 / 4
            };

            Console pause = null;

            pause = new PauseTransition(display.Width, display.Height, 2, display, () => ShowPosterFade(pause))
            {
                FontSize = display.FontSize
            };

            //Note that FadeIn automatically replaces the child console
            var c = new FadeIn(pause);

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        void ShowPosterFade(Console prev)
        {
            var c = new FadeOut(prev, ShowTitle, 1);

            prev.Parent.Children.Add(c);
            prev.Parent.Children.Remove(prev);
        }

        void ShowTitle()
        {
            index = 4;
            titleSlide.IsFocused     = true;
            GameHost.Instance.Screen = titleSlide;
        }

        //GameHost.Instance.Screen = new TitleDraw();
    }