MY FIRST TEAM
Getting Started

SETTING UP YOUR PACKAGE

Renaming Package and Files

PLAYER CLASS

The Constructor


The constructor is called before the game begins. 


public MyTeam(int team, Game g) 

{

super(team, g);

// Your team name and image.   The image should be in a 4:3 ratio.

setName("MyTeam");

setTeamImage("src/teams/student/myTeam/myTeam.png");


  // You can set your team colors here as RGB values.  

setColorPrimary(150, 150, 150);

setColorSecondary(255, 255, 255);

setColorAccent(255, 255, 255);

}

Strategy Method


This method is called every frame.  It is used to help set your team's strategy and build order.  


There are many ways to decide which units to build.  The example team simply tries to keep units at a certain ratio to each other.  You may also consider...


public void strategy()

{

  // In this example our player is ONLY setting a build order
  // However, you may want to determine when to attack or defend here too!


  // Checks what percentage of the fleet are each type
  // This approach scales by unit cost, not absolute numbers.


if(getFleetValuePercentage(Worker.class) < .5f)

{

    buildUnit(new Worker(this));

}

else

{

    buildUnit(new Fighter(this));

}

}

When you run the program, you'll see Fleet values at the bottom. 

Resources are listed twice 

Draw Method


This method is called every frame when it is enabled.  It can be toggled in:

public void draw(Graphics g)

{

  // You can use ANY drawing method you would like in here

  // This is very useful for showing what your units are trying to do

}

UNIT SUPERCLASS

Action Method


This method is called every frame.  During a unit's action, it can:

public void action()

{

    // If you want all your units to perform a default action, add code here
    // Reminder: It won't work unless subclasses call super.action() !

}


Draw Method


This method is called every frame when it is enabled.  It can be toggled in:

public void draw(Graphics g)

{

  // You can use ANY drawing method you would like in here

  // This is very useful for displaying data and decisions

}

Your Starter Code


In the action method we split up our logic into attacking and movement.  Eventually, you'll want to divide this up into even more layers.


public void action()

{

   attack(getWeaponOne());

   attack(getWeaponTwo());

   movement();

}

The attack method will use a weapon as long as the enemy is valid and that weapon slot is actually filled.  Using a weapon that isn't currently available due to cooldown has no effect, so it is safe to try and use it every frame.

public void attack(Weapon w)

{

   Unit enemy = getNearestEnemy();


   if(enemy != null && w != null)

   {

      w.use(enemy); 

   }

}

This movement code is a simple skirmishing method.  Find the nearest enemy, and if it is out of your range approach it.  Otherwise, move in the opposite direction.  What are some advantages and disadvantages of this strategy?  What other ways could we use to retreat?

public void movement()

{

   Unit enemy = getNearestEnemy();


   if(enemy != null)

   {    

      if(getDistance(enemy) > getMaxRange())

      {

         moveTo(enemy);

      }

      else

      {

         turnTo(enemy);

         turnAround();

         move();

      }

   }

}

BASIC FIGHTER

Design


public void design()

{

       // This unit costs 6 credits

          // Medium Frame (2) Weapons (2) + Upgrades (2)

  // For more information, see the units page. 


setFrame(Frame.MEDIUM);

setStyle(Style.DAGGER);

addWeapon(new MachineGun(this));

addWeapon(new SmallLaser(this));

addUpgrade(new Plating(this));

addUpgrade(new Shield(this));

}

Making Additional Combat Units


This is going to be a lot of your work in the project.   Here are a few basic things you can explore:

Overriding Methods


At the start, the fighter behaves the same way as any generic unit on your team.  In the future, you may want to override the action() method.  Or, you might keep action() the same and override specific methods.


For example, the Gods have the following code in action:


public final void action()

{

   core();

   special();

   act();

   movement();

   end();

}


Even the core method just calls other more specific methods:


public final void core()

{

   calculateCanBeAttackedSoon();

   calculateNearestEnemyThreat();

   calculateTargets();

   calculateStrengths();

   spreadMovement();

   continueRetreat();

   continueRally();

   antiMissileSystem();

   barrier();

}


Nearly all of my units follow this structure.  A specialized unit might only override movement(), or maybe even a specific method like spreadMovement().  Your system will likely not need as many layers as mine, but you'll find it can be helpful to structure your code in this way to really take advanage of inheritence and maximize readability.

Basic Worker

Improving Gatherering

Improving Mining


Try watching your miner.  If you look carefully, you'll notice that it isn't always mining!  It bobs in and out of range.  This results in some wasted time.  How can you modify the harvest method to be better?