예제 #1
0
        static void Main(string[] args)
        {
            //TestAudio();
            //KeyCapture();

            /* NOTE: Tetris.Lib has no sound support.
             * So sound functionality is implemented here
             *
             */
            var render = new TextConsoleRenderer(new VectorInt2(80, 40));

            render.Init();


            using (var masterLoop = new ConsoleGameLoop <ConsolePixel>(new InputProvider(), render))
            {
                using (var loop = new MasterGameLoop(masterLoop))
                {
                    // on startup:
                    var music         = new CachedSound(loop.ResourceManager.GetResource("music/Tetris_theme.mp3"));
                    var addFloor      = new CachedSound(loop.ResourceManager.GetResource("sfx/AddFloor.mp3"));
                    var lineCompelete = new CachedSound(loop.ResourceManager.GetResource("sfx/LineComplete.mp3"));

                    if (args.Any())
                    {
                        if (args[0].ToLowerInvariant() == "-j")
                        {
                            loop.Tetris.KeyA = TetrisGameLoop.KeyXArcadeLeft;
                            loop.Tetris.KeyB = TetrisGameLoop.KeyXArcadeRight;
                        }
                    }

                    masterLoop.Scene = loop;
                    masterLoop.Init();    // will init loop

                    // After init...
                    AudioPlaybackEngine.Instance.PlaySound(music);
                    loop.Tetris.GameA.OnEvent += (sender, ge) =>
                    {
                        if (ge.Event == TetrisEvents.AddFloor)
                        {
                            AudioPlaybackEngine.Instance.PlaySound(addFloor);
                        }
                        if (ge.Event == TetrisEvents.LineComplete)
                        {
                            AudioPlaybackEngine.Instance.PlaySound(lineCompelete);
                        }
                    };

                    masterLoop.Start();
                }
            }
        }
예제 #2
0
        public static void Run()
        {
            if (true)
            {
                System.Console.CursorVisible  = false;
                System.Console.OutputEncoding = Encoding.Unicode;

                var scale     = 1.5;
                var charScale = 3;

                // Setup: Display
                //DirectConsole.MaximizeWindow();
                var cons = DirectConsole.Setup(
                    (int)(80 * scale),
                    (int)(25 * scale),
                    7 * charScale,
                    10 * charScale,
                    "Consolas");

                var renderer = new ConsoleRendererCHAR_INFO(cons);
                var bridge   = new BridgeSokobanPixelToCHAR_INFO(renderer);

                // Setup: Input
                var input = new InputProvider()
                {
                    IsMouseEnabled = true
                };

                using (var consoleLoop = new ConsoleGameLoop <SokobanPixel>(input, bridge))
                {
                    using (var master = new SokoSolveMasterGameLoop(consoleLoop))
                    {
                        consoleLoop.Scene = master;
                        consoleLoop.Init();
                        consoleLoop.Start();
                    }
                }
            }
            else
            {
                System.Console.SetBufferSize(120, 60);
                System.Console.SetWindowSize(120, 60);
                var bridge = new BridgeSokobanPixelToConsolePixel(new ConsolePixelRenderer(BasicDirectConsole.Singleton));

                // Setup: Input
                var input = new InputProvider()
                {
                    IsMouseEnabled = true
                };

                using (var consoleLoop = new ConsoleGameLoop <SokobanPixel>(input, bridge))
                {
                    consoleLoop.SetGoalFramesPerSecond(5);
                    using (var master = new SokoSolveMasterGameLoop(consoleLoop))
                    {
                        consoleLoop.Scene = master;
                        consoleLoop.Init();
                        consoleLoop.Start();
                    }
                }
            }
        }