수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

안드로이드안에 자바소스 질문이요..ㅠㅠ

아리알찬

2023.04.01

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이 죽으면 게임을 끝내고 싶은데
어떻게 하면 좋을까요????

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2699380 메뉴가 계단식으로 나타나요.. ㅠ.ㅠ (5) 스릉흔다 2025-06-25
2699354 영문 웹폰트 관련 질문입니다!!! (1) 치킨마루 2025-06-25
2699329 윈도우 미디어 플레이어 URL 질문!!! (1) 제철 2025-06-25
2699296 동영상 배경 질문드려요!!!!!!!!!!!!!! 핫파랑 2025-06-24
2699214 position:fixed 에 대한 질문입니다.. (7) 사이 2025-06-24
2699183 제이쿼리 이미지 슬라이드 위치값 수정 초엘 2025-06-23
2699153 테마[ADORABLE]에서 페이지생성시 하위페이지는 2개밖에 안되나요? 흰여울 2025-06-23
2699129 네이버 블로그 또는 사이트의 글을 불러오기 갤원 2025-06-23
2699070 탭메뉴처럼 셀렉트 박스를 이용해서 내용을 출력할 수 있는 방법이 있을까요. (3) 큰꽃늘 2025-06-22
2699016 인터넷이 안되는 환경에서 validator설치방법 (3) 은송이 2025-06-22
2698988 대체 C++ 6.0 exe 아이콘은 어떻게 넣는건가요? 외국녀 2025-06-22
2698960 음성파일을 embed로 작업했는데..웹 표준코딩으로 변경하려면 어떻게 해야하나요? (1) 잎새 2025-06-21
2698932 메뉴목록 풍선창 만들기 html (2) 하늘이 2025-06-21
2698901 http://www.zeitgeistbot.com/ 이 사이트처럼 움직이는 효과를 무엇이라고 하나요? 누림 2025-06-21
2698876 table width값 크로스브라우징에 대한 문의 (2) 볼수록매력 2025-06-21
2698849 c언어 질문. (3) 아름나 2025-06-20
2698823 setInterval 이벤트 제거 하려면... 가온길 2025-06-20
2698796 이 오류를 이해를 못하겠어요 Addicted 2025-06-20
2698712 IF 문 이 계속 오류가 나요 (2) 옆집오빠야 2025-06-19
2698687 이미지를 클릭하면 그 이미지를 다운받게해주는 방법 질문요 ^^ (미해결) (5) 해지개 2025-06-19
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com