当前位置: 代码迷 >> JavaScript >> 【编程游戏】贺岁放礼花。(第一名奖励10000可用分)解决方法
  详细解决方案

【编程游戏】贺岁放礼花。(第一名奖励10000可用分)解决方法

热度:179   发布时间:2012-03-11 18:15:39.0
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)(续2)
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)(续1)
【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
博客



说明:
  2009年新年即将到来,让我们一起用代码点燃属于程序员的礼花!
  这个活动是我个人发起的,简单的说:就是用程序模拟燃放礼花的过程,色彩、轨迹等自由发挥,娱乐为主。

要求:
  单一的html文件,8000字内(能一次贴出来);
  尽量不含图片;
  兼容IE6/7/8、FF2/3。

考评:
  动画效果 50%
  可读性/代码简洁 30%
  运行效率 20%

奖项:
  一等奖一名(100专家分、税前10000可用分)
  二等奖一名(50专家分、税前2000可用分)

截止日期:
  2009春节

祝福大家新年快乐

集中燃放点:(实时更新)
【编程游戏】贺岁放礼花。(点燃续帖2-142楼sharp_ice的焰火)
【编程游戏】贺岁放礼花。(点燃续帖2-141楼sharp_ice的焰火)
【编程游戏】贺岁放礼花。(点燃续帖2-133楼langtse的焰火)(修改自169楼Free_Wind22)
【编程游戏】贺岁放礼花。(点燃续帖2-132楼dh20156的焰火)
【编程游戏】贺岁放礼花。(点燃续帖2-123楼dh20156的焰火)
【编程游戏】贺岁放礼花。(点燃续帖2-8楼wcwtitxu的焰火)
【编程游戏】贺岁放礼花。(点燃续帖2-6楼lshdic的焰火)
【编程游戏】贺岁放礼花。(点燃续帖2-5楼zswang的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-194楼lshdic的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-188楼zswang的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-172楼yonghengdexingxing的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-164楼lshdic的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-145楼KiteGirl的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-143楼KiteGirl的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-142楼KiteGirl的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-141楼YH_Random的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-131楼lshdic的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-123楼cicadu的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-116楼cgisir的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-106楼cgisir的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-77楼muxrwc的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-58楼froole的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-56楼hongmaohouzi的焰火)(请在IE下运行)
【编程游戏】贺岁放礼花。(点燃续帖1-47楼0009的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-37楼muxrwc的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-36楼cgisir的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-24楼KiteGirl的焰火)
【编程游戏】贺岁放礼花。(点燃续帖1-18楼Free_Wind22的焰火)
【编程游戏】贺岁放礼花。(点燃201楼KiteGirl的焰火)
【编程游戏】贺岁放礼花。(点燃200楼KiteGirl的焰火)
【编程游戏】贺岁放礼花。(点燃190楼lshdic的焰火)(请在IE下运行)
【编程游戏】贺岁放礼花。(点燃175楼web_show的焰火)(修改自169楼Free_Wind22)
【编程游戏】贺岁放礼花。(点燃169楼Free_Wind22的焰火)
【编程游戏】贺岁放礼花。(点燃106楼zhanghezheng的焰火)(请在IE下运行)
【编程游戏】贺岁放礼花。(点燃78楼lsc1202001的焰火)
【编程游戏】贺岁放礼花。(点燃60楼Free_Wind22的焰火)
【编程游戏】贺岁放礼花。(点燃46楼dh20156的焰火)
【编程游戏】贺岁放礼花。(点燃34楼zjsfdxbao的焰火)
【编程游戏】贺岁放礼花。(点燃17楼dh20156的焰火)
已经加入投票,请大家参与评分。

------解决方案--------------------
顶啊
------解决方案--------------------
js小菜飘过~~
------解决方案--------------------
顶。。。
------解决方案--------------------
关注
------解决方案--------------------

------解决方案--------------------
关注!
------解决方案--------------------
^_^
------解决方案--------------------
路过
------解决方案--------------------
呵呵
------解决方案--------------------
这个题目对于俺属于比较难...关注、学习

------解决方案--------------------
APPLET版
Java code

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.image.MemoryImageSource;
import java.util.Random;

public class jhanabi extends Applet implements Runnable
{

private int m_nAppX;
private int m_nAppY;
private int m_centerX;
private int m_centerY;
private int m_mouseX;
private int m_mouseY;
private int m_sleepTime;
private boolean isError;
private boolean m_isPaintFinished;
boolean isRunning;
boolean isInitialized;
Thread runner;
int pix0[];
MemoryImageSource offImage;
Image dbImg;
int pixls;
int pixls2;
Random rand;
int bits;
double bit_px[];
double bit_py[];
double bit_vx[];
double bit_vy[];
int bit_sx[];
int bit_sy[];
int bit_l[];
int bit_f[];
int bit_p[];
int bit_c[];
int bit_max;
int bit_sound;
int ru;
int rv;
AudioClip sound1;
AudioClip sound2;

public jhanabi()
{
m_mouseX = 0;
m_mouseY = 0;
m_sleepTime = 5;
isError = false;
isInitialized = false;
rand = new Random();
bits = 10000;
bit_px = new double[bits];
bit_py = new double[bits];
bit_vx = new double[bits];
bit_vy = new double[bits];
bit_sx = new int[bits];
bit_sy = new int[bits];
bit_l = new int[bits];
bit_f = new int[bits];
bit_p = new int[bits];
bit_c = new int[bits];
ru = 50;
rv = 50;
}

public void init()
{
String s =
getParameter("para_bits");
if(s != null)
{
bits = Integer.parseInt(s);
}
s = getParameter("para_max");
if(s != null)
{
bit_max = Integer.parseInt(s);
}
s = getParameter("para_blendx");
if(s != null)
{
ru = Integer.parseInt(s);
}
s = getParameter("para_blendy");
if(s != null)
{
rv = Integer.parseInt(s);
}
s = getParameter("para_sound");
if(s != null)
{
bit_sound =
Integer.parseInt(s);
}
m_nAppX = size().width;
m_nAppY = size().height;
m_centerX = m_nAppX / 2;
m_centerY = m_nAppY / 2;
m_mouseX = m_centerX;
m_mouseY = m_centerY;
resize(m_nAppX, m_nAppY);
pixls = m_nAppX * m_nAppY;
pixls2 = pixls - m_nAppX * 2;
pix0 = new int[pixls];
offImage = new 
MemoryImageSource(m_nAppX, m_nAppY, pix0, 0, m_nAppX);
offImage.setAnimated(true);
dbImg = createImage(offImage);
for(int i = 0; i < pixls; i++)
{
pix0[i] = 0xff000000;
}

sound1 =
getAudioClip(getDocumentBase(), "firework.au");
sound2 = getAudioClip(getDocumentBase(), "syu.au");
for(int j = 0; j < bits; j++)
{
bit_f[j] = 0;
}

isInitialized = true;
start();
}

public void run()
{
while(!isInitialized) 
{
try
{
Thread.sleep(200L);
}
catch(InterruptedException interruptedexception) { }
}
do
{
for(int i = 0; i < pixls2; i++)
{
int j = pix0[i];
int k = pix0[i + 1];
int l = pix0[i + m_nAppX];
int i1 = pix0[i + m_nAppX + 1];
int j1 = (j & 0xff0000) >> 16;
int k1 = ((((k & 0xff0000) >> 16) - j1) * ru >> 8) + j1;
j1 = (j & 0xff00) >> 8;
int l1 = ((((k & 0xff00) >> 8) - j1) * ru >> 8) + j1;
j1 = j & 0xff;
int i2 = (((k & 0xff) - j1) * ru >> 8) + j1;
j1 = (l & 0xff0000) >> 16;
int j2 = ((((i1 & 0xff0000) >> 16) - j1) * ru >> 8) + j1;
j1 = (l & 0xff00) >> 8;
int k2 = ((((i1 & 0xff00) >> 8) - j1) * ru >> 8) + j1;
j1 = l & 0xff;
int l2 = (((i1 & 0xff) - j1) * ru >> 8) + j1;
int i3 = ((j2 - k1) * rv >> 8) + k1;
int j3 = ((k2 - l1) * rv >> 8) + l1;
int k3 = ((l2 - i2) * rv >> 8) + i2;
pix0[i] = i3 << 16 | j3 << 8 | k3 | 0xff000000;
}

rend();
offImage.newPixels(0, 0, m_nAppX, m_nAppY);
try
{
Thread.sleep(m_sleepTime);
}
catch(InterruptedException interruptedexception1) { }
} while(true);
}

public void update(Graphics g)
{
paint(g);
}

public void paint(Graphics g)
{
g.drawImage(dbImg, 0, 0, this);
}

public void start()
{
if(isError)
{
return;
}
isRunning = true;
if(runner == null)
{
runner = new Thread(this);
runner.start();
}
}

public void stop()
{
if(runner != null)
{
runner.stop();
runner = null;
}
}

public boolean mouseMove(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
return true;
}

public boolean mouseDown(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
int k = (int)(rand.nextDouble() * 256D);
int l = (int)(rand.nextDouble() * 256D);
int i1 = (int)(rand.nextDouble() * 256D);
int j1 = k << 16 | l << 8 | i1 | 0xff000000;
int k1 = 0;
for(int l1 = 0; l1 < bits; l1++)
{
if(bit_f[l1] != 0)
{
continue;
}
bit_px[l1] = m_mouseX;
bit_py[l1] = m_mouseY;
double d = rand.nextDouble() * 6.2800000000000002D;
double d1 = rand.nextDouble();
bit_vx[l1] = Math.sin(d) * d1;
bit_vy[l1] = Math.cos(d) * d1;
bit_l[l1] = (int)(rand.nextDouble() * 100D) + 100;
bit_p[l1] = (int)(rand.nextDouble() * 3D);
bit_c[l1] = j1;
bit_sx[l1] = m_mouseX;
bit_sy[l1] = m_nAppY - 5;
bit_f[l1] = 2;
if(++k1 == bit_max)
{
break;
}
}

if(bit_sound > 1)
{
sound2.play();
}
return true;
}

public boolean mouseExit(Event event, int i, int j)
{
m_mouseX = i;
m_mouseY = j;
return true;
}

void rend()
{
boolean flag = false;
boolean flag1 = false;
boolean flag2 = false;
for(int i = 0; i < bits; i++)
{
switch(bit_f[i])
{
default:
break;

case 1: // '\001'
bit_vy[i] += rand.nextDouble() / 50D;
bit_px[i] += bit_vx[i];
bit_py[i] += bit_vy[i];
bit_l[i]--;
if(bit_l[i] == 0 || bit_px[i] < 0.0D || bit_py[i] < 0.0D || bit_px[i] > (double)m_nAppX || bit_py[i] > (double)(m_nAppY - 3))
{
bit_c[i] = 0xff000000;
bit_f[i] = 0;
} else
if(bit_p[i] == 0)
{
if((int)(rand.nextDouble() * 2D) == 0)
{
bit_set((int)bit_px[i], (int)bit_py[i], -1);
}
} else
{
bit_set((int)bit_px[i], (int)bit_py[i], bit_c[i]);
}
break;

case 2: // '\002'
bit_sy[i] -= 5;
if((double)bit_sy[i] <= bit_py[i])
{
bit_f[i] = 1;
flag2 = true;
}
if((int)(rand.nextDouble() * 20D) == 0)
{
int j = (int)(rand.nextDouble() * 2D);
int k = (int)(rand.nextDouble() * 5D);
bit_set(bit_sx[i] + j, bit_sy[i] + k, -1);
}
break;
}
}

if(flag2 && bit_sound > 0)
{
sound1.play();
}
}

void bit_set(int i, int j, int k)
{
int l = i + j * m_nAppX;
pix0[l] = k;
}
}
 
  相关解决方案