蘋果游戲源碼
Ⅰ 用C++編寫的小游戲源代碼
五子棋的代碼:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
using namespace std;
const int N=15; //15*15的棋盤
const char ChessBoardflag = ' '; //棋盤標志
const char flag1='o'; //玩家1或電腦的棋子標志
const char flag2='X'; //玩家2的棋子標志
typedef struct Coordinate //坐標類
{
int x; //代錶行
int y; //代表列
}Coordinate;
class GoBang //五子棋類
{
public:
GoBang() //初始化
{
InitChessBoard();
}
void Play() //下棋
{
Coordinate Pos1; // 玩家1或電腦
Coordinate Pos2; //玩家2
int n = 0;
while (1)
{
int mode = ChoiceMode();
while (1)
{
if (mode == 1) //電腦vs玩家
{
ComputerChess(Pos1,flag1); // 電腦下棋
if (GetVictory(Pos1, 0, flag1) == 1) //0表示電腦,真表示獲勝
break;
PlayChess(Pos2, 2, flag2); //玩家2下棋
if (GetVictory(Pos2, 2, flag2)) //2表示玩家2
break;
}
else //玩家1vs玩家2
{
PlayChess(Pos1, 1, flag1); // 玩家1下棋
if (GetVictory(Pos1, 1, flag1)) //1表示玩家1
break;
PlayChess(Pos2, 2, flag2); //玩家2下棋
if (GetVictory(Pos2, 2, flag2)) //2表示玩家2
break;
}
}
cout << "***再來一局***" << endl;
cout << "y or n :";
char c = 'y';
cin >> c;
if (c == 'n')
break;
}
}
protected:
int ChoiceMode() //選擇模式
{
int i = 0;
system("cls"); //系統調用,清屏
InitChessBoard(); //重新初始化棋盤
cout << "***0、退出 1、電腦vs玩家 2、玩家vs玩家***" << endl;
while (1)
{
cout << "請選擇:";
cin >> i;
if (i == 0) //選擇0退出
exit(1);
if (i == 1 || i == 2)
return i;
cout << "輸入不合法" << endl;
}
}
void InitChessBoard() //初始化棋盤
{
for (int i = 0; i < N + 1; ++i)
{
for (int j = 0; j < N + 1; ++j)
{
_ChessBoard[i][j] = ChessBoardflag;
}
}
}
void PrintChessBoard() //列印棋盤,這個函數可以自己調整
{
system("cls"); //系統調用,清空屏幕
for (int i = 0; i < N+1; ++i)
{
for (int j = 0; j < N+1; ++j)
{
if (i == 0) //列印列數字
{
if (j!=0)
printf("%d ", j);
else
printf(" ");
}
else if (j == 0) //列印行數字
printf("%2d ", i);
else
{
if (i < N+1)
{
printf("%c |",_ChessBoard[i][j]);
}
}
}
cout << endl;
cout << " ";
for (int m = 0; m < N; m++)
{
printf("--|");
}
cout << endl;
}
}
void PlayChess(Coordinate& pos, int player, int flag) //玩家下棋
{
PrintChessBoard(); //列印棋盤
while (1)
{
printf("玩家%d輸入坐標:", player);
cin >> pos.x >> pos.y;
if (JudgeValue(pos) == 1) //坐標合法
break;
cout << "坐標不合法,重新輸入" << endl;
}
_ChessBoard[pos.x][pos.y] = flag;
}
void ComputerChess(Coordinate& pos, char flag) //電腦下棋
{
PrintChessBoard(); //列印棋盤
int x = 0;
int y = 0;
while (1)
{
x = (rand() % N) + 1; //產生1~N的隨機數
srand((unsigned int) time(NULL));
y = (rand() % N) + 1; //產生1~N的隨機數
srand((unsigned int) time(NULL));
if (_ChessBoard[x][y] == ChessBoardflag) //如果這個位置是空的,也就是沒有棋子
break;
}
pos.x = x;
pos.y = y;
_ChessBoard[pos.x][pos.y] = flag;
}
int JudgeValue(const Coordinate& pos) //判斷輸入坐標是不是合法
{
if (pos.x > 0 && pos.x <= N&&pos.y > 0 && pos.y <= N)
{
if (_ChessBoard[pos.x][pos.y] == ChessBoardflag)
{
return 1; //合法
}
}
return 0; //非法
}
int JudgeVictory(Coordinate pos, char flag) //判斷有沒有人勝負(底層判斷)
{
int begin = 0;
int end = 0;
int begin1 = 0;
int end1 = 0;
//判斷行是否滿足條件
(pos.y - 4) > 0 ? begin = (pos.y - 4) : begin = 1;
(pos.y + 4) >N ? end = N : end = (pos.y + 4);
for (int i = pos.x, j = begin; j + 4 <= end; j++)
{
if (_ChessBoard[i][j] == flag&&_ChessBoard[i][j + 1] == flag&&
_ChessBoard[i][j + 2] == flag&&_ChessBoard[i][j + 3] == flag&&
_ChessBoard[i][j + 4] == flag)
return 1;
}
//判斷列是否滿足條件
(pos.x - 4) > 0 ? begin = (pos.x - 4) : begin = 1;
(pos.x + 4) > N ? end = N : end = (pos.x + 4);
for (int j = pos.y, i = begin; i + 4 <= end; i++)
{
if (_ChessBoard[i][j] == flag&&_ChessBoard[i + 1][j] == flag&&
_ChessBoard[i + 2][j] == flag&&_ChessBoard[i + 3][j] == flag&&
_ChessBoard[i + 4][j] == flag)
return 1;
}
int len = 0;
//判斷主對角線是否滿足條件
pos.x > pos.y ? len = pos.y - 1 : len = pos.x - 1;
if (len > 4)
len = 4;
begin = pos.x - len; //橫坐標的起始位置
begin1 = pos.y - len; //縱坐標的起始位置
pos.x > pos.y ? len = (N - pos.x) : len = (N - pos.y);
if (len>4)
len = 4;
end = pos.x + len; //橫坐標的結束位置
end1 = pos.y + len; //縱坐標的結束位置
for (int i = begin, j = begin1; (i + 4 <= end) && (j + 4 <= end1); ++i, ++j)
{
if (_ChessBoard[i][j] == flag&&_ChessBoard[i + 1][j + 1] == flag&&
_ChessBoard[i + 2][j + 2] == flag&&_ChessBoard[i + 3][j + 3] == flag&&
_ChessBoard[i + 4][j + 4] == flag)
return 1;
}
//判斷副對角線是否滿足條件
(pos.x - 1) >(N - pos.y) ? len = (N - pos.y) : len = pos.x - 1;
if (len > 4)
len = 4;
begin = pos.x - len; //橫坐標的起始位置
begin1 = pos.y + len; //縱坐標的起始位置
(N - pos.x) > (pos.y - 1) ? len = (pos.y - 1) : len = (N - pos.x);
if (len>4)
len = 4;
end = pos.x + len; //橫坐標的結束位置
end1 = pos.y - len; //縱坐標的結束位置
for (int i = begin, j = begin1; (i + 4 <= end) && (j - 4 >= end1); ++i, --j)
{
if (_ChessBoard[i][j] == flag&&_ChessBoard[i + 1][j - 1] == flag&&
_ChessBoard[i + 2][j - 2] == flag&&_ChessBoard[i + 3][j - 3] == flag&&
_ChessBoard[i + 4][j - 4] == flag)
return 1;
}
for (int i = 1; i < N + 1; ++i) //棋盤有沒有下滿
{
for (int j =1; j < N + 1; ++j)
{
if (_ChessBoard[i][j] == ChessBoardflag)
return 0; //0表示棋盤沒滿
}
}
return -1; //和棋
}
bool GetVictory(Coordinate& pos, int player, int flag) //對JudgeVictory的一層封裝,得到具體那個玩家獲勝
{
int n = JudgeVictory(pos, flag); //判斷有沒有人獲勝
if (n != 0) //有人獲勝,0表示沒有人獲勝
{
PrintChessBoard();
if (n == 1) //有玩家贏棋
{
if (player == 0) //0表示電腦獲勝,1表示玩家1,2表示玩家2
printf("***電腦獲勝*** ");
else
printf("***恭喜玩家%d獲勝*** ", player);
}
else
printf("***雙方和棋*** ");
return true; //已經有人獲勝
}
return false; //沒有人獲勝
}
private:
char _ChessBoard[N+1][N+1];
};
(1)蘋果游戲源碼擴展閱讀:
設計思路
1、進行問題分析與設計,計劃實現的功能為,開局選擇人機或雙人對戰,確定之後比賽開始。
2、比賽結束後初始化棋盤,詢問是否繼續比賽或退出,後續可加入復盤、悔棋等功能。
3、整個過程中,涉及到了棋子和棋盤兩種對象,同時要加上人機對弈時的AI對象,即涉及到三個對象。
Ⅱ c語言小游戲代碼
「貪吃蛇」C代碼,在dev C++試驗通過(用4個方向鍵控制)
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <Windows.h>
#define W 78 //游戲框的寬,x軸
#define H 26 //游戲框的高,y軸
int dir=3; //方向變數,初值3表示向「左」
int Flag=0; //吃了食物的標志(1是0否)
int score=0; //玩家得分
struct food{ int x; //食物的x坐標
int y; //食物的y坐標
}fod; //結構體fod有2個成員
struct snake{ int len; //蛇身長
int speed; //移動速度
int x[100]; //蛇身某節x坐標
int y[100]; //蛇身某節y坐標
}snk; //結構體snk有4個成員
void gtxy( int x,int y) //控制游標移動的函數
{ COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void gtxy( int x,int y); //以下聲明要用到的幾個自編函數
void csh( ); //初始化界面
void keymove( ); //按鍵操作移動蛇
void putFod( ); //投放食物
int Over( ); //游戲結束(1是0否)
void Color(int a); //設定顯示顏色的函數
int main( ) //主函數
{ csh( );
while(1)
{ Sleep(snk.speed);
keymove( );
putFod( );
if(Over( ))
{ system(「cls」);
gtxy(W/2+1,H/2); printf(「游戲結束!T__T」);
gtxy(W/2+1,H/2+2); printf(「玩家總分:%d分」,score);
getch( );
break;
}
}
return 0;
}
void csh( ) //初始化界面
{ int i;
gtxy(0,0);
CONSOLE_CURSOR_INFO cursor_info={1,0}; //以下兩行是隱藏游標的設置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
for(i=0;i<=W;i=i+2) //橫坐標要為偶數,因為這個要列印的字元佔2個位置
{Color(2); //設定列印顏色為綠色
gtxy(i,0); printf("■"); //列印上邊框
gtxy(i,H); printf("■"); //列印下邊框
}
for(i=1;i<H;i++)
{ gtxy(0,i); printf("■"); //列印左邊框
gtxy(W,i); printf("■"); //列印右邊框
}
while(1)
{ srand((unsigned)time(NULL)); //初始化隨機數發生器srand( )
fod.x=rand()%(W-4)+2; //隨機函數rand( )產生一個從0到比」(W-4)」小1的數再加2
fod.y=rand()%(H-2)+1; //隨機函數rand( )產生一個從0到比」(H-2)」小1的數再加1
if (fod.x%2==0) break; //fod.x是食物的橫坐標,要是2的倍數(為偶數)
}
Color(12); //設定列印顏色為淡紅
gtxy(fod.x,fod.y); printf("●"); //到食物坐標處列印初試食物
snk.len=3; //蛇身長初值為3節
snk.speed=350; //刷新蛇的時間,即移動速度初值為350毫秒
snk.x[0]=W/2+1; //蛇頭橫坐標要為偶數(因為W/2=39)
snk.y[0]=H/2; //蛇頭縱坐標
Color(9); //設定列印顏色為淡藍
gtxy(snk.x[0], snk.y[0]); printf("■"); //列印蛇頭
for(i=1;i<snk.len;i++)
{ snk.x[i]=snk.x[i-1]+2; snk.y[i]=snk.y[i-1];
gtxy(snk.x[i],snk.y[i]); printf("■"); //列印蛇身
}
Color(7, 0); //恢復默認的白字黑底
return;
}
void keymove( ) //按鍵操作移動蛇
{ int key;
if( kbhit( ) ) //如有按鍵輸入才執行下面操作
{ key=getch( );
if (key==224) //值為224表示按下了方向鍵,下面要再次獲取鍵值
{ key=getch( );
if(key==72&&dir!=2)dir=1; //72表示按下了向上方向鍵
if(key==80&&dir!=1)dir=2; //80為向下
if(key==75&&dir!=4)dir=3; //75為向左
if(key==77&&dir!=3)dir=4; //77為向右
}
if (key==32)
{ while(1) if((key=getch( ))==32) break; } //32為空格鍵,這兒用來暫停
}
if (Flag==0) //如沒吃食物,才執行下面操作擦掉蛇尾
{ gtxy(snk.x[snk.len-1],snk.y[snk.len-1]); printf(" "); }
int i;
for (i = snk.len - 1; i > 0; i--) //從蛇尾起每節存儲前一節坐標值(蛇頭除外)
{ snk.x[i]=snk.x[i-1]; snk.y[i]=snk.y[i-1]; }
switch (dir) //判斷蛇頭該往哪個方向移動,並獲取最新坐標值
{ case 1: snk.y[0]--; break; //dir=1要向上移動
case 2: snk.y[0]++; break; //dir=2要向下移動
case 3: snk.x[0]-=2; break; //dir=3要向左移動
case 4: snk.x[0]+=2; break; //dir=4要向右移動
}
Color(9);
gtxy(snk.x[0], snk.y[0]); printf("■"); //列印蛇頭
if (snk.x[0] == fod.x && snk.y[0] == fod.y) //如吃到食物則執行以下操作
{ printf("7"); snk.len++; score += 100; snk.speed -= 5; Flag = 1; } //7是響鈴
else Flag = 0; //沒吃到食物Flag的值為0
if(snk.speed<150) snk.speed= snk.speed+5; //作弊碼,不讓速度無限加快
}
void putFod( ) //投放食物
{ if (Flag == 1) //如吃到食物才執行以下操作,生成另一個食物
{ while (1)
{ int i,n= 1;
srand((unsigned)time(NULL)); //初始化隨機數發生器srand( )
fod.x = rand( ) % (W - 4) + 2; //產生在游戲框范圍內的一個x坐標值
fod.y = rand( ) % (H - 2) + 1; //產生在游戲框范圍內的一個y坐標值
for (i = 0; i < snk.len; i++) //隨機生成的食物不能在蛇的身體上
{ if (fod.x == snk.x[i] &&fod.y == snk.y[i]) { n= 0; break;} }
if (n && fod.x % 2 == 0) break; //n不為0且橫坐標為偶數,則食物坐標取值成功
}
Color(12); //設定字元為紅色
gtxy(fod.x, fod.y); printf("●"); //游標到取得的坐標處列印食物
}
return;
}
int Over( ) //判斷游戲是否結束的函數
{ int i;
Color(7);
gtxy(2,H+1); printf(「暫停鍵:space.」); //以下列印一些其它信息
gtxy(2,H+2); printf(「游戲得分:%d」,score);
if (snk.x[0] == 0 || snk.x[0] == W) return 1; //蛇頭觸碰左右邊界
if (snk.y[0] == 0 || snk.y[0] == H) return 1; //蛇頭觸碰上下邊界
for (i = 1; i < snk.len; i++)
{ if (snk.x[0] == snk.x[i] && snk.y[0] == snk.y[i]) return 1; } //蛇頭觸碰自身
return 0; //沒碰到邊界及自身時就返回0
}
void Color(int a) //設定顏色的函數
{ SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ),a ); }
Ⅲ vb 金山打字拯救蘋果 游戲的源代碼查看,可以發到我的郵箱里:[email protected].謝謝!
好像是......521541吧,我不太確定,不過,還是試試吧(*^__^*)嘻嘻……
Ⅳ 如何查看手機游戲的源代碼
你好,首先要有X管理器然後Mobile C(編程),用X打開游戲內部,然後復制出來,再用C打開。這種方式僅限於C語言基礎,若想完全弄懂可以上論壇看專帖,謝謝
騰訊電腦管家企業平台:http://..com/c/guanjia/
Ⅳ 誰能給我一個手機游戲的源代碼啊
這個地址也有,不過直接給你吧,這樣比較好
先給你看看主要的類吧
package Game;
import DreamBubbleMidlet;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.lci.Graphics;
import javax.microedition.lci.Image;
import javax.microedition.lci.game.GameCanvas;
import javax.microedition.lci.game.LayerManager;
import javax.microedition.lci.game.Sprite;
public class Game extends GameCanvas implements Runnable {
protected DreamBubbleMidlet dreamBubbleMidlet;
protected Graphics g;
protected Image loadingImage;
protected Image pauseImage;
protected Image cursorImage;
protected Image jackStateImage;
protected Image johnStateImage;
protected Image numberImage;
protected Sprite cursor;
protected Sprite number;
protected LayerManager cursorManager;
protected LayerManager numberManager;
protected Hashtable bombTable;
protected Map map;
protected LayerManager gameLayerManager;
protected Role player;
protected Sprite playerGhost;
protected int screenWidth;
protected int screenHeight;
protected int delay = 50;
protected int[][] bornPlace;
protected int chooseIndex;
protected int stageIndex = 1;
protected int gameClock;
protected int loadPercent;
protected boolean isPause;
protected boolean isEnd;
protected boolean isPlaying;
protected boolean isLoading;
protected Thread mainThread;
public Game(DreamBubbleMidlet dreamBubbleMidlet) {
super(false);
this.setFullScreenMode(true);
this.dreamBubbleMidlet = dreamBubbleMidlet;
this.screenWidth = this.getWidth();
this.screenHeight = this.getHeight();
try {
this.loadingImage = Image.createImage("/Game/Loading.png");
this.pauseImage = Image.createImage("/Game/Pause.png");
this.cursorImage = Image.createImage("/Game/Cursor.png");
this.jackStateImage = Image.createImage("/State/JackState.png");
this.johnStateImage = Image.createImage("/State/JohnState.png");
this.numberImage = Image.createImage("/State/Number.png");
} catch (IOException e) {
e.printStackTrace();
}
this.g = this.getGraphics();
}
public void loadStage(int stage) {
this.isEnd = false;
this.isPause = false;
this.isPlaying = false;
this.gameLayerManager = new LayerManager();
this.cursorManager = new LayerManager();
this.numberManager = new LayerManager();
this.bombTable = new Hashtable();
this.cursor = new Sprite(this.cursorImage, 32, 32);
this.number = new Sprite(this.numberImage, 12, 10);
this.loadPercent = 20;
sleep();
loadMap(stage);
this.loadPercent = 40;
sleep();
loadPlayer();
this.loadPercent = 60;
sleep();
this.gameLayerManager.append(map.getBombLayer());
this.gameLayerManager.append(map.getBuildLayer());
this.gameLayerManager.append(map.getToolLayer());
this.gameLayerManager.append(map.getFloorLayer());
this.gameLayerManager.setViewWindow(0, -5, screenWidth,
Global.MAP_HEIGHT + 5);
this.cursorManager.append(cursor);
this.numberManager.append(number);
this.loadPercent = 80;
sleep();
this.loadPercent = 100;
sleep();
isPlaying = true;
}
public void run() {
while (!isEnd) {
long beginTime = System.currentTimeMillis();
this.drawScreen();
long endTime = System.currentTimeMillis();
if (endTime - beginTime < this.delay) {
try {
Thread.sleep(this.delay - (endTime - beginTime));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public void loadMap(int stage) {
switch (stage) {
case 0:
this.map = new Map(Global.MAP_BLOCK);
this.bornPlace = Global.MAP_BLOCK_BORNPLACE;
break;
case 1:
this.map = new Map(Global.MAP_FACTORY);
this.bornPlace = Global.MAP_FACTORY_BORNPLACE;
break;
case 2:
this.map = new Map(Global.MAP_FOREST);
this.bornPlace = Global.MAP_FOREST_BORNPLACE;
break;
case 3:
this.map = new Map(Global.MAP_PIRATE);
this.bornPlace = Global.MAP_PIRATE_BORNPLACE;
break;
case 4:
this.map = new Map(Global.MAP_FAUBOURG);
this.bornPlace = Global.MAP_FAUBOURG_BORNPLACE;
break;
}
}
public void loadPlayer() {
this.player = SingleGameRole.createSingleGameRole(this, Global.JACK,
this.bornPlace[0][0], this.bornPlace[0][1]);
this.gameLayerManager.append(player);
try {
this.playerGhost = new Sprite(Image.createImage("/Character/Jack.png"),
this.player.width, this.player.height);
this.gameLayerManager.append(playerGhost);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void playerUpdate() {
if(!this.player.isAlive)
this.playerGhost.setVisible(false);
this.playerGhost.setFrame(this.player.getFrame());
this.player.updateRole();
}
public void bombUpdate() {
Enumeration enu = this.bombTable.keys();
while (enu.hasMoreElements()) {
String key = (String) enu.nextElement();
Bomb bomb = (Bomb) (bombTable.get(key));
if (bomb.isvisable) {
bomb.update();
} else {
bombTable.remove(key);
bomb = null;
}
}
}
public void mapUpdate() {
this.map.update();
}
public void drawScreen() {
if (gameClock < 10000)
gameClock++;
else
gameClock = 0;
if (!this.isLoading) {
if (!isPause) {
this.operate();
this.bombUpdate();
this.playerUpdate();
this.mapUpdate();
g.setColor(0x000000);
g.fillRect(0, 0, getWidth(), getHeight());
this.drawState();
gameLayerManager.paint(g, 0, this.screenHeight
- Global.MAP_HEIGHT - 5);
} else {
this.drawPauseFrame();
}
} else {
this.drawLoadingFrame();
}
this.flushGraphics();
}
public void drawFailScreen() {
}
public void drawState() {
if (this.player.type == Global.JACK) {
g.drawImage(jackStateImage, 60, 5, Graphics.TOP | Graphics.LEFT);
}
if (this.player.type == Global.JOHN) {
g.drawImage(johnStateImage, 60, 5, Graphics.TOP | Graphics.LEFT);
}
this.number.setFrame(this.player.bombNums);
this.numberManager.paint(g, 101, 15);
this.number.setFrame(this.player.speed);
this.numberManager.paint(g, 133, 15);
this.number.setFrame(this.player.power);
this.numberManager.paint(g, 165, 15);
}
protected void drawPauseFrame() {
g.setColor(0x000000);
g.fillRect(0, 0, getWidth(), getHeight());
this.drawState();
if (gameClock % 5 == 0)
this.cursor.setFrame((this.cursor.getFrame() + 1) % 4);
this.gameLayerManager.paint(g, 0, this.screenHeight - Global.MAP_HEIGHT
- 5);
this.cursorManager.paint(g, screenWidth / 2 - pauseImage.getWidth() / 2
- 32, screenHeight / 2 - pauseImage.getHeight() / 2
+ this.chooseIndex * 33 + 24);
g.drawImage(pauseImage, screenWidth / 2, screenHeight / 2,
Graphics.HCENTER | Graphics.VCENTER);
}
protected void drawLoadingFrame() {
g.setColor(66, 70, 246);
g.fillRect(0, 0, screenWidth, screenHeight);
g.drawImage(loadingImage, screenWidth / 2, 2 * screenHeight / 5,
Graphics.HCENTER | Graphics.VCENTER);
g.setColor(0, 255, 0);
g.fillRect((screenWidth - 120) / 2, 2 * screenHeight / 3,
(this.loadPercent * 120) / 100, 10);
g.setColor(255, 0, 0);
g.drawRect((screenWidth - 120) / 2, 2 * screenHeight / 3, 120, 10);
}
public void showMe() {
new Loading(this.stageIndex);
if (this.mainThread == null) {
mainThread = new Thread(this);
mainThread.start();
}
this.dreamBubbleMidlet.show(this);
}
public void operate() {
int keyStates = getKeyStates();
this.playerGhost.setPosition(this.player.xCoodinate, this.player.yCoodinate);
if ((keyStates & DOWN_PRESSED) != 0) {
this.player.walk(Global.SOUTH);
} else {
if ((keyStates & UP_PRESSED) != 0) {
this.player.walk(Global.NORTH);
} else {
if ((keyStates & RIGHT_PRESSED) != 0) {
this.player.walk(Global.EAST);
} else {
if ((keyStates & LEFT_PRESSED) != 0) {
this.player.walk(Global.WEST);
}
}
}
}
}
protected void keyPressed(int key) {
if (!this.isPlaying)
return;
if (!this.isPause && key == -7) {// 右鍵
this.chooseIndex = 0;
this.pauseGame();
return;
}
if (key == 35) {// #鍵
this.nextStage();
return;
}
if (key == 42) {// *鍵
this.preStage();
return;
}
if (this.isPause) {
switch (key) {
case -1:
case -3:
if (this.chooseIndex == 0)
this.chooseIndex = 2;
else
this.chooseIndex = (this.chooseIndex - 1) % 3;
break;
case -2:
case -4:
this.chooseIndex = (this.chooseIndex + 1) % 3;
break;
case -5:// 確認鍵
case -6:// 左軟鍵
switch (chooseIndex) {
case 0:
this.continueGame();
break;
case 1:
this.restart();
break;
case 2:
this.endGame();
break;
}
break;
default:
break;
}
} else {
switch (key) {
case 53:
case -5:// 確認鍵
this.player.setBomb(this.player.getRow(), this.player.getCol());
break;
}
}
}
public void restart() {
new Loading(this.stageIndex);
}
public void continueGame() {
this.isPause = false;
this.player.play();
}
public void pauseGame() {
this.isPause = true;
this.player.stop();
}
public void endGame() {
this.isEnd = true;
this.mainThread = null;
System.gc();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.dreamBubbleMidlet.menu.showMe();
}
public void nextStage() {
if (this.stageIndex < 4) {
this.stageIndex++;
}
new Loading(this.stageIndex);
}
public void preStage() {
if (this.stageIndex > 0) {
this.stageIndex--;
}
new Loading(this.stageIndex);
}
class Loading implements Runnable {
private Thread innerThread;
private int stageIndex;
public Loading(int stageIndex) {
this.stageIndex = stageIndex;
innerThread = new Thread(this);
innerThread.start();
}
public void run() {
isLoading = true;
loadPercent = 0;
System.gc();
loadStage(stageIndex);
isLoading = false;
}
}
public void sleep() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
這個是游戲主體類
下面是游戲的人物類
package Game;
import javax.microedition.lci.Image;
import javax.microedition.lci.game.Sprite;
public abstract class Role extends Sprite {
/**
* 人物的基本屬性
*/
protected int type;
protected int xCoodinate;
protected int yCoodinate;
protected int row;
protected int col;
protected int width;
protected int height;
protected int speed;
protected int status;
protected boolean isCanOperate = false;
protected boolean isAlive = true;
/**
* 人物放置炸彈的基本屬性
*/
protected int power;
protected int bombNums;
protected int characterClock = 0;
protected int deadTime = 0;
protected Game game;
protected Role(Image image, int width, int Height, Game game) {
super(image, width, Height);
this.game = game;
}
/**
* 人物拾起道具
* @param tool
*/
public abstract void pickupTool(int tool);
/**
* 碰撞檢測以及坐標的改變,如果對行走條件有特殊需求,既可以在這里寫自己的條件
* @param direction
*/
public abstract void collisionCheck(int direction);
public void updateRole() {
if (this.characterClock < 10000) {
this.characterClock++;
} else {
this.characterClock = 100;
}
int row = this.getRow();
int col = this.getCol();
if (this.isAlive) {
int tool = this.game.map.getToolLayer().getCell(col, row);
if (tool > 0) {
this.pickupTool(tool);
this.game.map.getToolLayer().setCell(col, row, 0);
}
if (this.game.map.hasFeature(row, col, Global.DEADLY)) {
this.isAlive = false;
return;
}
if (this.status == Global.BORN
&& this.characterClock > Global.BORN_TIME) {
this.status = Global.SOUTH;
this.setFrame(Global.SOUTH * 6);
this.isCanOperate = true;
}
if (this.status == Global.BORN) {
if (this.characterClock % 2 == 0)
this.setFrame(Global.BORN * 6 + (this.getFrame() - 1) % 4);
return;
}
} else {
this.isCanOperate = false;
if (this.deadTime <= 20) {
this.deadTime++;
} else {
this.deadTime = 100;
this.setVisible(false);
return;
}
if (this.characterClock % 2 == 0) {
if (this.getFrame() < Global.DEAD * 6) {
this.setFrame(Global.DEAD * 6);
} else {
if (this.getFrame() < 29) {
this.setFrame(this.getFrame() + 1);
} else {
if (this.characterClock % 4 == 0) {
this.setFrame(29);
this.setVisible(true);
} else {
this.setVisible(false);
}
}
}
}
}
}
public void walk(int direction) {
if (!isAlive)
return;
if (!isCanOperate)
return;
if(direction==9) return;
this.collisionCheck(direction);
if (this.characterClock % 2 == 0) {
if (this.status == direction) {
this.setFrame(this.status * 6 + (this.getFrame() + 1) % 6);
} else {
this.status = direction;
this.setFrame(this.status * 6);
}
}
this.setPosition(xCoodinate, yCoodinate);
}
public void stop() {
this.isCanOperate = false;
}
public void play() {
this.isCanOperate = true;
}
public abstract void setBomb(int row, int col);
public void increaseBomb() {
if (this.bombNums < Global.MAX_BOMB_NUMBER)
this.bombNums++;
}
public int getRow() {
return getRow(getBottomY(yCoodinate) - Global.MAP_CELL / 2);
}
public int getCol() {
return getCol(xCoodinate + Global.MAP_CELL / 2);
}
protected int getBottomY(int y) {
return y + this.height - 1;
}
protected int getRightX(int x) {
return x + Global.MAP_CELL - 1;
}
protected int getPreY(int y) {
return getBottomY(y) + 1 - Global.MAP_CELL;
}
protected int getRow(int x) {
return x / Global.MAP_CELL;
}
protected int getCol(int y) {
return y / Global.MAP_CELL;
}
}
我的QQ是609419340
看不明白的可以隨時來問我哦,還可以當時傳給你撒
Ⅵ 怎樣獲得一款游戲的源代碼
源碼可以找游戲公司要,比如夢幻誅仙為什麼那麼多私服,就是源碼搭出來的
Ⅶ 手游SDK ios版源碼哪裡有
溪谷軟體有,可以去看看
Ⅷ 求C++小游戲源代碼啊~
一個戀愛小測試賊靈驗哦
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,a,b,c,d,e,f,g,h,i,j,k,l,sum;
cout<<"歡迎來到戀愛指數測試器*>-<*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"獨家的哦*^0^*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"以下異性均為合適年齡"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"下列問題如果是則輸入2,如果不是則輸入1,一點也沒感覺輸入0"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"加油,面對你自己!*-o-*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"question one:"<<"你是否面對異性時有莫名心跳?"<<endl;
cin>>n;
cout<<endl;
cout<<"question two:"<<"你是否有看到異性被撩時很憤怒?"<<endl;
cin>>m;
cout<<endl;
cout<<"question three:"<<"你是否懼怕見到一位異性的家長"<<endl;
cin>>a;
cout<<endl;
cout<<"question four:"<<"你是否經常刷一位異性的QQ或其他軟體"<<endl;
cin>>b;
cout<<endl;
cout<<"question five:"<<"想不想真心和Ta用情頭?"<<endl;
cin>>c;
cout<<endl;
cout<<"question six:"<<"和Ta邂逅過嗎?"<<endl;
cin>>d;
cout<<endl;
cout<<"question seven:"<<"吃過同一個飯碗里的東西嗎?"<<endl;
cin>>e;
cout<<endl;
cout<<"question eight:"<<"有過一個人在夢里與Ta相遇嗎?"<<endl;
cin>>f;
cout<<endl;
cout<<"question nine:"<<"有為了等Ta一個人站在風雨中嗎?"<<endl;
cin>>g;
cout<<endl;
cout<<"question ten:"<<"想kissTa不,想摸Ta的頭發嗎?"<<endl;
cin>>h;
cout<<endl;
sum=n+m+a+b+c+d+e+f+g+h;
cout<<"正在測評中,請稍後..."<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
if(sum>=16&&sum<=20)
cout<<"你的戀愛指數為:A。你是一個深深愛著Ta的人,你往往會走到最後^-^。"<<endl;
if(sum<=15&&sum>=12)
cout<<"你的戀愛指數為:B。你是一個矛盾卻又不失愛意的人,你的愛往往一波三折!-!。"<<endl;
if(sum<=11&&sum>=7)
cout<<"你的戀愛指數為:C。你是一個有點點情絲的人,你想表,卻又懼怕現實,你仍須努力o-o。"<<endl;
if(sum<=6&&sum>=0)
cout<<"你的戀愛指數為:D。你是一個無暇無垢,不食人間煙火的人,想一路踏歌,證道路上需佳人陪伴+-+。"<<endl;
if(sum>20||sum<0)
cout<<"你出格了喲ooo.ooo"<<endl;
cout<<"人生在世,恍如昨世,孤獨的身影終難走遠,你的那個Ta就在不遠方,就如漫天繁星,總有一顆屬於你!"<<endl;\
cout<<"快抓緊你身邊的那個Ta^-^oooooo"<<endl;
cout<<endl;
cout<<"作品創造者:yang sky one"<<endl;
cout<<"戀愛指數測試器已關閉,需重啟………………"<<endl;
return 0;
}
Ⅸ 手機游戲源代碼是什麼,怎麼使用
不知道你玩的啥游戲,但是看樣子估計是c++代碼,我英文學的不好
從英文描述中我猜測這是v c++的代碼,「//」在代碼中表示注釋,前三行是注釋,其大意如下:
stdafx.cpp :源文件,包括剛才的標准單元?
fixyou.pch將是預編譯的標題
stdafx.obj將包含預編譯的類型信息
「cpp」明顯是c++源碼文件的縮寫名,而最後一行是頭文件。
所謂頭文件預編譯,就是把一個工程(Project)中使用的一些MFC標准頭文件(如Windows.H、Afxwin.H)預先編譯,以後該工程編譯時,不再編譯這部分頭文件,僅僅使用預編譯的結果。這樣快編譯速度,節省時間。
預編譯頭文件通過編譯stdafx.cpp生成,以工程名命名,由於預編譯的頭文件的後綴是「pch」,所以編譯結果文件是projectname.pch。
編譯器通過一個頭文件stdafx.h來使用預編譯頭文件。stdafx.h這個頭文件名是可以在project的編譯設置里指定的。編譯器認為,所有在指令#include "stdafx.h"前的代碼都是預編譯的,它跳過#include "stdafx. h"指令,使用projectname.pch編譯這條指令之後的所有代碼。
因此,所有的CPP實現文件第一條語句都是:#include "stdafx.h"。
其實我學的pascal,所以對c++了解的少,如果你真的想學會他,還是自己找幾本c++的書學一下,這樣才能「使用」代碼得心應手。
Ⅹ 游戲源代碼是什麼
源代碼(也稱源程序),是指一系列人類可讀的計算機語言指令。游戲源代碼簡單來說就是游戲最原始程序的代碼。