Example #1
0
        public Game1()
            : base()
        {
            fpsMeterStopwatch.Start();

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 1080;
            graphics.PreferredBackBufferWidth = 1920;
            //graphics.IsFullScreen = true;
            Content.RootDirectory = "Content";

            String ip = "192.168.2.15";

            //WebRequest req = WebRequest.Create("https://dl.dropbox.com/u/1814002/TurtleTurner2000/ip.txt");
            //WebResponse resp = req.GetResponse();
            //using (Stream streampje = resp.GetResponseStream())
            //{
            //    using (TextReader reader = new StreamReader(streampje))
            //    {
            //        ip = reader.ReadLine();
            //    }
            //}

            deveClient = new DeveClient(ip, 1337);
            deveClient.Start();

            DeveOutgoingMessage outje = new DeveOutgoingMessage();
            outje.WriteInt32((int)ServerReceiveMessageType.LoginMessageScreenClient);
            outje.WriteInt32(graphics.PreferredBackBufferWidth);
            outje.WriteInt32(graphics.PreferredBackBufferHeight);
            deveClient.Send(outje);
        }
        void kenServer_ReceivedMessage(object sender, ActionEventArgs e)
        {
            form.DebugMSG(e.Id + ": " + e.Action);
            switch (e.Action)
            {
                case "connected":
                    DeveClient deveClient = new DeveClient("localhost", 1337);
                    deveClient.Start();

                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                    outje.WriteInt32(0); //Join message
                    outje.WriteInt32(1); //Android
                    deveClient.Send(outje);

                    clients.Add(e.Id, deveClient);

                    break;
                case "closed":
                    clients[e.Id].Stop();

                    clients.Remove(e.Id);
                    //deveServer.messages.Enqueue(inc);

                    break;
                default:
                    DeveClient deveClientNow = clients[e.Id];

                    DeveOutgoingMessage outje2 = new DeveOutgoingMessage();
                    outje2.WriteInt32(1); //Identifier for command message
                    outje2.WriteString(e.Action);
                    deveClientNow.Send(outje2);

                    break;
            }
        }
Example #3
0
        public Game1()
            : base()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 1080;
            graphics.PreferredBackBufferWidth = 1920;
            graphics.IsFullScreen = true;
            Content.RootDirectory = "Content";

            String ip = "";
            WebRequest req = WebRequest.Create("https://dl.dropbox.com/u/1814002/TurtleTurner2000/ip.txt");
            WebResponse resp = req.GetResponse();
            using (Stream streampje = resp.GetResponseStream())
            {
                using (TextReader reader = new StreamReader(streampje))
                {
                    ip = reader.ReadLine();
                }
            }
            //deveClient = new DeveClient("localhost", 1337);
            deveClient = new DeveClient(ip, 1337);
            deveClient.Start();

            DeveOutgoingMessage outje = new DeveOutgoingMessage();
            outje.WriteInt32(0);
            outje.WriteInt32(0);
            outje.WriteInt32(graphics.PreferredBackBufferWidth);
            outje.WriteInt32(graphics.PreferredBackBufferHeight);
            deveClient.Send(outje);
        }
Example #4
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);

            Content.RootDirectory = "Content";

            String ip = "";
            WebRequest req = WebRequest.Create("https://dl.dropbox.com/u/1814002/TurtleTurner2000/ip.txt");
            WebResponse resp = req.GetResponse();
            using (Stream streampje = resp.GetResponseStream())
            {
                using (TextReader reader = new StreamReader(streampje))
                {
                    ip = reader.ReadLine();
                }
            }

            deveClient = new DeveClient(ip, 1337);
            deveClient.Start();

            DeveOutgoingMessage outje = new DeveOutgoingMessage();
            outje.WriteInt32(0); //Join message
            outje.WriteInt32(1); //Android
            deveClient.Send(outje);

            graphics.IsFullScreen = true;
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 480;
            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;

            this.currentTouchCollection = TouchPanel.GetState();
        }
Example #5
0
 public void SendMeClicking()
 {
     DeveOutgoingMessage outje = new DeveOutgoingMessage();
     outje.WriteInt32(1); //Identifier for command message
     outje.WriteString(stringtosend);
     deveClient.Send(outje);
 }
Example #6
0
 public void SendMeClicking()
 {
     DeveOutgoingMessage outje = new DeveOutgoingMessage();
     outje.WriteInt32((int)ServerReceiveMessageType.NewButtonState); //Identifier for command message
     outje.WriteString(stringtosend);
     outje.WriteString(pressed.ToString());
     deveClient.Send(outje);
 }
        public void SendNewPos()
        {
            DeveOutgoingMessage outje = new DeveOutgoingMessage();
            outje.WriteInt32((int)ServerSendMessageType.SetScreenSize);
            outje.WriteInt32(rect.X);
            outje.WriteInt32(rect.Y);
            outje.WriteInt32(rect.Width);
            outje.WriteInt32(rect.Height);

            outje.WriteInt32(game.totSize.X);
            outje.WriteInt32(game.totSize.Y);
            outje.WriteInt32(game.totSize.Width);
            outje.WriteInt32(game.totSize.Height);
            deveConnection.Send(outje);
        }
        public void Update(GameTime gameTime)
        {
            xSpeed = 0f;
            ySpeed = 0f;

            if (leftArrow)
            {
                xSpeed += -300f;
            }
            if (rightArrow)
            {
                xSpeed += 300f;
            }
            if (upArrown)
            {
                ySpeed += -300f;
            }
            if (downArrow)
            {
                ySpeed += 300f;
            }

            if (dirty)
            {

                DeveOutgoingMessage outje = new DeveOutgoingMessage();
                outje.WriteInt32((int)ServerSendMessageType.SetPlayerLocation);
                outje.WriteString(guid);
                outje.WriteInt32((int)posx);
                outje.WriteInt32((int)posy);
                outje.WriteInt32((int)xSpeed);
                outje.WriteInt32((int)ySpeed);

                game.SendToScreens(outje);

                dirty = false;
            }

            posx += xSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            posy += ySpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
        }
Example #9
0
 public void SendFile(String fileName)
 {
     DeveOutgoingMessage msg = new DeveOutgoingMessage(DeveMessageType.Data);
     msg.WriteString("file");
     using (FileStream read = new FileStream(fileName, FileMode.Open))
     {
         msg.WriteString(Path.GetFileName(fileName));
         msg.WriteInt32((int)read.Length);
         byte[] b = new byte[read.Length];
         read.Read(b, 0, (int)read.Length);
         msg.WriteBytes(b);
     }
     deveClient.Send(msg);
 }
        public void SendNewAreas()
        {
            Graphics g = panel1.CreateGraphics();
            g.FillRectangle(Brushes.CornflowerBlue, new Rectangle(0, 0, 1000000, 1000000));

            Rectangle totSize = new Rectangle();
            totSize.X = 0;
            totSize.Y = 0;
            totSize.Width = clientjes.Count * 1920;
            totSize.Height = clientjes.Count * 1080;

            for (int i = 0; i < clientjes.Count; i++)
            {
                Clientje curClient = clientjes[i];

                Rectangle curSize = new Rectangle();
                curSize.X = i * 1920;
                curSize.Y = 0;
                curSize.Width = 1920;
                curSize.Height = 1080;

                DeveOutgoingMessage outje = new DeveOutgoingMessage();
                outje.WriteInt32(0); //Identifier

                outje.WriteInt32(totSize.X);
                outje.WriteInt32(totSize.Y);
                outje.WriteInt32(totSize.Width);
                outje.WriteInt32(totSize.Height);

                outje.WriteInt32(curSize.X);
                outje.WriteInt32(curSize.Y);
                outje.WriteInt32(curSize.Width);
                outje.WriteInt32(curSize.Height);

                drawFatRect(Pens.Red, g, curSize, 5, i.ToString());

                curClient.deveConnection.Send(outje);
            }
        }
        public void SendRandomSquirtle()
        {
            DeveOutgoingMessage outje = new DeveOutgoingMessage();

            outje.WriteInt32(1);

            int rrr = r.Next(4);

            if (rrr == 0) //Links
            {
                outje.WriteInt32(0);
                outje.WriteInt32(r.Next(0, 1080));
                outje.WriteInt32(r.Next(100, 1000));
                outje.WriteInt32(r.Next(-1000, 1000));
            }
            else if (rrr == 1) //Rechts
            {
                outje.WriteInt32(clientjes.Count * 1920);
                outje.WriteInt32(r.Next(0, 1080));
                outje.WriteInt32(r.Next(-1000, -100));
                outje.WriteInt32(r.Next(-1000, 1000));
            }
            else if (rrr == 2) //Boven
            {
                outje.WriteInt32(r.Next(0, clientjes.Count * 1920));
                outje.WriteInt32(0);
                outje.WriteInt32(r.Next(-1000, 1000));
                outje.WriteInt32(r.Next(100, 1000));
            }
            else if (rrr == 3) //Onder
            {
                outje.WriteInt32(r.Next(0, clientjes.Count * 1920));
                outje.WriteInt32(1080);
                outje.WriteInt32(r.Next(-1000, 1000));
                outje.WriteInt32(r.Next(-1000, -100));
            }

            foreach (Clientje clientje in clientjes)
            {
                clientje.deveConnection.Send(outje);
            }
        }
Example #12
0
        public void Runner()
        {
            while (true)
            {
                DeveIncomingMessage inc;
                if ((inc = deveServer.ReadMessage()) != null)
                {
                    switch (inc.MessageType)
                    {
                        case DeveMessageType.KeepAlive:
                            break;
                        case DeveMessageType.Data:

                            int hetTypeMessage = inc.ReadInt32();
                            if (hetTypeMessage == 0) //Een join message
                            {
                                int hetTypeDevice = inc.ReadInt32();
                                if (hetTypeDevice == 0) //Een screen client
                                {
                                    DebugMSG("Het is een screen client :D:D:D");

                                    ScreenClientje screenClientje = new ScreenClientje(inc.Sender, curNumberOfScreen);
                                    screenClientjes.Add(inc.Sender, screenClientje);
                                    allClientjes.Add(inc.Sender, screenClientje);
                                    curNumberOfScreen++;

                                    SendNewAreas();
                                }
                                else if (hetTypeDevice == 1) //Android
                                {
                                    DebugMSG("Het is een Android :)");

                                    ControlClientje controlClientje = new ControlClientje(inc.Sender);
                                    controlClientjes.Add(inc.Sender, controlClientje);
                                    allClientjes.Add(inc.Sender, controlClientje);

                                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                    outje.WriteInt32(1); //Add beestje bij alle screens
                                    outje.WriteString(controlClientje.guid);

                                    SendToScreens(outje);
                                }
                            }
                            else if (hetTypeMessage == 1) //Een message met button klik stuff
                            {

                                ControlClientje curControlClient = controlClientjes[inc.Sender];

                                String direction = inc.ReadString();

                                DebugMSG("Got message with: " + direction + " from: " + inc.Sender);

                                if (direction == "left")
                                {
                                    curControlClient.posx -= 50;
                                }
                                else if (direction == "right")
                                {
                                    curControlClient.posx += 50;
                                }
                                else if (direction == "up")
                                {
                                    curControlClient.posy -= 50;
                                }
                                else if (direction == "down")
                                {
                                    curControlClient.posy += 50;
                                }

                                DebugMSG("X: " + curControlClient.posx + " Y: " + curControlClient.posy);

                                DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                outje.WriteInt32(3);
                                outje.WriteString(curControlClient.guid);
                                outje.WriteInt32(curControlClient.posx);
                                outje.WriteInt32(curControlClient.posy);

                                SendToScreens(outje);
                            }

                            break;
                        case DeveMessageType.StatusChanged:
                            byte newStatus = inc.ReadByte();
                            NetworkStatus ns = (NetworkStatus)newStatus;
                            switch (ns)
                            {
                                case NetworkStatus.Connected:

                                    DebugMSG("Er connect iets :O");
                                    break;
                                case NetworkStatus.Disconnected:

                                    if (controlClientjes.ContainsKey(inc.Sender))
                                    {
                                        ControlClientje controlClientje = controlClientjes[inc.Sender];
                                        DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                        outje.WriteInt32(2);
                                        outje.WriteString(controlClientje.guid);
                                        SendToScreens(outje);

                                    }

                                    RemoveFromAllClientLists(inc.Sender);

                                    break;
                                default:
                                    break;
                            }
                            break;
                        default:
                            break;
                    }
                }
                Thread.Sleep(1);
            }
        }
Example #13
0
        public void SendNewAreas()
        {
            Rectangle totSize = new Rectangle();
            totSize.X = 0;
            totSize.Y = 0;
            totSize.Width = clientjes.Count * 1920;
            totSize.Height = clientjes.Count * 1080;

            for (int i = 0; i < clientjes.Count; i++)
            {
                Clientje curClient = clientjes[i];

                Rectangle curSize = new Rectangle();
                curSize.X = i * 1920;
                curSize.Y = 0;
                curSize.Width = 1920;
                curSize.Height = 1080;

                DeveOutgoingMessage outje = new DeveOutgoingMessage();
                outje.WriteInt32(0); //Identifier

                outje.WriteInt32(totSize.X);
                outje.WriteInt32(totSize.Y);
                outje.WriteInt32(totSize.Width);
                outje.WriteInt32(totSize.Height);

                outje.WriteInt32(curSize.X);
                outje.WriteInt32(curSize.Y);
                outje.WriteInt32(curSize.Width);
                outje.WriteInt32(curSize.Height);

                //drawFatRect(Pens.Red, g, curSize, 5, i.ToString());

                curClient.deveConnection.Send(outje);
            }
        }
Example #14
0
        private void button5_Click(object sender, EventArgs e)
        {
            DeveOutgoingMessage outje = new DeveOutgoingMessage();

            outje.WriteInt32(1);

            outje.WriteInt32(0);
            outje.WriteInt32(500);
            outje.WriteInt32(1000);
            outje.WriteInt32(0);

            foreach (Clientje clientje in clientjes)
            {
                clientje.deveConnection.Send(outje);
            }
        }
Example #15
0
        public void HandleDataMessage(DeveIncomingMessage inc)
        {
            ServerReceiveMessageType messageType = (ServerReceiveMessageType)inc.ReadInt32();

            switch (messageType)
            {
                case ServerReceiveMessageType.LoginMessageScreenClient:
                    {
                        DebugMSG("Screen client connected");

                        int xscr = random.Next(100, 1000);
                        int yscr = random.Next(100, 1000);
                        int widthscr = inc.ReadInt32();
                        int heightscr = inc.ReadInt32();

                        ScreenClientje screenClientje = new ScreenClientje(new Rectangle(xscr, yscr, widthscr, heightscr), this, inc.Sender);
                        screenClientjes.Add(inc.Sender, screenClientje);
                        allClientjes.Add(inc.Sender, screenClientje);

                        DeveOutgoingMessage outje = new DeveOutgoingMessage();
                        outje.WriteInt32((int)ServerSendMessageType.MapString);
                        outje.WriteInt32(map[0].Count);
                        outje.WriteInt32(map.Count);
                        foreach (var mapline in map)
                        {
                            StringBuilder build = new StringBuilder();

                            foreach (String str in mapline)
                            {
                                build.Append(str);
                            }

                            outje.WriteString(build.ToString());
                        }

                        screenClientje.deveConnection.Send(outje);

                        foreach (var controlClientje in controlClientjes.Values)
                        {
                            outje = new DeveOutgoingMessage();
                            outje.WriteInt32((int)ServerSendMessageType.SpawnNewPlayer); //Add beestje bij alle screens
                            outje.WriteString(controlClientje.guid);

                            screenClientje.deveConnection.Send(outje);

                            outje = new DeveOutgoingMessage();
                            outje.WriteInt32((int)ServerSendMessageType.SetPlayerLocation);
                            outje.WriteString(controlClientje.guid);
                            outje.WriteInt32((int)controlClientje.posx);
                            outje.WriteInt32((int)controlClientje.posy);
                            outje.WriteInt32(0);
                            outje.WriteInt32(0);

                            screenClientje.deveConnection.Send(outje);
                        }
                    }
                    break;
                case ServerReceiveMessageType.LoginMessageControlClient:
                    {
                        DebugMSG("Het is een Android :)");

                        ControlClientje controlClientje = new ControlClientje(inc.Sender, this);
                        controlClientjes.Add(inc.Sender, controlClientje);
                        allClientjes.Add(inc.Sender, controlClientje);

                        DeveOutgoingMessage outje = new DeveOutgoingMessage();
                        outje.WriteInt32((int)ServerSendMessageType.SpawnNewPlayer); //Add beestje bij alle screens
                        outje.WriteString(controlClientje.guid);

                        SendToScreens(outje);
                    }
                    break;
                case ServerReceiveMessageType.NewButtonState:
                    {
                        ControlClientje curControlClient = controlClientjes[inc.Sender];

                        String direction = inc.ReadString();
                        String onOrOffString = inc.ReadString();
                        Boolean onOrOff = onOrOffString == "True";

                        DebugMSG("Got message with: " + direction + ": " + onOrOff);

                        if (direction == "left")
                        {
                            curControlClient.LeftArrow = onOrOff;
                        }
                        else if (direction == "right")
                        {
                            curControlClient.RightArrow = onOrOff;
                        }
                        else if (direction == "up")
                        {
                            curControlClient.UpArrown = onOrOff;
                        }
                        else if (direction == "down")
                        {
                            curControlClient.DownArrow = onOrOff;
                        }

                        //DebugMSG("X: " + curControlClient.posx + " Y: " + curControlClient.posy);

                        //DeveOutgoingMessage outje = new DeveOutgoingMessage();
                        //outje.WriteInt32((int)ServerSendMessageType.SetPlayerLocation);
                        //outje.WriteString(curControlClient.guid);
                        //outje.WriteInt32((int)curControlClient.posx);
                        //outje.WriteInt32((int)curControlClient.posy);

                        //SendToScreens(outje);
                        break;
                    }
                default:
                    DebugMSG("Unknown message type");
                    break;
            }
        }
Example #16
0
        private void UpdateNetwork(GameTime gameTime)
        {
            DeveIncomingMessage inc;
            while ((inc = deveServer.ReadMessage()) != null)
            {
                switch (inc.MessageType)
                {
                    case DeveMessageType.KeepAlive:
                        break;
                    case DeveMessageType.Data:
                        HandleDataMessage(inc);

                        break;
                    case DeveMessageType.StatusChanged:
                        byte newStatus = inc.ReadByte();
                        NetworkStatus ns = (NetworkStatus)newStatus;
                        switch (ns)
                        {
                            case NetworkStatus.Connected:

                                DebugMSG("Er connect iets :O");
                                break;
                            case NetworkStatus.Disconnected:

                                if (controlClientjes.ContainsKey(inc.Sender))
                                {
                                    ControlClientje controlClientje = controlClientjes[inc.Sender];
                                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                    outje.WriteInt32((int)ServerSendMessageType.RemovePlayer);
                                    outje.WriteString(controlClientje.guid);
                                    SendToScreens(outje);

                                }

                                RemoveFromAllClientLists(inc.Sender);

                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
        }