// return a decklist object of the deck list with the
        // given ID
        public DeckList LoadFromID(string id)
        {
            Console.WriteLine($"Loading deck: {id}");
            if (decks.ContainsKey(id))
            {
                return(decks[id]);
            }

            //TESTING IMPLEMENTATION
            if (id.StartsWith("TEST "))
            {
                DeckList d = new DeckList();
                d.AddCard(cardLoader.GetByID(id.Substring(5)), 8);
                d.AddCard(cardLoader.GetByID("Resist Token"), 6);
                d.AddCard(cardLoader.GetByID("Mana Token"), 6);
                Console.WriteLine("Loaded test deck");
                return(d);
            }
            else
            {
                // TODO: What's the default deck?
                DeckList d = new DeckList();
                d.AddCard(cardLoader.GetByID("Resist Token"), 20);
                return(d);
            }
        }
        private void LoadDecks()
        {
            string path = Path.Combine("Assets", "Resources", "Decks");

            foreach (string fileName in Directory.EnumerateFiles(path, "*.yaml"))
            {
                YamlStream yaml = new YamlStream();
                yaml.Load(File.OpenText(fileName));

                YamlMappingNode root     = yaml.Documents[0].RootNode as YamlMappingNode;
                string          deckId   = root.Children[new YamlScalarNode("id")].ToString();
                string          deckName = root.Children[new YamlScalarNode("name")].ToString();

                DeckList         deck         = new DeckList();
                YamlSequenceNode cardSequence = root.Children[new YamlScalarNode("cards")] as YamlSequenceNode;
                foreach (YamlMappingNode cardItem in cardSequence)
                {
                    deck.AddCard(
                        cardLoader.GetByID(cardItem.Children[new YamlScalarNode("id")].ToString()),
                        int.Parse(cardItem.Children[new YamlScalarNode("count")].ToString())
                        );
                }

                decks.Add(deckId, deck);
                int deckCardCount = deck.GetCards().Select(deck.GetCopiesOf).Sum();
                Console.WriteLine($"Loaded deck {deckName} ({deckCardCount} cards).");
            }
        }
示例#3
0
        /*
         * // WHERE ALL PENDING PENDING INPUT REQUESTS GO
         * private List<InputRequest> pendingInputRequests;
         * public InputRequest[] PendingInputRequests{
         * get{ return pendingInputRequests.ToArray(); }
         * }
         */



        // when hidden list is null, will init players with "hidden decks" of unkown cards
        //      functionality intended for clients
        // when ids is null, will init with newly generated ids
        //      functionality intended for servers
        // when both are null, will start a game with no players
        // MUST KEEP THE INDEXES OF THE OBJECTS GIVEN TO IT
        public GameManager(DeckList[] deckLists = null, XmlElement[] serializedPlayers = null, XmlElement[] serializedLanes = null)
        {
            // setup players
            int numPlayers = deckLists != null ? deckLists.Length : (serializedPlayers != null ? serializedPlayers.Length : 0);

            Players = new Player[numPlayers];
            for (int i = 0; i < numPlayers; i++)
            {
                DeckList hiddenList = new DeckList();
                hiddenList.AddCard(new UnknownCard(), 20);                 // TODO: support decks of different sizes?
                DeckList list = deckLists != null ? deckLists[i] : hiddenList;

                Players[i] = new Player(list, serializedPlayers?[i]);
            }
            // setup lanes
            if (serializedLanes == null)              // ...from scratch
            {
                Lanes = new Lane[NUM_LANES];
                for (int i = 0; i < NUM_LANES; i++)
                {
                    Lanes[i] = new Lane();
                }
            }
            else                 // ...with pre-determined ids
            {
                Lanes = new Lane[serializedLanes.Length];
                for (int i = 0; i < serializedLanes.Length; i++)
                {
                    int j = Int32.Parse(serializedLanes[i].Attributes["index"].Value);
                    Lanes[j] = new Lane(serializedLanes[i]);
                }
            }
        }
示例#4
0
    // Here is where important public variables should be initialized. Be careful if you are testing
    // individual scenes without running the game from the beginning; since the GameController normall
    //stays constant between scenes, you may need to write a special case to make sure the scene gets
    //initialized properly.

    void Start()
    {
        //The Services class is just a static class that acts as a list of all the major systems in the game.
        //Right now, Services has three attributes: the gameController (this), the eventManager, and the
        // encounter.
        Services.GC           = this;
        Services.eventManager = new EventManager();



        //These lines initialize the public attributes in the GameController
        partyDeck = new DeckList();
        nextNPC   = new Kelly();
        _gameFSM  = new FiniteStateMachine <GameController>(this);



        //PURELY FOR TESTING THE CARD ENCOUNTER SCENE. In the real game, we don't want to start playing
        // cards right away. Feel free to uncomment if you want to test the card game, but be mindful.
        #region

        partyDeck.AddCard(new Bubbly());              //These lines add basic cards to the deck
        partyDeck.AddCard(new Dance());
        partyDeck.AddCard(new Gutsy());
        partyDeck.AddCard(new PrivateTalk());
        partyDeck.AddCard(new Chat());
        partyDeck.AddCard(new Encourage());


        Debug.Log("Added cards");


        _gameFSM = new FiniteStateMachine <GameController>(this); //This line creates a state machine for
        _gameFSM.TransitionTo <CardGame>();
        Debug.Log("transitioned to card game");

        #endregion
    }
        public static void Main()
        {
            //find local IP
            IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress   ipAddr  = ipEntry.AddressList[0];
            //consts
            string    HostName = ipAddr.ToString(); //by default, is using same local IP addr as server; assuming above process is deterministic
            const int Port     = 4011;
            //objs
            TcpClient     client;
            NetworkStream stream;

            // used for testing delta code
            List <Deck> decks = new List <Deck>();

            Console.WriteLine("Connecting to server at {0}:{1}...", HostName, Port);

            try{
                //actual work
                client = new TcpClient(HostName, Port);

                Console.WriteLine("Connected!");

                CardLoader cl = new CardLoader();

                Console.WriteLine("Testing Unkown Card == Card: {0}",
                                  new UnknownCard() == cl.LoadCard("Exostellar Marine Squad")?
                                  "Success" : "Fail");

                Console.WriteLine("Testing Card == Unkown Card: {0}",
                                  cl.LoadCard("Exostellar Marine Squad") == new UnknownCard() ?
                                  "Success" : "Fail");


                stream = client.GetStream();

                byte[] data;

                /*
                 * //send a message
                 * Console.WriteLine("Press Enter to start a message...");
                 * Console.Read();
                 * data = System.Text.Encoding.UTF8.GetBytes("<file type='HI!!!'>");
                 * stream.Write(data, 0, data.Length);
                 *
                 * //test if will wait for EOF
                 * Console.WriteLine("Press Enter to finish the message...");
                 * Console.Read();
                 * data = System.Text.Encoding.UTF8.GetBytes("</file>GARBAGE");
                 * stream.Write(data, 0, data.Length);
                 *
                 * //recieve
                 * data = new byte[256];
                 * stream.Read(data, 0, data.Length);
                 * Console.WriteLine("Response from server: {0}",System.Text.Encoding.UTF8.GetString(data));
                 * // */

                //join a game
                Console.WriteLine("Press Enter to join a game...");
                Console.Read();
                data = System.Text.Encoding.UTF8.GetBytes("<file type='joinMatch'><deck id='testing'/></file>");
                stream.Write(data, 0, data.Length);

                //*
                //get matchstart message
                data = new byte[256];
                stream.Read(data, 0, data.Length);
                string startResp = System.Text.Encoding.UTF8.GetString(data);
                Console.WriteLine("Response from server: {0}", startResp);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(startResp);
                foreach (XmlElement e in doc.GetElementsByTagName("playerIds"))
                {
                    Deck     deck = new Deck(e.Attributes["deck"].Value);
                    DeckList list = new DeckList();
                    list.AddCard(new UnknownCard(), 20); // the dummy placeholder deck
                    deck.LoadCards(list);
                    decks.Add(deck);
                }
                // */

                //send a gameaction message
                Console.WriteLine("Press Enter to make a move...");
                Console.Read();
                data = System.Text.Encoding.UTF8.GetBytes("<file type='gameAction'><action></action></file>");
                stream.Write(data, 0, data.Length);

                // get and parse XML deltas
                data = new byte[256];
                stream.Read(data, 0, data.Length);
                string resp = System.Text.Encoding.UTF8.GetString(data);
                Console.WriteLine("Response from server: {0}", resp);
                doc = new XmlDocument();
                doc.LoadXml(resp);
                foreach (XmlElement e in doc.GetElementsByTagName("delta"))
                {
                    Delta d = Delta.FromXml(e, cl);
                    Console.WriteLine("Delta of type {0} parsed.", d.GetType());
                }

                //get and parse A LOT of Xml, for analysis purposes
                int       tests      = 1000;
                long      avMillis   = 0;
                Stopwatch watch      = new Stopwatch();
                Stopwatch totalWatch = new Stopwatch();
                totalWatch.Start();
                for (int i = 0; i < tests; i++)
                {
                    watch.Start();

                    // send request
                    data = System.Text.Encoding.UTF8.GetBytes("<file type='gameAction'><action></action></file>");
                    stream.Write(data, 0, data.Length);

                    // get and parse XML deltas
                    data = new byte[256];
                    stream.Read(data, 0, data.Length);
                    resp = System.Text.Encoding.UTF8.GetString(data);
                    doc  = new XmlDocument();
                    doc.LoadXml(resp);
                    foreach (XmlElement e in doc.GetElementsByTagName("delta"))
                    {
                        Delta d = Delta.FromXml(e, cl);
                    }
                    watch.Stop();
                    avMillis += watch.ElapsedMilliseconds / ((long)tests);
                    watch.Reset();
                }
                totalWatch.Stop();
                Console.WriteLine("{0} tests parsing Xml run; avergage time was {1} millis; total time was {2} millis.", tests, avMillis, totalWatch.ElapsedMilliseconds);

                //send a end turn message
                Console.WriteLine("Press Enter to end turn...");
                Console.Read();
                data = System.Text.Encoding.UTF8.GetBytes("<file type='lockInTurn'></file>");
                stream.Write(data, 0, data.Length);

                data = new byte[256];
                stream.Read(data, 0, data.Length);
                Console.WriteLine("Response from server: {0}", System.Text.Encoding.UTF8.GetString(data));

                //send a gameaction message
                Console.WriteLine("Press Enter to make a move...");
                Console.Read();
                data = System.Text.Encoding.UTF8.GetBytes("<file type='gameAction'><action></action></file>");
                stream.Write(data, 0, data.Length);

                data = new byte[256];
                stream.Read(data, 0, data.Length);
                Console.WriteLine("Response from server: {0}", System.Text.Encoding.UTF8.GetString(data));

                //send a gameaction message
                Console.WriteLine("Press Enter to make a move...");
                Console.Read();
                data = System.Text.Encoding.UTF8.GetBytes("<file type='gameAction'><action></action></file>");
                stream.Write(data, 0, data.Length);

                data = new byte[256];
                stream.Read(data, 0, data.Length);
                Console.WriteLine("Response from server: {0}", System.Text.Encoding.UTF8.GetString(data));

                //send a end turn message
                Console.WriteLine("Press Enter to end turn...");
                Console.Read();
                data = System.Text.Encoding.UTF8.GetBytes("<file type='lockInTurn'></file>");
                stream.Write(data, 0, data.Length);

                //wait for user then close
                Console.WriteLine("Presse Enter to disconnect...");
                Console.Read();
                stream.Close();
                client.Close();
            }catch (SocketException e) {
                Console.WriteLine("SocketEsception: {0}", e);
            }
        }
示例#6
0
    // This is called even before the Start function. I just wanted to perform the DontDestroyOnLoad
    // as early as possible.
    private void Awake()
    {
        //The Services class is just a static class that acts as a list of all the major systems in the game.
        //Right now, Services has three attributes: the gameController (this), the eventManager, and the
        // encounter.
        if (Services.gameController == null)
        {
            Object.DontDestroyOnLoad(this);

            /*
             * flowchartGameObject = GameObject.Find("Flowchart");
             * Object.DontDestroyOnLoad(flowchartGameObject);
             * flowchart = flowchartGameObject.GetComponent<Fungus.Flowchart>();
             */
            cardInfo.ReadFromSpreadsheet();


            Services.gameController = this;
            Services.eventManager   = new EventManager();

            //Services.allCardInformation = AllCardInformation(cardSpreadsheet);



            //These lines initialize the public attributes in the GameController
            partyDeck = new DeckList();
            nextNPC   = new Kelly();

            //The gameController state machine is private, because this should be pretty much
            //the only script changing the game state at such a high level.
            _gameFSM = new FiniteStateMachine <GameController>(this);

            //PURELY FOR TESTING THE CARD ENCOUNTER SCENE. In the real game, we don't want to start playing
            // cards right away. Feel free to uncomment if you want to test the card game, but be mindful.

            #region

            /*
             * partyDeck.AddCard(new Bubbly());              //These lines add basic cards to the deck
             * partyDeck.AddCard(new Dance());
             * partyDeck.AddCard(new Gutsy());
             * partyDeck.AddCard(new PrivateTalk());
             * partyDeck.AddCard(new Chat());
             * partyDeck.AddCard(new Encourage());
             */
            partyDeck.AddCard(new Dance());
            partyDeck.AddCard(new Chill());
            partyDeck.AddCard(new Gutsy());

            _gameFSM.TransitionTo <StartMenu>();


            //_gameFSM = new FiniteStateMachine<GameController>(this); //This line creates a state machine for
            //_gameFSM.TransitionTo<CardGame>();

            #endregion
        }

        else
        {
            this.enabled = false;
        }
    }