Beispiel #1
0
 public Game1()
 {
     server = null;
     state = PongState.Title;
     graphics = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
 }
Beispiel #2
0
 public static Server CreateSession(string ipAddress, int port = 1337)
 {
     Server s = new Server();
     s.listener = new TcpListener(IPAddress.Parse(ipAddress), port);
     s.listener.Start();
     s.t = new Thread(new ThreadStart(s.Listen));
     s.t.Start();
     return s;
 }
Beispiel #3
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);
        }