Rev 583 |
Rev 615 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.PonPonChun.game;
import com.gebauz.Bauzoid.math.RandomChooser;
import com.gebauz.PonPonChun.game.entities.Block;
import com.gebauz.PonPonChun.game.entities.PlayField;
public abstract class GameModeLogic
extends GameLogicObject
{
// Constants========================================================================================
// Embedded Types===================================================================================
// Members==========================================================================================
private GameLogic.
GameMode mGameMode
;
protected RandomChooser mBlockRandomizer =
new RandomChooser
();
// Methods==========================================================================================
public GameModeLogic
(GameLogic gameLogic, GameLogic.
GameMode mode
)
{
super(gameLogic
);
mGameMode = mode
;
}
public abstract void init
(String param
);
public abstract void exit
();
public abstract void update
(float deltaTime
);
public abstract void render
();
/** Generate a row that does not have triplets. */
public int[] generateRow
(int[] lastRow,
int[] prevLastRow
)
{
int[] lastTypes =
new int[] { -
1, -
1 };
int[] row =
new int[PlayField.
NUM_CELLS_X];
for (int dx =
0; dx
< PlayField.
NUM_CELLS_X; dx++
)
{
// prevent triplets along the row and along the upper rows
int type = mBlockRandomizer.
chooseEntry();
int compare1 =
(lastRow ==
null) ? -
1 : lastRow
[dx
];
int compare2 =
(prevLastRow ==
null) ? -
1 : prevLastRow
[dx
];
//while (((type == lastTypes[0]) && (type == lastTypes[1])) ||
// ((type == compare1) && (type == compare2)))
while (isTriplet
(type, lastTypes
[0], lastTypes
[1]) ||
isTriplet
(type, compare1, compare2
))
{
//type = getGameLogic().getGame().getRandomInt(0, Block.NUM_TYPES-1);
type = mBlockRandomizer.
chooseEntry();
}
if ((type == compare1
) && (type == compare2
))
System.
out.
println("CANT BE");
lastTypes
[1] = lastTypes
[0];
lastTypes
[0] = type
;
row
[dx
] = type
;
}
return row
;
}
public boolean isTriplet
(int a,
int b,
int c
)
{
if ((a == b
) && (a == c
))
return true;
if (((a == Block.
TYPE_BOMB) && (b == c
)) ||
((b == Block.
TYPE_BOMB) && (a == c
)) ||
((c == Block.
TYPE_BOMB) && (a == b
)))
return true;
if (((a == Block.
TYPE_BOMB) && (b == Block.
TYPE_BOMB)) ||
((a == Block.
TYPE_BOMB) && (c == Block.
TYPE_BOMB)) ||
((b == Block.
TYPE_BOMB) && (c == Block.
TYPE_BOMB)))
return true;
return false;
}
// Getters/Setters==================================================================================
public final GameLogic.
GameMode getGameMode
()
{
return mGameMode
;
}
}