当前位置: 首页 手机游戏下载资讯 手游资讯

推荐游戏代码,推荐游戏代码大全

一、简单的程序代码游戏

简单的程序代码游戏有《代码英雄》、《像素危城》、《像素生存游戏2》、《重生细胞》。

1、《代码英雄》

横版像素风格的游戏,大家需要根据代码来让角色进行移动,同时在冒险的过程当中也会遇到各类敌人,玩家们需要小心的应对。

2、《像素危城》

同样是采用了简单的像素画风,不过本作玩家首先要面对的就是生存问题,丧失将出现在城市当中的任何地点,大家需要拿好手中的武器进行反抗。

3、《像素生存游戏2》

独特的趣味冒险设定是本作的一大亮点,玩家们在游戏当中还可以创造出各种武器和装备,多种副本挑战也会让游戏的难度变得更大。

4、《重生细胞》

roguelike游戏的经典作品,横版战斗风格将为玩家们呈现出不错的打击感,大家需要通过不断的闯关去揭开主角身上的重重谜团。

代码介绍:

代码(code)是程序员用开发工具所支持的语言写出来的源文件,是一组由字符、符号或信号码元以离散形式表示信息的明确的规则体系。

代码设计的原则包括唯一确定性、标准化和通用性、可扩充性与稳定性、便于识别与记忆、力求短小与格式统一以及容易修改等。源代码是代码的分支,某种意义上来说,源代码相当于代码。现代程序语言中,源代码可以书籍或磁带形式出现,但最为常用格式是文本文件,这种典型格式的目的是为了编译出计算机程序。计算机源代码最终目的是将人类可读文本翻译成为计算机可执行的二进制指令,这种过程叫编译,它由通过编译器完成。

二、c语言小游戏代码

最基础的贪吃蛇的代码

#include<stdio.h>

#include<windows.h>//基本型态定义。支援型态定义函数。使用者界面函数图形装置界面函数。

#include<conio.h>//用户通过按键盘产生的对应操作(控制台)

#include<stdlib.h>

#include<time.h>//日期和时间头文件

#define LEN 30

#define WID 25

int Snake[LEN][WID]={0};//数组的元素代表蛇的各个部位

char Sna_Hea_Dir='a';//记录蛇头的移动方向

int Sna_Hea_X, Sna_Hea_Y;//记录蛇头的位置

int Snake_Len= 3;//记录蛇的长度

clock_t Now_Time;//记录当前时间,以便自动移动

int Wait_Time;//记录自动移动的时间间隔

int Eat_Apple= 1;//吃到苹果表示为1

int Level;

int All_Score=-1;

int Apple_Num=-1;

HANDLE hConsole= GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出的句柄<windows.h>

//句柄:标志应用程序中的不同对象和同类对象中的不同的实例方便操控,

void gotoxy(int x, int y)//设置光标位置

{

COORD pos={x,y};//定义一个字符在控制台屏幕上的坐标POS

SetConsoleCursorPosition(hConsole, pos);//定位光标位置的函数<windows.h>

}

void Hide_Cursor()//隐藏光标固定函数

{

CONSOLE_CURSOR_INFO cursor_info={1, 0};

SetConsoleCursorInfo(hConsole,&cursor_info);

}

void SetColor(int color)//设置颜色

{

SetConsoleTextAttribute(hConsole, color);

//是API设置字体颜色和背景色的函数格式:SetConsoleTextAttribute(句柄,颜色);

}

void Print_Snake()//打印蛇头和蛇的脖子和蛇尾

{

int iy, ix, color;

for(iy= 0; iy< WID;++iy)

for(ix= 0; ix< LEN;++ix)

{

if(Snake[ix][iy]== 1)//蛇头

{

SetColor(0xf);//oxf代表分配的内存地址 setcolor:34行自定义设置颜色的函数

gotoxy(ix*2, iy);

printf("※");

}

if(Snake[ix][iy]== 2)//蛇的脖子

{

color= rand()%15+ 1;//rand()函数是产生随机数的一个随机函数。C语言里还有 srand()函数等。

//头文件:stdlib.h

if(color== 14)

color-= rand()% 13+ 1;//变色

SetColor(color);

gotoxy(ix*2, iy);

printf("■");

}

if(Snake[ix][iy]== Snake_Len)

{

gotoxy(ix*2, iy);

SetColor(0xe);

printf("≈");

}

}

}

void Clear_Snake()//擦除贪吃蛇

{

int iy, ix;

for(iy= 0; iy< WID;++iy)

for(ix= 0; ix< LEN;++ix)

{

gotoxy(ix*2, iy);

if(Snake[ix][iy]== Snake_Len)

printf("");

}

}

void Rand_Apple()//随机产生苹果

{

int ix, iy;

do

{

ix= rand()% LEN;

iy= rand()% WID;

}while(Snake[ix][iy]);

Snake[ix][iy]=-1;

gotoxy(ix*2, iy);

printf("⊙");

Eat_Apple= 0;

}

void Game_Over()//蛇死掉了

{

gotoxy(30, 10);

printf("Game Over");

Sleep(3000);

system("pause> nul");

exit(0);

}

void Move_Snake()//让蛇动起来

{

int ix, iy;

for(ix= 0; ix< LEN;++ix)//先标记蛇头

for(iy= 0; iy< WID;++iy)

if(Snake[ix][iy]== 1)

{

switch(Sna_Hea_Dir)//根据新的蛇头方向标志蛇头

{

case'w':

if(iy== 0)

Game_Over();

else

Sna_Hea_Y= iy- 1;

Sna_Hea_X= ix;

break;

case's':

if(iy==(WID-1))

Game_Over();

else

Sna_Hea_Y= iy+ 1;

Sna_Hea_X= ix;

break;

case'a':

if(ix== 0)

Game_Over();

else

Sna_Hea_X= ix- 1;

Sna_Hea_Y= iy;

break;

case'd':

if(ix==(LEN- 1))

Game_Over();

else

Sna_Hea_X= ix+ 1;

Sna_Hea_Y= iy;

break;

default:

break;

}

}

if(Snake[Sna_Hea_X][Sna_Hea_Y]!=1&&Snake[Sna_Hea_X][Sna_Hea_Y]!=0&&Snake[Sna_Hea_X][Sna_Hea_Y]!=-1)

Game_Over();

if(Snake[Sna_Hea_X][Sna_Hea_Y]< 0)//吃到苹果

{

++Snake_Len;

Eat_Apple= 1;

}

for(ix= 0; ix< LEN;++ix)//处理蛇尾

for(iy= 0; iy< WID;++iy)

{

if(Snake[ix][iy]> 0)

{

if(Snake[ix][iy]!= Snake_Len)

Snake[ix][iy]+= 1;

else

Snake[ix][iy]= 0;

}

}

Snake[Sna_Hea_X][Sna_Hea_Y]= 1;//处理蛇头

}

void Get_Input()//控制蛇的移动方向

{

if(kbhit())

{

switch(getch())

{

case 87:

Sna_Hea_Dir='w';

break;

case 83:

Sna_Hea_Dir='s';

break;

case 65:

Sna_Hea_Dir='a';

break;

case 68:

Sna_Hea_Dir='d';

break;

default:

break;

}

}

if(clock()- Now_Time>= Wait_Time)//蛇到时间自动行走

{

Clear_Snake();

Move_Snake();

Print_Snake();

Now_Time= clock();

}

}

void Init()//初始化

{

system("title贪吃毛毛蛇");

system("mode con: cols=80 lines=25");

Hide_Cursor();

gotoxy(61, 4);

printf("You Score:");

gotoxy(61, 6);

printf("You Level:");

gotoxy(61, 8);

printf("The Lenght:");

gotoxy(61, 10);

printf("The Speed:");

gotoxy(61, 12);

printf("Apple Num:");

int i;

for(i= 0; i< Snake_Len;++i)//生成蛇

Snake[10+i][15]= i+1;

int iy, ix;//打印蛇

for(iy= 0; iy< WID;++iy)

for(ix= 0; ix< LEN;++ix)

{

if(Snake[ix][iy])

{

SetColor(Snake[ix][iy]);

gotoxy(ix*2, iy);

printf("■");

}

}

}

void Pri_News()//打印信息

{

SetColor(0xe);

gotoxy(73,4);

All_Score+= Level;

printf("%3d", All_Score);

gotoxy(73, 6);

printf("%3d", Level);

gotoxy(73, 8);

printf("%3d",Snake_Len);

gotoxy(73, 10);

printf("0.%3ds", Wait_Time/10);

gotoxy(73, 12);

printf("%d", Apple_Num);

}

void Lev_Sys()//等级系统

{

if(((Apple_Num-1)/ 10)== Level)

{

++Level;

if(Wait_Time> 50)

Wait_Time-= 50;

else

if(Wait_Time> 10)

Wait_Time-= 10;

else

Wait_Time-= 1;

}

}

int main(void)

{

Init();

srand((unsigned)time(NULL));//设置随机数的种子

Now_Time= clock();

int speed1=1000,speed2,a;

printf("\n");

printf("请输入你想要的速度\n");

scanf("%d",&speed2);

Level=1;

Wait_Time=speed1-speed2;

printf("请输入你想要的苹果数\n");

scanf("%d",&a);

while(a--)

Rand_Apple();

while(1)

{

if(Eat_Apple)

{

++Apple_Num;

Rand_Apple();

Lev_Sys();

Pri_News();

}

Get_Input();

Sleep(10);

}

return 0;

}

三、谁能给我一个手机游戏的源代码啊

这个地址也有,不过直接给你吧,这样比较好

先给你看看主要的类吧

package Game;

import DreamBubbleMidlet;

import java.io.IOException;

import java.util.Enumeration;

import java.util.Hashtable;

import javax.microedition.lcdui.Graphics;

import javax.microedition.lcdui.Image;

import javax.microedition.lcdui.game.GameCanvas;

import javax.microedition.lcdui.game.LayerManager;

import javax.microedition.lcdui.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.lcdui.Image;

import javax.microedition.lcdui.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

看不明白的可以随时来问我哦,还可以当时传给你撒

标签: 手游

声明:

1、本文来源于互联网,所有内容仅代表作者本人的观点,与本网站立场无关,作者文责自负。

2、本网站部份内容来自互联网收集整理,对于不当转载或引用而引起的民事纷争、行政处理或其他损失,本网不承担责任。

3、如果有侵权内容、不妥之处,请第一时间联系我们删除,请联系