|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
[TASK 8.2.3] Pair Programming: Fek vs Jappilas (The Yooung Padawan)
Questo e' il task:
8.2.3: Modificare bagofgem in modo che il punteggio delle gemme che fanno parte di un gruppo sia moltiplicato per un Bonus. Il valore del bonus deve essere modificabile da GameConfig.xml Prima la lista di test: - Aggiunta di una gem con bonus - Rimozione di una gem con bonus - Calcolo del punteggio totale, passando il bonus attraverso il costruttore
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ed ecco il primo test:
Codice:
package it.diamonds.tests;
import it.diamonds.gems.BagOfGems;
import it.diamonds.gems.Gem;
import junit.framework.TestCase;
public class TestBagOfGems extends TestCase
{
public void testAddGemWithBonus()
{
BagOfGems bag = new BagOfGems();
bag.addGemWithBonus(Gem.diamond(0));
assertAreEqual(1, bag.getNumberOfGemsWithBonus());
}
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
aggiunti due metodi in BagOfGems.java:
Codice:
public void addGemWithBonus(Gem gem)
{
// TODO Auto-generated method stub
}
public int getNumberOfGemsWithBonus()
{
return 1;
}
green bar
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
Ultima modifica di jappilas : 12-01-2006 alle 15:23. |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ci aggiorniamo a domani sera.
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
spero di aver ammansito la formica errante per allora...
( per chi si stesse chiedendo di che parlo, Ant che fa un po' i capricci per come è configurato il mio environment... )
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
Update: la Formica (
i prossimi test e relativi fix nel flusso di sviluppo TDD, arriveranno presto
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
|
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ecco il prossimo test:
Codice:
public void testAddTwoGemsWithBonus()
{
BagOfGems bag = new BagOfGems();
bag.addGemWithBonus(Gem.diamond(0));
bag.addGemWithBonus(Gem.diamond(0));
assertEquals(2, bag.getNumberOfGemsWithBonus());
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
dichiarata
Codice:
private int gemsWithBonus; Codice:
public void addGemWithBonus(Gem gem)
{
gemsWithBonus ++ ;
}
public int getNumberOfGemsWithBonus()
{
int tempValue = gemsWithBonus;
gemsWithBonus =0;
return tempValue;
}
green bar
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
|
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Per prima cosa: Keep It Simple Sweety.
Questo codice fa passare tutti i test: Codice:
public int getNumberOfGemsWithBonus()
{
return gemsWithBonus;
}
Codice:
public class TestBagOfGems extends TestCase
{
BagOfGems bag;
public void setUp()
{
bag = new BagOfGems();
}
public void testAddGemWithBonus()
{
bag.addGemWithBonus(createDiamond());
assertEquals(1, bag.getNumberOfGemsWithBonus());
}
public void testAddTwoGemsWithBonus()
{
bag.addGemWithBonus(createDiamond());
bag.addGemWithBonus(createDiamond());
assertEquals(2, bag.getNumberOfGemsWithBonus());
}
public void testAddTwoDifferentGemsWithBonus()
{
bag.addGemWithBonus(createDiamond());
bag.addGemWithBonus(createRuby());
assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.DIAMOND));
assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.RUBY));
}
private Gem createRuby()
{
return Gem.create(GemType.RUBY, 0);
}
private Gem createDiamond()
{
return Gem.diamond(0);
}
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#10 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
la prima versione del test aggiunto è soddisfatta da codice molto minimale
( ammetto di essermela cavata con poco )Codice:
public Object getNumberOfGemsWithBonus(GemType gem)
{
return 1;
}
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
Ultima modifica di jappilas : 14-01-2006 alle 15:39. |
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ottimo
Codice:
public void testAddManyDifferentGemsWithBonus()
{
bag.addGemWithBonus(createDiamond());
bag.addGemWithBonus(createDiamond());
bag.addGemWithBonus(createRuby());
bag.addGemWithBonus(createRuby());
bag.addGemWithBonus(createSapphire());
assertEquals(2, bag.getNumberOfGemsWithBonus(GemType.DIAMOND));
assertEquals(2, bag.getNumberOfGemsWithBonus(GemType.RUBY));
assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.SAPPHIRE));
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#12 | |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
Quote:
aggiunta una seconda hashmap e relativa inizializzazione nel costruttore Codice:
private HashMap<GemType, Integer> numberOfGemsWithBonus; Codice:
numberOfGemsWithBonus = new HashMap<GemType, Integer>();
numberOfGemsWithBonus.put(EMERALD, 0);
numberOfGemsWithBonus.put(RUBY, 0);
numberOfGemsWithBonus.put(SAPPHIRE, 0);
numberOfGemsWithBonus.put(TOPAZ, 0);
numberOfGemsWithBonus.put(DIAMOND, 0);
Codice:
public void addGemWithBonus(Gem gem)
{
++gemsWithBonus;
numberOfGemsWithBonus.put(gem.getType(),
numberOfGemsWithBonus.get(gem.getType()) + 1);
}
Codice:
public Object getNumberOfGemsWithBonus(GemType gem)
{
return numberOfGemsWithBonus.get(gem);
}
con queste modifiche, all green
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
Ultima modifica di jappilas : 17-01-2006 alle 10:17. |
|
|
|
|
|
|
#13 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ed ecco il prossimo test, per la rimozione delle gemme.
Codice:
public void testRemoveGemWithBonus()
{
Gem ruby = createRuby();
bag.addGemWithBonus(createDiamond());
bag.addGemWithBonus(ruby);
bag.removeGem(ruby);
assertEquals(1, bag.getNumberOfGemsWithBonus(GemType.DIAMOND));
assertEquals(0, bag.getNumberOfGemsWithBonus(GemType.RUBY));
assertEquals(1, bag.getNumberOfGemsWithBonus());
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#14 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
aggiunto metodo removeGemWithBonus alla classe BagOfGems:
Codice:
public void removeGemWithBonus(Gem gem)
{
--gemsWithBonus;
numberOfGemsWithBonus.put(gem.getType(), numberOfGemsWithBonus.get(gem.getType()) - 1);
}
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
|
|
|
|
|
|
#15 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ed ecco l'ultimo test:
Codice:
public void setUp()
{
bag = new BagOfGems(BONUS_PERCENTAGE);
}
public void testScoreWithBonus()
{
bag.addGemWithBonus(createDiamond());
bag.addGemWithBonus(createRuby());
bag.addGem(createDiamond());
assertEquals(
GemType.DIAMOND.score() +
GemType.RUBY.score() * BONUS_PERCENTAGE / 100 +
GemType.DIAMOND.score() * BONUS_PERCENTAGE / 100,
bag.computeTotalScore());
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#16 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
modificata la computeTotalScore
Codice:
public int computeTotalScore()
{
int totalScore = 0;
for(GemType gemType : numberOfGems.keySet())
{
totalScore += computeScore(gemType);
}
for(GemType gemType : numberOfGemsWithBonus.keySet())
{
totalScore += computeScoreWithBonus(gemType);
}
return totalScore;
}
Codice:
private int computeScoreWithBonus(GemType gemType)
{
return numberOfGemsWithBonus.get(gemType) * gemType.score()
* gemScorePercentageBonus / 100;
}
Codice:
public BagOfGems()
{
mainBagConstructor();
gemScorePercentageBonus = 100;
}
public BagOfGems(int bonusPercent)
{
mainBagConstructor();
gemScorePercentageBonus = bonusPercent;
}
private void mainBagConstructor()
{
numberOfGems = new HashMap<GemType, Integer>();
numberOfGems.put(EMERALD, 0);
numberOfGems.put(RUBY, 0);
numberOfGems.put(SAPPHIRE, 0);
numberOfGems.put(TOPAZ, 0);
numberOfGems.put(DIAMOND, 0);
numberOfGemsWithBonus = new HashMap<GemType, Integer>();
numberOfGemsWithBonus.put(EMERALD, 0);
numberOfGemsWithBonus.put(RUBY, 0);
numberOfGemsWithBonus.put(SAPPHIRE, 0);
numberOfGemsWithBonus.put(TOPAZ, 0);
numberOfGemsWithBonus.put(DIAMOND, 0);
gemsWithBonus = 0;
};
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
|
|
|
|
|
|
#17 |
|
Senior Member
Iscritto dal: Oct 2002
Città: San Jose, California
Messaggi: 11794
|
Ed ecco il codice di BagOfGems dopo un po' di refactoring:
Codice:
package it.diamonds.gems;
import java.util.HashMap;
import static it.diamonds.gems.GemType.*;
public class BagOfGems
{
private HashMap<GemType, Integer> numberOfGems;
private HashMap<GemType, Integer> numberOfGemsWithBonus;
final private int bonusPercentage;
public BagOfGems(int bonusPercentage)
{
this.bonusPercentage = bonusPercentage;
numberOfGems = new HashMap<GemType, Integer>();
numberOfGems.put(EMERALD, 0);
numberOfGems.put(RUBY, 0);
numberOfGems.put(SAPPHIRE, 0);
numberOfGems.put(TOPAZ, 0);
numberOfGems.put(DIAMOND, 0);
numberOfGemsWithBonus = new HashMap<GemType, Integer>();
numberOfGemsWithBonus.put(EMERALD, 0);
numberOfGemsWithBonus.put(RUBY, 0);
numberOfGemsWithBonus.put(SAPPHIRE, 0);
numberOfGemsWithBonus.put(TOPAZ, 0);
numberOfGemsWithBonus.put(DIAMOND, 0);
};
private int computeScore(GemType gemType)
{
return numberOfGems.get(gemType) * gemType.score();
}
private int computeScoreWithBonus(GemType gemType)
{
return numberOfGemsWithBonus.get(gemType) * gemType.score() * bonusPercentage / 100;
}
public int computeTotalScore()
{
int totalScore = 0;
for(GemType gemType : numberOfGems.keySet())
{
totalScore += computeScore(gemType);
}
for(GemType gemType : numberOfGemsWithBonus.keySet())
{
totalScore += computeScoreWithBonus(gemType);
}
return totalScore;
}
public int getNumberOfGemsWithoutBonus()
{
int totalNumber = 0;
for(int value : numberOfGems.values())
{
totalNumber += value;
}
return totalNumber;
}
public int getNumberOfGemsWithBonus()
{
int totalNumber = 0;
for(int value : numberOfGemsWithBonus.values())
{
totalNumber += value;
}
return totalNumber;
}
public void addGem(Gem gem)
{
numberOfGems.put(gem.getType(), numberOfGems.get(gem.getType()) + 1);
}
public void removeGem(Gem gem)
{
numberOfGems.put(gem.getType(), numberOfGems.get(gem.getType()) - 1);
}
public void addGemWithBonus(Gem gem)
{
numberOfGemsWithBonus.put(gem.getType(), numberOfGemsWithBonus.get(gem.getType()) + 1);
}
public int getNumberOfGemsWithBonus(GemType gem)
{
return numberOfGemsWithBonus.get(gem);
}
public void removeGemWithBonus(Gem gem)
{
numberOfGemsWithBonus.put(gem.getType(), numberOfGemsWithBonus.get(gem.getType()) - 1);
}
}
__________________
"We in the game industry are lucky enough to be able to create our visions" @ NVIDIA |
|
|
|
|
|
#18 |
|
Senior Member
Iscritto dal: Apr 2003
Città: Genova
Messaggi: 4747
|
aggiunta una riga
Codice:
bagOfGems = new BagOfGems(config.getInteger("BonusPercentage"));
aggiunta la property BonusPercentage in GameConfig.xml; task da considerare concluso ?
__________________
Jappilas is a character created by a friend for his own comic - I feel honored he allowed me to bear his name Saber's true name belongs to myth - a Heroic Soul out of legends, fighting in our time to fullfill her only wish Let her image remind of her story, and of the emotions that flew from my heart when i assisted to her Fate
Ultima modifica di jappilas : 15-01-2006 alle 19:30. |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:05.











)








