示例#1
0
 public StartButton(ConsoleGraphics graphics)
 {
     this.graphics   = graphics;
     ImgStartButton  = graphics.LoadImage("start_button.png");
     ButtonPositionX = 100;
     ButtonPositionY = 100;
 }
示例#2
0
 public Ball(ConsoleGraphics graphics, Arcanoid arcanoid)
 {
     this.graphics = graphics;
     this.arcanoid = arcanoid;
     ImgBall       = graphics.LoadImage("ballBlue.png");
     BallPositionX = graphics.ClientWidth / 2 - ImgBall.Width / 2;
     BallPositionY = graphics.ClientWidth / 2 - ImgBall.Height * 2;
 }
        public void GenerateBitmapFromCanvas(int width, int height)
        {
            var canvas   = new Canvas((width, height), 16);
            var diagonal = canvas.Size.Up.Left.To((0, 0)).ToArray();

            diagonal.ForEach(p => canvas[p].Brush = ConsoleColor.Red);
            var bmp = new ConsoleImage(canvas).ToBitmap();

            foreach (var p in diagonal)
            {
                Equal(Color.FromArgb(Color.Red.ToArgb()), bmp.GetPixel(p.X * ConsoleImage.WidthZoomFactor, p.Y * ConsoleImage.HeightZoomFactor));
                Equal(Color.FromArgb(Color.Red.ToArgb()), bmp.GetPixel(p.X * ConsoleImage.WidthZoomFactor + 1, p.Y * ConsoleImage.HeightZoomFactor + 1));
            }
        }
示例#4
0
        public static void Main(string[] args)
        {
            Console.CursorVisible = false;
            var  exit   = false;
            var  logo   = new ConsoleImage(new System.Drawing.Bitmap("image.png"));
            byte choice = 0;

            if (System.IO.File.Exists("game.stgs"))
            {
                settings = new Settings("game.stgs");
            }

            var actions = new Action[4];

            // play the game
            actions[0] = () => {
                Console.Clear();
                Tetris.Reset();
                Tetris.PlayGame(settings.waitTime, settings.startingLevel, settings.tickDuration, settings.cycleDuration);
                logo.Paint();
            };

            // options
            actions[1] = () => {
                NavigateOptions();
                logo.Paint();
            };

            // how to play
            actions[2] = () => {
                NavigateControls();
                logo.Paint();
            };

            // quit the game
            actions[3] = () => exit = true;

            logo.Paint();

            while (!exit)
            {
                MakeMainMenu();
                choice = PrintCursor(35, 11, 4, choice, actions[choice]);
            }
        }
示例#5
0
        private void DrawTitileScreen()
        {
            bool proceed = false;

            while (!proceed)
            {
                canvas.Render(consoleGraphics);
                consoleGraphics.DrawString("TETЯIS", "Times New Roman", (uint)Colors.Yellow, 150, 80, 100);
                consoleGraphics.DrawString(" PRESS SPACE TO START", "Consolas", (uint)Colors.Yellow, 230, 650, 20);
                consoleGraphics.DrawString("LOGO BY FREEPNG.RU   EDUCATIONAL PROJECT ©2019", "Consolas", (uint)Colors.Yellow, 225, 750, 10);
                ConsoleImage logo = consoleGraphics.LoadImage(@"logo.bmp");
                consoleGraphics.DrawImage(logo, 255, 300);
                consoleGraphics.FlipPages();

                if (Input.IsKeyDown(Keys.SPACE))
                {
                    proceed = true;
                }
            }

            Utility.SleepLong();
        }
示例#6
0
        public static float[] GetBitmapFloatArray(Bitmap original, OnnxSession session, string inputKey, bool bw)
        {
            var batchSize   = session.GetBatchSize(inputKey);
            var shapeWidth  = session.GetShapeWIdth(inputKey);
            var shapeHeight = session.GetShapeHeight(inputKey);

            using (original)
                using (var resized = ResizeImage(original, shapeWidth, shapeHeight))
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("Processing image:");
                    Console.ResetColor();
                    ConsoleImage.ConsoleWriteImage(resized);
                    float[] data = new float[batchSize * (shapeWidth * shapeHeight)];
                    for (int x = 0; x < resized.Width; x++)
                    {
                        for (int y = 0; y < resized.Height; y++)
                        {
                            var color = resized.GetPixel(x, y);

                            float pixelValue = color.ToArgb();

                            if (bw)
                            {
                                pixelValue = 255 - (color.R + color.G + color.B) / 3;
                            }

                            //Todo, how do we handle batchsize > 1?, Fr now just grow the array cloning the first batch.
                            for (int i = 0; i < batchSize; i++)
                            {
                                var pos = y * resized.Width + x + (shapeWidth * shapeWidth * i);
                                data[pos] = pixelValue;
                            }
                        }
                    }

                    return(data);
                }
        }
示例#7
0
 public static void LoadImages(ConsoleGraphics graphics)
 {
     SnakeImage = graphics.LoadImage("images/snake.png");
     TreeImage  = graphics.LoadImage("images/tree.png");
 }
示例#8
0
        private static void Main(string[] args)
        {
            ConsoleUtils.TryEnableUnicode();

            // Try to render Jazz2 logo
            if (ConsoleImage.RenderFromManifestResource("ConsoleImage.udl", out int imageTop) && imageTop >= 0)
            {
                int width = Console.BufferWidth;

                // Show version number in the right corner
                string appVersion = "v" + Game.App.AssemblyVersion;

                int currentCursorTop = Console.CursorTop;
                Console.SetCursorPosition(width - appVersion.Length - 2, imageTop + 1);
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine(appVersion);
                Console.ResetColor();
                Console.CursorTop = currentCursorTop;
            }

            // Override working directory
            try {
                Environment.CurrentDirectory = Jazz2.Game.App.AssemblyPath;
            } catch (Exception ex) {
                Log.Write(LogType.Warning, "Cannot override working directory: " + ex);
            }

            // Process parameters
            int port;

            if (!TryRemoveArg(ref args, "/port:", out port))
            {
                port = 0;
            }

            string overrideHostname;

            if (!TryRemoveArg(ref args, "/override-hostname:", out overrideHostname))
            {
                overrideHostname = null;
            }

            string name;

            if (!TryRemoveArg(ref args, "/name:", out name) || string.IsNullOrWhiteSpace(name))
            {
                name = "Unnamed server";
            }

            int minPlayers;

            if (!TryRemoveArg(ref args, "/min-players:", out minPlayers))
            {
                minPlayers = 0;
            }

            int maxPlayers;

            if (!TryRemoveArg(ref args, "/max-players:", out maxPlayers))
            {
                maxPlayers = 0;
            }

            string levelName;

            if (!TryRemoveArg(ref args, "/level:", out levelName))
            {
                levelName = "unknown/battle2";
            }

            string levelTypeRaw;
            MultiplayerLevelType levelType;

            if (!TryRemoveArg(ref args, "/level-type:", out levelTypeRaw) || !Enum.TryParse(levelTypeRaw, out levelType))
            {
                levelType = MultiplayerLevelType.Battle;
            }

            string configPath;

            if (!TryRemoveArg(ref args, "/config:", out configPath))
            {
                if (File.Exists("Jazz2.Server.default"))
                {
                    configPath = "Jazz2.Server.default";
                }
                else
                {
                    configPath = null;
                }
            }

            bool startUnloaded = TryRemoveArg(ref args, "/unloaded");
            bool isPrivate     = TryRemoveArg(ref args, "/private");
            bool enableUPnP    = TryRemoveArg(ref args, "/upnp");

            // Initialization
            Version v           = Assembly.GetEntryAssembly().GetName().Version;
            byte    neededMajor = (byte)v.Major;
            byte    neededMinor = (byte)v.Minor;
            byte    neededBuild = (byte)v.Build;

            Log.Write(LogType.Info, "Starting server...");
            Log.PushIndent();

            // Start game server
            DualityApp.Init(DualityApp.ExecutionContext.Server, null, args);

            AsyncManager.Init();

            gameServer = new GameServer();

            if (overrideHostname != null)
            {
                try {
                    gameServer.OverrideHostname(overrideHostname);
                } catch {
                    Log.Write(LogType.Error, "Cannot set override public hostname!");
                }
            }

            gameServer.Run(configPath, port, name, minPlayers, maxPlayers, isPrivate, enableUPnP, neededMajor, neededMinor, neededBuild);

            Log.PopIndent();

            if (!startUnloaded)
            {
                if (gameServer.ActivePlaylistIndex == -1)
                {
                    gameServer.ChangeLevel(levelName, levelType);
                }
                else
                {
                    gameServer.ChangeLevelFromPlaylist(gameServer.ActivePlaylistIndex);
                }

                Log.Write(LogType.Info, "Ready to play!");
            }
            else
            {
                Log.Write(LogType.Verbose, "Server is unloaded.");
            }

            Log.Write(LogType.Info, "");

            // Check for updates
            Updater.CheckUpdates(OnCheckUpdates);

            // Processing of console commands
            ProcessConsoleCommands();

            // Shutdown
            Log.Write(LogType.Info, "Closing...");

            gameServer.Dispose();
        }
示例#9
0
        private static void Main(string[] args)
        {
#if DEBUG
            if (Console.BufferWidth < 120)
            {
                Console.BufferWidth = 120;
                Console.WindowWidth = 120;
            }
#endif

            if (!ConsoleUtils.IsOutputRedirected)
            {
                ConsoleImage.RenderFromManifestResource("ConsoleImage.udl");
            }

            bool isMasterServer = TryRemoveArg(ref args, "/master");

            if (!TryRemoveArg(ref args, "/port:", out port))
            {
                port = (isMasterServer ? 10667 : 10666);
            }

            if (!isMasterServer)
            {
                if (!TryRemoveArg(ref args, "/name:", out name) || string.IsNullOrWhiteSpace(name))
                {
                    name = "Unnamed server";
                }

                if (!TryRemoveArg(ref args, "/players:", out maxPlayers))
                {
                    maxPlayers = 64;
                }
            }

            // Initialization
            Version v = Assembly.GetEntryAssembly().GetName().Version;
            neededMajor = (byte)v.Major;
            neededMinor = (byte)v.Minor;
            neededBuild = (byte)v.Build;

            if (isMasterServer)
            {
                Log.Write(LogType.Info, "Starting master server...");
                Log.PushIndent();
                Log.Write(LogType.Info, "Port: " + port);

                registeredHosts = new Dictionary <IPEndPoint, ServerDescription>();

                server = new ServerConnection(token, port, 0);
                server.MessageReceived += OnMasterMessageReceived;

                Log.PopIndent();
            }
            else
            {
                Log.Write(LogType.Info, "Starting server...");
                Log.PushIndent();
                Log.Write(LogType.Info, "Port: " + port);
                Log.Write(LogType.Info, "Server Name: " + name);
                Log.Write(LogType.Info, "Max. Players: " + maxPlayers);

                callbacks = new Dictionary <byte, Action <NetIncomingMessage, bool> >();
                players   = new Dictionary <NetConnection, Player>();


                server = new ServerConnection(token, port, maxPlayers);
                server.MessageReceived     += OnMessageReceived;
                server.DiscoveryRequest    += OnDiscoveryRequest;
                server.ClientConnected     += OnClientConnected;
                server.ClientStatusChanged += OnClientStatusChanged;

                // ToDo: Renew it periodically
                RegisterToMasterServer();

                RegisterCallback <LevelReady>(OnLevelReady);
                RegisterCallback <UpdateSelf>(OnUpdateSelf);

                Log.PopIndent();
            }

            // Create game loop (~60fps)
            threadGame = new Thread(OnGameLoop);
            threadGame.IsBackground = true;
            threadGame.Start();

            Log.Write(LogType.Info, "Ready!");
            Console.WriteLine();

            // Processing of console commands
            while (true)
            {
                string command = Console.ReadLine();
                if (!string.IsNullOrEmpty(command))
                {
                    switch (command)
                    {
                    case "quit":
                    case "exit":
                        goto Finalize;

                    default:
                        Log.Write(LogType.Warning, "Unknown command: " + command);
                        break;
                    }
                }
            }

Finalize:
            // Shutdown
            Console.WriteLine();
            Log.Write(LogType.Info, "Closing...");

            if (isMasterServer)
            {
                server.MessageReceived -= OnMasterMessageReceived;
            }
            else
            {
                server.ClientStatusChanged -= OnClientStatusChanged;
                server.ClientConnected     -= OnClientConnected;
                server.MessageReceived     -= OnMessageReceived;
                server.DiscoveryRequest    -= OnDiscoveryRequest;
            }

            //ClearCallbacks();

            Thread threadGame_ = threadGame;
            threadGame = null;
            threadGame_.Join();

            server.Close();
        }
示例#10
0
 public SamplePlayer(ConsoleGraphics graphics)
 {
     image = graphics.LoadImage("pacman.png");
 }
示例#11
0
 public CGameObject(ConsoleGraphics graphics, string img)
 {
     image         = graphics.LoadImage(img);
     this.graphics = graphics;
 }
示例#12
0
        private static void Main(string[] args)
        {
            ConsoleUtils.TryEnableUnicode();

            int imageTop;

            if (ConsoleImage.RenderFromManifestResource("ConsoleImage.udl", out imageTop) && imageTop >= 0)
            {
                int width = Console.BufferWidth;

                // Show version number in the right corner
                string appVersion = "v" + Game.App.AssemblyVersion;

                int currentCursorTop = Console.CursorTop;
                Console.SetCursorPosition(width - appVersion.Length - 2, imageTop + 1);
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine(appVersion);
                Console.ResetColor();
                Console.CursorTop = currentCursorTop;
            }

            // Process parameters
            int port;

            if (!TryRemoveArg(ref args, "/port:", out port))
            {
                port = 10666;
            }

            string overrideHostname;

            if (!TryRemoveArg(ref args, "/override-hostname:", out overrideHostname))
            {
                overrideHostname = null;
            }

            string name;

            if (!TryRemoveArg(ref args, "/name:", out name) || string.IsNullOrWhiteSpace(name))
            {
                name = "Unnamed server";
            }

            int maxPlayers;

            if (!TryRemoveArg(ref args, "/players:", out maxPlayers))
            {
                maxPlayers = 64;
            }

            string levelName;

            if (!TryRemoveArg(ref args, "/level:", out levelName))
            {
                levelName = "unknown/battle2";
            }

            bool isPrivate  = TryRemoveArg(ref args, "/private");
            bool enableUPnP = TryRemoveArg(ref args, "/upnp");

            // Initialization
            Version v           = Assembly.GetEntryAssembly().GetName().Version;
            byte    neededMajor = (byte)v.Major;
            byte    neededMinor = (byte)v.Minor;
            byte    neededBuild = (byte)v.Build;

            Log.Write(LogType.Info, "Starting server...", true);

            // Start game server
            gameServer = new GameServer();

            if (overrideHostname != null)
            {
                try {
                    gameServer.OverrideHostname(overrideHostname);
                } catch {
                    Log.Write(LogType.Error, "Cannot set override public hostname!");
                }
            }

            gameServer.Run(port, name, maxPlayers, isPrivate, enableUPnP, neededMajor, neededMinor, neededBuild);

            Log.PopIndent();

            gameServer.ChangeLevel(levelName, MultiplayerLevelType.Battle);

            Log.Write(LogType.Info, "Ready!");
            Log.Write(LogType.Info, "");

            // Processing of console commands
            ProcessConsoleCommands();

            // Shutdown
            Log.Write(LogType.Info, "Closing...");

            gameServer.Dispose();
        }