안녕하세요 제발 도와주세요 담주 졸작 발표덴 이거때문에 3주이상 찾고 헤매고다니고 있네요
디펜스 게임 만들는중인데요
로크갯 부분도 보내고 소스도 올리게요
소스 첨부할게요 dlskagns11@naver.com << 제주소에요 답변 및 메일 보내주세요
필요한 소스 부분들 압축으로 보내드릴게요
많은 답변 부탁드립니다.
intro.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg1"
android:gravity="center"
>
<Button
android:id="@+id/Button01"
android:layout_width="114dp"
android:layout_height="42dp"
android:layout_x="100dp"
android:layout_y="98dp"
android:background="#BCBF8F"
android:text="@string/Start_Game" />
<Button
android:id="@+id/Button02"
android:layout_width="116dp"
android:layout_height="42dp"
android:layout_x="101dp"
android:layout_y="179dp"
android:background="#BCBF8F"
android:text="@string/ranking" />
<Button
android:id="@+id/Button03"
android:layout_width="119dp"
android:layout_height="43dp"
android:layout_x="100dp"
android:layout_y="264dp"
android:background="#BCBF8F"
android:text="@string/advice" />
</AbsoluteLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.game.GameRun
android:id="@+id/GameRun"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</FrameLayout>
ranking.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Ranking"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="랭킹점수 "
android:textSize="50sp"
android:padding = "10dip"/>
<TableRow>
<TextView android:text="1위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="2위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="3위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="4위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="5위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="6위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="7위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
<TableRow>
<TextView android:text="8위:"/>
<EditText android:id="@+id/entry"
android:layout_span="3"/>
</TableRow>
</TableLayout>
advice.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Advice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bk"
android:orientation="vertical" >
</LinearLayout>
GameMain.java
package com.game;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.view.View.OnClickListener;
public class GameMain extends Activity implements OnClickListener {
private static final String MediaPlayer = null;
/** Called when the activity is first created. */
Button btn1,btn2,btn3;
private Button btn4;
private Object player;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.intro);
btn1 = (Button)findViewById(R.id.Button01);
btn1.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.Button02);
btn2.setOnClickListener(this);
btn3 = (Button)findViewById(R.id.Button03);
btn3.setOnClickListener(this);
}
public void onClick(View v){
Intent intent;
switch(v.getId()) {
case R.id.Button01:
intent = new Intent(this, run.class);
startActivity(intent);
break;
case R.id.Button02:
intent = new Intent(this, rankingActivity.class);
startActivity(intent);
break;
case R.id.Button03:
intent = new Intent(this, adviceActivity.class);
startActivity(intent);
break;
}
}
}
GameRun.java
package com.game;
import java.util.HashMap;
import android.app.Activity;
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.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.view.SurfaceHolder.Callback;
import android.widget.Button;
public class GameRun extends SurfaceView implements Callback {
private GameThread m_GameThread;
private CMopMgr m_cMopMgr = new CMopMgr();
private CTowerMgr m_cTowerMgr = new CTowerMgr();
class CMop{
public int m_nX;
public int m_nY;
public long m_lBeforTime; // 이전에 움직였던 밀리세컨드
public long m_nSleep; // 이전과 다음이동사이의 밀리세컨드
public int m_nSpeed; // 한 이동 단위에 움직일 pixel 숫자
public int m_nMoveArea; // 이동할 구역
public int m_nMopHealth; // 몹체력
public boolean m_bUsed; // 생성되었나
public boolean m_bDie; // 몹이 죽었나 - 재생되지 않음
public int m_nDirection; // 이전 몹의 방향
// x, y, 방향(동쪽이 1이며 시계방향으로 증가함)
public int m_aMovePos[][] =
{
{ 93, 0, 2}, // 시작점임 남쪽 으로
{ 93, 19, 3}, // 서쪽 으로
{ 23, 19, 2}, // 남쪽 으로
{ 23, 143, 1}, // 동쪽 으로
{ 94, 143, 4}, // 북쪽 으로
{ 94, 95, 1}, // 동쪽 으로
{206, 95, 2}, // 남쪽 으로
{206, 215, 3}, // 서쪽 으로
{ 24, 215, 2}, // 남쪽 으로
{ 24, 286, 1}, // 동쪽 으로
{282, 286, 4}, // 북쪽 으로
{282, 19, 3}, // 서쪽 으로
{175, 19, 4}, // 위쪽 으로
{175, 0, 0} // 종착지
};
private int m_score;
CMop(){
m_nX = 93;
m_nY = 0;
m_lBeforTime = System.currentTimeMillis(); // 현재 시간을 설정한다
m_nSleep = 10; // 10 밀리세컨드마다 움직인다.
m_nSpeed = 2; // 2pixel 씩 움직인다
m_nMoveArea = 1; // 처음 시작은 위 중간즈음이다
m_bUsed = false;// 생성되지 않은 상태임
m_nMopHealth = 100; // 몹체력은 100으로 초기화
m_bDie = false;// 몹은 살아있는걸로 초기화됨
m_nDirection = -1;
}
// 다음 포지션으로 이동
public void MovePosition(){
// 이전 움직인 시간 이후 m_nSleep 이상 흘렀다면 움직인다.
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; // 오버 카운트를 1 증가 시킨다
m_nMoveArea = 1;
return;
}
// 방향에 따라 X,Y 좌표를 각각 이동 시킨다
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 int m_nMopCnt = 20; // 몹 개수
public CMop mop[] = new CMop[m_nMopCnt]; // 몹 Count
public int m_nUsedMopCnt = 0; // 생성되었던 몹 Count
public int m_nDieMopCnt = 0; // 죽은 몹 count
public long m_lRegen = 1000; // 다음몹 생성되는 시간(1초)
public int m_nOverCount = 0; // 몹이 한바퀴 도달하면 1 증가
public long m_lBeforRegen = System.currentTimeMillis();
public String m_nOverCoun;
CMopMgr(){
for(int n = 0 ; n < m_nMopCnt ; n++){
mop[n] = new CMop();
}
}
// 신규몹 추가 - m_bStart 플래그만 true 로 설정
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++){
// 죽었거나 생성되지 않은 몹이면 continue..
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; // 타워 X좌표
public int m_nY = 0; // 타워 Y좌표
public int m_nMopIndex; // 공격 몹의 Index
public long m_lAttackTime = 0; // 공격시간
public long m_lAttackSleep = 1500; // 공격 간격 1.5초
public boolean m_bUsed = false; // 사용되는 타워여부
public boolean m_bUsedMissale = false; // 미사일이 발사 되었나
public int m_nMissalePos = 0; // 미사일 진행 거리(0~5)
public long m_lMissaleSleep = 8; // 미사일 1틱 간격(0.2초)
public long m_lMissaleTime = 0; // 이전 미사일 진행했던 시간
public int m_nMissaleX = 0; // 미사일 X좌표
public int m_nMissaleY = 0; // 미사일 Y좌표
void AttackMop(int nMopIndex){
// 사용중인 타워가 아니라면 return;
if(m_bUsed == false) return;
// 공격 간격이 안되었다면 return;
if( (System.currentTimeMillis() - m_lAttackTime) > m_lAttackSleep){
m_lAttackTime = System.currentTimeMillis();
}
else return;
// 미사일이 발사된 상태면 return
if(m_bUsedMissale == true) return;
// 미사일 발사
m_bUsedMissale = true;
// 타겟몹 설정
m_nMopIndex = nMopIndex;
}
void MoveMissale(){
// 사용중인 타워가 아니면 return
if(m_bUsed == false) return;
// 미사일이 발사되지 않았으면 return
if(m_bUsedMissale == false) return;
// 미사일 진행 간격이 아니면 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 = 50; // 타워 숫자
public CTower tower[] = new CTower[m_nTowerCnt]; // 타워 객체
public int m_nUsedTowerCnt = 0; // 사용되는 타워 Count
CTowerMgr(){
for(int n = 0 ; n < m_nTowerCnt ; n++){
tower[n] = new CTower();
}
}
// 신규타워 추가 - m_bUsed 플래그만 true로 설정
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;
int m_score;
private Object jumsu;
private SurfaceView m_Score;
public GameThread (SurfaceHolder surfaceholder, Context context){
m_SurfaceHolder = surfaceholder;
Resources res = context.getResources();
// png 그림 이미지를 로딩
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 run(){
Canvas canvas = null;
while(!m_bStop){
canvas = m_SurfaceHolder.lockCanvas(null);
try {
synchronized(m_SurfaceHolder){
Rect rcSrc = new Rect();
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); //화면 캔버스를 하얀색으로 표현한다.
paint.setTextSize(20);
canvas.drawText( " 타워 설치 가능 : " + (m_cTowerMgr.m_nTowerCnt - m_cTowerMgr.GetTowerCount() ) ,5,20, paint);
canvas.drawText( " 아웃 카운트 : " + (10 - m_cMopMgr.m_nOverCount),5,40, paint);
canvas.drawText( " 점수 : "+ (m_score) ,5,60, 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);
}
@Override
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 stopFrorever(){
synchronized(this){
notify();
}
}
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
try{
m_GameThread.start();
}catch(Exception e){
Log.e("에러", "쓰레드");
}
}
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
boolean tryjoin = true;
//this.stopFrorever();
while(tryjoin){
try{
m_GameThread.join();
tryjoin = false;
}catch(InterruptedException e){
// e.getStackTrace();
}
}
}
}
adviceActivity.java
package com.game;
import android.app.*;
import android.os.*;
import android.view.Window;
public class adviceActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window win = getWindow();// 타이틀바 제목 없애준다.
win.requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.advice);
}
}
package com.game;
import android.app.*;
import android.os.*;
import android.view.Window;
public class rankingActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window win = getWindow();// 타이틀바 제목 없애준다.
win.requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.ranking);
}
}
run
package com.game;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class run extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window win = getWindow();// 타이틀바 제목 없애준다.
win.requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity
android:name=".GameMain"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="GameRun"></activity>
<activity android:name="run"></activity>
<activity android:name="adviceActivity"></activity>
<activity android:name="rankingActivity"></activity>
</application>
</manifest>
sorry Activity Game