Wednesday, May 13, 2009

Coding the IPL for E71

STATUTORY WARNING: The write-up below insists that you be blessed with Java know-how.

I decided to code a little cricket game for my E71, a la IPL. To begin with, I thought I'll start with designing my player classes. I've come up with the following classes:

public abstract class Player {

private Team team;
private String firstName;
private String lastName;
private boolean isRightHanded;
private String fieldingPosition;

// all players bat
public void bat() {
// ... implementation ...
}

// all players field
public void field() {
if(fieldingPosition.equals(FieldingPosition.WICKETKEEPER)
keepWickets();
else
field(fieldingPosition);
}
}

public interface Bowler {
// Given that each player bowls differently, action, guide, etc.
public void bowl();
}


All this is fine, until I decided we can add a few new characteristics. In which case, some players will need their own classes. Par example:

public class TurbanedMumbaiIndianOffSpinner extends Player implements Bowler {

public void slapPlayer(Player p) {
// ... implementation ...
p.isSlapped(this);
}

}

public class AppamLikeBowlers implements Bowler {

private boolean radarOn;

public AppamLikeBowlers {
radarOn = false;
}

public void cry() {
// ... implementation ...
}

public void isSlapped(Player slappingPlayer) {
cry();
}

}


Making some progress, I guess.

No comments:

Post a Comment