Ejemplo n.º 1
0
 //本方坦克移动
 public void myTankMove(bool upPress, bool downPress, bool leftPress, bool rightPress, Tank playerTank, List <Wall> wallList, List <Stell> stellList)
 {
     if (upPress)
     {
         playerTank.Direction = 0;
         Rectangle rec = new Rectangle(playerTank.X, playerTank.Y - 2, playerTank.Width, playerTank.Height);
         if (wallTankHit(rec, wallList) || stellTankHit(rec, stellList))
         {
         }
         else
         {
             playerTank.Y -= 2;
         }
         playerTank.refreshRectangle(playerTank.X, playerTank.Y);
     }
     else if (downPress)
     {
         playerTank.Direction = 1;
         Rectangle rec = new Rectangle(playerTank.X, playerTank.Y + 2, playerTank.Width, playerTank.Height);
         if (wallTankHit(rec, wallList) || stellTankHit(rec, stellList))
         {
         }
         else
         {
             playerTank.Y += 2;
         }
         playerTank.refreshRectangle(playerTank.X, playerTank.Y);
     }
     else if (leftPress)
     {
         playerTank.Direction = 2;
         Rectangle rec = new Rectangle(playerTank.X - 2, playerTank.Y, playerTank.Width, playerTank.Height);
         if (wallTankHit(rec, wallList) || stellTankHit(rec, stellList))
         {
         }
         else
         {
             playerTank.X -= 2;
         }
         playerTank.refreshRectangle(playerTank.X, playerTank.Y);
     }
     else if (rightPress)
     {
         playerTank.Direction = 3;
         Rectangle rec = new Rectangle(playerTank.X + 2, playerTank.Y, playerTank.Width, playerTank.Height);
         if (wallTankHit(rec, wallList) || stellTankHit(rec, stellList))
         {
         }
         else
         {
             playerTank.X += 2;
         }
         playerTank.refreshRectangle(playerTank.X, playerTank.Y);
     }
 }
Ejemplo n.º 2
0
 //提炼敌方坦克刷新及消失判断方法
 private void enemyDisapper(Tank tank)
 {
     tank.refreshRectangle(tank.X, tank.Y);
     if (playerBulletHitEnemy(playerBulletList, tank) != null)
     {
         Bullet hitNum = playerBulletHitEnemy(playerBulletList, tank);
         tank.IsOver = false;
         tank.refreshRectangle(-100, -100);
         playerBulletList.Remove(hitNum);
         hitCount++;
         if (hitCount == 4)
         {
             MessageBox.Show("You Win!");
         }
     }
     Thread.Sleep(10);
 }
Ejemplo n.º 3
0
 //玩家坦克移动
 private void playerMove()
 {
     //玩家被击中,重生
     if (playerTankHitIntersect(playerTank, enemyTank, enemyBulletList))
     {
         if (playerHited == 2)
         {
             for (int i = 0; i < 4; i++)
             {
                 enemyTank[i].IsOver = false;
             }
             gameRun = false;
             MessageBox.Show("Game Over!");
         }
         playerHited++;
         playerTank.X         = 320; playerTank.Y = 560;
         playerTank.Direction = 0;
         playerTank.refreshRectangle(playerTank.X, playerTank.Y);
     }
     if (hitCount == 4)
     {
         Thread.Sleep(10000);
     }
     if (upPress)
     {
         if (playerTank.Y >= 0)
         {
             myTankMove(upPress, downPress, leftPress, rightPress, playerTank, wallList, stellList);
             rotate = RotateFlipType.RotateNoneFlipX;
         }
     }
     else if (downPress)
     {
         if (playerTank.Y <= 570)
         {
             myTankMove(upPress, downPress, leftPress, rightPress, playerTank, wallList, stellList);
             rotate = RotateFlipType.Rotate180FlipX;
         }
     }
     else if (leftPress)
     {
         if (playerTank.X >= 0)
         {
             myTankMove(upPress, downPress, leftPress, rightPress, playerTank, wallList, stellList);
             rotate = RotateFlipType.Rotate90FlipX;
         }
     }
     else if (rightPress)
     {
         if (playerTank.X <= 800)
         {
             myTankMove(upPress, downPress, leftPress, rightPress, playerTank, wallList, stellList);
             rotate = RotateFlipType.Rotate90FlipY;
         }
     }
 }