流小海2

班级

TA还未加入任何班级

课程

乐器演奏 吉他自学入门
128万+浏览/ 42598学员/ 4.6评分
稻米
免费
2万+浏览/ 840学员/ 4.3评分
平面设计 PS抠图秘技
12万+浏览/ 6616学员/ 4.6评分
1万+浏览/ 409学员/ 4.8评分

笔记

来自千锋3G学院-Android游戏开发教程-数独-第6讲(0)

1、对话框的使用方法 2、自定义对话框的方法 3、在对话框当中显示候选的数字 MyView.java文件:package com.example.shudu03;import android.app.AlertDialog;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.FontMetrics;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.widget.TextView;public class MyView extends View {    public MyView(Context context) {        super(context);    }    private float width;    private float height;    private Game game=new Game();        @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        this.width=w/9f;        this.height=h/9f;        super.onSizeChanged(w, h, oldw, oldh);    }        @Override    protected void onDraw(Canvas canvas) {        //画背景        Paint paintBackgroud=new Paint();        paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor));        canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud);                //画第一条颜色重的线的画笔        Paint paintOne=new Paint();        paintOne.setColor(getResources().getColor(R.color.oneLine));                //画第二条颜色轻的线的画笔        Paint paintTwo=new Paint();        paintTwo.setColor(getResources().getColor(R.color.twoLine));                //画颜色重的线        Paint paintThree=new Paint();        paintThree.setColor(getResources().getColor(R.color.threeLine));        for(int i=0;i<9;i++){            canvas.drawLine(0, i*height, getWidth(), i*height, paintOne);            canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo);            canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne);            canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo);        }                for(int i=0;i<9;i++){            if(i%3 != 0){                continue;            }            canvas.drawLine(0, i*height, getWidth(), i*height, paintThree);            canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo);            canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree);            canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo);        }                //画数字的画笔        Paint paintData=new Paint();        paintData.setColor(getResources().getColor(R.color.textColor));        paintData.setStyle(Paint.Style.STROKE);        paintData.setTextSize((float) (height*0.75));        paintData.setTextAlign(Paint.Align.CENTER);                FontMetrics fm=paintData.getFontMetrics();        float x=width/2;        float y=height/2-(fm.ascent+fm.descent)/2;                for(int i=0;i<9;i++){            for(int j=0;j<9;j++){                canvas.drawText(game.getTileString(i,                        j), i*width+x, j*height+y, paintData);            }        }        super.onDraw(canvas);            }    @Override    public boolean onTouchEvent(MotionEvent event) {        if(event.getAction()!=event.ACTION_DOWN){            return super.onTouchEvent(event);        }                int selectedx=(int)(event.getX()/width);        int selectedy=(int)(event.getY()/height);                int used[]=game.getUsedByArray(selectedx, selectedy);        StringBuffer result=new StringBuffer(0);        for(int i=0; i<used.length;i++){            System.out.println(used[i]);            result=result.append(String.valueOf(used[i]));                    }                LayoutInflater layoutInflater=LayoutInflater.from(this.getContext());                View layout=layoutInflater.inflate(R.layout.dialog, null);                TextView textView=(TextView)layout.findViewById(R.id.textView1);        textView.setText(result);                        AlertDialog.Builder builder=new AlertDialog.Builder(this.getContext());        builder.setView(layout);        AlertDialog alertDialog=builder.create();        alertDialog.show();        return true;    }                }

来自千锋3G学院-Android游戏开发教程-数独-第2讲(0)

1、Paint的设置方法setAntiAlias:设置画笔的锯齿效果setColor:设置画笔颜色setARGB:设置画笔的a、r、g、b值,接受整形参数。setAlpha:设置Alpha值setTextSize:设置字体尺寸setStyle:设置画笔风格,空心或者实心setStrokeWidth:设置空心的边框宽度getColor:得到画笔的颜色getAlpha:得到画笔的Alpha值2、使用Canvas绘制点、线和图形绘制直线:drawLine(float startX, float startY, float stopX, float stopY, Paint paint)绘制矩形:drawRect(float left, float top, float right, float bottom, Paint paint)绘制圆形:drawCircle(float cx, float cy, float radius, Paint paint)3、使用Canvas绘制文字drawText(String text, float x, float y, Paint paint)4、使用Canvas绘制图片的方法drawBitmap(Bitmap bitmap, float left, float top, Paint paint )相应的代码如下:canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),100, 400, paint);

来自千锋3G学院-Android游戏开发教程-数独-第3讲(0)

1、绘制九宫格2、在九宫格中放置数字MyView.java文件:package com.example.shudu03;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.view.View;public class MyView extends View {    public MyView(Context context) {        super(context);    }    private float width;    private float height;        @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        this.width=w/9f;        this.height=h/9f;        super.onSizeChanged(w, h, oldw, oldh);    }        @Override    protected void onDraw(Canvas canvas) {        //画背景        Paint paintBackgroud=new Paint();        paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor));        canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud);                //画第一条颜色重的线的画笔        Paint paintOne=new Paint();        paintOne.setColor(getResources().getColor(R.color.oneLine));                //画第二条颜色轻的线的画笔        Paint paintTwo=new Paint();        paintTwo.setColor(getResources().getColor(R.color.twoLine));                //画横竖三条颜色重的线        Paint paintThree=new Paint();        paintThree.setColor(getResources().getColor(R.color.threeLine));        for(int i=0;i<9;i++){            canvas.drawLine(0, i*height, getWidth(), i*height, paintOne);            canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo);            canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne);            canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo);        }                for(int i=0;i<9;i++){            if(i%3 != 0){                continue;            }            canvas.drawLine(0, i*height, getWidth(), i*height, paintThree);            canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo);            canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree);            canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo);        }                //画数字的画笔        Paint paintData=new Paint();        paintData.setColor(getResources().getColor(R.color.textColor));        paintData.setStyle(Paint.Style.STROKE);        paintData.setTextSize((float) (height*0.75));        paintData.setTextAlign(Paint.Align.CENTER);                float x=width/2;        canvas.drawText("1", 3*width+x, 61, paintData);        super.onDraw(canvas);    }       }color.xml文件:<?xml version="1.0" encoding="utf-8"?><resources>    <color name="backgroundColor">#ffe2e5e7</color>    <color name="textColor">#ff252525</color>    <color name="oneLine">#ffeceff0</color>    <color name="twoLine">#fffbfbfb</color>    <color name="threeLine">#ff858585</color></resources>MainActivity.java文件:package com.example.shudu03;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);//        setContentView(R.layout.activity_main);        setContentView(new MyView(this));    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.main, menu);        return true;    }} 

来自千锋3G学院-Android游戏开发教程-数独-第4讲(0)

1、FontMetrics的使用方法FontMetrics fm=paint.getFontMetrics();top:baseLine到字符框的最顶端的高度,是负数bottom:baseLine到字符框的最低端的高度,是正数ascent:baseLine到字符视觉最顶端的高度,是负数descent:baseLine到字符视觉最顶端的高度,是正数(ascent+descent)/2 关键代码:float x=width/2;               float y=height/2 - (ascent+descent)/2Game.java文件:package com.example.shudu03;public class Game {    private final String str="360000000"+"004230800"    +"000004200"+"070460003"+"820000014"+"500013020"            +"001900000"+"007048300"+"000000045";    private int shuduku[]=new int[9*9];        public Game() {        shuduku=formPuzzleString(str);    }        //根据九宫格的坐标,返回该坐标所引该填写数据    private int getTile(int x,int y){        return shuduku[y*9+x];    }        //将九宫格坐标的数字转化为String类型    public String getTileString(int x,int y){        int v=getTile(x,y);        if(v==0){            return "";        }        else{            return String.valueOf(v);        }    }        protected int[] formPuzzleString(String str){        int[] shudu=new int[str.length()];        for(int i=0;i<shudu.length;i++){            shudu[i]=str.charAt(i)-'0';        }        return shudu;    }}MyView.java文件:package com.example.shudu03;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.Paint.FontMetrics;import android.view.View;public class MyView extends View {    public MyView(Context context) {        super(context);    }    private float width;    private float height;    private Game game=new Game();        @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        this.width=w/9f;        this.height=h/9f;        super.onSizeChanged(w, h, oldw, oldh);    }        @Override    protected void onDraw(Canvas canvas) {        //画背景        Paint paintBackgroud=new Paint();        paintBackgroud.setColor(getResources().getColor(R.color.backgroundColor));        canvas.drawRect(0, 0, getWidth(), getHeight(), paintBackgroud);                //画第一条颜色重的线的画笔        Paint paintOne=new Paint();        paintOne.setColor(getResources().getColor(R.color.oneLine));                //画第二条颜色轻的线的画笔        Paint paintTwo=new Paint();        paintTwo.setColor(getResources().getColor(R.color.twoLine));                //画颜色重的线        Paint paintThree=new Paint();        paintThree.setColor(getResources().getColor(R.color.threeLine));        for(int i=0;i<9;i++){            canvas.drawLine(0, i*height, getWidth(), i*height, paintOne);            canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo);            canvas.drawLine(i*width, 0, i*width, getHeight(), paintOne);            canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo);        }                for(int i=0;i<9;i++){            if(i%3 != 0){                continue;            }            canvas.drawLine(0, i*height, getWidth(), i*height, paintThree);            canvas.drawLine(0, i*height+1, getWidth(), i*height+1, paintTwo);            canvas.drawLine(i*width, 0, i*width, getHeight(),paintThree);            canvas.drawLine(i*width+1, 0, i*width+1, getHeight(), paintTwo);        }                //画数字的画笔        Paint paintData=new Paint();        paintData.setColor(getResources().getColor(R.color.textColor));        paintData.setStyle(Paint.Style.STROKE);        paintData.setTextSize((float) (height*0.75));        paintData.setTextAlign(Paint.Align.CENTER);                FontMetrics fm=paintData.getFontMetrics();        float x=width/2;        float y=height/2-(fm.ascent+fm.descent)/2;                for(int i=0;i<9;i++){            for(int j=0;j<9;j++){                canvas.drawText(game.getTileString(i,                        j), i*width+x, j*height+y, paintData);            }        }        super.onDraw(canvas);            }                } 

留言

功能维护升级中,维护完成完后将再次开放,非常抱歉给您学习造成的不便。