当前位置: 编程技术>移动开发
本页文章导读:
▪西游体裁手游《多米诺骨牌-和悟空比IQ》 西游题材手游《多米诺骨牌-和悟空比IQ》
依然是我们3个人,第二款小游戏,多米诺骨牌,依附西游题材。先给个游戏下载链接:
ios下载:https://itunes.apple.com/cn/app/duo-mi-nuo-gu-pai-he-wu-kong-b.........
▪ 右方MENU划屏代码 右侧MENU划屏代码
参考http://my.eoe.cn/1188496/archive/20296.htmlMainActivity
package com.nico;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.Motio.........
▪ UITableView添外框 UITableView加外框
tableView.layer.borderWidth = 1;tableView.layer.borderColor = [[UIColor grayColor] CGColor];要引入quartz core framework
......
[1]西游体裁手游《多米诺骨牌-和悟空比IQ》
来源: 互联网 发布时间: 2014-02-18
西游题材手游《多米诺骨牌-和悟空比IQ》
依然是我们3个人,第二款小游戏,多米诺骨牌,依附西游题材。先给个游戏下载链接:
ios下载:https://itunes.apple.com/cn/app/duo-mi-nuo-gu-pai-he-wu-kong-biiq/id770029894?mt=8
android下载:http://as.baidu.com/a/item?docid=5153565
游戏视频地址:
http://v.youku.com/v_show/id_XNjQ4MDcyMzEy.html
《和悟空比IQ》是一款智力休闲手游,这款游戏主要是看玩家的眼力和反应速度,游戏的玩法非常简单,你需要在一堆骨牌中找到最关键的那张骨牌并且推倒它,最终打碎八卦炉。这款游戏的最大特点就是眼力和脑力并重,这游戏想要通关不是那么容易的。
进入游戏先选择模式,游戏总共有2个模式:开始游戏和挑战模式。我们首先点击开始游戏进行游戏。
每个关卡的目的只有一个,就是推倒骨牌最终打碎八卦炉,不过看起来容易,做起来难,每一关开始你只有几十秒的时间用来思考,而且必须要推倒所有的骨牌,一旦有剩余骨牌没有推倒,下一关开始的思考时间将变少。一旦时间用完或者八卦炉没有被打碎,则需要重新从第一关开始。
每关的玩法就是看眼力进行正确的推倒,从一大堆骨牌中,发现最关键的那个点,并且一击达成。
游戏注重的是策略和反应,如何在短短的十几秒中,发现诸多骨牌中最关键的一张,你要开动脑筋,找出他们之间的规律,挑战IQ的时候到了!
[2] 右方MENU划屏代码
来源: 互联网 发布时间: 2014-02-18
右侧MENU划屏代码
参考http://my.eoe.cn/1188496/archive/20296.html
MainActivity
划屏任务
XML文件
参考http://my.eoe.cn/1188496/archive/20296.html
MainActivity
package com.nico;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
public class MainActivity extends Activity implements
GestureDetector.OnGestureListener, OnTouchListener {
public LinearLayout leftview = null;
public LinearLayout rightview = null;
public ImageView setBtn = null;
public GestureDetector gestureD = null;
public int window_width;
public int max_width;
public boolean isScroll = false;
public int mScrollX = 0;
public ImageView img = null;
final public static int SPEED = 30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
initView();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@SuppressWarnings("deprecation")
public void initView() {
leftview = (LinearLayout) findViewById(R.id.left_part);
rightview = (LinearLayout) findViewById(R.id.right_part);
setBtn = (ImageView) findViewById(R.id.set_btn);
img = (ImageView) findViewById(R.id.bg);
gestureD = new GestureDetector(this);
leftview.setOnTouchListener(this);
img.setOnTouchListener(this);
gestureD.setIsLongpressEnabled(false);
getmaxWidth();
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
//拖动过程中
isScroll = true;
//distanceX是处理后点X跟前点X的距离,此时mScrollX为X方向移动距离
mScrollX += distanceX;
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) leftview
.getLayoutParams();
int leftmargin = params.leftMargin;
//左边距 - X方向移动的距离 等于新的左边距
leftmargin -= mScrollX;
//到头了,停止移动,设定左边距为-max_width 或 0
if (leftmargin <= -max_width) {
leftmargin = -max_width;
params.leftMargin = leftmargin;
isScroll = false;
} else if (leftmargin >= 0) {
leftmargin = 0;
params.leftMargin = leftmargin;
isScroll = false;
}
//其他范围内,正常设定左边距
params.leftMargin = leftmargin;
leftview.setLayoutParams(params);
//返回false,继续传递这个事件
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
//单击的时候实现左右移动
isScroll = false;
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) leftview
.getLayoutParams();
int leftmargin = params.leftMargin;
if (leftmargin == 0) {
new MoveAsyTask(leftview, max_width).execute(-SPEED);
} else {
new MoveAsyTask(leftview, max_width).execute(SPEED);
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
//按下第一个动作时,mScrollX置为0,isScroll重置为false
mScrollX = 0;
isScroll = false;
return true;
}
public boolean hasMeasured = false;
void getmaxWidth() {
ViewTreeObserver viewTreeObserver = leftview.getViewTreeObserver();
// 获取控件宽度
viewTreeObserver.addOnPreDrawListener(new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
if (!hasMeasured) {
window_width = getWindowManager().getDefaultDisplay()
.getWidth();
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) leftview
.getLayoutParams();
layoutParams.width = window_width;
leftview.setLayoutParams(layoutParams);
max_width = rightview.getWidth();
hasMeasured = true;
}
return true;
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEvent.ACTION_UP == event.getAction() && isScroll == true) {
RelativeLayout.LayoutParams params = (LayoutParams) leftview
.getLayoutParams();
int leftmargin = params.leftMargin;
//滑动结束后,判断拖动距离是否大于一般屏宽,是则向前,否则缩回去
if (leftmargin < -window_width / 2) {
new MoveAsyTask(leftview, max_width).execute(-SPEED);
} else {
new MoveAsyTask(leftview, max_width).execute(SPEED);
}
}
return gestureD.onTouchEvent(event);
}
}
划屏任务
package com.nico;
import android.os.AsyncTask;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
public class MoveAsyTask extends AsyncTask<Integer, Integer, String> {
public LinearLayout view;
public int max_width;
public MoveAsyTask(LinearLayout v, int mw) {
view = v;
max_width = mw;
}
@Override
protected void onProgressUpdate(Integer... values) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view
.getLayoutParams();
//更新视图
int leftmargin = params.leftMargin;
int guide = values[0];
if (guide > 0) {
// 往右
leftmargin = Math.min(leftmargin + guide, 0);
} else {
leftmargin = Math.max(leftmargin + guide, -max_width);
// 往左
}
params.leftMargin = leftmargin;
view.setLayoutParams(params);
}
@Override
protected String doInBackground(Integer... params) {
int times = 0;
if (max_width % Math.abs(params[0]) == 0)// 整除
times = max_width / Math.abs(params[0]);
else
times = max_width / Math.abs(params[0]) + 1;// 有余数
for (int i = 0; i < times; i++) {
publishProgress(params[0]);
try {
Thread.sleep(Math.abs(params[0]));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
}
}
XML文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/right_part"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:background="@android:color/background_dark"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/right_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置"
android:textColor="@android:color/white"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/left_part"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/left_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/nav_bg" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="我"
android:textColor="@android:color/white"
android:textSize="20sp" />
<ImageView
android:id="@+id/set_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="/blog_article/@drawable/set_btn/index.html" />
</RelativeLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/bg"
android:background="@drawable/guide_bg" />
</LinearLayout>
</RelativeLayout>
[3] UITableView添外框
来源: 互联网 发布时间: 2014-02-18
UITableView加外框
tableView.layer.borderWidth = 1;
tableView.layer.borderColor = [[UIColor grayColor] CGColor];
要引入quartz core framework
tableView.layer.borderWidth = 1;
tableView.layer.borderColor = [[UIColor grayColor] CGColor];
要引入quartz core framework
最新技术文章: