設計結構四大金剛
[初始化]、[計算]、[繪圖]、[終結]
package tw.edu.pccu.MyGame003;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
public class MyGameMain
{
private MyData m_Data = null;
private MyIcon m_icon = null;
private MyCrab m_crab = null;
private boolean m_bIsEnable = false; //是否計算, 給 f_Update 用的
private boolean m_bIsVisible = false; //是否顯示, 給 f_Render 用的
//建構式
public MyGameMain()
{
m_Data = new MyData();
m_icon = new MyIcon();
m_crab = new MyCrab();
}
//初始化
public boolean f_Initial( Resources e_res, int e_nScreenWidth, int e_nScreenHeight )
{
boolean l_bResult = false;
//
m_Data.m_nScreenWidth = e_nScreenWidth;
m_Data.m_nScreenHeight = e_nScreenHeight;
m_Data.m_fLimitLeft = 10.0f;
m_Data.m_fLimitRight = m_Data.m_nScreenWidth - 10.0f;
m_Data.m_fLimitTop = 10.0f;
m_Data.m_fLimitBottom = m_Data.m_nScreenHeight - 80.0f;
//
l_bResult = m_icon.f_Initial( e_res, m_Data );
l_bResult = m_crab.f_Initial(e_res, m_Data );
//
m_bIsEnable = true;
m_bIsVisible = true;
return true;
}
//計算
public void f_Update( float e_fdt )
{
if( m_bIsEnable==false )
return; //不用計算
//
m_icon.f_Update(e_fdt);
m_crab.f_Update(e_fdt);
}
//繪圖
public void f_Render( Canvas e_canvas )
{
//清圖
e_canvas.drawColor(Color.YELLOW);
//
if( m_bIsVisible==false )
return; //不用繪圖
//
m_icon.f_Render(e_canvas);
m_crab.f_Render(e_canvas);
}
//終結
public void f_Destroy()
{
m_icon.f_Destroy();
m_crab.f_Destroy();
}
}
留言列表