Exemplo n.º 1
0
 public Player(string name, string TypeOfTanks, string TypeOfBullet)
 {
     this.name = name;
     tank = new Tank(TypeOfTanks);
     this.TypeOfBullet = TypeOfBullet;
     score = 0;
 }
Exemplo n.º 2
0
        public void SetupGame()
        {
            Tank tank = new Tank(TankResources.Tank1);
            //tank.Index = NumberOfTanks;
            tank.SpeedMove = 3;
            tank.setSize( new Size(40, 40));
            tank.setPosition(new Position(100, 200));
            tank.ActionNormal = () => new List<Instruction>()
            {
                new Instruction(TypeInstruction.MoveBackward,100),
                new Instruction(TypeInstruction.RotateLeft, 45),
                new Instruction(TypeInstruction.MoveForward, 50),
                new Instruction(TypeInstruction.RotateRight, 37),
                new Instruction(TypeInstruction.Fire,0),
            };
            Tanks.Add(tank);
            //NumberOfTanks++;

            tank = new Tank(TankResources.Tank2);
            //tank.Index = NumberOfTanks;
            tank.SpeedMove = 3;
            tank.setSize (new Size(40, 40));
            tank.setPosition (new Position(100, 100));
            tank.ActionNormal = () => new List<Instruction>()
            {
                new Instruction(TypeInstruction.RotateLeft, 50),
                new Instruction(TypeInstruction.MoveForward, 100),
                new Instruction(TypeInstruction.Fire,0),
            };
            Tanks.Add(tank);
            //NumberOfTanks++;

            tank = new Tank(TankResources.Tank3);
            tank.SpeedMove = 3;
            tank.Index = NumberOfTanks;
            tank.setSize (new Size(40, 40));
            tank.setPosition (new Position(300, 300));
            tank.ActionNormal = () => new List<Instruction>()
            {
                new Instruction(TypeInstruction.MoveForward, 100),
                new Instruction(TypeInstruction.RotateLeft, 90),
                new Instruction(TypeInstruction.RotateRight,180),
                new Instruction(TypeInstruction.Fire,0),
            };
            Tanks.Add(tank);
            //NumberOfTanks++;

            tank = new Tank(TankResources.Tank4);
            //tank.Index = NumberOfTanks;
            tank.SpeedMove = 4;
            tank.setSize (new Size(40, 40));
            tank.setPosition (new Position(100, 400));
            tank.Direction = 45;
            tank.ActionNormal = () => new List<Instruction>()
            {
                new Instruction(TypeInstruction.MoveForward, 300),
                new Instruction(TypeInstruction.RotateLeft, 135),
                new Instruction(TypeInstruction.MoveForward, 210),
                new Instruction(TypeInstruction.RotateRight, 45),
                new Instruction(TypeInstruction.MoveBackward, 300),
                new Instruction(TypeInstruction.RotateLeft, 45),
                new Instruction(TypeInstruction.MoveForward, 210),
                new Instruction(TypeInstruction.RotateRight, 135),
                new Instruction(TypeInstruction.Fire,0),
            };
            Tanks.Add(tank);
            //NumberOfTanks++;
            updateObjects();
            //updateBattlefield();
        }
Exemplo n.º 3
0
 private void ProcessTank(Tank tank)
 {
     tank.Update();
     Position p = new Position(tank.getPosition().X, tank.getPosition().Y);
     for (int i = 0; i < tank.Instructions.Count; i++) {
         if (tank.Instructions[i].Type == TypeInstruction.MoveForward) {
             float value = Math.Min(tank.Instructions[i].Parameter, tank.SpeedMove);
             tank.MoveForward(value);
             tank.Instructions[i].Parameter -= value;
             for (int j = 0; j < Tanks.Count; j++)
                 if (Tanks[j] != tank && tank.IsCollided(Tanks[j])) {
                     tank.setPosition(p);
                     break;
                 }
             if (tank.Instructions[i].Parameter == 0) tank.Instructions.RemoveAt(i--);
             else break;
         } else if (tank.Instructions[i].Type == TypeInstruction.MoveBackward) {
             float value = Math.Min(tank.Instructions[i].Parameter, tank.SpeedMove);
             tank.MoveBackward(value);
             tank.Instructions[i].Parameter -= value;
             for (int j = 0; j < Tanks.Count; j++)
                 if (Tanks[j] != tank && tank.IsCollided(Tanks[j])) {
                     tank.setPosition(p);
                     break;
                 }
             if (tank.Instructions[i].Parameter == 0) tank.Instructions.RemoveAt(i--);
             else break;
         } else if (tank.Instructions[i].Type == TypeInstruction.RotateLeft) {
             float value = Math.Min(tank.Instructions[i].Parameter, 5);
             tank.RotateLeft(value);
             tank.Instructions[i].Parameter -= value;
             if (tank.Instructions[i].Parameter == 0) tank.Instructions.RemoveAt(i--);
             else break;
         } else if (tank.Instructions[i].Type == TypeInstruction.RotateRight) {
             float value = Math.Min(tank.Instructions[i].Parameter, 5);
             tank.RotateRight(value);
             tank.Instructions[i].Parameter -= value;
             if (tank.Instructions[i].Parameter == 0) tank.Instructions.RemoveAt(i--);
             else break;
         } else if (tank.Instructions[i].Type == TypeInstruction.Fire) {
             if (tank.AllowToFire) {
                 tank.Fire();
                 Bullets.Add(tank.bullet);
                 tank.Instructions.RemoveAt(i);
                 NeedToUpdate = true;
                 //tank.UpdateStats();
             }
         }
     }
 }