Skip to content

Commit

Permalink
More Edits
Browse files Browse the repository at this point in the history
Doing The GetPets, and finishing players
  • Loading branch information
lwoollett committed May 2, 2017
1 parent aa81f6e commit 2acb098
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
1 change: 0 additions & 1 deletion nogui/Cat.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nogui;

public class Cat extends Pet{

public Cat(String name) {
super(name);
super.setHungerNeed(3.00);
Expand Down
92 changes: 91 additions & 1 deletion nogui/Game.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,97 @@
package nogui;

import java.util.ArrayList;
import java.util.Scanner;

public class Game {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int pnum = 0;
ArrayList<Player> players = new ArrayList<Player>();
ArrayList<Pet> pets = new ArrayList<Pet>();

private void populatepets(){
pets.add(new Cat("UnNamed"));
pets.add(new Cow("UnNamed"));
pets.add(new Dog("UnNamed"));
pets.add(new Rabbit("UnNamed"));
pets.add(new Rat("UnNamed"));
pets.add(new Velociraptor("UnNamed"));
}

public int getNumber(int ln, int hn){
System.out.println("Please Enter A Number Between " + ln + " and " + hn);
int num = sc.nextInt();
if(num > ln && num < hn){
return num;
}else{
while(num < ln || num > hn){
System.out.println("Number was not between " + ln + " and " + hn);
System.out.println("Please Enter A Number Between " + ln + " and " + hn);
num = sc.nextInt();
}
return num;
}
}

private void getPlayers() {
System.out.println("Game Started");
System.out.println("How Many Players: ");
pnum = getNumber(1, 3);

for(int i=0; i < pnum; i++){
System.out.println("What is player " + (i + 1) + "'s name? ");
String name = sc.next();
boolean dupe = true;
while(dupe){
int samecounter = 0;
for(Player p : players){
if(name.equals(p.getName())){
samecounter += 1;
System.out.println("Name is the same as another players. Please choose another name: ");
name = sc.next();
}
}
if(samecounter == 0){
dupe = false;
}
}
players.add(new Player(name));

}
}

private void getPets(){
for(Player p : players){
ArrayList<Pet> currentpets = new ArrayList<Pet>();

System.out.println("How many pets for " + p.getName() + ": ");
int petnum = getNumber(1,3);
for(int i = 0; i < petnum; i++){
System.out.println("Pet options are:");
int c = 1; //Counter for which pet, relating to which option
for(Pet option : pets){
System.out.println(c + ". " + option.getClass().getSimpleName() + ".");
c++;
}
System.out.println("Please Choose Your Pet With A Number:");
int selected = getNumber(1, 6);
Pet selectedpet = pets.get(selected - 1);
System.out.println("Please Enter A Name For Your Pet: ");
String petname = sc.next();
selectedpet.setPetname(petname);
System.out.println("You now have a pet named " + selectedpet.getPetname());
currentpets.add(selectedpet);
}
p.setPets(currentpets);
}
}

public static void main(String[] args){
Game game = new Game();
game.populatepets();
game.getPlayers();
game.getPets();

}

}
7 changes: 3 additions & 4 deletions nogui/Pet.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public void goToToilet(){
}

public void nextDay(){
hunger -= 20;
tiredness -= 20;
hunger -= 5 * hungerNeed;
tiredness -= 5 * sleepiness;
toiletneed -= 20;

}

/*
Expand All @@ -66,7 +65,7 @@ public void nextDay(){
public String getPetname() {
return petname;
}

public int getHunger() {
return hunger;
}
Expand Down
9 changes: 7 additions & 2 deletions nogui/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public Player(String n){

public void nextDay(){
actions = 2;
for(Pet p: pets){
p.nextDay();
for(Pet pet: pets){
pet.nextDay();
}
}

public String getName(){
return name;
}
Expand All @@ -45,6 +46,10 @@ public ArrayList<Pet> getPets(){
return pets;
}

public void setPets(ArrayList<Pet> p){
pets = p;
}

public ArrayList<Toy> getToys(){
return toys;
}
Expand Down

0 comments on commit 2acb098

Please sign in to comment.