Example #1
0
        /// <summary>
        /// Same
        /// </summary>
        /// <param name="settings"></param>
        public EnergoServer(ServerSettings settings = null)
        {
            MaxPlayersInRoom = 6;
            _uniqueIds       = new Dictionary <string, object>();
            _current         = this;

            Settings  = settings == null ? new ServerSettings() : settings;
            Users     = new Dictionary <string, User>();
            Maps      = new Dictionary <string, Map>();
            GameRooms = new Dictionary <string, GameRoom>();

            var admin = new User("Admin", AllocateSmallUniqueId(AdminId));

            Users.Add(admin.Id, admin);

            var mapCreator     = new DefaultMapCreator();
            var defaultMapInit = mapCreator.Map;
        }
Example #2
0
        //public Round Round { get; private set; }

        public GameRoom(string name, User leader)
        {
            if (leader.GameRoomRef != null)
            {
                throw new Exception(Constants.Instance.ErrorMessage.Is_In_Game_Room);
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                name = GenerateGameRoomName(leader);
            }
            Name = name;

            //be sure game room id is unique
            Id = EnergoServer.GenerateSmallUniqueId();
            //todo setup it according to map settings and also allow to set it in room settings
            MaxPlayers = EnergoServer.MaxPlayersInRoom;

            Players = new Dictionary <string, PlayerInRoom>();
            Players.Add(leader.Id, new PlayerInRoom(leader));
            Leader = leader;

            //todo push mapId here
            //maybe allow to change map (it means and max players too) when room already created?
            var mapId = string.Empty;
            //todo generate context somewhere else
            var gameContext = new GameContext(this, mapId);

            EnergoServer.Current.CreateGameRoom(leader, this);

            Stages = new StateBatch(gameContext)
                     .Add <CreateGameStage>()
                     .Add(new StateBatch(gameContext, context =>
                                         { return(context.Room.Stages.CurrentBatch.RoundNumber < 2); }) //it will re-run round 3 times
                          .Add <BuildPhase>())
                                                                                                        // .Add<ProduceEnergyPhase>())
                     .StartRound();
        }
Example #3
0
 public static void Init()
 {
     _current = new EnergoServer();
 }