Пример #1
0
        /// <summary>
        /// Executes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="client">The client.</param>
        /// <returns>PacketStream.</returns>
        public PacketStream Execute(string[] args, TcpClient client)
        {
            Name = args[0];
            var rows = int.Parse(args[1]);
            var cols = int.Parse(args[2]);

            //gets a new Data Structure to hold the info of a multi player game
            var mpStart = model.start(Name, rows, cols, client);

            var startPacketStream = new PacketStream
            {
                MultiPlayer   = true,
                MultiPlayerDs = mpStart,
                StringStream  = ""
            };

            //create the controller to run the multi player game from the host side
            var mpgStart = new MultiPlayerGameController(mpStart, true);

            mpgStart.SetModel(model);
            //initialize the game controller
            mpgStart.Initialize();
            mpgStart.ManageCommunication();
            return(startPacketStream);
        }
Пример #2
0
        /// <summary>
        /// Executes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <param name="client">The client.</param>
        /// <returns>PacketStream.</returns>
        public PacketStream Execute(string[] args, TcpClient client)
        {
            var joinPacketStream = new PacketStream
            {
                MultiPlayer  = true,
                StringStream = ""
            };

            var           name = args[0];
            MultiPlayerDS mpJoin;

            try
            {
                //gets the multi player data structure that holds the info for the multi player game
                mpJoin = model.GetMultiPlayerDataStructure(name);
                //attach the guest client to the class structure
                mpJoin.GuestClient = client;
                //set the game to be full and no other clients can join
                mpJoin.AvailableToJoin = false;

                //create the controller to run the game from the guest side
                var mpgJoin = new MultiPlayerGameController(mpJoin, false);
                mpgJoin.SetModel(model);
                mpgJoin.Initialize();
                mpgJoin.ManageCommunication();
            }
            catch
            {
                Console.WriteLine("the name of game to join isn't exist");
            }

            return(joinPacketStream);
        }