提取碼:cnq6
php
這是導入本身喜歡的圖片後,在如下代碼中修改本身喜歡的名字和圖片地址html
protected void onDraw(Canvas canvas) { super.onDraw(canvas); width = getWidth(); height = getHeight(); pixl = width / SnakeConfig.snakeNum; if (!isInit) { initPoint(); isInit = true; } mPaint.setStrokeWidth(pixl * 2); snakePaint.setStrokeWidth(pixl - 2); initWall(canvas); initSnake(canvas); drawSnakeBuf(canvas); }
private void initWall(Canvas canvas) { RectF rel; paintWall.setStyle(Paint.Style.FILL_AND_STROKE); paintWall.setColor(Color.BLACK); for (int i = bengin; i < width - pixl; i += pixl) { for (int j = bengin; j < width - pixl; j += pixl) { if (i == bengin || j == bengin || i > width - 2 * pixl || j > width - 2 * pixl) { rel = new RectF(i, j, i + pixl, j + pixl); canvas.drawRoundRect(rel, 10, 10, paintWall); } } } paintWall.setStyle(Paint.Style.STROKE); paintWall.setColor(Color.LTGRAY); for (int i = bengin; i < width - pixl; i += pixl) { for (int j = bengin; j < width - pixl; j += pixl) { if (i == bengin || j == bengin || i > width - 2 * pixl || j > width - 2 * pixl) { } else { rel = new RectF(i, j, i + pixl, j + pixl); canvas.drawRoundRect(rel, 4, 4, paintWall); } } } }
private void moveToRight() { int len = snakeDatas.size(); for (int i = len - 1; i > 0; i--) { snakeDatas.get(i).x = snakeDatas.get(i - 1).x; snakeDatas.get(i).y = snakeDatas.get(i - 1).y; } snakeDatas.get(0).x = snakeDatas.get(0).x + pixl; }
public boolean isSamePoint(Snake snake, Snake snakeBuf2) { if ((snake.x - snakeBuf2.x) < -2 || (snake.x - snakeBuf2.x) > 2) { return false; } if ((snake.y - snakeBuf2.y) < -2 || (snake.y - snakeBuf2.y) > 2) { return false; } return true; }
up.xml
把圖片引用,就獲得了一個按鈕。<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/up_p" android:state_pressed="true"></item> <item android:drawable="@drawable/up_n"></item> </selector>
「程序員的宿命啊,就是被扔,這代碼啊,是寫了扔,扔了寫。」android
——強調了本身姓名的嚴域俊先生程序員