當前位置:首頁 » 操作系統 » 積分游戲源碼

積分游戲源碼

發布時間: 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;
}

❿ 積分商城系統源碼誰有好的推薦

功能上要比較完善

熱點內容
微信猜拳演算法 發布:2024-10-26 19:23:35 瀏覽:389
android編譯第三方庫 發布:2024-10-26 19:14:20 瀏覽:614
蘋果手機怎麼用藍牙傳照片給安卓 發布:2024-10-26 18:57:40 瀏覽:614
ios8程序加密 發布:2024-10-26 18:30:27 瀏覽:532
密碼門鎖沒電了用什麼數據線 發布:2024-10-26 18:21:11 瀏覽:854
linuxloop 發布:2024-10-26 18:20:46 瀏覽:931
linuxvg查看 發布:2024-10-26 18:09:51 瀏覽:585
圖標是鑰匙的加密軟體 發布:2024-10-26 18:07:31 瀏覽:625
vip七九寶琉璃怎麼配置魂環 發布:2024-10-26 17:51:17 瀏覽:571
opencv編譯linux 發布:2024-10-26 17:49:50 瀏覽:983