Beispiel #1
0
        public Game StartGame(GameSetup setup)
        {
            string hash = setup.Hash;
            string filepath = getFilePath(hash);

            setups.Remove(hash);
            Game game = Game.FromSetup(setup, filepath);
            games.Add(hash, game);

            return game;
        }
Beispiel #2
0
        public static Game FromSetup(GameSetup setup, string filepath)
        {
            using (FileStream fs = new FileStream(filepath, FileMode.CreateNew))
            {
                fs.Write(setup.Hash);
                fs.Write(setup.Owner);
                fs.Write(setup.Repository);
                fs.Write(setup.Token);
                fs.Write((int)setup.Settings);

                var users = setup.GetUsers().ToArray();
                fs.Write(users.Length);
                foreach (var u in users)
                    u.ToStream(fs);

                var contributors = setup.GetContributors().Where(c => c.Active).ToArray();
                fs.Write(contributors.Length);
                foreach (var c in contributors)
                    fs.Write(c.Name);

                var commits = setup.GetCommits().ToArray();
                fs.Write(commits.Length);
                foreach (var c in commits)
                {
                    byte[] text = Encoding.ASCII.GetBytes(c.Sha);
                    fs.Write(text, 0, 40);
                    fs.WriteZeros(users.Length);
                }
                var mess = (setup as IGame).GetMessages().ToArray();
                foreach (var m in mess)
                    m.ToStream(fs);
            }

            var game = Game.FromFile(filepath);

            game.Add(StateMessage.CreateStarted());
            game.Add(new RoundStartMessage(1));

            return game;
        }
Beispiel #3
0
 public void AddSetup(GameSetup setup)
 {
     setups.Add(setup.Hash, setup);
 }
Beispiel #4
0
 public bool TryGetSetup(string hash, out GameSetup setup)
 {
     return setups.TryGetValue(hash, out setup);
 }