Skip to content

Commit

Permalink
renaming levels classes to beginner, intermediate, zombie and pro
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hermida committed Apr 6, 2011
1 parent bab5f5c commit 871f2b0
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import org.eclipse.swt.graphics.Image;

public class FirstLevel implements Level {
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class Beginner implements Level {

private final MoodManager moodManager;

public FirstLevel() {
public Beginner() {
this(new TinyMoodManager());
}

public FirstLevel(MoodManager moodManager) {
public Beginner(MoodManager moodManager) {
this.moodManager = moodManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import org.eclipse.swt.graphics.Image;

public class SecondLevel implements Level {
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class Intermediate implements Level {

private final MoodManager moodManager;

public SecondLevel() {
public Intermediate() {
this(new TinyMoodManager());
}

public SecondLevel(MoodManager moodManager) {
public Intermediate(MoodManager moodManager) {
this.moodManager = moodManager;
}

Expand Down
23 changes: 0 additions & 23 deletions src/com/happyprog/tdgotchi/level/Levels.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import org.eclipse.swt.graphics.Image;

public class ThirdLevel implements Level {
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class Pro implements Level {

private final MoodManager moodManager;

public ThirdLevel() {
public Pro() {
this(new TinyMoodManager());
}

public ThirdLevel(MoodManager moodManager) {
public Pro(MoodManager moodManager) {
this.moodManager = moodManager;
}

Expand Down
63 changes: 0 additions & 63 deletions src/com/happyprog/tdgotchi/level/TamagotchiLevels.java

This file was deleted.

65 changes: 65 additions & 0 deletions src/com/happyprog/tdgotchi/level/TinyLevelManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.happyprog.tdgotchi.level;

import org.eclipse.swt.graphics.Image;

import com.happyprog.tdgotchi.scoreboard.LevelManager;

public class TinyLevelManager implements LevelManager {

private final Level beginner;
private final Level zombie;
private final Level intermediate;
private final Level pro;

public TinyLevelManager() {
this(new Beginner(), new Intermediate(), new Pro(), new Zombie());
}

public TinyLevelManager(Level beginner, Level intermediate, Level pro, Level zombie) {
this.beginner = beginner;
this.intermediate = intermediate;
this.pro = pro;
this.zombie = zombie;
}

@Override
public Level getBeginner() {
return beginner;
}

@Override
public Level getZombie() {
return zombie;
}

@Override
public Image getBeginnerHealth() {
return beginner.getHealth();
}

@Override
public Image getZombieHealth() {
return zombie.getHealth();
}

@Override
public Level getIntermediate() {
return intermediate;
}

@Override
public Image getIntermediateHealth() {
return intermediate.getHealth();
}

@Override
public Level getPro() {
return pro;
}

@Override
public Image getProHealth() {
return pro.getHealth();
}

}
1 change: 1 addition & 0 deletions src/com/happyprog/tdgotchi/level/TinyMoodManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.eclipse.swt.graphics.Image;

import com.happyprog.tdgotchi.Activator;
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class TinyMoodManager implements MoodManager {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import org.eclipse.swt.graphics.Image;

import com.happyprog.tdgotchi.Activator;
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class ZombieLevel implements Level {
public class Zombie implements Level {

private final MoodManager moodManager;

public ZombieLevel() {
public Zombie() {
this(new TinyMoodManager());
}

public ZombieLevel(MoodManager moodManager) {
public Zombie(MoodManager moodManager) {
this.moodManager = moodManager;
}

Expand Down
25 changes: 25 additions & 0 deletions src/com/happyprog/tdgotchi/scoreboard/LevelManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.happyprog.tdgotchi.scoreboard;

import org.eclipse.swt.graphics.Image;

import com.happyprog.tdgotchi.level.Level;

public interface LevelManager {

Level getBeginner();

Level getZombie();

Level getIntermediate();

Level getPro();

Image getBeginnerHealth();

Image getZombieHealth();

Image getIntermediateHealth();

Image getProHealth();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.happyprog.tdgotchi.level;
package com.happyprog.tdgotchi.scoreboard;

import org.eclipse.swt.graphics.Image;

Expand Down
29 changes: 14 additions & 15 deletions src/com/happyprog/tdgotchi/scoreboard/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import org.eclipse.swt.graphics.Image;

import com.happyprog.tdgotchi.level.Levels;
import com.happyprog.tdgotchi.level.TamagotchiLevels;
import com.happyprog.tdgotchi.level.TinyLevelManager;
import com.happyprog.tdgotchi.subscriber.JUnitTestSubscriber;
import com.happyprog.tdgotchi.subscriber.TestSubscriber;
import com.happyprog.tdgotchi.views.Tamagotchi;
Expand All @@ -18,17 +17,17 @@ public class Scoreboard implements TestObserver, TamagotchiObserver {

private TestRun previousTestRun;
private int score;
private final Levels levels;
private final LevelManager levels;

private enum TestRun {
PASS, FAIL
}

public Scoreboard(View view) {
this(view, new TinyTamagotchi(), new JUnitTestSubscriber(), new TamagotchiLevels());
this(view, new TinyTamagotchi(), new JUnitTestSubscriber(), new TinyLevelManager());
}

public Scoreboard(View view, Tamagotchi tamagotchi, TestSubscriber subscriber, Levels levels) {
public Scoreboard(View view, Tamagotchi tamagotchi, TestSubscriber subscriber, LevelManager levels) {
this.view = view;
this.tamagotchi = tamagotchi;
this.subscriber = subscriber;
Expand Down Expand Up @@ -70,29 +69,29 @@ private void updateScoreWith(int points) {

private void updateTamagoshiAndHealthLevel() {
if (score < 0) {
tamagotchi.setLevel(levels.getZombieLevel());
view.updateHealth(levels.getZombieLevelHealth());
tamagotchi.setLevel(levels.getZombie());
view.updateHealth(levels.getZombieHealth());
return;
}

if (score >= 0 && score <= 10) {
tamagotchi.setLevel(levels.getFirstLevel());
view.updateHealth(levels.getFirstLevelHealth());
tamagotchi.setLevel(levels.getBeginner());
view.updateHealth(levels.getBeginnerHealth());
return;
}

if (score > 10 && score <= 20) {
tamagotchi.setLevel(levels.getSecondLevel());
view.updateHealth(levels.getSecondLevelHealth());
tamagotchi.setLevel(levels.getIntermediate());
view.updateHealth(levels.getIntermediateHealth());
return;
}

tamagotchi.setLevel(levels.getThirdLevel());
view.updateHealth(levels.getThirdLevelHealth());
tamagotchi.setLevel(levels.getPro());
view.updateHealth(levels.getProHealth());
}

private void startTamagotchi(Tamagotchi tamagotchi) {
tamagotchi.setLevel(levels.getFirstLevel());
tamagotchi.setLevel(levels.getBeginner());
tamagotchi.addObserver(this);
tamagotchi.start();
}
Expand All @@ -106,6 +105,6 @@ public void onImageSetCallback() {
}

public Image getDefaultHealth() {
return levels.getFirstLevelHealth();
return levels.getBeginnerHealth();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
import org.junit.Before;
import org.junit.Test;

public class FirstLevelTest {
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class BeginnerTest {

private MoodManager moodManager;
private FirstLevel level;
private Beginner level;

@Before
public void before() {
moodManager = mock(MoodManager.class);
level = new FirstLevel(moodManager);
level = new Beginner(moodManager);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import org.junit.Before;
import org.junit.Test;

public class SecondLevelTest {
import com.happyprog.tdgotchi.scoreboard.MoodManager;

public class IntermediateTest {
private MoodManager moodManager;
private SecondLevel level;
private Intermediate level;

@Before
public void before() {
moodManager = mock(MoodManager.class);
level = new SecondLevel(moodManager);
level = new Intermediate(moodManager);
}

@Test
Expand Down
Loading

0 comments on commit 871f2b0

Please sign in to comment.