안드로이드안에 자바소스 질문이요..ㅠㅠ
아리알찬
package exam.Android_G;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.view.SurfaceHolder.Callback;
public class GameRun extends SurfaceView implements Callback {
private GameThread m_GameThread;
private CMopMgrm_cMopMgr= new CMopMgr();
private CTowerMgrm_cTowerMgr= new CTowerMgr();
class CMop{
public intm_nX;
public intm_nY;
public longm_lBeforTime;
public longm_nSleep;
public intm_nSpeed;
public intm_nMoveArea;
public intm_nMopHealth;
public boolean m_bUsed;
public boolean m_bDie;
public intm_nDirection;
public intm_aMovePos[][] =
{
{ 93, 0, 2},
{ 93, 11, 3},
{ 23, 11, 2},
{ 23, 135, 1},
{ 94, 135, 4},
{ 94, 87, 1},
{206, 87, 2},
{206, 207, 3},
{ 24, 207, 2},
{ 24, 275, 1},
{282, 275, 4},
{282, 11, 3},
{175, 11, 4},
{175, 0, 0}
};
CMop(){
m_nX= 93;
m_nY= 0;
m_lBeforTime= System.currentTimeMillis();
m_nSleep= 10;
m_nSpeed= 2;
m_nMoveArea= 1;
m_bUsed= false;
m_nMopHealth= 100;
m_bDie= false;
m_nDirection= -1;
}
public void MovePosition(){
if( (System.currentTimeMillis() - m_lBeforTime) m_nSleep ){
m_lBeforTime = System.currentTimeMillis();
}
else{
return;
}
int nDir = m_aMovePos[m_nMoveArea-1][2];
if(m_nDirection != nDir){
m_nDirection = nDir;
}if(m_nMoveArea 13){
m_nDirection = -1;
m_nX = 93;
m_nY = 0;
m_cMopMgr.m_nOverCount += 1;
m_nMoveArea = 1;
return;
}if(nDir == 1){
m_nX += m_nSpeed;
if(m_aMovePos[m_nMoveArea][0] m_nX) m_nMoveArea++;
}
else if(nDir == 2){
m_nY += m_nSpeed;
if(m_aMovePos[m_nMoveArea][1] m_nY) m_nMoveArea++;
}
else if(nDir == 3){
m_nX -= m_nSpeed;
if(m_aMovePos[m_nMoveArea][0] m_nX) m_nMoveArea++;
}
else if(nDir == 4){
m_nY -= m_nSpeed;
if(m_aMovePos[m_nMoveArea][1] m_nY) m_nMoveArea++;
}
}
}
class CMopMgr{
public static final intm_nMopCnt= 20;
public CMopmop[]= new CMop[m_nMopCnt];
public intm_nUsedMopCnt= 0;
public intm_nDieMopCnt= 0;
public longm_lRegen= 1000;
public intm_nOverCount= 0;
public longm_lBeforRegen= System.currentTimeMillis();
CMopMgr(){
for(int n = 0 ; n m_nMopCnt ; n++){
mop[n] = new CMop();
}
}public void AddMop(){
if( (System.currentTimeMillis() - m_lBeforRegen) m_lRegen){
m_lBeforRegen = System.currentTimeMillis();
}
else return;
if(m_nUsedMopCnt = (m_nMopCnt-1))return;
mop[m_nUsedMopCnt].m_bUsed = true;
m_nUsedMopCnt ++;
}public void MoveMop(){
for(int n = 0 ; n m_nMopCnt ; n++){
if(mop[n].m_bUsed == true){
mop[n].MovePosition();
}
}
}
public int FindMop(int nTowerIndex){
for(int n = 0 ; n m_nMopCnt ; n++){if(mop[n].m_bUsed == false){
continue;
}
if(mop[n].m_bDie == true){
continue;
}
int nX = m_cTowerMgr.tower[nTowerIndex].m_nX - mop[n].m_nX;
int nY = m_cTowerMgr.tower[nTowerIndex].m_nY - mop[n].m_nY;
int nDistance = nX * nX + nY * nY;
if(nDistance 3000) return n;
}
return -1;
}
}class CTower{
public int m_nX= 0;
public int m_nY= 0;
public intm_nMopIndex;
public longm_lAttackTime= 0;
public longm_lAttackSleep= 1500;
public boolean m_bUsed= false;
pupublic booleanm_bUsedMissale= false;
public intm_nMissalePos= 0;
public longm_lMissaleSleep= 8;
public longm_lMissaleTime= 0;
public intm_nMissaleX= 0;
public intm_nMissaleY= 0;
void AttackMop(int nMopIndex){
if(m_bUsed == false) return;if( (System.currentTimeMillis() - m_lAttackTime) m_lAttackSleep){
m_lAttackTime = System.currentTimeMillis();
}
else return;if(m_bUsedMissale == true) return;m_bUsedMissale = true;
m_nMopIndex = nMopIndex;
}
void MoveMissale(){
if(m_bUsed == false) return;if(m_bUsedMissale == false) return;if( (System.currentTimeMillis() - m_lMissaleTime) m_lMissaleSleep ){
m_lMissaleTime = System.currentTimeMillis();
}
else return;if(m_nMissalePos 6){m_nMissalePos= 0;
m_bUsedMissale= false;if(m_cMopMgr.mop[m_nMopIndex].m_nMopHealth 0){
return;
}
m_cMopMgr.mop[m_nMopIndex].m_nMopHealth -= 30;
if(m_cMopMgr.mop[m_nMopIndex].m_nMopHealth = 0){
m_cMopMgr.mop[m_nMopIndex].m_bUsed = false;
m_cMopMgr.m_nDieMopCnt+= 1;
}
return;
}
int nMopX= m_cMopMgr.mop[m_nMopIndex].m_nX;
int nMopY= m_cMopMgr.mop[m_nMopIndex].m_nY;int nWidth= m_nX - nMopX;
int nHeight= m_nY - nMopY;m_nMissaleX= m_nX - (nWidth / (8 - m_nMissalePos) );
m_nMissaleY = m_nY - (nHeight / (8 - m_nMissalePos) );
m_nMissalePos++;
}
}
class CTowerMgr{
public static final int m_nTowerCnt= 10;
public CTowertower[]= new CTower[m_nTowerCnt];
public intm_nUsedTowerCnt= 0;
CTowerMgr(){
for(int n = 0 ; n m_nTowerCnt ; n++){
tower[n] = new CTower();
}
}public void AddTower(int x, int y){
if(m_nUsedTowerCnt = m_nTowerCnt)return;
tower[m_nUsedTowerCnt].m_bUsed = true;
tower[m_nUsedTowerCnt].m_nX = x;
tower[m_nUsedTowerCnt].m_nY = y;
m_nUsedTowerCnt ++;
}
public int GetTowerCount(){
return m_nUsedTowerCnt;
}
}
class GameThread extends Thread {
private int m_nDisplayWidth;
private int m_nDisplayHeight;
private Bitmap m_bmpBg;
private Bitmap m_bmpMop;
private Bitmap m_bmpMissile;
private Bitmap m_bmpTower;
private SurfaceHolder m_SurfaceHolder;
public boolean m_bStop;
public GameThread (SurfaceHolder surfaceholder, Context context){
m_SurfaceHolder = surfaceholder;
Resources res = context.getResources();
m_bmpBg = BitmapFactory.decodeResource(res,R.drawable.bg);
m_bmpMop = BitmapFactory.decodeResource(res,R.drawable.mop);
m_bmpMissile = BitmapFactory.decodeResource(res,R.drawable.missile);
m_bmpTower = BitmapFactory.decodeResource(res,R.drawable.tower);
Display display =
((WindowManager)context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
m_nDisplayWidth = display.getWidth();
m_nDisplayHeight = display.getHeight();
m_bStop = false;
}
public void setStop(){
m_bStop = true;
}
public void run(){
while(!m_bStop){
Canvas canvas = null;
try {
canvas = m_SurfaceHolder.lockCanvas(null);
synchronized(m_SurfaceHolder){
Rect rcSrc = new Rect();
p; Rect rcDest = new Rect();
rcSrc.set(0,0,470,498);
rcDest.set(0,0,m_nDisplayHeight,m_nDisplayHeight);
canvas.drawBitmap(m_bmpBg , rcSrc, rcDest, null);
m_cMopMgr.AddMop();
m_cMopMgr.MoveMop();
for(int n = 0 ; n m_cMopMgr.m_nMopCnt ; n++){
if(m_cMopMgr.mop[n].m_bUsed == true){
canvas.drawBitmap(m_bmpMop ,m_cMopMgr.mop[n].m_nX,m_cMopMgr.mop[n].m_nY, null);
}
}
for(int n = 0 ; n m_cTowerMgr.m_nTowerCnt ; n++){
if(m_cTowerMgr.tower[n].m_bUsed == true){
canvas.drawBitmap(m_bmpTower ,m_cTowerMgr.tower[n].m_nX,m_cTowerMgr.tower[n].m_nY, null);if(m_cTowerMgr.tower[n].m_bUsedMissale){
canvas.drawBitmap(m_bmpMissile ,m_cTowerMgr.tower[n].m_nMissaleX,m_cTowerMgr.tower[n].m_nMissaleY, null);
}
else{
int nMop = m_cMopMgr.FindMop(n);
if(nMop = 0){
m_cTowerMgr.tower[n].AttackMop(nMop);
}
}
m_cTowerMgr.tower[n].MoveMissale();
}
}
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawText( 만들 수 있는 타워 개수: + (m_cTowerMgr.m_nTowerCnt - m_cTowerMgr.GetTowerCount() ) ,5,20, paint);
canvas.drawText( 몹수 : + (10 - m_cMopMgr.m_nOverCount),5,40, paint);
sleep(10);
}
}
catch (InterruptedException e){
e.printStackTrace();
}
finally{
if(canvas != null){
m_SurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
void AddTower(int x, int y){
m_cTowerMgr.AddTower(x-8,y-12);
}
}
public GameRun(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
SurfaceHolder holder = getHolder();
holder.addCallback(this);
m_GameThread = new GameThread(holder, context);
}
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_UP){
m_GameThread.AddTower((int)event.getX(), (int)event.getY());
}
return true;
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
m_GameThread.setDaemon(true);
m_GameThread.start();
}
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
m_GameThread.setStop();
}
}안드로이드안에 넣은 자바소스인데요
여기서 mop이 죽으면 게임을 끝내고 싶은데
어떻게 하면 좋을까요????