program.cs

来自「经典游戏程序设计:visual c++ 上的杀人游戏源代码」· CS 代码 · 共 66 行

CS
66 行
字号
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 + =
减小字号Ctrl + -
显示快捷键?