Skip to content

Instantly share code, notes, and snippets.

@moomoohk
Created August 24, 2014 16:40
Show Gist options
  • Save moomoohk/88fc9f4808022fd3127a to your computer and use it in GitHub Desktop.
Save moomoohk/88fc9f4808022fd3127a to your computer and use it in GitHub Desktop.
library person;
import 'agent.dart';
import "../../../main.dart";
class Person extends Agent {
String firstName, lastName;
int age;
Person(String firstName, String lastName, int age, double resources)
: super(firstName.trim() + " " + lastName.trim(), resources),
this.firstName = firstName.trim(),
this.lastName = lastName.trim(),
this.age = age {
Game.profile.getPeople().add(this);
}
String getFirstName() => this.firstName;
String getLastName() => this.lastName;
String getName() => getFirstName() + (getLastName().length == 0 ? "" : " " + getLastName());
int getAge() => this.age;
String toString() => "name[" + getName() + "] " + super.toString();
static Person getWealthiestPerson() {
if (Game.profile.getPeople().length == 0) return null;
Person maxPerson = Game.profile.getPeople()[0];
Game.profile.getPeople().forEach((Person p) {
if (p != null && maxPerson != null && p.getResources() > maxPerson.getResources()) maxPerson = p;
});
return maxPerson;
}
static Person getPoorestPerson() {
if (Game.profile.getPeople().length == 0) return null;
Person minPerson = Game.profile.getPeople()[0];
Game.profile.getPeople().forEach((Person p) {
if (minPerson != null && p.getResources() < minPerson.getResources()) minPerson = p;
});
return minPerson;
}
}
package com.moomoohk.MarketMaven.Components;
import java.io.Serializable;
import com.moomoohk.MarketMaven.Game;
public class Person extends Agent implements Serializable
{
private static final long serialVersionUID = 1L;
public final int ID;
private String firstName, lastName;
private int age;
public Person(String firstName, String lastName, int age, double resources)
{
super(resources);
this.firstName = firstName.trim();
this.lastName = lastName.trim();
this.age = age;
Game.profile.getPeople().add(this);
this.ID = Game.profile.getPeople().size() - 1;
}
public String getFirstName()
{
return this.firstName;
}
public String getLastName()
{
return this.lastName;
}
public String getFullName()
{
return getFirstName() + (getLastName().length() == 0 ? "" : " " + getLastName());
}
public int getAge()
{
return this.age;
}
public String toString()
{
return "name[" + getFullName() + "] " + super.toString();
}
public static Person getWealthiestPerson()
{
if (Game.profile.getPeople().size() == 0)
return null;
Person maxPerson = Game.profile.getPeople().get(0);
for (Person a : Game.profile.getPeople())
if (a != null && maxPerson != null && a.getResources() > maxPerson.getResources())
maxPerson = a;
return maxPerson;
}
public static Person getPoorestPerson()
{
if (Game.profile.getPeople().size() == 0)
return null;
Person minPerson = Game.profile.getPeople().get(0);
for (Person a : Game.profile.getPeople())
if (minPerson != null && a.getResources() < minPerson.getResources())
minPerson = a;
return minPerson;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment