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

苹果游戏源码

发布时间: 2022-07-07 16:31:49

Ⅰ 用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++的书学一下,这样才能“使用”代码得心应手。

Ⅹ 游戏源代码是什么

源代码(也称源程序),是指一系列人类可读的计算机语言指令。游戏源代码简单来说就是游戏最原始程序的代码。

热点内容
vb数据库数组 发布:2024-11-19 09:23:40 浏览:827
安卓游戏数据保存在哪里找 发布:2024-11-19 09:22:02 浏览:309
解压出来的文件乱码 发布:2024-11-19 09:15:40 浏览:939
北航ftp是多少 发布:2024-11-19 09:15:32 浏览:821
浏览保存密码如何取消 发布:2024-11-19 09:10:17 浏览:89
安卓怎么关短信重复提醒 发布:2024-11-19 09:02:00 浏览:635
html与php的区别 发布:2024-11-19 09:00:53 浏览:193
晚安密码多少 发布:2024-11-19 09:00:51 浏览:945
易语言脚本模块 发布:2024-11-19 09:00:44 浏览:484
经典矩阵C语言 发布:2024-11-19 08:56:23 浏览:268