Пример #1
0
            public static Game FromBytes(byte[] bytes, string fileLocation)
            {
                int rounds      = bytes[0];
                int playerIndex = 0;

                Player[] players = new Player[TYPE.Maximum()];

                for (int i = 1; i < bytes.Length;)
                {
                    string name       = "";
                    int    nameLength = bytes[i++];

                    int target = i + nameLength;
                    for (; i < target; i++)
                    {
                        name += (char)bytes[i];
                    }

                    target = i + rounds;
                    byte[][] tricks = new byte[rounds][];
                    for (int j = 0; i < target; j++)
                    {
                        tricks[j] = new [] {
                            bytes[i++],
                            bytes[i++]
                        };
                    }

                    Player player = new Player(name, tricks);
                    players[playerIndex++] = player;
                }

                Array.Resize(ref players, playerIndex);
                return(new Game(players, fileLocation));
            }
Пример #2
0
        private static void CreateGame()
        {
            int      typeSelection = MultipleChoice.Show("Select game", GameTypeMethods.GetAllFullNames()) + 1;
            GameType gameType      = (GameType)Enum.GetValues(typeof(GameType)).GetValue(typeSelection);

            Console.WriteLine();

            int players =
                NumberInput.Show("How many players", gameType.Minimum(), gameType.Maximum());

            Console.Clear();

            string[] names = LineEditor.RequestStringBatch("Enter player names", players);
            Console.Clear();

            if (names != null)
            {
                dynamic game = gameType.CreateGame(names);
                MainMenu(game);
            }
        }