Ejemplo n.º 1
0
        public static Client SetClient(TcpClient clientSocket)
        {
            Client c = new Client();
            c.clientSocket = clientSocket;

            return c;
        }
Ejemplo n.º 2
0
 public static Client Connect(string ipAddress, int socket = 1337)
 {
     Client c = new Client();
     try {
         c.clientSocket = new TcpClient(ipAddress, socket);
         c.t = new Thread(new ThreadStart(c.ListenForCommands));
         c.t.Start();
     } catch (SocketException) {
         Console.WriteLine("No connection could be made!"); //LOG
     } catch (Exception e) {
         Console.WriteLine("Why is this going wrong: {0}", e); //LOG
     }
     return c;
 }
Ejemplo n.º 3
0
        void OnServerConnect(object sender, EventArgs e)
        {
            client = Client.SetClient(server.client);

            me = new Paddle(this, new Vector2(720, 300));
            you = new Paddle(this, new Vector2(80, 300));
            Components.Add(me);
            Components.Add(you);

            state = PongState.Game;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            KeyboardState currentState = Keyboard.GetState();
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (Keyboard.GetState().IsKeyDown(Keys.Escape)) {
                this.Exit();
            }

            if (state == PongState.Title) {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter) && !keyPressed) {
                    keyPressed = true;
                    Console.WriteLine("hit"); //LOG
                    server = Server.CreateSession("127.0.0.1");
                    server.onClientConnect += OnServerConnect;
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Space) && !keyPressed) {
                    keyPressed = true;
                    client = Client.Connect("127.0.0.1");
                    client.onClientConnect += OnClientConnect;
                }
                if (keyPressed &&
                    (Keyboard.GetState().IsKeyUp(Keys.Enter) && Keyboard.GetState().IsKeyUp(Keys.Space))) {
                    keyPressed = false;
                }

            } else if(state == PongState.Game) {
                if (you.Enabled) {
                    you.Enabled = false;
                }
                if (server != null) {
                    server.Send(me._info);
                } else {
                    if (client.recieve != null) {
                        you.Update(client.recieve.velocity);
                    }
                }
            }
            base.Update(gameTime);
        }