打地鼠html5源码(html5 js 打地鼠小游戏)
本文目录一览:
求下用FLASH做一个简单的打地鼠的游戏的具体步骤
1.
准备美术素材,
鼠洞,鼠进洞动画,出洞动画,
打鼠的锤子
2.
把 鼠洞,鼠进洞动画,出洞动画
,这些组合到一个MovieClip,然后复制几个(假如是10个)放到舞台上,取好名mc0~mc9
3.
写程序,
(1)用打鼠的锤子
代替鼠标
(2)
控制地vnu
: 设个定时器,一定时间内用随机数取,取0-9的中任意数,播放出洞动画,
出洞的mc侦听鼠标点击,被点后计分,
没被点,定时播放进洞动画,收进洞里,不能点击.
4.
这是最简单的,要其它规则自己加,比如,设定有不同的地鼠,打到多少后游戏结束,或者定时结束,统计打了多少个
flash 仿“金山打字通之打地鼠”(打字游戏) 源码
个简单的Flash打字游戏
上一篇 / 下一篇 2007-09-25 16:42:03
查看( 142 ) / 评论( 3 ) / 评分( 5 / 0 )
代码:
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
打字游戏 ——V1.0
日期:2007-9-24
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
定义变量
----------------------------------------------------------------------------------------------
*/
fscommand("fullscreen", true);
var Bring_num:Number = 0;
var Bring_maxnum:Number = 20;
var Grade_num:Number = 1;
var Grade_bring:Number = 100;
var Move_speed:Number = 2;
var Bring_speed:Number = 0;
var Press_num:Number = 0;
var Right_num:Number = 0;
var Loss_num:Number = 0;
var Grade_boolean:Boolean = false;
var Interval_num:Number = 0;
var Listener:Object = new Object();
var Addsound:Sound = new Sound();
var Addblast_mc:Object = new Object();
var Time_m:Number = 0;
var Time_s:Number = 1;
var Hide_id:Number;
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Bring_word函数功能:随机产生字符
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
function Bring_word() {
var color_array:Array = new Array(0xffffff, 0x9B4A8B, 0xE0C0DB, 0xAC285E, 0x235CB1, 0x379D37, 0xB1A323);
var txtstyle:TextFormat = new TextFormat();
txtstyle.bold = true;
txtstyle.font = "宋体";
txtstyle.size = 20;
txtstyle.color = color_array[random(7)];
_root.Bring_num++;
if (_root.Bring_num=Bring_maxnum) {
_root.Bring_num = 0;
}
switch (random(2)) {
case 0 :
txt = random(26)+97;
break;
case 1 :
txt = random(10)+48;
break;
}
_root.createTextField("txt"+_root.Bring_num, _root.Bring_num, random(Stage.width), -(random(200)+10), 25, 25);
this["txt"+_root.Bring_num].text = chr(txt);
this["txt"+_root.Bring_num].setTextFormat(txtstyle);
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Interval_event();初始化时产生的字符个数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
function Interval_event() {
Bring_word();
Interval_num++;
if (Interval_num=3) {
clearInterval(Interval_id);
}
}
var Interval_id:Number = setInterval(Interval_event, 1000);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cyc_event下落函数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
function cyc_event() {
function _event() {
for (var i = 0; i=Bring_maxnum; i++) {
var n:Number = random(2) ? -Math.random()*9 : Math.random()*9;
_root["txt"+i]._y += Move_speed;
_root["txt"+i]._x += n;
if (_root["txt"+i]._yStage.height) {
_root["txt"+i].removeTextField();
Bring_word();
Loss_num++;
loss_txt.text = Loss_num;
}
}
}
var cyc_id:Number = setInterval(_event, 50);
}
cyc_event();
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
监听键盘
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
Key.addListener(Listener);
Listener.onKeyDown = function() {
Press_num++;
//trace(Press_num);
if (Grade_boolean) {
Grade_num++;
Grade_boolean = false;
grade_txt.text = "第"+Grade_num+"关";
Move_speed += 2;
for (var i = 0; i3; i++) {
Bring_word();
}
}
//trace("Press_num="+Press_num);
for (i=0; i=Bring_maxnum; i++) {
if (_root["txt"+i].text == chr(Key.getAscii())) {
Right_num++;
Addsound.attachSound("Sound_mc");
Addsound.start();
//_root.attachMovie("Blast_mc", "Addblast_mc", _root.getNextHighestDepth(), {_x:_root["txt"+i]._x, _y:_root["txt"+i]._y});
Blast_mc.play();
Blast_mc._x = _root["txt"+i]._x;
Blast_mc._y = _root["txt"+i]._y;
_root["txt"+i].removeTextField();
Bring_word();
if (Right_num=Grade_bring and Right_num%Grade_bring == 0) {
Grade_boolean = true;
} else {
Grade_boolean = false;
}
}
}
right_txt.text = String(Right_num);
if (Press_num-Right_num0) {
wrong_txt.text = String(Press_num-Right_num);
} else {
Press_num += Math.abs(Press_num-Right_num);
}
};
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
时间函数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
*/
function Time_event() {
Time_s++;
if (Time_s/601) {
Time_m++;
Time_s = 1;
}
time_txt.text = Time_m+":"+Time_s%60;
}
setInterval(Time_event, 1000);
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
简介函数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
var newmenu:ContextMenu = new ContextMenu();
newmenu.hideBuiltInItems();
this.menu = newmenu;
newmenu.customItems.push(new ContextMenuItem("作者:Edward.yang", by_event));
newmenu.customItems.push(new ContextMenuItem("QQ:77839683", getqq));
newmenu.customItems.push(new ContextMenuItem("退出", exit_event, true));
function exit_event() {
fscommand("quit", "");
}
function by_event() {
Hide_id = setInterval(hide_by, 5000);
by_mc.gotoAndStop(2);
by_mc._alpha = 0;
by_mc.onEnterFrame = function() {
this._alpha += (100-this._alpha)/8;
this._x += (Stage.width/2-this._x)/8;
this._y += (Stage.height/2-this._y)/8;
//trace(this._alpha);
if (this._alpha=100) {
delete by_mc.onEnterFrame;
}
};
}
function hide_by() {
by_mc.onEnterFrame = function() {
this._alpha -= 8;
//trace(this._alpha);
if (this._alpha=0) {
this.gotoAndStop(1);
clearInterval(Hide_id);
delete by_mc.onEnterFrame;
}
};
}
function getqq() {
getURL("tencent://message/?uin=77839683");
打地鼠的代码怎么写啊???
package com.lzw;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Shrewmouse extends JFrame implements Runnable {
private JLabel[] mouses; //存放显示底数的标签数组
private ImageIcon imgMouse; //地鼠图片对象
public static void main(String args[]){
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
Shrewmouse frame=new Shrewmouse(); //创建窗体
frame.setVisible(true); //显示窗体
new Thread(frame).start(); //启动线程
}catch(Exception e){
e.printStackTrace();
}
}
});
}
public Shrewmouse(){
super();
this.setResizable(false); //禁止调整窗体大小
this.getContentPane().setLayout(null); //窗体不使用布局管理器
this.setTitle("简易的打地鼠游戏"); //设置窗体标题
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon img=new ImageIcon(getClass().getResource("background.jpg"));
//初始化背景图片
imgMouse=new ImageIcon(getClass().getResource("mouse1.jpg"));
//初始化地鼠图片对象
mouses=new JLabel[6]; //创建显示地鼠的标签数组
for(int i=0;i6;i++){ //遍历数组
mouses[i]=new JLabel(); //初始化每一个数组元素
mouses[i].setSize(imgMouse.getIconWidth(),imgMouse.getIconHeight());
//设置标签与地鼠图片相同大小
mouses[i].addMouseListener(new MouseAdapter(){//为标签添加鼠标事件监听适配器
/**
* 处理鼠标单击事件的方法
*/
@Override
public void mouseClicked(MouseEvent e){
Object source=e.getSource(); //获取事件源,即地鼠标签
if(source instanceof JLabel){ //如果事件是标签组件
JLabel mouse=(JLabel)source; //强制转换为JLabel标签
mouse.setIcon(null); //取消标签图标
}
}
});
this.getContentPane().add(mouses[i]); //添加显示地鼠的标签到窗体
}
mouses[0].setLocation(253, 300); //设置每个标签的位置
mouses[1].setLocation(333, 250);
mouses[2].setLocation(388, 296);
mouses[3].setLocation(362, 364);
mouses[4].setLocation(189, 353);
mouses[5].setLocation(240, 409);
final JLabel backLabel=new JLabel(); //创建显示背景的标签
backLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
this.setBounds(100,100,img.getIconWidth(),img.getIconHeight());
backLabel.setIcon(img); //添加背景到标签
this.getContentPane().add(backLabel); //添加背景标签到窗体
}
/**
* 线程的核心方法
*/
public void run(){
while(true){ //使用无限循环
try{
Thread.sleep(3000); //使线程休眠3秒
int index=(int)(Math.random()*6); //生成随机的地鼠索引
if(mouses[index].getIcon()==null){ //如果地鼠标签没有设置图片
mouses[index].setIcon(imgMouse); //为该标签添加地鼠图片
}
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
}