예제 #1
0
        public void NetTest2()
        {
            Thread serverThread = new Thread(DoServerStuff);

            serverThread.Start();

            NetBreakoutPongClient.GameServer server = new NetBreakoutPongClient.GameServer();

            NetBreakoutPongClient.ClassicPongGameData resultData = server.GetData();

            NetBreakoutPongClient.ClassicPongGameData expectedData = new NetBreakoutPongClient.ClassicPongGameData();
            expectedData.gameBall.Position  = new NetBreakoutPongClient.Location(250, 300);
            expectedData.gameBall.Radius    = 50;
            expectedData.myPaddle.Height    = 40;
            expectedData.myPaddle.Width     = 150;
            expectedData.myPaddle.Position  = new NetBreakoutPongClient.Location(500, 580);
            expectedData.oppPaddle.Height   = 40;
            expectedData.oppPaddle.Width    = 150;
            expectedData.oppPaddle.Position = new NetBreakoutPongClient.Location(300, 20);

            serverThread.Join();
            server.Dispose();

            // Assert.AreEqual(false, resultData.WinnerPlayerOne); // Fix later.. maybe
        }
예제 #2
0
        public void NetTest1()
        {
            Thread serverThread = new Thread(DoServerStuff);

            serverThread.Start();
            //now being a client
            NetBreakoutPongClient.GameServer server = new NetBreakoutPongClient.GameServer();

            NetBreakoutPongClient.ClassicPongGameData resultData = server.GetData();

            NetBreakoutPongClient.ClassicPongGameData expectedData = new NetBreakoutPongClient.ClassicPongGameData();
            expectedData.gameBall.Position  = new NetBreakoutPongClient.Location(250, 300);
            expectedData.gameBall.Radius    = 50;
            expectedData.myPaddle.Height    = 40;
            expectedData.myPaddle.Width     = 150;
            expectedData.myPaddle.Position  = new NetBreakoutPongClient.Location(500, 580);
            expectedData.oppPaddle.Height   = 40;
            expectedData.oppPaddle.Width    = 150;
            expectedData.oppPaddle.Position = new NetBreakoutPongClient.Location(300, 20);
            serverThread.Join();

            server.Dispose();

            Assert.AreEqual(expectedData.myPaddle.Position.X, resultData.myPaddle.Position.X);
        }
        public void Gameplay()
        {
            PaintGame(server.GetData());

            while (gameData.ILost == false && gameData.OppLost == false)
            {
                server.SendKeypress(new Keypress(leftKeyPressed, rightKeyPressed));
                leftKeyPressed = rightKeyPressed = false;
                gameData       = server.GetData();
                PaintGame(gameData);
            }
        }
예제 #4
0
        public void Gameplay()
        {
            do
            {
                gameData = server.GetData();
                PaintGame(gameData);

                while (gameData.ILost == false && gameData.OppLost == false)
                {
                    server.SendKeypress(new Keypress(leftKeyPressed, rightKeyPressed));
                    gameData = server.GetData();
                    PaintGame(gameData);
                }

                server.SendContinue(QueryContinue());
            } while (server.ContinueApproved());
        }
예제 #5
0
        private void PaintGame(ClassicPongGameData data)
        {
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                Rectangle myPaddle = new Rectangle();
                myPaddle.Fill      = myPaddleColor;
                myPaddle.Height    = data.myPaddle.Height;
                myPaddle.Width     = data.myPaddle.Width;

                Canvas.SetTop(myPaddle, (data.myPaddle.Position.Y - (data.myPaddle.Height / 2)));
                Canvas.SetLeft(myPaddle, (data.myPaddle.Position.X - (data.myPaddle.Width / 2)));

                Rectangle oppPaddle = new Rectangle();
                oppPaddle.Fill      = oppPaddleColor;
                oppPaddle.Height    = data.oppPaddle.Height;
                oppPaddle.Width     = data.oppPaddle.Width;

                Canvas.SetTop(oppPaddle, (data.oppPaddle.Position.Y - (data.oppPaddle.Height / 2)));
                Canvas.SetLeft(oppPaddle, (data.oppPaddle.Position.X - (data.oppPaddle.Width / 2)));

                Ellipse gameBall = new Ellipse();
                gameBall.Width   = data.gameBall.Radius * 2;
                gameBall.Height  = data.gameBall.Radius * 2;
                gameBall.Fill    = ballColor;

                Canvas.SetTop(gameBall, (data.gameBall.Position.Y - (data.gameBall.Radius)));
                Canvas.SetLeft(gameBall, (data.gameBall.Position.X - (data.gameBall.Radius)));

                if (gameCanvas.Children.Count > 0)
                {
                    gameCanvas.Children.Clear();
                }

                gameCanvas.Children.Add(myPaddle);
                gameCanvas.Children.Add(oppPaddle);
                gameCanvas.Children.Add(gameBall);

                if (data.ILost || data.OppLost)
                {
                    PrintGameOver(data.ILost);
                }
            }));
        }
예제 #6
0
        public Driver()
        {
            gameData = new ClassicPongGameData();

            //Initialize my paddle
            gameData.myPaddle.Height     = 20;
            gameData.myPaddle.Width      = 80;
            gameData.myPaddle.Position.X = 150;
            gameData.myPaddle.Position.Y = 590;

            //Initialize opponent paddle
            gameData.oppPaddle.Height     = 20;
            gameData.oppPaddle.Width      = 80;
            gameData.oppPaddle.Position.X = 150;
            gameData.oppPaddle.Position.Y = 10;

            //Initialize the ball
            gameData.gameBall.Radius     = 10;
            gameData.gameBall.Position.X = 250;
            gameData.gameBall.Position.Y = 300;

            gameData.ILost   = false;
            gameData.OppLost = false;
        }