⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawcanvas.java

📁 自已编的算24点的小游戏,原码和图片都已附上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		    	}
		    	else if(drawlist.modal==1){
		    		int i=0;
		    		for(;i<4;i++){
		    			if(copy_cardArrays[i]+1==temp){
		    				copy_cardArrays[i]=-1;
		    				break;
		    			}
		    		}
		    		if(i==4 && String.valueOf(temp).length()==2){
		    			errorAction=true;
		    			alert_sprite.setFrame(0);
		    			layermanager.insert(alert_sprite, 0);
		    		}
		    	}
		    }
		    else if(Character.isDigit(old_ch) || old_ch==')'){
		    	if(drawlist.modal==0){
		    		if(String.valueOf(temp).length()>1){
		    			errorAction=true;
						alert_sprite.setFrame(0);
						layermanager.insert(alert_sprite, 0);
		    		}else if(ch=='('){
		    			errorAction=true;
						alert_sprite.setFrame(1);
					    layermanager.insert(alert_sprite, 0);
		    		}else if(ch!='=' && ch!=')'){
		    			if(temp_num==4){
		    				errorAction=true;
					    	alert_sprite.setFrame(1);
					    	layermanager.insert(alert_sprite, 0);
		    			}
		    		}else if(ch=='='){
	    				if(temp_num<4){
	    		    		errorAction=true;
	    		    		alert_sprite.setFrame(2);
	    		    		layermanager.insert(alert_sprite, 0);
	    		    	}else if(kuo_left_num!=kuo_right_num){
	    		    		errorAction=true;
	    		    		alert_sprite.setFrame(3);
	    		    		layermanager.insert(alert_sprite, 0);
	    		    	}
	    			}
		    	}
		    	else if(drawlist.modal==1){
		    		if(String.valueOf(temp).length()>2){
			    		errorAction=true;
			    		alert_sprite.setFrame(0);
			    		layermanager.insert(alert_sprite, 0);
			    	}else if(ch=='('){
			    		errorAction=true;
						alert_sprite.setFrame(1);
					    layermanager.insert(alert_sprite, 0);
			    	}else if(Character.isDigit(ch)){
			    		int i=0;
			    		for(;i<4;i++){
			    			if(copy_cardArrays[i]+1==temp){
			    				copy_cardArrays[i]=-1;
			    				break;
			    			}
			    		}
			    		if(i==4 && String.valueOf(temp).length()==2){
			    			errorAction=true;
			    			alert_sprite.setFrame(0);
			    			layermanager.insert(alert_sprite, 0);
			    		}
			    	}else if(ch!='=' && ch!=')'){
			    		if(temp_num==4){
		    				errorAction=true;
					    	alert_sprite.setFrame(1);
					    	layermanager.insert(alert_sprite, 0);
		    			}
			    	}else if(ch=='='){
	    				if(temp_num<4){
	    		    		errorAction=true;
	    		    		alert_sprite.setFrame(2);
	    		    		layermanager.insert(alert_sprite, 0);
	    		    	}else if(kuo_left_num!=kuo_right_num){
	    		    		errorAction=true;
	    		    		alert_sprite.setFrame(3);
	    		    		layermanager.insert(alert_sprite, 0);
	    		    	}
	    			}
		    	}
		    }
		    if(errorAction==true){
			    try{
			    	timer_thread.timer_stop=true;
		    		Thread.sleep(2000);
		    	}catch(InterruptedException e){
		    		System.out.println(e.getMessage());
		    	}finally{
		    		delete_str();
		    		layermanager.remove(alert_sprite);
		    		thread.interrupt();
		    	} 
		    }else{
		    	if(!Character.isDigit(ch) && ch!='(' && ch!=')'){
					temp=0;
					int result=0;
					if(ch=='='){
						if(!str_num.equals("=")){
			    		result=seeking_expressions.express_value(str_num);
			    		str_num+=String.valueOf(result);
						}else{
							result=0;
							str_num+="无解";
						}
			    		if(result==24){
			    			correct_num++;
			    			alert_sprite.setFrame(5);
			    			layermanager.insert(alert_sprite, 0);
			    		}else{
			    			alert_sprite.setFrame(6);
			    			layermanager.insert(alert_sprite, 0);
			    		}
			    		try{
			    			timer_thread.timer_stop=true;
				    		Thread.sleep(2000);	
				    	}catch(InterruptedException e){
				    		System.out.println(e.getMessage());
				    	}finally{
				    		layermanager.remove(alert_sprite);
				    		thread.interrupt();
				    	}
				    	next_stage();
			    	}
				}
		    }
	}
	public void delete_str(){
		if(Character.isDigit(ch)){
			if(String.valueOf(temp).length()==1){
				temp/=10;
				temp_num--;
			}else{
				temp/=10;
			}
		}
		ch=old_ch;
		str_num=str_num.substring(0, str_num.length()-1);
	}
	public void next_stage(){
		card_ID=0;
    	card_x=86;card_y=3;
    	_initData2=true;
    	card_move=true;
    	str_num="";
		temp=0;
		temp_num=0;
		ch=' ';
		old_ch=' ';
		kuo_left_num=0;
		kuo_right_num=0;
	}
	public void get_listform(DrawList drawlist){
		this.drawlist=drawlist;
	}
	public void set_index_title(short index_title){
		this.index_title=index_title;
	}
	public void time_over(){
		alert_sprite.setFrame(4);
		layermanager.insert(alert_sprite, 0);
		try{
    		Thread.sleep(2000);
    	}catch(InterruptedException e){
    		System.out.println(e.getMessage());
    	}finally{
    		layermanager.remove(alert_sprite);
    	}
	}
	public void scene1_animation(){
		_scene.drawImage(backImage1 , 0 , 0, Graphics.TOP|Graphics.LEFT);
		_scene.drawImage(scrollcard, card_step1_x, card_step1_y, Graphics.TOP|Graphics.LEFT);
		_scene.drawImage(scrollcard, card_step2_x, card_step2_y, Graphics.TOP|Graphics.LEFT);
		if(card_step1_x<12)
			_scene.drawImage(scrollcard, card_step1_x+164, card_step1_y-164, Graphics.TOP|Graphics.LEFT);
		if(card_step2_x>-28)
			_scene.drawImage(scrollcard, card_step2_x-164, card_step2_y+164, Graphics.TOP|Graphics.LEFT);
		if(_initData1==true){
			if(!drawlist.list_dos){
				font_width=0;
				card_frame=0;
				brance_mark.setVisible(false);
			}
			for(int i=0;i<4;i++)
			layermanager.remove(brance_sprite[i]);
			_initData1=false;
		}
		if(font_width>70)font_width=70;
		_scene.setClip(10, 64, font_width+=4, 25);
		_scene.drawImage(font_count, 10, 64, Graphics.TOP|Graphics.LEFT);
		_scene.setClip(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
		if(card_frame<10 && font_width>=70){
			brance_mark.setVisible(true);
			brance_mark.setFrame(card_frame++);
		}
		layermanager.append(brance_mark);
		if(index_title==0){
			title_sprite[0].setFrame(0);
			title_sprite[1].setFrame(3);
		}else{
			title_sprite[0].setFrame(1);
			title_sprite[1].setFrame(2);
		}
		for(int i=0;i<2;i++)
		layermanager.append(title_sprite[i]);
		_scene.setColor(200);
		if(index_title==0)
			_scene.fillTriangle(10, 111, 16, 115, 10, 119); 
		else
			_scene.fillTriangle(10, 140, 16, 144, 10, 148);
		layermanager.paint(_scene, 0, 0);
		flushGraphics();
	}
	public void scene2_animation(){
		_scene.drawImage(backImage1 , 0 , 0, Graphics.TOP|Graphics.LEFT);
		_scene.drawImage(fatcardimage, 74, 0, Graphics.TOP|Graphics.LEFT);
		if(_initData2==true){
			_scene.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
			cardArrays=random_data();
			System.arraycopy(cardArrays, 0, copy_cardArrays, 0, 4);
			for(int i=0;i<4;i++){
				brance_sprite[i].setFrame(cardArrays[i]);
				brance_sprite[i].setPosition(card_x, card_y);
				layermanager.append(brance_sprite[i]);
		    }
			layermanager.remove(brance_mark);
			layermanager.remove(title_sprite[0]);
			layermanager.remove(title_sprite[1]);
			try{
				is=getClass().getResourceAsStream("/bgs.wav");
				player=Manager.createPlayer(is,"audio/x-wav");
			}catch(IOException ioe){
				System.out.println("无法导入声音流");
			}catch(MediaException me){
				System.out.println("无法创建wav播放器");
			}
			string_time=timer_thread.get_str_timer();
			_initData2=false;
		}
		if(card_ID<4)
		brance_sprite[card_ID].setPosition(card_x, card_y);
		music_set();
		_scene.drawString(string_time.toString(), 5, 8, Graphics.TOP|Graphics.LEFT);
		_scene.drawString(str_num, 5, 140, Graphics.TOP|Graphics.LEFT);
		layermanager.paint(_scene, 0, 0);
		flushGraphics();	
	}
	public void scene3_animation(){
		_scene.drawImage(backImage2 , 0 , 0, Graphics.TOP|Graphics.LEFT);
		if(_initData3==true){
			_scene.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE));
            _scene.setColor(255, 255, 255);
            this.removeCommand(back);
            this.removeCommand(help);
            this.addCommand(exit);
            this.addCommand(repeat);
			answer_correct="你答对了"+correct_num+"道题目";
			score_now=correct_num*10;
			try{
				RecordStore recordStore=RecordStore.openRecordStore("Scores", true);
				byte[] get_score=recordStore.getRecord(0);
				DataInputStream rs=new DataInputStream(new ByteArrayInputStream(get_score));
				score_old=rs.readInt();
				if(score_now>score_old){
					score_old=score_now;
					DataOutputStream ws=new DataOutputStream(new ByteArrayOutputStream());
					ws.writeInt(score_now);
					ws.close();
				}
				rs.close();
				recordStore.closeRecordStore();
			}catch(Exception e){
				System.out.println(e.getMessage());
			}
			answer_old_score="最高分为: "+score_old;
			answer_now_score="得分为: "+score_now;
			_initData3=false;
		}
		switch(word_ID){
		case 0:
			_scene.drawString(answer_correct, word_x, 30, Graphics.TOP|Graphics.LEFT);
			break;
		case 1:
			_scene.drawString(answer_correct, 40, 30, Graphics.TOP|Graphics.LEFT);
			_scene.drawString(answer_old_score, word_x, 70, Graphics.TOP|Graphics.LEFT);
			break;
		case 2:
			_scene.drawString(answer_correct, 40, 30, Graphics.TOP|Graphics.LEFT);
			_scene.drawString(answer_old_score, 40, 70, Graphics.TOP|Graphics.LEFT);
			_scene.drawString(answer_now_score, word_x, 110, Graphics.TOP|Graphics.LEFT);
			break;
		case 3:
			_scene.drawString(answer_correct, 40, 30, Graphics.TOP|Graphics.LEFT);
			_scene.drawString(answer_old_score, 40, 70, Graphics.TOP|Graphics.LEFT);
			_scene.drawString(answer_now_score, 40, 110, Graphics.TOP|Graphics.LEFT);
			break;
		}
		flushGraphics();	
	}
	public void music_set(){
		try{
		   if(card_y<=8)
			player.start();
		   else if(card_ID==4){
			player.close();
		   }
		}catch(MediaException me){
			System.out.println("无法播放");
		}
	}
	public byte[] random_data(){
		Random random=new Random();
		byte arrays[]=new byte[4];
		if(drawlist.modal==0){
			for(int i=0;i<4;i++){
				arrays[i]=(byte)random.nextInt(9);
			}
		}else if(drawlist.modal==1){
			for(int i=0;i<4;i++){
				arrays[i]=(byte)random.nextInt(13);
			}
		}
		return arrays;
	}
	public void commandAction(Command c,Displayable d){
		on_off=!on_off;
		if(c==exit){
			try{
			((Game_24_Point)midlet).destroyApp(true);
			}catch(MIDletStateChangeException e){
				System.out.println("退出发生错误");
			}
			midlet.notifyDestroyed();
		}
		else if(c==back){
			this.addCommand(exit);
	    	this.removeCommand(back);
	    	this.removeCommand(help);
	    	this.removeCommand(repeat);
	    	scene_ID=0;
	    	timer_thread.timer_break=true;
	    	timer_thread=null;
	    	thread=null;
	    	if(card_ID!=4)
	    	   player.close();
		}
		else if(c==help && card_ID==4){
			if(on_off==true){
				layermanager.insert(help_sprite, 0);
			    this.removeCommand(back);
			    timer_thread.add_timer();
			    timer_thread.timer_stop=true;
			}else{
				layermanager.remove(help_sprite);
				this.addCommand(back);
				thread.interrupt();
			}
		}else if(c==repeat){
			this.removeCommand(repeat);
			scene_ID=0;
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -