package com.example.mgp;
import java.util.Random;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
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;
public class Pan_Activity extends SurfaceView implements SurfaceHolder.Callback{
private GameThread m_GameThread;//움직임
private DiceRandom m_DR;//랜덤 주사위
private Play m_play; //플레이어
public Context context;
public SurfaceHolder m_SurfaceHolder;
//-------------------------------------
// 생성자
//-------------------------------------
public Pan_Activity(Context context) {
super(context);
}
class DiceRandom extends GameThread{
public int nR;
public double w = 1280/11; //거리??
public double h = 720/11; //
public double m_aMovePos[][] = {
};//주사위 위치값
DiceRandom(){
nR = new Random().nextInt(11)+1;//랜덤 주사위
}
//멈춘자리에서 다시 이동
public void MovePosition() {
}
}
class Play extends GameThread{
}
//게임 움직임을 동작하게 하는거
class GameThread extends Thread{
public double m_nDisplayWidth; // 화면 가로 크기
public double m_nDisplayHeight; // 화면 세로 크기
private Bitmap m_bmpBg; // 배경
private Bitmap m_dicebutton; // 주사위 버튼
private Bitmap m_dice; // 주사위
private Bitmap m_play; // 말
//public boolean m_bStop; // 쓰레드가 작동하게 설정
//-------------------------------------
// Thread 생성자
//-------------------------------------
public GameThread() {
}
public GameThread(SurfaceHolder surfaceholder, Context context) {
m_SurfaceHolder = surfaceholder;
Resources res = context.getResources();
m_bmpBg = BitmapFactory.decodeResource(res, R.drawable.zz);
m_dicebutton = BitmapFactory.decodeResource(res, R.drawable.button_on);
m_dice = BitmapFactory.decodeResource(res, R.drawable.d2);
m_play = BitmapFactory.decodeResource(res, R.drawable.ic_launcher);
// 화면의 가로, 세로 사이즈를 구함.
Display display = ((WindowManager) context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
m_nDisplayWidth = display.getWidth(); // 화면의 폭
m_nDisplayHeight = display.getHeight(); // 화면의 높이
}
//-------------------------------------
// Thread run
//-------------------------------------
public void run() {
while (true) {
Canvas canvas = null; // canvas를 만든다
try
{
canvas = m_SurfaceHolder.lockCanvas(null); // canvas를 잠그고 버퍼 할당
synchronized(m_SurfaceHolder) // 동기화 유지
{
Rect rcSrc = new Rect();
Rect rcDest = new Rect();
rcSrc.set(0, 0, m_bmpBg.getWidth(), m_bmpBg.getHeight());
rcDest.set(0, 0, (int)m_nDisplayWidth, (int)m_nDisplayHeight);
canvas.drawBitmap(m_bmpBg, rcSrc, rcDest, null);//배경 화면
canvas.drawBitmap(m_dicebutton, 640,360, null);//버튼 배치
canvas.drawBitmap(m_play , 1150, 630, null); //말 배치
}
}
finally
{
if (canvas != null) {
m_SurfaceHolder.unlockCanvasAndPost(canvas); // canvas의 내용을 View에 전송
}
}
}
}
/*void point(int x, int y) {
}*/
}
public Pan_Activity(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
SurfaceHolder holder = getHolder();
holder.addCallback(this);
m_GameThread = new GameThread(holder, context);//쓰레드 생성
}
//-------------------------------------
// onTouchEvent
//-------------------------------------
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
//touch_X=event.getX(); // 터치된 X좌표 호출
//touch_Y=event.getY(); // 터치된 Y좌표 호출
boolean onKey = false;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
onKey = false;
}
return true;
}//onTouchEvent
//-------------------------------------
// SurfaceView가 만들어질 때 호출됨
//-------------------------------------
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
//-------------------------------------
// SurfaceView가 종료될 때 호출됨
//-------------------------------------
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
m_GameThread.start();
//-------------------------------------
// SurfaceView의 크기가 바뀔 때 호출됨
//-------------------------------------
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
}