示例#1
0
        public Game1()
        {
            WIDTH = (config["screenWidth"] != null)? (int)config["screenWidth"] : 800;
            HEIGHT = (config["screenWidth"] != null) ? (int)config["screenHeight"] : 600;

            CardLibrary.init();
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            textures = new Dictionary<String, Texture2D>();
            fonts = new Dictionary<String, SpriteFont>();
            client = new Client.Client();

            // Adding Wonders Visual
            wonders = new Dictionary<String, Visual>();
            foreach (JObject j in (JArray)wondersJson["wonders"])
            {
                wonders.Add((string)j["name"], new Visual(new Vector2(0, 0), 0, 0, (string)j["a"]["image"]));
            }

            cards = new Dictionary<string, Visual>();
            foreach (JObject j in (JArray)cardsJson["cards"])
            {
                cards.Add((string)j["name"] + "_" + j["age"] + "_" + j["players"], new Visual(new Vector2(0, 0), 0, 0, (string)j["name"] + "_" + j["age"] + "_" + j["players"]));
            }

            interfaces = new Dictionary<String, Interface>();
            interfaces.Add("mainmenu", new MainMenu());
            interfaces.Add("lobby", new Lobby());
            interfaces.Add("hostlobby", new HostLobby());
            interfaces.Add("maingame", new MainGame(this));
            activeInterface = interfaces["mainmenu"];
        }
示例#2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
                this.Exit();
            if ((!leftkeylock) && (keyboardState.IsKeyDown(Keys.Left)))
            {
                cycle--;
                leftkeylock = true;
            }
            if ((!rightkeylock) && (keyboardState.IsKeyDown(Keys.Right)))
            {
                cycle++;
                rightkeylock = true;
            }

            if ((leftkeylock) && (keyboardState.IsKeyUp(Keys.Left)))
                leftkeylock = false;
            if ((rightkeylock) && (keyboardState.IsKeyUp(Keys.Right)))
                rightkeylock = false;

            activeInterface.Update(gameTime, Mouse.GetState());

            Dictionary<string, string> message;

            if (!client.isConnected() && (activeInterface != interfaces["mainmenu"]))
            {
                if (!client.getState().isGameInProgress() && activeInterface == interfaces["maingame"])
                {
                    client.disconnect();
                    if (host != null) host.shutdown();
                }
                else
                {

                    activeInterface.reset();
                    activeInterface = interfaces["mainmenu"];
                    message = new Dictionary<string, string>();
                    message.Add("connection", "Lost Connection");
                    activeInterface.receiveMessage(message);
                    interfaces["maingame"] = new MainGame(this);
                    if (host != null) host.shutdown();
                    client = new Client.Client();
                }
            }

            else if (client.getState().isGameInProgress() && activeInterface == interfaces["lobby"])
            {
                message = MainGame.createMessage();
                activeInterface.reset();
                client.registar(interfaces[message["nextInterface"]]);
                activeInterface = interfaces[message["nextInterface"]];
                activeInterface.receiveMessage(message);
            }

            else if ((message = activeInterface.isFinished()) != null)
            {
                if (message["nextInterface"] == "hostlobby")
                {
                    Console.WriteLine("StartHost");
                    if (host != null) host.shutdown();
                    host = new Server.Server();
                    Console.WriteLine("StartClient");
                    client.joinHost(true);
                }
                if ((message["nextInterface"] == "mainmenu"))
                {
                    if (host != null) host.shutdown();
                    client.disconnect();
                    client = new Client.Client();
                    interfaces["maingame"] = new MainGame(this);
                }
                if ((message["nextInterface"] == "lobby"))
                {
                    Console.WriteLine("Join StartClient");
                    client.joinHost(false);
                    if (!client.isConnected())
                    {
                        message["nextInterface"] = "mainmenu";
                        message["connection"] = "Failed to Connect";
                    }
                }
                if ((message["nextInterface"] == "maingame"))
                {
                    if (activeInterface == interfaces["hostlobby"]) host.startGame();
                    while (!client.getState().isGameInProgress())
                    { Console.WriteLine("stuck"); }
                }
                activeInterface.reset();
                client.registar(interfaces[message["nextInterface"]]);
                activeInterface = interfaces[message["nextInterface"]];
                activeInterface.receiveMessage(message);
            }

            ProcessKeyboard();
            prevState = Keyboard.GetState();

            base.Update(gameTime);
        }