⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program.cs

📁 经典游戏程序设计:visual c++ 上的杀人游戏源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServerLib;
using System.Threading;

namespace ServerHostApp
{
    //This app is to manage host server, it can create new game, can 
    //
    class Program
    {
        static void Main(string[] args)
        {
            Database.InitialDatabase();
            InitialGameHost();
        }


        /// <summary>
        /// 
        /// </summary>
        private static void InitialGameHost()
        {
            String strUserInput = "";
            String strInputPrompt = "\n\rPlease create newe game host or exit app, E-Exit N-New:";
            String strExitPrompt = "\n\rAre you sure to exit? Y-Yes,N-No:";
            String strForbiddenExit = "\n\rYou can not exit app, because there are some game hosts are still running!";

            while(true)
            {
                //New game host
                if(strUserInput == "N" || strUserInput == "NEW")
                {
                    Thread threadGame = new Thread(new ThreadStart(Service.LaunchServer));
                    threadGame.Start();
                }

                //Exit App
                else if(strUserInput == "E" || strUserInput == "EXIT")
                {
                    Console.Write(strExitPrompt);    
                    strUserInput = Console.ReadLine().Trim().ToUpper();
                    if(strUserInput == "Y" || strUserInput == "YES")
                    {
                        //TODO: 1. Need to search all the game host threads
                        //TODO: 2. Need to enumerate each game host to let Host App admin confirm that it can be canceled.

                        //int nWorkingThreads = 0;
                        //int nCompletedThreads = 0;
                        //ThreadPool.GetAvailableThreads(out nWorkingThreads, out nCompletedThreads);
                        //if(nWorkingThreads > 0)
                        //    Console.WriteLine(strForbiddenExit);
                        //else 
                            return ;
                    }
                }

                Console.Write(strInputPrompt);    
                strUserInput = Console.ReadLine().Trim().ToUpper();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -