当前位置:首页 » 操作系统 » 积分游戏源码

积分游戏源码

发布时间: 2022-05-23 20:34:59

❶ 急需一份俄罗斯方块源代码,java写的

使用Java实现小游戏:俄罗斯方块
使用一个二维数组保存游戏的地图:
//游戏地图格子,每个格子保存一个方块,数组纪录方块的状态
privateStatemap[][]=newState[rows][columns];123
游戏前先将所有地图中的格子初始化为空:
/*初始化所有的方块为空*/
for(inti=0;i<map.length;i++){
for(intj=0;j<map[i].length;j++){
map[i][j]=State.EMPTY;
}
}1234567
玩游戏过程中,我们能够看到界面上的方块,那么就得将地图中所有的方块绘制出来,当然,除了需要绘制方块外,游戏积分和游戏结束的字符串在必要的时候也需要绘制:
/**
*绘制窗体内容,包括游戏方块,游戏积分或结束字符串
*/
@Override
publicvoidpaint(Graphicsg){
super.paint(g);
for(inti=0;i<rows;i++){
for(intj=0;j<columns;j++){
if(map[i][j]==State.ACTIVE){//绘制活动块
g.setColor(activeColor);
g.fillRoundRect(j*BLOCK_SIZE,i*BLOCK_SIZE+25,
BLOCK_SIZE-1,BLOCK_SIZE-1,BLOCK_SIZE/5,
BLOCK_SIZE/5);
}elseif(map[i][j]==State.STOPED){//绘制静止块
g.setColor(stopedColor);
g.fillRoundRect(j*BLOCK_SIZE,i*BLOCK_SIZE+25,
BLOCK_SIZE-1,BLOCK_SIZE-1,BLOCK_SIZE/5,
BLOCK_SIZE/5);
}
}
}

/*打印得分*/
g.setColor(scoreColor);
g.setFont(newFont("TimesNewRoman",Font.BOLD,30));
g.drawString("SCORE:"+totalScore,5,70);

//游戏结束,打印结束字符串
if(!isGoingOn){
g.setColor(Color.RED);
g.setFont(newFont("TimesNewRoman",Font.BOLD,40));
g.drawString("GAMEOVER!",this.getWidth()/2-140,
this.getHeight()/2);
}
}
通过随机数的方式产生方块所组成的几种图形,一般七种图形:条形、田形、正7形、反7形、T形、Z形和反Z形,如生成条形:
map[0][randPos]=map[0][randPos-1]=map[0][randPos+1]
=map[0][randPos+2]=State.ACTIVE;123
生成图形后,实现下落的操作。如果遇到阻碍,则不能再继续下落:
isFall=true;//是否能够下落
//从当前行检查,如果遇到阻碍,则停止下落
for(inti=0;i<blockRows;i++){
for(intj=0;j<columns;j++){
//遍历到行中块为活动块,而下一行块为静止块,则遇到阻碍
if(map[rowIndex-i][j]==State.ACTIVE
&&map[rowIndex-i+1][j]==State.STOPED){
isFall=false;//停止下落
break;
}
}
if(!isFall)
break;
}123456789101112131415
如果未遇到阻碍,则下落的时候,方块图形整体向下移动一行:
//图形下落一行
for(inti=0;i<blockRows;i++){
for(intj=0;j<columns;j++){
if(map[rowIndex-i][j]==State.ACTIVE){//活动块向下移动一行
map[rowIndex-i][j]=State.EMPTY;//原活动块变成空块
map[rowIndex-i+1][j]=State.ACTIVE;//下一行块变成活动块
}
}
}12345678910
向左、向右方向移动时是类似的操作:
/**
*向左走
*/
privatevoidleft(){
//标记左边是否有阻碍
booleanhasBlock=false;

/*判断是否左边有阻碍*/
for(inti=0;i<blockRows;i++){
if(map[rowIndex-i][0]==State.ACTIVE){//判断左边是否为墙
hasBlock=true;
break;//有阻碍,不用再循环判断行
}else{
for(intj=1;j<columns;j++){//判断左边是否有其它块
if(map[rowIndex-i][j]==State.ACTIVE
&&map[rowIndex-i][j-1]==State.STOPED){
hasBlock=true;
break;//有阻碍,不用再循环判断列
}
}
if(hasBlock)
break;//有阻碍,不用再循环判断行
}
}

/*左边没有阻碍,则将图形向左移动一个块的距离*/
if(!hasBlock){
for(inti=0;i<blockRows;i++){
for(intj=1;j<columns;j++){
if(map[rowIndex-i][j]==State.ACTIVE){
map[rowIndex-i][j]=State.EMPTY;
map[rowIndex-i][j-1]=State.ACTIVE;
}
}
}

//重绘
repaint();
}
}3738394041
向下加速移动时,就是减小每次正常状态下落的时间间隔:
/**
*向下直走
*/
privatevoiddown(){
//标记可以加速下落
immediate=true;
}12345678
如何变换图形方向,这里仅使用了非常简单的方法来实现方向变换,当然可以有更优的算法实现方向变换操作,大家可以自己研究:
/**
*旋转方块图形
*/
privatevoidrotate(){
try{
if(shape==4){//方形,旋转前后是同一个形状
return;
}elseif(shape==0){//条状
//临时数组,放置旋转后图形
State[][]tmp=newState[4][4];
intstartColumn=0;
//找到图形开始的第一个方块位置
for(inti=0;i<columns;i++){
if(map[rowIndex][i]==State.ACTIVE){
startColumn=i;
break;
}
}
//查找旋转之后是否有阻碍,如果有阻碍,则不旋转
for(inti=0;i<4;i++){
for(intj=0;j<4;j++){
if(map[rowIndex-3+i][j+startColumn]==State.STOPED){
return;
}
}
}

if(map[rowIndex][startColumn+1]==State.ACTIVE){//横向条形,变换为竖立条形
for(inti=0;i<4;i++){
tmp[i][0]=State.ACTIVE;
for(intj=1;j<4;j++){
tmp[i][j]=State.EMPTY;
}
}
blockRows=4;
}else{//竖立条形,变换为横向条形
for(intj=0;j<4;j++){
tmp[3][j]=State.ACTIVE;
for(inti=0;i<3;i++){
tmp[i][j]=State.EMPTY;
}
}
blockRows=1;
}
//将原地图中图形修改为变换后图形
for(inti=0;i<4;i++){
for(intj=0;j<4;j++){
map[rowIndex-3+i][startColumn+j]=tmp[i][j];
}
}
}else{
//临时数组,放置旋转后图形
State[][]tmp=newState[3][3];
intstartColumn=columns;
//找到图形开始的第一个方块位置
for(intj=0;j<3;j++){
for(inti=0;i<columns;i++){
if(map[rowIndex-j][i]==State.ACTIVE){
startColumn=i<startColumn?i:startColumn;
}
}
}
//判断变换后是否会遇到阻碍
for(inti=0;i<3;i++){
for(intj=0;j<3;j++){
if(map[rowIndex-2+j][startColumn+2-i]==State.STOPED)
return;
}
}
//变换
for(inti=0;i<3;i++){
for(intj=0;j<3;j++){
tmp[2-j][i]=map[rowIndex-2+i][startColumn+j];
}
}
//将原地图中图形修改为变换后图形
for(inti=0;i<3;i++){
for(intj=0;j<3;j++){
map[rowIndex-2+i][startColumn+j]=tmp[i][j];
}
}

//重绘
repaint();
//重新修改行指针
for(inti=0;i<3;i++){
for(intj=0;j<3;j++){
if(map[rowIndex-i][startColumn+j]!=null
||map[rowIndex-i][startColumn+j]!=State.EMPTY){
rowIndex=rowIndex-i;
blockRows=3;
return;
}
}
}
}
}catch(Exceptione){
//遇到数组下标越界,说明不能变换图形形状,不作任何处理
}
}3738394
当图形下落遇到阻碍时停止,我们就需要判断这时是否有某一行或几行可以消除掉,这时可以先获取每行中方块的个数,然后再进行判断:
int[]blocksCount=newint[rows];//记录每行有方块的列数
inteliminateRows=0;//消除的行数
/*计算每行方块数量*/
for(inti=0;i<rows;i++){
blocksCount[i]=0;
for(intj=0;j<columns;j++){
if(map[i][j]==State.STOPED)
blocksCount[i]++;
}
}1234567891011
如果有满行的方块,则消除掉该行方块:
/*实现有满行的方块消除操作*/
for(inti=0;i<rows;i++){
if(blocksCount[i]==columns){
//清除一行
for(intm=i;m>=0;m--){
for(intn=0;n<columns;n++){
map[m][n]=(m==0)?State.EMPTY:map[m-1][n];
}
}
eliminateRows++;//记录消除行数
}
}12345678910111213
最后我们再重绘显示积分就可以了。
重复以上的生成图形、图形下落、左右下移动、判断消除行的操作,一个简单的俄罗斯方块就完成了。

❷ 有没有积分制管理源码出售

积分制源码有的,一般找正规的软件开发公司购买,有保障。会有专人对接。

Teamtoken员工钱包的创导者,是以激励为核心的企业管理软件云(SaaS),核心价值是为每个企业员工提供一个员工钱包,让每个员工有属于自己的积分账户、现金币账户、虚拟股账户、期权账户、企业年金账户等,实现管理员工在企业的数字资产.还提供了以激励为核心的应用生态,包括如团队协作软件、绩效管理软件、CRM软件等,这些软件也正是员工钱包的数据来源,让协作、绩效、销售等工作能实时体现对员工工作的认可,并奖励对应的积分、现金、股票或者期权等,让管理更具有激励效果。

❸ 推荐一些游戏源码网站

v3源码 。挺不错的。种类齐全,源码下载,学习娱乐 都可以

❹ 求java小程序源代码 在线等 急急急!!!

下面是俄罗斯方块游戏源代码
还没完,这代码太长了,我用我另一个号再粘上
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;
/**
* 游戏主类,继承自JFrame类,负责游戏的全局控制。
* 内含
* 1, 一个GameCanvas画布类的实例引用,
* 2, 一个保存当前活动块(ErsBlock)实例的引用,
* 3, 一个保存当前控制面板(ControlPanel)实例的引用;*/
public class ErsBlocksGame extends JFrame {
/**
* 每填满一行计多少分*/
public final static int PER_LINE_SCORE = 100;
/**
* 积多少分以后能升级*/
public final static int PER_LEVEL_SCORE = PER_LINE_SCORE * 20;
/**
* 最大级数是10级*/
public final static int MAX_LEVEL = 10;
/**
* 默认级数是5*/
public final static int DEFAULT_LEVEL = 5;

private GameCanvas canvas;
private ErsBlock block;
private boolean playing = false;
private ControlPanel ctrlPanel;

private JMenuBar bar = new JMenuBar();
private JMenu
mGame = new JMenu("游戏设置"),
mControl = new JMenu("游戏控制"),
mWindowStyle = new JMenu("窗口风格");
private JMenuItem
miNewGame = new JMenuItem("新游戏"),
miSetBlockColor = new JMenuItem("设置颜色 ..."),
miSetBackColor = new JMenuItem("设置底色 ..."),
miTurnHarder = new JMenuItem("提升等级"),
miTurnEasier = new JMenuItem("调底等级"),
miExit = new JMenuItem("退出"),

miPlay = new JMenuItem("开始游戏"),
miPause = new JMenuItem("暂停"),
miResume = new JMenuItem("继续");

private JCheckBoxMenuItem
miAsWindows = new JCheckBoxMenuItem("风格1"),
miAsMotif = new JCheckBoxMenuItem("风格2"),
miAsMetal = new JCheckBoxMenuItem("风格3", true);

/**
* 主游戏类的构造函数
* @param title String,窗口标题*/
public ErsBlocksGame(String title) {
super(title);
//this.setTitle("lskdf");
setSize(315, 392);
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
//获得屏幕的大小

setLocation((scrSize.width - getSize().width) / 2,
(scrSize.height - getSize().height) / 2);

createMenu();

Container container = getContentPane();
container.setLayout(new BorderLayout(6, 0));

canvas = new GameCanvas(20, 12);
ctrlPanel = new ControlPanel(this);

container.add(canvas, BorderLayout.CENTER);
container.add(ctrlPanel, BorderLayout.EAST);

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
JOptionPane about=new JOptionPane();
stopGame();
System.exit(0);
}
});
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ce) {
canvas.fanning();
}
});
show();
canvas.fanning();
}
// 游戏“复位”
public void reset() {
ctrlPanel.reset();
canvas.reset();
}
/**
* 判断游戏是否还在进行
* @return boolean, true-还在运行,false-已经停止*/
public boolean isPlaying() {
return playing;
}
/**
* 得到当前活动的块
* @return ErsBlock, 当前活动块的引用*/
public ErsBlock getCurBlock() {
return block;
}
/**
* 得到当前画布
* @return GameCanvas, 当前画布的引用 */
public GameCanvas getCanvas() {
return canvas;
}

/**
* 开始游戏*/
public void playGame() {
play();
ctrlPanel.setPlayButtonEnable(false);
miPlay.setEnabled(false);
ctrlPanel.requestFocus();
}
/**
* 游戏暂停*/
public void pauseGame() {
if (block != null) block.pauseMove();
ctrlPanel.setPauseButtonLabel(false);
miPause.setEnabled(false);
miResume.setEnabled(true);
}
/**
* 让暂停中的游戏继续*/
public void resumeGame() {
if (block != null) block.resumeMove();
ctrlPanel.setPauseButtonLabel(true);
miPause.setEnabled(true);
miResume.setEnabled(false);
ctrlPanel.requestFocus();
}
/**
* 用户停止游戏 */
public void stopGame() {
playing = false;
if (block != null) block.stopMove();
miPlay.setEnabled(true);
miPause.setEnabled(true);
miResume.setEnabled(false);
ctrlPanel.setPlayButtonEnable(true);
ctrlPanel.setPauseButtonLabel(true);
}
/**
* 得到当前游戏者设置的游戏难度
* @return int, 游戏难度1-MAX_LEVEL*/
public int getLevel() {
return ctrlPanel.getLevel();
}
/**
* 让用户设置游戏难度
* @param level int, 游戏难度1-MAX_LEVEL*/
public void setLevel(int level) {
if (level < 11 && level > 0) ctrlPanel.setLevel(level);
}
/**
* 得到游戏积分
* @return int, 积分。*/
public int getScore() {
if (canvas != null) return canvas.getScore();
return 0;
}
/**
* 得到自上次升级以来的游戏积分,升级以后,此积分清零
* @return int, 积分。*/
public int getScoreForLevelUpdate() {
if (canvas != null) return canvas.getScoreForLevelUpdate();
return 0;
}
/**
* 当分数累计到一定的数量时,升一次级
* @return boolean, ture-update successufl, false-update fail
*/
public boolean levelUpdate() {
int curLevel = getLevel();
if (curLevel < MAX_LEVEL) {
setLevel(curLevel + 1);
canvas.resetScoreForLevelUpdate();
return true;
}
return false;
}
/**
* 游戏开始*/
private void play() {
reset();
playing = true;
Thread thread = new Thread(new Game());
thread.start();
}

/**
* 报告游戏结束了*/
private void reportGameOver() {
JOptionPane.showMessageDialog(this, "游戏结束!");
}
/**
* 建立并设置窗口菜单 */
private void createMenu() {
bar.add(mGame);
bar.add(mControl);
bar.add(mWindowStyle);

mGame.add(miNewGame);
mGame.addSeparator();
mGame.add(miSetBlockColor);
mGame.add(miSetBackColor);
mGame.addSeparator();
mGame.add(miTurnHarder);
mGame.add(miTurnEasier);
mGame.addSeparator();
mGame.add(miExit);

mControl.add(miPlay);
mControl.add(miPause);
mControl.add(miResume);

mWindowStyle.add(miAsWindows);
mWindowStyle.add(miAsMotif);
mWindowStyle.add(miAsMetal);

setJMenuBar(bar);

miPause.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK));
miResume.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));

miNewGame.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
stopGame();
reset();
setLevel(DEFAULT_LEVEL);
}
});
miSetBlockColor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Color newFrontColor =
JColorChooser.showDialog(ErsBlocksGame.this,
"设置积木颜色", canvas.getBlockColor());
if (newFrontColor != null)
canvas.setBlockColor(newFrontColor);
}
});
miSetBackColor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Color newBackColor =
JColorChooser.showDialog(ErsBlocksGame.this,
"设置底版颜色", canvas.getBackgroundColor());
if (newBackColor != null)
canvas.setBackgroundColor(newBackColor);
}
});
miTurnHarder.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int curLevel = getLevel();
if (curLevel < MAX_LEVEL) setLevel(curLevel + 1);
}
});
miTurnEasier.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int curLevel = getLevel();
if (curLevel > 1) setLevel(curLevel - 1);
}
});
miExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
});
miPlay.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
playGame();
}
});
miPause.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
pauseGame();
}
});
miResume.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
resumeGame();
}
});

miAsWindows.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
ctrlPanel.fanning();
miAsWindows.setState(true);
miAsMetal.setState(false);
miAsMotif.setState(false);
}
});
miAsMotif.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
ctrlPanel.fanning();
miAsWindows.setState(false);
miAsMetal.setState(false);
miAsMotif.setState(true);
}
});
miAsMetal.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
setWindowStyle(plaf);
canvas.fanning();
ctrlPanel.fanning();
miAsWindows.setState(false);
miAsMetal.setState(true);
miAsMotif.setState(false);
}
});
}
/**
* 根据字串设置窗口外观
* @param plaf String, 窗口外观的描述
*/
private void setWindowStyle(String plaf) {
try {
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
}
}
/**
* 一轮游戏过程,实现了Runnable接口
* 一轮游戏是一个大循环,在这个循环中,每隔100毫秒,
* 检查游戏中的当前块是否已经到底了,如果没有,
* 就继续等待。如果到底了,就看有没有全填满的行,
* 如果有就删除它,并为游戏者加分,同时随机产生一个
* 新的当前块,让它自动下落。
* 当新产生一个块时,先检查画布最顶上的一行是否已经
* 被占了,如果是,可以判断Game Over了。*/
private class Game implements Runnable {
public void run() {
//产生新方快
int col = (int) (Math.random() * (canvas.getCols() - 3)),
style = ErsBlock.STYLES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];
while (playing) {
if (block != null) { //第一次循环时,block为空
if (block.isAlive()) {
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
continue;
}
}
checkFullLine(); //检查是否有全填满的行
if (isGameOver()) { //检查游戏是否应该结束了
miPlay.setEnabled(true);
miPause.setEnabled(true);
miResume.setEnabled(false);
ctrlPanel.setPlayButtonEnable(true);
ctrlPanel.setPauseButtonLabel(true);

reportGameOver();
return;
}
block = new ErsBlock(style, -1, col, getLevel(), canvas);
block.start();

col = (int) (Math.random() * (canvas.getCols() - 3));
style = ErsBlock.STYLES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];

ctrlPanel.setTipStyle(style);
}
}
/**
* 检查画布中是否有全填满的行,如果有就删除之*/
public void checkFullLine() {
for (int i = 0; i < canvas.getRows(); i++) {
int row = -1;
boolean fullLineColorBox = true;
for (int j = 0; j < canvas.getCols(); j++) {
if (!canvas.getBox(i, j).isColorBox()) {
fullLineColorBox = false;
break;
}
}
if (fullLineColorBox) {
row = i--;
canvas.removeLine(row);
}
}
}

/**
* 根据最顶行是否被占,判断游戏是否已经结束了。
* @return boolean, true-游戏结束了,false-游戏未结束*/
private boolean isGameOver() {
for (int i = 0; i < canvas.getCols(); i++) {
ErsBox box = canvas.getBox(0, i);
if (box.isColorBox()) return true;
}
return false;
}
}

❺ 积分游戏有什么

QQ游戏中的游戏积分是QQ游戏中使用的虚拟游戏数据,可以在游戏中用来在部分游戏场次中作为计量单位,以增加游戏乐趣,是玩家级别的一种体现方式。因此,您可以在不断升高积分的过程中享受我们游戏的乐趣、结识更多的朋友、提高千姿百态的游戏技巧。温馨提示:积分是游戏中的计量单位,是不能进行兑换的。

❻ 求html5 接金币游戏源码,手机网页版。

http://www.7k7k.com/swf/139070.htm

❼ C#小游戏的积分问题

假定4个玩家的积分均放在数组money中,即有

int[]money=newint[]{20,20,20,20};

每一局的选择同样为int[]sel=newint[4];

同样每局赌注为int[]wager=newwager[4];


这样假定你一局算出来的马序号为1-3,存在intwinner中,比如

intwinner=3;
for(inti=0;i<sel.Length;i++)
{
if(sel[i]==winner)//胜
{
money[i]+=wager[i];//加分
}
else//负
{
money[i]-=wager[i];//减分
}
console.WriteLine("玩家{0},分数为{1}",i+1,money[i]);//输出结果
}

在注意一下,在投注要判断一下玩家投注值是不是超过它当前的money分数值。

❽ 求C#单击小游戏源代码

我原来用写过一个五子棋的小程序,可惜现在人在外地出差,源码在家里的电脑上面。
不过我推荐你一个网站,上面有好多源码,其中也包括一些小游戏的源码,最重要的是下载不需要积分的。
http://51aspx.com/
这个是我在该站点搜索“游戏”关键字查询出来的结果,希望可以找到你喜欢的小游戏。
http://51aspx.com/S/%E6%B8%B8%E6%88%8F.html

❾ 游程编码源代码

这个...........楼上的诸位说的都是什么啊。今天刚好看到这个问题,把你的E-mail给我把,我有纯c的源码(RLC)。

算了,直接贴关键部分吧。这个有一点C++成分,很容易改的。
bool CompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen, int nBitsPerSample, void* nRuns, int nRunCount, int nRunSize);
bool DecompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen);

#define GetDWORD(buf,bit,mask) ((*(DWORD*)(((BYTE*)buf)+((bit)>>3)))>>((bit)&7)&(mask))
#define GetWORD(buf,bit,mask) ((*(WORD*)(((BYTE*)buf)+((bit)>>3)))>>((bit)&7)&(mask))

int GetBitCount(int n)
{
int nBitCount = 0;
while(n)
n >>= 1, nBitCount++;
return nBitCount;
}

int BinarySearch(void* pValue, int nVlaueSize, void* pArray, int nCount)
{
int nIndex, nResult, nStart = 0, nEnd = nCount-1;
while(nStart <= nEnd)
{
nIndex = (nEnd+nStart)/2;
if((nResult = memcmp((BYTE*)pArray+nIndex*nVlaueSize, pValue, nVlaueSize)) == 0)
return nIndex;
if(nResult > 0)
nEnd = nIndex-1;
else
nStart = nIndex+1;
}
return -1;
}

bool CompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen, int nBitsPerSample, void* nRuns, int nRunCount, int nRunSize)
{
pDes = (BYTE*)malloc(nSrcLen*2);
memset(pDes, 0, nSrcLen*2);

nDesLen = sizeof(DWORD);
*(DWORD*)pDes = nSrcLen; // save source length
*(pDes+nDesLen++) = nBitsPerSample; // save bits per sample
*(pDes+nDesLen++) = nRunCount; // save runs count
*(pDes+nDesLen++) = nRunSize; // save run bytes
memcpy(pDes+nDesLen, nRuns, nRunCount*nRunSize); // save runs
nDesLen += nRunCount*nRunSize;
nDesLen <<= 3; // bytes to bits
if(nRunCount == 0)
nRunCount = 256, nRunSize = 1, nRuns = NULL;

int nBitsPerTypeIndex = GetBitCount(nRunCount-1);
int nMaxRunLength = (1 << nBitsPerSample)-1, nRunLength, nRunIndex, nByte = 0;
// loop in the source buffer
while(nByte < nSrcLen)
if((nRuns && (nRunIndex = BinarySearch(pSrc+nByte, nRunSize, nRuns, nRunCount)) != -1 &&
memcmp(pSrc+nByte+nRunSize, (BYTE*)nRuns+nRunIndex*nRunSize, nRunSize) == 0) ||
(!nRuns && (nRunIndex = *(pSrc+nByte)) == *(pSrc+nByte+1)))
{ // set bit to 1 to indicate type found
*(pDes+(nDesLen>>3)) |= 1 << (nDesLen&7);
*(DWORD*)(pDes+(++nDesLen>>3)) |= nRunIndex << (nDesLen&7);
nDesLen += nBitsPerTypeIndex;
// skip the two repeated runs
nByte += nRunSize*2;
// get run length - 2 (without the two repeated runs)
nRunLength = 0;
while(nRunLength < nMaxRunLength && nByte < nSrcLen &&
((nRuns && memcmp(pSrc+nByte, (BYTE*)nRuns+nRunIndex*nRunSize, nRunSize) == 0) || (!nRuns && (BYTE)nRunIndex == *(pSrc+nByte))))
nRunLength++, nByte += nRunSize;
// save run length and increment destination length by bits per sample
*(DWORD*)(pDes+(nDesLen>>3)) |= nRunLength << (nDesLen&7);
nDesLen += nBitsPerSample;
}
else // one byte
*(WORD*)(pDes+(++nDesLen>>3)) |= *(pSrc+nByte++) << (nDesLen&7), nDesLen += 8;
nDesLen = (nDesLen+7)/8; // bits to bytes
pDes = (BYTE*)realloc(pDes, nDesLen);

return true;
}

bool DecompressRunLength(BYTE *pSrc, int nSrcLen, BYTE *&pDes, int &nDesLen)
{
if(nSrcLen == 0)
return true;

// allocate destination buffer
nDesLen = *(DWORD*)pSrc;
pDes = (BYTE*)malloc(nDesLen);
memset(pDes, 0, nDesLen);

// compression information
int nSrcIndex = sizeof(DWORD);
int nBitsPerSample = *(pSrc+nSrcIndex++);
int nRunCount = *(pSrc+nSrcIndex++);
int nRunSize = *(pSrc+nSrcIndex++);
void* nRuns = pSrc+nSrcIndex;
nSrcIndex += nRunSize*nRunCount;
nSrcIndex <<= 3; // bytes to bits
if(nRunCount == 0)
nRunCount = 256, nRunSize = 1, nRuns = NULL;

int nBitsPerTypeIndex = GetBitCount(nRunCount-1);
int nMaxTypeIndex = (1 << nBitsPerTypeIndex)-1;
int nMaxRunLength = (1 << nBitsPerSample)-1;
int nDesIndex = 0, nRunLength, nRunIndex, nRun, nByte;

nSrcLen <<= 3; // bytes to bits
while(nSrcIndex < nSrcLen-8)
if((*(pSrc+(nSrcIndex>>3)) >> (nSrcIndex++&7)) & 1)
{
nRunIndex = GetDWORD(pSrc, nSrcIndex, nMaxTypeIndex), nSrcIndex += nBitsPerTypeIndex;
nRunLength = GetDWORD(pSrc, nSrcIndex, nMaxRunLength)+2, nSrcIndex += nBitsPerSample;
for(nRun = 0; nRun < nRunLength; nRun++)
for(nByte = 0; nByte < nRunSize; nByte++, nDesIndex += 8)
*(WORD*)(pDes+(nDesIndex>>3)) |= nRuns ? GetWORD(nRuns+nRunSize*nRunIndex, nByte<<3, 0xff) : (BYTE)nRunIndex;
}
else // one byte
*(WORD*)(pDes+(nDesIndex>>3)) |= GetWORD(pSrc, nSrcIndex, 0xff), nDesIndex += 8, nSrcIndex += 8;

return true;
}

❿ 积分商城系统源码谁有好的推荐

功能上要比较完善

热点内容
wincc中c脚本编译后有错误 发布:2024-10-26 17:25:01 浏览:746
获取了ip怎么进他的服务器 发布:2024-10-26 17:17:17 浏览:493
存储的反应 发布:2024-10-26 17:08:39 浏览:442
sql三张表查询 发布:2024-10-26 17:05:23 浏览:344
怎么看电脑wifi密码是多少 发布:2024-10-26 17:00:10 浏览:325
上传gif不会动 发布:2024-10-26 16:59:55 浏览:13
volte手机如何解锁密码 发布:2024-10-26 16:54:04 浏览:105
如何将安卓手机刷为蜂巢系统 发布:2024-10-26 16:43:44 浏览:831
androidnetcfg 发布:2024-10-26 16:42:40 浏览:929
imageloaderandroid 发布:2024-10-26 16:41:14 浏览:778