示例#1
0
        public JogoDeTenisEngine(Size clientSize, Jogo jogo)
        {
            _jogo = jogo;
            const int espacoForaDaParede = 100;
            var       tamanhoDoJogador   = new Size(20, 100);
            var       tamanhoDaBola      = new Size(20, 20);

            _jogadorEsquerda = new Jogador(
                new Rectangle(espacoForaDaParede, clientSize.Height / 2 - tamanhoDoJogador.Height / 2, tamanhoDoJogador.Width, tamanhoDoJogador.Height),
                clientSize,
                Keys.W,
                Keys.S);
            _jogadorDireita = new Jogador(
                new Rectangle(clientSize.Width - espacoForaDaParede - tamanhoDoJogador.Width,
                              clientSize.Height / 2 - tamanhoDoJogador.Height / 2, tamanhoDoJogador.Width, tamanhoDoJogador.Height),
                clientSize,
                Keys.Up,
                Keys.Down);
            _bola = new Bola(
                new Rectangle(espacoForaDaParede, clientSize.Height - espacoForaDaParede, tamanhoDaBola.Width, tamanhoDaBola.Height),
                clientSize);
        }
示例#2
0
 public void Executar(Bola bola)
 {
     if (MoverParaCima && MoverParaBaixo)
     {
         return;
     }
     if (MoverParaCima)
     {
         if (Retangulo.Top - Velocidade >= 0)
         {
             Retangulo.Y -= Velocidade;
             if (this.Retangulo.IntersectsWith(bola.Retangulo))
             {
                 Retangulo.Y += Velocidade;
             }
         }
         else
         {
             Retangulo.Y = 0;
         }
     }
     else if (MoverParaBaixo)
     {
         if (Retangulo.Bottom + Velocidade <= _enclosing.Height)
         {
             Retangulo.Y += Velocidade;
             if (this.Retangulo.IntersectsWith(bola.Retangulo))
             {
                 Retangulo.Y -= Velocidade;
             }
         }
         else
         {
             Retangulo.Y = _enclosing.Height - Retangulo.Height;
         }
     }
 }