コード例 #1
0
ファイル: Main.cs プロジェクト: simorgh33/RoadBuilder
        public void OnLoad()
        {
            LevelManager = new LevelManager();
            LevelManager.AddLevel("Level 1", new Level("Level1", 15, 9));
            LevelManager.AddLevel("Level 2", new Level("Level2", 3, 9));

            LevelManager.SelectLevel("Level 1");
            LevelManager.GenerateLevel();

            GamestateManager = new GamestateManager();
            KeyInputManager  = new KeyInputManager();
            EventHandler     = new EventHandler();

            MouseInputManager = new MouseInputManager("data\\res\\cursor\\cursor_normal.png", this.EventHandler);

            KeyInputManager.BindKey(Keys.Left, new Action(() => { Player.Position = new Point(Player.Position.X - 3, Player.Position.Y); }), GameState.GAME_IN_GAME, true);
            KeyInputManager.BindKey(Keys.Right, new Action(() => { Player.Position = new Point(Player.Position.X + 3, Player.Position.Y); }), GameState.GAME_IN_GAME, true);
            KeyInputManager.BindKey(Keys.Escape, PauseGame, GameState.GAME_IN_GAME, false);
            KeyInputManager.BindKey(Keys.Escape, ResumeGame, GameState.GAME_IN_PAUSE_SCREEN, false);

            //KeyInputManager.BindKey(Keys.Up, new Action(() => { LevelManager.SelectLevel("Level 1"); EventHandler.PushEvent(EVENT_LEVEL_CHANGED); }), GameState.GAME_IN_GAME, false);
            //KeyInputManager.BindKey(Keys.Down, new Action(() => { LevelManager.SelectLevel("Level 2"); EventHandler.PushEvent(EVENT_LEVEL_CHANGED); }), GameState.GAME_IN_GAME, false);

            Player = new Player("Player", 10, new Point(100, 100), new Size(50, 50), "data\\res\\textures\\player1.png", true, this.EventHandler);

            Timer1 = new GameTimer("Timer1", 30, this.EventHandler);
            Timer2 = new GameTimer("Timer2", 30, this.EventHandler);

            Button1 = new GameButton("Button1", 10, new Point(400, 550), new Size(120, 50), Color.Yellow, "Hallo Welt", this.EventHandler);

            Fontstring1 = new GameFont("Fontstring Hallo", 15, new Point(this.Width - 100, 15), String.Empty, new Font(FontFamily.GenericMonospace, 14), Color.LightGreen, this.EventHandler);
            Fontstring2 = new GameFont("Fontstring Hallo", 15, new Point(this.Width - 100, 40), Color.Blue, "Hallo", new Font(FontFamily.GenericMonospace, 14), Color.LightGreen, this.EventHandler);

            ///////// LAMBDA FUNCTIONS

            EventHandler.RegisterEvent(EventType.EVENT_FPS_UPDATE);
            EventHandler.RegisterEvent(EventType.EVENT_PLAYER_MOVED);
            EventHandler.RegisterEvent(EventType.EVENT_TIMER_TICK);
            EventHandler.RegisterEvent(EventType.EVENT_MOUSE_MOVE);
            EventHandler.RegisterEvent(EventType.EVENT_MOUSE_CLICK);
            EventHandler.RegisterEvent(EventType.EVENT_MOUSE_LEAVE);
            EventHandler.RegisterEvent(EventType.EVENT_MOUSE_ENTER);

            EventHandler.RegisterEventListener(new Action <string, Event>(((EventName, PushedEvent) => {
                Event RawEvent = (Event)PushedEvent;

                // MessageBox.Show(EventName);

                if (EventName == EventType.EVENT_TIMER_TICK)
                {
                    GameTimer gt = (GameTimer)RawEvent.Sender;

                    if (RawEvent.Sender.Name == Timer1.Name)
                    {
                        //MessageBox.Show("Timer 1 Ticked");
                    }
                    else if (RawEvent.Sender.Name == Timer2.Name)
                    {
                        // MessageBox.Show("Timer 2 Ticked");
                    }
                }
                else if (EventName == EventType.EVENT_GAME_PAUSED)
                {
                }
                else if (EventName == EventType.EVENT_GAME_RESUMED)
                {
                }
                else if (EventName == EventType.EVENT_MOUSE_MOVE)
                {
                    //MessageBox.Show("MOUSE MOVE");
                }
                else if (EventName == EventType.EVENT_MOUSE_ENTER)
                {
                    EVENT_MOUSE_ENTER Event = RawEvent as EVENT_MOUSE_ENTER;


                    Event.EnteredObject.RenderRectangle = true;
                }
                else if (EventName == EventType.EVENT_MOUSE_LEAVE)
                {
                    EVENT_MOUSE_LEAVE Event = RawEvent as EVENT_MOUSE_LEAVE;


                    Event.LeavedObject.RenderRectangle = false;
                }
                else if (EventName == EventType.EVENT_MOUSE_CLICK)
                {
                    EVENT_MOUSE_CLICK Event = RawEvent as EVENT_MOUSE_CLICK;

                    if (Event.ClickedObject != null)
                    {
                        if (Event.ClickedObject != Player && Event.ClickedObject != Fontstring1)
                        {
                            Tile t = ((Tile)Event.ClickedObject);
                            zufallszahl = new Random();
                            int random = zufallszahl.Next(1, 12);
                            if (t.IsClicked == false)
                            {
                                //Player.Move((Tile)Event.ClickedObject);
                                // MessageBox.Show("data\\res\\textures\\" +random+ ".png");
                                t.Texture = new Texture2D("data\\res\\textures\\" + random + ".png");
                                t.IsClicked = true;
                                int randomCoin = zufallszahl.Next(0, wert + 1);
                                if (randomCoin == 0 || randomCoin == 15)
                                {
                                    t.setCoin = true;
                                    t.Texture = new Texture2D("data\\res\\textures\\12.png");
                                    // MessageBox.Show("der wert ist" + wert + "zufall ist :" + randomCoin);
                                    wert = 100;
                                    // MessageBox.Show("der wert ist" + wert + "zufall ist :" + randomCoin);
                                }
                                wert = wert - 5;
                                // MessageBox.Show("der wert ist" +wert +"zufall ist :"+randomCoin);


                                Player.Move((Tile)Event.ClickedObject);
                                if (t.setCoin == true)
                                {
                                    MessageBox.Show("money,money,money");
                                }
                            }
                        }
                    }
                }
                else if (EventName == EventType.EVENT_FPS_UPDATE)
                {
                    EVENT_FPS_UPDATE Event = RawEvent as EVENT_FPS_UPDATE;

                    Fontstring1.Text = Event.FPS + " Fps";
                }
            })));

            MouseInputManager.RegisterInteractiveObject(Player);
            MouseInputManager.RegisterInteractiveObject(Button1);
            MouseInputManager.RegisterInteractiveObject(Fontstring1);

            MouseInputManager.RegisterInteractiveObjects(LevelManager.CurrentLevelObjects);

            MouseInputManager.AddCursorType(Cursortypes.MOUSEOVER, "data\\res\\cursor\\cursor_interact.png");

            GamestateManager.ChangeGamestate(GameState.GAME_IN_GAME);

            //Timer1.Start();
            //Timer2.Start();
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: simorgh33/RoadBuilder
        public void OnLoad()
        {
            LevelManager = new LevelManager();
            LevelManager.AddLevel("Level 1", new Level("Level1", 15, 9));
            LevelManager.AddLevel("Level 2", new Level("Level2", 3, 9));

            LevelManager.SelectLevel("Level 1");
            LevelManager.GenerateLevel();

            GamestateManager  = new GamestateManager();
            KeyInputManager   = new KeyInputManager();
            MouseInputManager = new MouseInputManager("data\\res\\cursor\\cursor_normal.png");
            EventHandler      = new EventHandler();

            KeyInputManager.BindKey(Keys.Left, new Action(() => { Player.Position = new Point(Player.Position.X - 3, Player.Position.Y); }), GameState.GAME_IN_GAME, true);
            KeyInputManager.BindKey(Keys.Right, new Action(() => { Player.Position = new Point(Player.Position.X + 3, Player.Position.Y); }), GameState.GAME_IN_GAME, true);
            KeyInputManager.BindKey(Keys.Escape, PauseGame, GameState.GAME_IN_GAME, false);
            KeyInputManager.BindKey(Keys.Escape, ResumeGame, GameState.GAME_IN_PAUSE_SCREEN, false);

            KeyInputManager.BindKey(Keys.Up, new Action(() => { LevelManager.SelectLevel("Level 1"); EventHandler.PushEvent(EVENT_LEVEL_CHANGED); }), GameState.GAME_IN_GAME, false);
            KeyInputManager.BindKey(Keys.Down, new Action(() => { LevelManager.SelectLevel("Level 2"); EventHandler.PushEvent(EVENT_LEVEL_CHANGED); }), GameState.GAME_IN_GAME, false);

            Player = new Player(10, new Point(100, 100), new Size(50, 50), "data\\res\\textures\\player1.png", true);
            Timer1 = new GameTimer();

            ///////// LAMBDA FUNCTIONS

            EventHandler.RegisterEvent(EVENT_GAME_PAUSED);
            EventHandler.RegisterEvent(EVENT_GAME_RESUMED);
            EventHandler.RegisterEvent(EVENT_MOUSE_CLICK);
            EventHandler.RegisterEvent(EVENT_TIMER_TICK);
            EventHandler.RegisterEvent(EVENT_LEVEL_CHANGED);

            EventHandler.RegisterEventListener(new Action <Event>(((e) => {
                Event Event = (Event)e;

                //MessageBox.Show("Event Triggered: " + Event.Name);

                if (Event == EVENT_GAME_PAUSED)
                {
                    Event = Event as EVENT_GAME_PAUSED;

                    MessageBox.Show("Game Paused");
                }
                else if (Event == EVENT_GAME_RESUMED)
                {
                    MessageBox.Show("Game Resumed");
                }
                else if (Event == EVENT_MOUSE_CLICK)
                {
                }
                else if (Event == EVENT_TIMER_TICK)
                {
                }
                else if (Event == EVENT_LEVEL_CHANGED)
                {
                    MouseInputManager.UnregisterInteractiveObjects(LevelManager.CurrentLevelObjects);
                    LevelManager.GenerateLevel();
                    MouseInputManager.RegisterInteractiveObjects(LevelManager.CurrentLevelObjects);
                }
            })));

            MouseInputManager.RegisterInteractiveObject(Player);

            MouseInputManager.RegisterInteractiveObjects(LevelManager.CurrentLevelObjects);

            MouseInputManager.AddCursorType(Cursortypes.MOUSEOVER, "data\\res\\cursor\\cursor_interact.png");

            MouseInputManager.RegisterClickListener(new Action <MouseClickEvent>(((e) => {
                MouseClickEvent Click = (MouseClickEvent)e;

                if (Click.Button == MouseButtons.Left)
                {
                    if (Click.ClickTarget != null)
                    {
                        //MessageBox.Show("Clicked with Left Mouse at Interactive Object: " + Click.ClickTarget.ID);

                        //MessageBox.Show("IDType: " + IDSystemManager.GetTypeFromID(Click.ClickTarget.ID).ToString());
                        if (Click.ClickTarget != Player)
                        {
                            Player.Move((Tile)Click.ClickTarget);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Clicked with Left Mouse at no Object ");
                    }
                }
                else if (Click.Button == MouseButtons.Right)
                {
                    if (Click.ClickTarget != null)
                    {
                        MessageBox.Show("Clicked with Right Mouse at Interactive Object: " + Click.ClickTarget.ID);
                    }
                    else
                    {
                        MessageBox.Show("Clicked with Left Mouse at no Object ");
                    }
                }
            })));

            MouseInputManager.RegisterMouseOverListener(new Action <MouseOverEvent>(((e) => {
                MouseOverEvent MouseOver = (MouseOverEvent)e;

                if (MouseOver.MouseOverType == MouseOverEvent.MOUSEOVER_ENTER)
                {
                    MouseOver.MouseOverTarget.RenderRectangle = true;
                }
                else if (MouseOver.MouseOverType == MouseOverEvent.MOUSEOVER_LEAVE)
                {
                    MouseOver.MouseOverTarget.RenderRectangle = false;
                }
            })));

            GamestateManager.ChangeGamestate(GameState.GAME_IN_GAME);

            Timer1.RegisterEventListener(new Action <TimerTickEvent>(((e) => {
                EventHandler.PushEvent(EVENT_TIMER_TICK);
            })));

            Timer1.Start();
        }