예제 #1
0
        public GameManager(GameForm gameForm, string playerName, bool isHost, string ip, int port)
        {
            this.gameForm = gameForm;

            if (isHost)
            {
                IsHost             = isHost;
                gameNetworkManager = new GameServer(port);
                randomSeed         = (int)DateTime.Now.Ticks;
                gameNetworkManager.enqueueMsg(NetworkMsgPrefix.SetSeed,
                                              GameNetworkUtilities.serializeRandomSeed(randomSeed));
            }
            else
            {
                gameNetworkManager = new GameClient(ip, port);
            }

            grid = new Grid(GRID_WIDTH, GRID_HEIGHT,
                            (int)((gameForm.Width - (Tile.WIDTH * GRID_WIDTH)) / 3),
                            (int)((gameForm.Height - (Tile.HEIGHT * GRID_HEIGHT)) / 3) + 30,
                            this);

            TeamBlue = new List <Character>();
            TeamRed  = new List <Character>();

            Player = new Player(playerName, true);

            otherPlayers       = new List <Player>();
            playersLeaderBoard = new PlayersLeaderBoard(Player);

            CharShop  = new CharShop(gameForm, this);
            spellShop = new Shop(gameForm, this, gameNetworkManager);

            stageTimer   = new StageTimer(this);
            stageManager = new StageManager(stageTimer,
                                            TeamBlue,
                                            TeamRed,
                                            grid,
                                            Player,
                                            playersLeaderBoard,
                                            CharShop,
                                            this,
                                            gameNetworkManager);
            stageTimer.switchStageEvent += stageManager.switchStage;

            stopwatch = new Stopwatch();
            timer     = new Timer
            {
                Interval = GAMELOOP_INTERVAL
            };
            timer.Tick += new EventHandler(gameLoop);
        }
예제 #2
0
파일: GUI.cs 프로젝트: sgpicone/SuperMaths
 private void tmrGameTimer_Tick(object sender, System.EventArgs e)
 {
     if (this.StageTimer > 0)
     {
         this.StageTimer -= 1;
         lblTimer.Text    = StageTimer.ToString();
     }
     else
     {
         tmrGameTimer.Stop();
         CheckAnswers();
     }
 }
예제 #3
0
 public StageManager(StageTimer stageTimer,
                     List <Character> teamBlue,
                     List <Character> teamRed,
                     Grid grid,
                     Player player,
                     PlayersLeaderBoard playersLeaderBoard,
                     CharShop charShop,
                     GameManager gameManager,
                     GameNetworkManager gameNetworkManager)
 {
     this.stageTimer         = stageTimer;
     this.teamBlue           = teamBlue;
     this.teamRed            = teamRed;
     this.grid               = grid;
     this.player             = player;
     this.playersLeaderBoard = playersLeaderBoard;
     this.charShop           = charShop;
     this.gameManager        = gameManager;
     this.gameNetworkManager = gameNetworkManager;
     charactersPrevPos       = new Dictionary <Character, Tile>();
     CurrentGameStage        = GameStage.Buy;
     CurrentRound            = 1;
 }
예제 #4
0
        /// <summary>
        /// Initialize the controller
        /// </summary>
        /// <param name="attachToVe">If true then the game is attached to the virtual environment</param>
        public void Initialise(bool attachToVe)
        {
            AttachedToVe = attachToVe;

            ModelFactory = new ModelFactory(this);
            Game = ModelFactory.CreateGame(UUID.Random(), "Game1");

            Commands = new WaterWarsCommands(this);
            Resolver = new OpenSimResolver(this);
            ViewerWebServices = new ViewerWebServices(this);
            HudManager = new HudViewManager(this);
            Events = new WaterWars.Events.Events(this);
            Feeds = new WaterWars.Feeds.Feeds(this);
            GameDateManager = new GameDateManager(this);
            RoundManager = new RoundManager(this);
            StageTimer = new StageTimer(this);

            RainfallGenerator.Initialize(EventManager);
            WaterDistributor.Initialize(EventManager);

            if (null != Persister)
                Persister.Initialize(this);

            if (null != m_recorder)
                m_recorder.Initialize(this);

            // This has to be called before we establish a game state so that the persisted game object
            // can first be created
            EventManager.TriggerSystemInitialized();

            new RegistrationState(this).Activate();

            if (AttachedToVe)
            {
                Groups = new OpenSimGroupsMediator(this);

                CheckVeRequirements();

                foreach (Scene scene in Scenes)
                {
                    // Stop players deleting or editing objects they 'own'
                    scene.Permissions.OnRezObject += delegate(int objectCount, UUID owner, Vector3 objectPosition, Scene myScene) {
                        return Groups.IsPlayerAnAdmin(owner);
                    };
                    scene.Permissions.OnDeleteObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return Groups.IsPlayerAnAdmin(userID);
                    };
                    scene.Permissions.OnTakeObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return Groups.IsPlayerAnAdmin(userID);
                    };
                    scene.Permissions.OnTakeCopyObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return Groups.IsPlayerAnAdmin(userID);
                    };
                    scene.Permissions.OnEditObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return Groups.IsPlayerAnAdmin(userID);
                    };
                    scene.Permissions.OnMoveObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return Groups.IsPlayerAnAdmin(userID);
                    };

                    EntityBase[] entities = scene.Entities.GetAllByType<SceneObjectGroup>();

                    // Pass 1 - pick up the game manager view (first level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

            //                    m_log.InfoFormat(
            //                        "[WATER WARS]: Pass 1 - processing {0} {1} at {2} in existing scene",
            //                        so.Name, so.LocalId, so.AbsolutePosition);

                        // This is messy, but there's actually only one game manager from which objects can come.
                        if (so.Name == GameManagerView.IN_WORLD_NAME)
                        {
                            GameManagerView = new GameManagerView(this, scene);
                            GameManagerView.Initialize(so);
                            Dispatcher.RegisterGameManagerView(GameManagerView);
                        }
                        else if (
                            so.Name == StepBuiltDecorator.IN_WORLD_NAME
                            || so.Name == WaterAllocationDecorator.IN_WORLD_NAME)
                        {
                            // FIXME: Temporarily, just delete our one decorator by name.
                            // Eventually, the decorators will need to be re-registered with their game asset view.
                            so.Scene.DeleteSceneObject(so, false);
                        }
                    }
                }

                if (GameManagerView == null)
                    throw new Exception(
                        string.Format(
                            "Could not find GameManagerView named {0} in any of the scenes.  ABORTING.",
                            GameManagerView.IN_WORLD_NAME));

                foreach (Scene scene in Scenes)
                {
                    m_log.InfoFormat("[WATER WARS]: Processing buypoints on scene {0}", scene.RegionInfo.RegionName);

                    // We'll keep track of these so that we can use them in pass 3
                    Dictionary<UUID, BuyPointView> buyPointViews = new Dictionary<UUID, BuyPointView>();

                    EntityBase[] entities = scene.Entities.GetAllByType<SceneObjectGroup>();

                    // Pass 2 - pick up the buy points (second level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        try
                        {
            //                    m_log.InfoFormat(
            //                        "[WATER WARS]: Pass 2 - processing {0} {1} at {2} in existing scene",
            //                        so.Name, so.LocalId, so.AbsolutePosition);

                            IConfig config = GetPrimConfig(so);

                            if (config != null)
                            {
                                AbstractGameAssetType modelType = GetModelTypeFromPrimConfig(config);

                                if (modelType == AbstractGameAssetType.Parcel)
                                {
                                    // We're using in-world buy point positioning to register them - not taking these from an
                                    // internal database and pushing them back up to the ve
                                    //
                                    // FIXME: The below might be old advice since I have now changed things such that
                                    // we can specify the uuid upfront
                                    //
                                    // We can't incorporate the first update buy point call within bpv.Initialize() because it
                                    // won't yet have registered with the dispatcher (which forms an intermediate layer between the
                                    // game logic and the view code).
                                    // We can't register with the dispatcher before initializing the view because no UUID will yet
                                    // exist for the dispatcher to record.
                                    // It might be possible to simplify this if we adapt OpenSim to allow us to specify the UUID
                                    // up-front.  But other VE systems may not allow this.
                                    BuyPoint bp = Resolver.RegisterBuyPoint(so);
                                    BuyPointView bpv = GameManagerView.CreateBuyPointView(so, bp);
                                    buyPointViews.Add(bpv.Uuid, bpv);
                                    State.UpdateBuyPointStatus(bp);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_log.Error(
                                string.Format(
                                    "[WATER WARS]: Could not register {0} at {1} in {2}, ",
                                    so.Name, so.AbsolutePosition, so.Scene.RegionInfo.RegionName),
                                ex);
                        }
                    }

                    // Pass 3 - pick up the fields and game assets (third level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        try
                        {
                            IConfig config = GetPrimConfig(so);

                            if (config != null)
                            {
                                AbstractGameAssetType modelType = GetModelTypeFromPrimConfig(config);

                                if (modelType == AbstractGameAssetType.Field)
                                {
                                    Field f = Resolver.RegisterField(so);
                                    BuyPointView bpv = null;
                                    if (buyPointViews.TryGetValue(f.BuyPoint.Uuid, out bpv))
                                        bpv.CreateFieldView(so);
                                    else
                                        throw new Exception(
                                            string.Format(
                                                "Could not find BuyPointView for field {0}, parcel {1} at {2}",
                                                f.Name, f.BuyPoint.Name, f.BuyPoint.Location.LocalPosition));
                                }
                                else if (
                                    modelType == AbstractGameAssetType.Crops
                                    || modelType == AbstractGameAssetType.Houses
                                    || modelType == AbstractGameAssetType.Factory)
                                {
                                    // For now, just delete any existing game assets immediately.
                                    so.Scene.DeleteSceneObject(so, false);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_log.Error(
                                string.Format(
                                    "[WATER WARS]: Could not register {0} at {1} in {2}, ",
                                    so.Name, so.AbsolutePosition, so.Scene.RegionInfo.RegionName),
                                ex);
                        }
                    }
                }

                HudManager.Initialise();

                // Register in-game objects as they are created
                //m_scene.EventManager.OnObjectBeingAddedToScene += OnObjectAddedToScene;

                // At the moment, reset the game immediately on restarting so that we have a blank slate
                State.ResetGame();

            //                string statePath = Path.Combine(WaterWarsConstants.STATE_PATH, WaterWarsConstants.STATE_FILE_NAME);
            //                if (File.Exists(statePath))
            //                    RestoreGame(statePath);
            }
        }
예제 #5
0
        //quick test method, not final implementation
        private void DisplayStage(AStage Stage)
        {
            Label   lblBase;
            TextBox answer;

            this.Stage = Stage;
            //GroupBox grpbxProblemsGroup = new GroupBox();
            this.pnlGame.SuspendLayout();
            //grpbxProblemsGroup.Text = null;
            //grpbxProblemsGroup.Name = "grpbxProblemsGroup";
            //grpbxProblemsGroup.Size = this.pnlGame.Size;
            //grpbxProblemsGroup.Location = new System.Drawing.Point(0, 0);
            //create controls for each problem
            int vstartX = 260, startY = 60, ostartX = 280;
            int incX = 0, incY = 0;
            int maxProbCount = 2;

            this.StageTimer = this.Stage.TimeLimit;
            foreach (Problem p in Stage.Problems)
            {
                if (p.Values.Count() > maxProbCount)
                {
                    maxProbCount = p.Values.Count();
                }
            }
            int ansStart = vstartX + maxProbCount * 40;

            //int rgb = new Random().Next(Int32.MinValue, Int32.MaxValue);
            for (int p = 0; p < this.Stage.Problems.Count(); p++)
            {
                incX = 0;
                for (int v = 0; v < this.Stage.Problems[p].Values.Count(); v++)
                {
                    lblBase = new Label();
                    //lblBase.ForeColor = Color.FromArgb(rgb);
                    //lblBase.BackColor = Color.FromArgb(-rgb);
                    lblBase.Size      = new System.Drawing.Size(25, 25);
                    lblBase.Text      = this.Stage.Problems[p].Values[v].ToString();
                    lblBase.Name      = "lbl_Val" + v + "_Prob" + p;
                    lblBase.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                    lblBase.Location  = new System.Drawing.Point(vstartX + incX, startY + incY);
                    this.pnlGame.Controls.Add(lblBase);
                    incX += 40;
                }
                incX = 0;
                for (int o = 0; o < this.Stage.Problems[p].Operators.Count(); o++)
                {
                    lblBase = new Label();
                    //lblBase.ForeColor = Color.FromArgb(rgb);
                    //lblBase.BackColor = Color.FromArgb(-rgb);
                    lblBase.Size      = new System.Drawing.Size(25, 25);
                    lblBase.Text      = this.Stage.Problems[p].Operators[o].OperatorToString();
                    lblBase.Name      = "lbl_Op" + o + "_Prob" + p;
                    lblBase.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                    lblBase.Location  = new System.Drawing.Point(ostartX + incX, startY + incY);
                    this.pnlGame.Controls.Add(lblBase);
                    incX += 40;
                }
                //rgb = new Random().Next(Int32.MinValue,Int32.MaxValue);
                //Thread.Sleep(10);
                answer          = new TextBox();
                answer.TabIndex = p;
                answer.Text     = "0";
                answer.Size     = new System.Drawing.Size(80, 23);
                answer.Name     = "Ans" + p + "Prob" + p;
                answer.Location = new System.Drawing.Point(ansStart, startY + incY);
                this.pnlGame.Controls.Add(answer);

                incY += 30;
            }
            Button btnCheckAnswers = new Button();

            btnCheckAnswers.Name     = "btnCheckAnswers";
            btnCheckAnswers.Text     = "Check Answers";
            btnCheckAnswers.Location = new System.Drawing.Point(ansStart - 30, startY + incY);
            btnCheckAnswers.Size     = new System.Drawing.Size(140, 23);
            btnCheckAnswers.Click   += new System.EventHandler(this.btnCheckAnswers_Click);
            this.pnlGame.Controls.Add(btnCheckAnswers);

            lblTimer          = new Label();
            lblTimer.Name     = "lblTimer";
            lblTimer.Text     = StageTimer.ToString();
            lblTimer.Location = new System.Drawing.Point(ansStart - 100, startY + incY);
            lblTimer.Size     = new System.Drawing.Size(140, 23);
            this.pnlGame.Controls.Add(lblTimer);

            //this.pnlGame.Controls.Add(grpbxProblemsGroup);
            this.pnlGame.ResumeLayout();
            showStartQuizScreen();
            //this.pnlGame.Visible = true;
            //this.pnlSettings.Visible = false;
            //this.pnlMain.Visible = false;
            //this.pnlDifficultySelect.Visible = false;
        }
예제 #6
0
        /// <summary>
        /// Initialize the controller
        /// </summary>
        /// <param name="attachToVe">If true then the game is attached to the virtual environment</param>
        public void Initialise(bool attachToVe)
        {
            AttachedToVe = attachToVe;

            ModelFactory = new ModelFactory(this);
            Game         = ModelFactory.CreateGame(UUID.Random(), "Game1");

            Commands          = new WaterWarsCommands(this);
            Resolver          = new OpenSimResolver(this);
            ViewerWebServices = new ViewerWebServices(this);
            HudManager        = new HudViewManager(this);
            Events            = new WaterWars.Events.Events(this);
            Feeds             = new WaterWars.Feeds.Feeds(this);
            GameDateManager   = new GameDateManager(this);
            RoundManager      = new RoundManager(this);
            StageTimer        = new StageTimer(this);

            RainfallGenerator.Initialize(EventManager);
            WaterDistributor.Initialize(EventManager);

            if (null != Persister)
            {
                Persister.Initialize(this);
            }

            if (null != m_recorder)
            {
                m_recorder.Initialize(this);
            }

            // This has to be called before we establish a game state so that the persisted game object
            // can first be created
            EventManager.TriggerSystemInitialized();

            new RegistrationState(this).Activate();

            if (AttachedToVe)
            {
                Groups = new OpenSimGroupsMediator(this);

                CheckVeRequirements();

                foreach (Scene scene in Scenes)
                {
                    // Stop players deleting or editing objects they 'own'
                    scene.Permissions.OnRezObject += delegate(int objectCount, UUID owner, Vector3 objectPosition, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(owner));
                    };
                    scene.Permissions.OnDeleteObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnTakeObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnTakeCopyObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnEditObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnMoveObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };

                    EntityBase[] entities = scene.Entities.GetAllByType <SceneObjectGroup>();

                    // Pass 1 - pick up the game manager view (first level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        //                    m_log.InfoFormat(
                        //                        "[WATER WARS]: Pass 1 - processing {0} {1} at {2} in existing scene",
                        //                        so.Name, so.LocalId, so.AbsolutePosition);

                        // This is messy, but there's actually only one game manager from which objects can come.
                        if (so.Name == GameManagerView.IN_WORLD_NAME)
                        {
                            GameManagerView = new GameManagerView(this, scene);
                            GameManagerView.Initialize(so);
                            Dispatcher.RegisterGameManagerView(GameManagerView);
                        }
                        else if (
                            so.Name == StepBuiltDecorator.IN_WORLD_NAME ||
                            so.Name == WaterAllocationDecorator.IN_WORLD_NAME)
                        {
                            // FIXME: Temporarily, just delete our one decorator by name.
                            // Eventually, the decorators will need to be re-registered with their game asset view.
                            so.Scene.DeleteSceneObject(so, false);
                        }
                    }
                }

                if (GameManagerView == null)
                {
                    throw new Exception(
                              string.Format(
                                  "Could not find GameManagerView named {0} in any of the scenes.  ABORTING.",
                                  GameManagerView.IN_WORLD_NAME));
                }

                foreach (Scene scene in Scenes)
                {
                    m_log.InfoFormat("[WATER WARS]: Processing buypoints on scene {0}", scene.RegionInfo.RegionName);

                    // We'll keep track of these so that we can use them in pass 3
                    Dictionary <UUID, BuyPointView> buyPointViews = new Dictionary <UUID, BuyPointView>();

                    EntityBase[] entities = scene.Entities.GetAllByType <SceneObjectGroup>();

                    // Pass 2 - pick up the buy points (second level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        try
                        {
                            //                    m_log.InfoFormat(
                            //                        "[WATER WARS]: Pass 2 - processing {0} {1} at {2} in existing scene",
                            //                        so.Name, so.LocalId, so.AbsolutePosition);

                            IConfig config = GetPrimConfig(so);

                            if (config != null)
                            {
                                AbstractGameAssetType modelType = GetModelTypeFromPrimConfig(config);

                                if (modelType == AbstractGameAssetType.Parcel)
                                {
                                    // We're using in-world buy point positioning to register them - not taking these from an
                                    // internal database and pushing them back up to the ve
                                    //
                                    // FIXME: The below might be old advice since I have now changed things such that
                                    // we can specify the uuid upfront
                                    //
                                    // We can't incorporate the first update buy point call within bpv.Initialize() because it
                                    // won't yet have registered with the dispatcher (which forms an intermediate layer between the
                                    // game logic and the view code).
                                    // We can't register with the dispatcher before initializing the view because no UUID will yet
                                    // exist for the dispatcher to record.
                                    // It might be possible to simplify this if we adapt OpenSim to allow us to specify the UUID
                                    // up-front.  But other VE systems may not allow this.
                                    BuyPoint     bp  = Resolver.RegisterBuyPoint(so);
                                    BuyPointView bpv = GameManagerView.CreateBuyPointView(so, bp);
                                    buyPointViews.Add(bpv.Uuid, bpv);
                                    State.UpdateBuyPointStatus(bp);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_log.Error(
                                string.Format(
                                    "[WATER WARS]: Could not register {0} at {1} in {2}, ",
                                    so.Name, so.AbsolutePosition, so.Scene.RegionInfo.RegionName),
                                ex);
                        }
                    }

                    // Pass 3 - pick up the fields and game assets (third level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        try
                        {
                            IConfig config = GetPrimConfig(so);

                            if (config != null)
                            {
                                AbstractGameAssetType modelType = GetModelTypeFromPrimConfig(config);

                                if (modelType == AbstractGameAssetType.Field)
                                {
                                    Field        f   = Resolver.RegisterField(so);
                                    BuyPointView bpv = null;
                                    if (buyPointViews.TryGetValue(f.BuyPoint.Uuid, out bpv))
                                    {
                                        bpv.CreateFieldView(so);
                                    }
                                    else
                                    {
                                        throw new Exception(
                                                  string.Format(
                                                      "Could not find BuyPointView for field {0}, parcel {1} at {2}",
                                                      f.Name, f.BuyPoint.Name, f.BuyPoint.Location.LocalPosition));
                                    }
                                }
                                else if (
                                    modelType == AbstractGameAssetType.Crops ||
                                    modelType == AbstractGameAssetType.Houses ||
                                    modelType == AbstractGameAssetType.Factory)
                                {
                                    // For now, just delete any existing game assets immediately.
                                    so.Scene.DeleteSceneObject(so, false);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_log.Error(
                                string.Format(
                                    "[WATER WARS]: Could not register {0} at {1} in {2}, ",
                                    so.Name, so.AbsolutePosition, so.Scene.RegionInfo.RegionName),
                                ex);
                        }
                    }
                }

                HudManager.Initialise();

                // Register in-game objects as they are created
                //m_scene.EventManager.OnObjectBeingAddedToScene += OnObjectAddedToScene;

                // At the moment, reset the game immediately on restarting so that we have a blank slate
                State.ResetGame();

//                string statePath = Path.Combine(WaterWarsConstants.STATE_PATH, WaterWarsConstants.STATE_FILE_NAME);
//                if (File.Exists(statePath))
//                    RestoreGame(statePath);
            }
        }