示例#1
0
文件: Form1.cs 项目: SatanSec/Tank
        public void start()
        {
            pnlStart.Hide();
            pnlPause.Hide();
            //清空游戏元素映射
            mapping.Clear();
            //清空游戏图片
            clearAll();
            //创建玩家坦克
            player = new PlayerTank(300,300);
            this.Controls.Add(player.picture);
            mapping.Add(player);
            //创建敌人坦克
            int num = 5;
            enemy = new EnemyTank[num];

            Random ran = new Random();
            for (int i = 0; i < enemy.Length; i++)
            {
                enemy[i] = new EnemyTank(0, 0, ran.Next(1,4));
                this.Controls.Add(enemy[i].picture);
                mapping.Add(enemy[i]);
                Thread.Sleep(100);
            }
            //设置游戏状态
            pause = false;
        }
示例#2
0
        void timerTick2(object sender, EventArgs e)
        {
            if (tanksAliveCounter != 0)
            {
                tankShootIterator++;
                EnemyTank tempTank = new EnemyTank(this, 0);

                if (tankShootIterator == tankShootTime)
                {
                    tankShootIterator = 0;
                    tempTank          = enemyTanksToShoot();
                    // Debug.WriteLine("x = " + temp.xGridPosition.ToString() + " y = " + temp.yGridPosition.ToString());
                    //Debug.WriteLine("------------------------------------------");

                    if (enemyShootStateHolder == (int)enemyTankShellState.initState)
                    {
                        enemyShootsList.Add(new Rectangle());

                        enemyShootsList[enemyShootCount].Height = 5;
                        enemyShootsList[enemyShootCount].Width  = 4;
                        enemyShootsList[enemyShootCount].Fill   = new SolidColorBrush(Colors.Red);
                        enemyShootStateHolder = (int)enemyTankShellState.shootState;
                        enemyShootX           = tempTank.xGridPosition * 60 + 38;
                        enemyShootY           = tempTank.yGridPosition * 60 + 60;
                        this.obstacleCanvas.Children.Add(enemyShootsList[enemyShootCount]);
                        Canvas.SetTop(enemyShootsList[enemyShootCount], enemyShootY);
                        Canvas.SetLeft(enemyShootsList[enemyShootCount], enemyShootX);

                        enemyShootCount++;
                    }
                }

                if (enemyShootStateHolder == (int)enemyTankShellState.shootState)
                {
                    enemyShootY += ammoVelocity;
                    this.obstacleCanvas.Children.Remove(enemyShootsList[enemyShootCount - 1]);
                    this.obstacleCanvas.Children.Add(enemyShootsList[enemyShootCount - 1]);
                    Canvas.SetTop(enemyShootsList[enemyShootCount - 1], enemyShootY);
                    Canvas.SetLeft(enemyShootsList[enemyShootCount - 1], enemyShootX);
                    if (enemyShootY == enemyShootRange)
                    {
                        enemyShootStateHolder = (int)enemyTankShellState.hitState;
                    }
                }
                if (enemyShootStateHolder == (int)enemyTankShellState.hitState)
                {
                    if (isHerePlayerTank(enemyShootX))
                    {
                        if (gameParams.health - enemyTankDamage > 0)
                        {
                            gameParams.health -= enemyTankDamage;
                        }
                        else
                        {
                            gameParams.health = 0;
                            if (defeat == false)
                            {
                                defeat = true;
                                Defeat wind = new Defeat(this);
                                this.IsEnabled = false;
                                wind.Show();
                            }
                        }
                    }
                    enemyShootStateHolder = (int)enemyTankShellState.initState;
                    this.obstacleCanvas.Children.Remove(enemyShootsList[enemyShootCount - 1]);
                }
            }
        }