intergration of switchable abstract classes
This commit is contained in:
@@ -13,7 +13,8 @@ public class CanvasView extends View
|
||||
Resources r;
|
||||
|
||||
GameStateInterface Foreground = null;
|
||||
GameStateInterface Background = null;
|
||||
GameStateInterface Gamemenu = null;
|
||||
GameStateInterface Gameplay = null;
|
||||
|
||||
// Score.
|
||||
public int startLevel = 0;
|
||||
@@ -27,52 +28,79 @@ public class CanvasView extends View
|
||||
|
||||
super.setBackgroundColor(Color.BLACK);
|
||||
|
||||
Foreground = new GamePlay();
|
||||
Foreground.Instance = Foreground;
|
||||
Gameplay = new GamePlay();
|
||||
//Gameplay.Instance = Gameplay;
|
||||
|
||||
Gamemenu = new GameMenu();
|
||||
//Gamemenu.Instance = Gamemenu;
|
||||
}
|
||||
|
||||
public void SetActivity(Activity activity)
|
||||
{
|
||||
((GamePlay)Foreground.Instance).Instance.SetActivity(activity);
|
||||
((GamePlay)Foreground.Instance).SetCanvas(this);
|
||||
((GamePlay)Foreground.Instance).SetStartLevel(startLevel);
|
||||
((GamePlay)Foreground.Instance).SetPayedVersion(PayedVersion);
|
||||
Gamemenu.SetActivity(activity);
|
||||
Gamemenu.SetCanvas(this);
|
||||
Gamemenu.SetPayedVersion(PayedVersion);
|
||||
|
||||
((GamePlay)Foreground.Instance).SetGameState(GamePlay.GS_LOAD);
|
||||
Gameplay.SetActivity(activity);
|
||||
Gameplay.SetCanvas(this);
|
||||
Gameplay.SetPayedVersion(PayedVersion);
|
||||
|
||||
Foreground = Gamemenu;
|
||||
|
||||
// Game Start. First Load
|
||||
((GamePlay)Gameplay).SetStartLevel(startLevel);
|
||||
((GamePlay)Gameplay).SetGameState(GamePlay.GS_LOAD);
|
||||
|
||||
// Start Game.
|
||||
if (((GamePlay)Foreground.Instance).GetGameState() == GamePlay.GS_READY)
|
||||
((GamePlay)Foreground.Instance).SetGameState(GamePlay.GS_START);
|
||||
if (((GamePlay)Gameplay).GetGameState() == GameStateInterface.GS_READY)
|
||||
((GamePlay)Gameplay).SetGameState(GameStateInterface.GS_START);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
{
|
||||
Foreground.Instance.DrawFrame(canvas);
|
||||
Foreground.DrawFrame(canvas);
|
||||
}
|
||||
|
||||
public void onPause()
|
||||
{
|
||||
Foreground.Instance.onPause();
|
||||
Foreground.onPause();
|
||||
}
|
||||
|
||||
public void sendMove(float x, float y, boolean pointerUp)
|
||||
{
|
||||
Foreground.Instance.SendMove(x, y, pointerUp);
|
||||
Foreground.SendMove(x, y, pointerUp);
|
||||
}
|
||||
|
||||
public void OnGameStateChanged(int gameState)
|
||||
{
|
||||
gameStateChanged(gameState);
|
||||
}
|
||||
|
||||
public void OnGameStateChanged(int gameState, boolean isPostBack)
|
||||
{
|
||||
if (isPostBack == false)
|
||||
gameStateChanged(gameState);
|
||||
}
|
||||
|
||||
private void gameStateChanged(int gameState)
|
||||
{
|
||||
switch(gameState)
|
||||
{
|
||||
case GameStateInterface.GS_READY:
|
||||
{
|
||||
Foreground = Gameplay;
|
||||
break;
|
||||
}
|
||||
case GameStateInterface.GS_PAUSED:
|
||||
{
|
||||
|
||||
//Gamemenu.SetGameState(Foreground.GetGameState(), true);
|
||||
Foreground = Gamemenu;
|
||||
break;
|
||||
}
|
||||
case GameStateInterface.GS_GAMEOVER:
|
||||
{
|
||||
|
||||
Foreground = Gamemenu;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,19 @@ public class GameMenu extends GameStateInterface
|
||||
canvasView.OnGameStateChanged(GameState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetGameState(int gameState, boolean isPostBack)
|
||||
{
|
||||
GameState = gameState;
|
||||
|
||||
switch(GameState)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
canvasView.OnGameStateChanged(GameState, isPostBack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@@ -91,6 +91,28 @@ public class GamePlay extends GameStateInterface
|
||||
canvasView.OnGameStateChanged(GameState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void SetGameState(int gameState, boolean isPostBack)
|
||||
{
|
||||
GameState = gameState;
|
||||
|
||||
switch(GameState)
|
||||
{
|
||||
case GS_LOAD:
|
||||
{
|
||||
Load();
|
||||
break;
|
||||
}
|
||||
case GS_START:
|
||||
{
|
||||
StartGame();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
canvasView.OnGameStateChanged(GameState, isPostBack);
|
||||
}
|
||||
|
||||
// Set
|
||||
@Override
|
||||
public void SetCanvas(CanvasView _CanvasView)
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.graphics.Canvas;
|
||||
|
||||
public abstract class GameStateInterface
|
||||
{
|
||||
public GameStateInterface Instance;
|
||||
//public GameStateInterface Instance;
|
||||
|
||||
// GameState Parameters
|
||||
final static int GS_STOPPED = 0;
|
||||
@@ -24,6 +24,8 @@ public abstract class GameStateInterface
|
||||
|
||||
public abstract void SetGameState(int gameState);
|
||||
|
||||
public abstract void SetGameState(int gameState, boolean isPostBack);
|
||||
|
||||
public abstract void onPause();
|
||||
|
||||
// SetParameters.
|
||||
|
||||
Reference in New Issue
Block a user