Beispiel #1
0
        public MainMenu(RenderWindow window, ImageManager imageManager, Client client, Server server)
            : base(window, imageManager)
        {
            imageManager = new ImageManager();
            p = new Player(null, imageManager);
            mouse = new Sprite(imageManager.GetImage("mouse"));
            pImage = new RenderImage(window.Width, window.Height);
            pImage.DefaultView.Zoom(0.08F);
            pImage.DefaultView.Center = p.Center + new Vector2f(0, -30);
            pImage.SetView(pImage.DefaultView);

            this.window = window;
            this.client = client;
            this.server = server;
            items = new MenuItem[nbrItem];
            items[0] = new MenuItem("Local Game", new Vector2f(0, 100), StartLocal);
            items[1] = new MenuItem("Connect", new Vector2f(0, 130), Connect);
            items[2] = new MenuItem("Options", new Vector2f(0, 160), Option);
            items[3] = new MenuItem("Load map", new Vector2f(0, 190), LoadMap);
            items[4] = new MenuItem("Save map", new Vector2f(0, 220), SaveMap);
            items[5] = new MenuItem("Exit", new Vector2f(0, 280), Exit);

            foreach (MenuItem i in items)
                i.CenterX((int)window.Width);
        }
Beispiel #2
0
        public Client(RenderWindow window, ImageManager imageManager)
            : base(window, imageManager)
        {
            this.window = window;
            world = new RenderImage(800, 600);

            inputManager = new InputManager(this);

            ticker = new Ticker();

            window.ShowMouseCursor (false);
            window.SetFramerateLimit (60);

            NetPeerConfiguration netConfiguration = new NetPeerConfiguration("2dThing");
            client = new NetClient(netConfiguration);

            uMsgBuffer = new UserMessageBuffer();
            otherClients = new Dictionary<int, NetworkClient>();
            chat = new Chat(this);

            LoadRessources();

            blockTypeDisplay = new Cube(blockType, imageManager);
            blockTypeDisplay.Position = new Vector2f(window.Width - 2*Cube.WIDTH, window.Height - 2* Cube.HEIGHT);
            layerDisplay = new LayerDisplay(imageManager);
            layerDisplay.Position = blockTypeDisplay.Position - new Vector2f(0, 50);

            mouse = new Sprite (imageManager.GetImage("mouse"));
        }
Beispiel #3
0
        public Server(ImageManager imageManager)
        {
            this.imageManager = imageManager;
            this.ticker = new Ticker();

            NetPeerConfiguration netConfiguration = new NetPeerConfiguration("2dThing");
            netConfiguration.Port = 55017;
            server = new NetServer(netConfiguration);
            clientList = new Dictionary<NetConnection, NetworkClient>();
        }
Beispiel #4
0
 public ConnectMenu(RenderWindow window, ImageManager imageManager, Client client, Server server)
     : base(window, imageManager)
 {
     this.server = server;
     this.client = client;
     p = new Player(null, imageManager);
     randomiser = new Random();
     pImage = new RenderImage(window.Width, window.Height);
     pImage.DefaultView.Zoom(0.08F);
     pImage.DefaultView.Center = p.Center + new Vector2f(0, -40);
     pImage.DefaultView.Rotate(135);
     pImage.SetView(pImage.DefaultView);
     mouse = new Sprite(imageManager.GetImage("mouse"));
     title = new MenuItem("Enter an IP to connect to...", new Vector2f(0, 100), null);
     title.CenterX((int)window.Width);
     ip = new MenuItem("", new Vector2f(0, 150), null);
     ip.CenterX((int)window.Width);
     connecting = new MenuItem("Connecting...", new Vector2f(0, 180), null);
     connecting.CenterX((int)window.Width);
 }
Beispiel #5
0
 public LayerDisplay(ImageManager imageManager)
 {
     this.imageManager = imageManager;
     layer = new Sprite(imageManager.GetImage("layer"));
 }
Beispiel #6
0
 public Screen(RenderWindow window, ImageManager imageManager)
 {
     this.window = window;
     this.imageManager = imageManager;
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            bool isClient = false;
            bool isServer = false;
            String ip = "localhost";
            String pseudo = null;
            int index = 0;
            if (args.Length != 0) {
                foreach (string v in args) {
                    if (v == "-server") {
                        isServer = true;
                        isClient = false;
                    }

                    if (v == "-client") {
                        isServer = false;
                        isClient = true;
                        ip = args[index + 1];
                    }

                    if (v == "-pseudo") {
                        pseudo = args[index + 1];
                    }

                    index++;
                }
            }

            ImageManager imageManager = new ImageManager();

            if (isServer) {
                Server server = new Server(imageManager);
                server.Run();
            } else {
                RenderWindow window = new RenderWindow(new VideoMode(800, 600), "2dThing");

                Dictionary<int,Screen > screens = new Dictionary<int, Screen>();
                int screen = 0;

                Server server = new Server(imageManager);
                Client client = new Client(window, imageManager);
                client.IP = ip;

                MainMenu mainMenu = new MainMenu(window, imageManager, client, server);
                ConnectMenu connectMenu = new ConnectMenu(window, imageManager, client, server);

                screens.Add(Screen.MAINMENU, mainMenu);
                screens.Add(Screen.GAME, client);
                screens.Add(Screen.CONNECT, connectMenu);
                screens.Add(Screen.LOAD, new LoadMenu(window, imageManager, server));
                screens.Add(Screen.SAVE, new SaveMenu(window, imageManager, client));

                if (isClient) {
                    client.Connect();
                    client.LoadEventHandler();
                    screen = Screen.GAME;
                } else
                    mainMenu.LoadEventHandler();

                while (screen >= 0) {
                    int prevScreen = screen;
                    screen = screens[screen].Run();

                    if (screen >= 0) {
                        screens[prevScreen].UnloadEventHandler();
                        screens[screen].LoadEventHandler();
                    }
                }
                client.Disconnect();
                if (server != null)
                    server.Stop();
            }
        }
Beispiel #8
0
 public SaveMenu(RenderWindow window, ImageManager imageManger, Client client)
     : base(window, imageManger)
 {
     this.client = client;
     fl = new FileLister(".", false, "*.map");
 }
Beispiel #9
0
 public LoadMenu(RenderWindow window, ImageManager imageManger, Server server)
     : base(window, imageManger)
 {
     this.server = server;
     fl = new FileLister(".", true, "*.map");
 }