package com.wing.poem.control;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.widget.ArrayAdapter;

import com.wing.poem.PoemActivity;
import com.wing.poem.R;
import com.wing.poem.vo.CheckPoint;
import com.wing.poem.vo.Poem;

public class Rule {
	public enum STATUS { 
			NORMAL,ERROR,OVER,RIGHT;
		} 
	private CheckPoint chpoint;
	private PoemActivity activity;
	private ArrayAdapter<String> adapter;
	private static Rule rule;
	public static Rule getInstance(PoemActivity activity){
		if(rule == null)
			rule  = new Rule(activity);
		return rule;
		
	}
	private Rule(PoemActivity activity){
		this.activity = activity;
	}
	public void init(CheckPoint p,ArrayAdapter<String> adapter){
		this.adapter = adapter;
		chpoint = p;
	}
	/**
	 * 
	 * @param p
	 * @param adapter
	 * @param count
	 * @return
	 */
	public void checkRight(int acitonNumber){
		
		final STATUS result = getStatus(acitonNumber);
		Log.d("check", result+":"+acitonNumber);

		if(result!=STATUS.NORMAL){
			activity.handler.removeMessages(0);
			String tips = activity.getResources().getStringArray(R.array.tips)[result.ordinal()];
	        new AlertDialog.Builder(activity)
	        .setTitle(tips)
	        .setPositiveButton(result==STATUS.RIGHT?R.string.next:R.string.retry,
	            new DialogInterface.OnClickListener() {
	                public void onClick(DialogInterface dialog, int whichButton) {
	                	activity.initPoem(result==STATUS.RIGHT?true:false);
	                }
	            }
	        ).setCancelable(false).show();
		}
		
	}
	private STATUS getStatus(int time){
		if(time<1)
			return STATUS.OVER;
		int[] key = chpoint.getKey();
		if(adapter.getCount() >key.length){
				return  STATUS.NORMAL;
		}else if(key.length == adapter.getCount()){
			for(int i=0;i<key.length;i++){
				Log.d("check", i+":"+key[i]+":"+chpoint.getPoem().getContent().get(key[i])+":"+adapter.getItem(i));
				if(!chpoint.getPoem().getContent().get(key[i]).equalsIgnoreCase(adapter.getItem(i)))
						return STATUS.NORMAL;
			}
			chpoint.setAchieve(time);
			return STATUS.RIGHT;
		}else{
			return STATUS.ERROR;
		}
	}
}
最近下载更多
17366635519  LV1 2022年8月30日
511076827  LV33 2022年4月11日
GZW012345  LV8 2022年4月8日
李秋天  LV6 2021年12月21日
wyx065747  LV67 2021年1月3日
fengxiao  LV8 2020年12月30日
a566566  LV9 2020年12月27日
小田田  LV4 2020年12月18日
cpemy_abc  LV10 2020年6月9日
没骨气的鱼  LV4 2020年6月6日
最近浏览更多
anjuw521  LV1 2024年7月10日
AIWU1234  LV2 2024年6月9日
求学的熊猫  LV11 2024年6月3日
yhwyhw1  LV2 2023年12月19日
lmroman  LV8 2023年4月27日
sunny1314 2023年3月30日
暂无贡献等级
yzhszz  LV3 2022年12月27日
不正经的90后程序猿  LV1 2022年9月12日
17366635519  LV1 2022年8月30日
1532593037  LV8 2022年6月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友