Exemplo n.º 1
0
        public static (MiddlewareLocal, MiddlewareLocal) GenerateLinkedMiddlewareLocalPair()
        {
            MiddlewareLocal mid1 = new MiddlewareLocal();
            MiddlewareLocal mid2 = new MiddlewareLocal();

            // assign them together
            mid1.ConnectMiddlewareTogether(mid2);

            return(mid1, mid2);
        }
Exemplo n.º 2
0
        public static (MiddlewareLocal, MiddlewareLocal, MiddlewareLocal) GenerateLinkedMiddlewareLocalTriple()
        {
            MiddlewareLocal mid1    = new MiddlewareLocal();
            MiddlewareLocal mid2    = new MiddlewareLocal();
            MiddlewareLocal midHost = new MiddlewareLocal();

            // assign them together
            midHost.ConnectMiddlewareTogether(mid1);
            midHost.ConnectMiddlewareTogether(mid2);

            return(mid1, mid2, midHost);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine(string.Format("{0}{1}", "Initializing".Pastel(Color.DarkGreen), "...".Pastel(Color.Yellow)));

            Middleware myMiddleware;
            Host       h       = null;
            var        isHost  = args[0] == "-h" || args[0] == "--host";
            var        isLocal = isHost ? (args.Length > 2 && args[2] == "--local") : (args.Length > 1 && args[1] == "--local");

            Console.WriteLine(string.Format("Session started as {0}", isHost ? "host" : "client"));

            if (isHost)
            {
                myMiddleware = new MiddlewareLocal();

                var otherPlayerAddress = args[1];
                var arr        = otherPlayerAddress.Split(":");
                var playerIp   = arr[0];
                var playerPort = int.Parse(arr[1]);

                var playerMiddleware = new MiddlewareNetwork(playerIp, playerPort, false);

                var port     = 3001;
                var middHost = new MiddlewareNetwork("192.168.1.198", port, true);

                middHost.AddInputHandler((i, s) => Console.WriteLine(string.Format("Host got message from {0}: {1}", i, s)));

                middHost.ConnectMiddleware(myMiddleware);
                middHost.ConnectMiddleware(playerMiddleware);
                myMiddleware.ConnectMiddleware(middHost);

                h = new Host(middHost, new List <IMiddleware> {
                    myMiddleware,
                    playerMiddleware,
                });

                GameState state = new GameState(
                    new Player[] {
                    new Player(
                        0,
                        new List <Card> {
                    },
                        new List <Card> {
                        CardSet.SpawnCard(CardSet.CardName.MurlocTidehunter)
                    },
                        new List <Card> {
                        CardSet.SpawnCard(CardSet.CardName.MurlocTidehunter), CardSet.SpawnCard(CardSet.CardName.GoldshireFootman), CardSet.SpawnCard(CardSet.CardName.MurlocScout)
                    }
                        ),
                    new Player(
                        1,
                        new List <Card> {
                    },
                        new List <Card> {
                        CardSet.SpawnCard(CardSet.CardName.FlashHeal), CardSet.SpawnCard(CardSet.CardName.FrostwolfWarlord)
                    },
                        new List <Card> {
                        CardSet.SpawnCard(CardSet.CardName.IronforgeRifleman)
                    }
                        ),
                }
                    );

                h.state = state;
            }
            else
            {
                var serverAddress = args[0];
                var arr           = serverAddress.Split(":");
                var serverIp      = arr[0];
                var serverPort    = int.Parse(arr[1]);

                var port = 3002;
                myMiddleware = new MiddlewareNetwork("192.168.1.199", port, true);
                var serverMiddleware = new MiddlewareNetwork(serverIp, serverPort, false);

                myMiddleware.ConnectMiddleware(serverMiddleware);
                serverMiddleware.ConnectMiddleware(myMiddleware);
            }

            myMiddleware.AddInputHandler((i, s) => Console.WriteLine(string.Format("You got message from the host:\n{0}", s)));

            if (h != null)
            {
                Console.WriteLine("Press any key to start the game");
                Console.ReadKey();
                h.StartGame();
            }

            while (true)
            {
                var command = Console.ReadLine();
                myMiddleware.SendData(command);
            }
        }
Exemplo n.º 4
0
 public void ConnectMiddlewareTogether(MiddlewareLocal middleware)
 {
     this.connectedMiddleware.Add(middleware);
     middleware.ConnectMiddleware(this);
 }