福尔摩斯的烟斗

班级

TA还未加入任何班级

课程

理论基础 数学之美
2万+浏览/ 706学员/ 4.4评分
小青
免费
6万+浏览/ 1391学员/ 4.2评分
8283浏览/ 86学员/ 0评分
4万+浏览/ 422学员/ 5评分
1万+浏览/ 409学员/ 4.8评分

笔记

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

Paint paint = new Paint(); paint.setColor(Color.BLACK); // 设置画笔透明度以及RGB属性1、a(透明度)1~255越小越透明 。2、R(红色)0~255越小越淡。3、G(绿色) // 0~255。4、B(蓝色)0~255。 paint.setARGB(200, 5, 100, 230); // 设置抗锯齿 注:设置这个属性后会消耗大量资源,绘制图形时会变慢。 paint.setAntiAlias(true); // 设置画笔的大小,也就是粗细。 paint.setStrokeWidth(1); // 设置画笔的样式。1、STROKE:空心图不填充颜色, paint.setStyle(Style.STROKE); // 绘制矩形,1、左边界的位置,2、上边界的位置,3、有边界的位置,4、下边界的位置。 paint.setTextSize(100); canvas.drawRect(200, 100, 300, 400, paint); // 绘制一条线,前俩个参数是x,y的起始位置的坐标,后俩个是x,y的终止位置的坐标。 canvas.drawLine(100, 100, 400, 400, paint); // 绘制圆形,前两个是圆心 x,y坐标,radius:是圆的半径。 canvas.drawCircle(200, 200, 50, paint); canvas.drawText("appde", 150, 300, paint); canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),300,100,paint);    Paint backgroundpaint = new Paint(); backgroundpaint.setColor(getResources().getColor( R.color.BackgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundpaint);Paint blackpaint = new Paint(); blackpaint.setColor(getResources().getColor(R.color.black));Paint strikingpaint = new Paint(); strikingpaint.setColor(getResources().getColor(R.color.Striking));Paint brightpaint = new Paint(); brightpaint.setColor(getResources().getColor(R.color.Bright));for (int i = 0; i < 9; i++) { canvas.drawLine(0, i * height, getWidth(), i * height, strikingpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), strikingpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); } for (int i = 0; i < 9; i++) { if (i % 3 != 0) { continue; } canvas.drawLine(0, i * height, getWidth(), i * height, blackpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), blackpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); }Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); float x = width / 2; canvas.drawText("1", 3 * width + x, 61, textpaint);

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

public class Game { private final String str = "360000000004230800000004200"+ "070460003820000014500013020"+ "001900000007048300000000045"; private int [] soduku = new int [9*9]; public Game(){ soduku = fromPuzzleString(str); }// 根据9宫格的坐标,返回坐标的格子中的数据; private int getTile(int x, int y){ return soduku[y* 9 + x]; } public String getTileString(int x, int y){ int v = getTile(x,y); if(v == 0){ return ""; }else{ return String.valueOf(v); } } protected int[] fromPuzzleString(String src){ int[] sudo = new int[str.length()]; for(int i = 0;i < sudo.length;i++){ sudo[i] = str.charAt(i) - '0'; } return sudo; }}   //画字体 Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); textpaint.setAntiAlias(true); //计算字体大小 FontMetrics fm = textpaint.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(new Game().getTileString(i, j), i * width + x,j * height + y, textpaint); } }

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

//取出不可用的数据; public int[] getUsedTilesByCoor(int x, int y){ return used[x][y]; } //计算单元格中不可用的数据; public int[] calculateUsedTiles(int x, int y){ int [] c = new int[9]; //计算Y轴方向不可用数据; for(int i = 0; i < 9; i ++){ if( i == y ){ continue; } int t = getTile(x,i); if(t!=0){ c[t-1]=t; } } //计算X轴方向不可用数据: for(int i = 0; i < 9 ; i++){ if(i == x){ continue; } int t = getTile(i,y); if(t != 0){ c[t-1] = t; } } //计算小九宫格不可用数据; int startx = (x / 3) * 3; int starty = (y / 3) * 3; for(int i = startx; i < startx + 3; i++){ for(int j = starty; j < starty + 3; j++){ if(i == x && j == y){ continue; } int t = getTile(i,j); if(t != 0 ){ c[t-1] = t; } } } int nused = 0; for(int t : c){ if(t != 0){ nused ++; } } int [] c1 = new int[nused]; nused = 0 ; for(int t : c){ if(t != 0){ c1[nused++] = t; } } return c1; } //获取屏幕点击的焦点 @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() != MotionEvent.ACTION_DOWN){ return super.onTouchEvent(event); } int selectedX = (int)(event.getX()/width); int selectedY = (int)(event.getY()/height); int used[] = game.getUsedTilesByCoor(selectedX, selectedY); for(int i = 0 ; i < used.length ; i++){ System.out.println(used[i]); } return true; }

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

//可以分成2大块来看!!! //1、第一块是 创建View,把自定义的布局文件转换成View对象; LayoutInflater layout = LayoutInflater.from(this.getContext()); View layoutView = layout.inflate(R.layout.dialog, null); TextView textView = (TextView) layoutView.findViewById(R.id.textID); textView.setText(sb.toString()); //2、创建Dialog对象并把设置好的View填充进去; AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); builder.setView(layoutView); AlertDialog dialog = builder.create(); dialog.show();

留言

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