当前位置:首页 > 代码 > 正文

免费的游戏源代码(免费游戏源码分享)

admin 发布:2022-12-19 11:55 121


本篇文章给大家谈谈免费的游戏源代码,以及免费游戏源码分享对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求java小游戏源代码

表1. CheckerDrag.java

// CheckerDrag.javaimport java.awt.*;import java.awt.event.*;public class CheckerDrag extends java.applet.Applet{ // Dimension of checkerboard square. // 棋盘上每个小方格的尺寸 final static int SQUAREDIM = 40; // Dimension of checkerboard -- includes black outline. // 棋盘的尺寸 – 包括黑色的轮廓线 final static int BOARDDIM = 8 * SQUAREDIM + 2; // Dimension of checker -- 3/4 the dimension of a square. // 棋子的尺寸 – 方格尺寸的3/4 final static int CHECKERDIM = 3 * SQUAREDIM / 4; // Square colors are dark green or white. // 方格的颜色为深绿色或者白色 final static Color darkGreen = new Color (0, 128, 0); // Dragging flag -- set to true when user presses mouse button over checker // and cleared to false when user releases mouse button. // 拖动标记 --当用户在棋子上按下鼠标按键时设为true, // 释放鼠标按键时设为false boolean inDrag = false; // Left coordinate of checkerboard's upper-left corner. // 棋盘左上角的左方向坐标 int boardx; // Top coordinate of checkerboard's upper-left corner. //棋盘左上角的上方向坐标 int boardy; // Left coordinate of checker rectangle origin (upper-left corner). // 棋子矩形原点(左上角)的左方向坐标 int ox; // Top coordinate of checker rectangle origin (upper-left corner). // 棋子矩形原点(左上角)的上方向坐标 int oy; // Left displacement between mouse coordinates at time of press and checker // rectangle origin. // 在按键时的鼠标坐标与棋子矩形原点之间的左方向位移 int relx; // Top displacement between mouse coordinates at time of press and checker // rectangle origin. // 在按键时的鼠标坐标与棋子矩形原点之间的上方向位移 int rely; // Width of applet drawing area. // applet绘图区域的宽度 int width; // Height of applet drawing area. // applet绘图区域的高度 int height; // Image buffer. // 图像缓冲 Image imBuffer; // Graphics context associated with image buffer. // 图像缓冲相关联的图形背景 Graphics imG; public void init () { // Obtain the size of the applet's drawing area. // 获取applet绘图区域的尺寸 width = getSize ().width; height = getSize ().height; // Create image buffer. // 创建图像缓冲 imBuffer = createImage (width, height); // Retrieve graphics context associated with image buffer. // 取出图像缓冲相关联的图形背景 imG = imBuffer.getGraphics (); // Initialize checkerboard's origin, so that board is centered. // 初始化棋盘的原点,使棋盘在屏幕上居中 boardx = (width - BOARDDIM) / 2 + 1; boardy = (height - BOARDDIM) / 2 + 1; // Initialize checker's rectangle's starting origin so that checker is // centered in the square located in the top row and second column from // the left. // 初始化棋子矩形的起始原点,使得棋子在第一行左数第二列的方格里居中 ox = boardx + SQUAREDIM + (SQUAREDIM - CHECKERDIM) / 2 + 1; oy = boardy + (SQUAREDIM - CHECKERDIM) / 2 + 1; // Attach a mouse listener to the applet. That listener listens for // mouse-button press and mouse-button release events. // 向applet添加一个用来监听鼠标按键的按下和释放事件的鼠标监听器 addMouseListener (new MouseAdapter () { public void mousePressed (MouseEvent e) { // Obtain mouse coordinates at time of press. // 获取按键时的鼠标坐标 int x = e.getX (); int y = e.getY (); // If mouse is over draggable checker at time // of press (i.e., contains (x, y) returns // true), save distance between current mouse // coordinates and draggable checker origin // (which will always be positive) and set drag // flag to true (to indicate drag in progress). // 在按键时如果鼠标位于可拖动的棋子上方 // (也就是contains (x, y)返回true),则保存当前 // 鼠标坐标与棋子的原点之间的距离(始终为正值)并且 // 将拖动标志设为true(用来表明正处在拖动过程中) if (contains (x, y)) { relx = x - ox; rely = y - oy; inDrag = true; } } boolean contains (int x, int y) { // Calculate center of draggable checker. // 计算棋子的中心位置 int cox = ox + CHECKERDIM / 2; int coy = oy + CHECKERDIM / 2; // Return true if (x, y) locates with bounds // of draggable checker. CHECKERDIM / 2 is the // radius. // 如果(x, y)仍处于棋子范围内则返回true // CHECKERDIM / 2为半径 return (cox - x) * (cox - x) + (coy - y) * (coy - y) CHECKERDIM / 2 * CHECKERDIM / 2; } public void mouseReleased (MouseEvent e) { // When mouse is released, clear inDrag (to // indicate no drag in progress) if inDrag is // already set. // 当鼠标按键被释放时,如果inDrag已经为true, // 则将其置为false(用来表明不在拖动过程中) if (inDrag) inDrag = false; } }); // Attach a mouse motion listener to the applet. That listener listens // for mouse drag events. //向applet添加一个用来监听鼠标拖动事件的鼠标运动监听器 addMouseMotionListener (new MouseMotionAdapter () { public void mouseDragged (MouseEvent e) { if (inDrag) { // Calculate draggable checker's new // origin (the upper-left corner of // the checker rectangle). // 计算棋子新的原点(棋子矩形的左上角) int tmpox = e.getX () - relx; int tmpoy = e.getY () - rely; // If the checker is not being moved // (at least partly) off board, // assign the previously calculated // origin (tmpox, tmpoy) as the // permanent origin (ox, oy), and // redraw the display area (with the // draggable checker at the new // coordinates). // 如果棋子(至少是棋子的一部分)没有被 // 移出棋盘,则将之前计算的原点 // (tmpox, tmpoy)赋值给永久性的原点(ox, oy), // 并且刷新显示区域(此时的棋子已经位于新坐标上) if (tmpox boardx tmpoy boardy tmpox + CHECKERDIM boardx + BOARDDIM tmpoy + CHECKERDIM boardy + BOARDDIM) { ox = tmpox; oy = tmpoy; repaint (); } } } }); } public void paint (Graphics g) { // Paint the checkerboard over which the checker will be dragged. // 在棋子将要被拖动的位置上绘制棋盘 paintCheckerBoard (imG, boardx, boardy); // Paint the checker that will be dragged. // 绘制即将被拖动的棋子 paintChecker (imG, ox, oy); // Draw contents of image buffer. // 绘制图像缓冲的内容 g.drawImage (imBuffer, 0, 0, this); } void paintChecker (Graphics g, int x, int y) { // Set checker shadow color. // 设置棋子阴影的颜色 g.setColor (Color.black); // Paint checker shadow. // 绘制棋子的阴影 g.fillOval (x, y, CHECKERDIM, CHECKERDIM); // Set checker color. // 设置棋子颜色 g.setColor (Color.red); // Paint checker. // 绘制棋子 g.fillOval (x, y, CHECKERDIM - CHECKERDIM / 13, CHECKERDIM - CHECKERDIM / 13); } void paintCheckerBoard (Graphics g, int x, int y) { // Paint checkerboard outline. // 绘制棋盘轮廓线 g.setColor (Color.black); g.drawRect (x, y, 8 * SQUAREDIM + 1, 8 * SQUAREDIM + 1); // Paint checkerboard. // 绘制棋盘 for (int row = 0; row 8; row++) { g.setColor (((row 1) != 0) ? darkGreen : Color.white); for (int col = 0; col 8; col++) { g.fillRect (x + 1 + col * SQUAREDIM, y + 1 + row * SQUAREDIM, SQUAREDIM, SQUAREDIM); g.setColor ((g.getColor () == darkGreen) ? Color.white : darkGreen); } } } // The AWT invokes the update() method in response to the repaint() method // calls that are made as a checker is dragged. The default implementation // of this method, which is inherited from the Container class, clears the // applet's drawing area to the background color prior to calling paint(). // This clearing followed by drawing causes flicker. CheckerDrag overrides // update() to prevent the background from being cleared, which eliminates // the flicker. // AWT调用了update()方法来响应拖动棋子时所调用的repaint()方法。该方法从 // Container类继承的默认实现会在调用paint()之前,将applet的绘图区域清除 // 为背景色,这种绘制之后的清除就导致了闪烁。CheckerDrag重写了update()来 // 防止背景被清除,从而消除了闪烁。 public void update (Graphics g) { paint (g); }}

贪吃蛇游戏的源代码

贪吃蛇源码:

!doctype html

html

body style='overflow:hidden'

canvas id="can" width="400" height="400" style="background:Black;display: block;margin:20px auto;"/canvas

script

var sn = [ 42, 41 ], dz = 43, fx = 1, n, ctx = document.getElementById("can").getContext("2d");

function draw(t, c) {

ctx.fillStyle = c;

ctx.fillRect(t % 20 * 20 + 1, ~~(t / 20) * 20 + 1, 18, 18);

}

document.onkeydown = function(e) {

fx = sn[1] - sn[0] == (n = [ -1, -20, 1, 20 ][(e || event).keyCode - 37] || fx) ? fx : n

};

!function() {

sn.unshift(n = sn[0] + fx);

if (sn.indexOf(n, 1) 0 || n0||n399 || fx == 1 n % 20 == 0 || fx == -1 n % 20 == 19)

return alert("GAME OVER");

draw(n, "Lime");

if (n == dz) {

while (sn.indexOf(dz = ~~(Math.random() * 400)) = 0);

draw(dz, "Yellow");

} else

draw(sn.pop(), "Black");

setTimeout(arguments.callee, 130);

}();

/script

/body

/html

哪个网站有。所有所有游戏的源代码

您好,现在很多网站都可以查询到游戏的源代码。

例如17171、u9、766都是可以进行相关查询的。

源代码(也称源程序)是指未编译的按照一定的程序设计语言规范书写的文本文件,是一系列人类可读的计算机语言指令。

在现代程序语言中,源代码可以是以书籍或者磁带的形式出现,但最为常用的格式是文本文件,这种典型格式的目的是为了编译出计算机程序。

跪求C++大神,只需要写一个小游戏源代码,事成有现金酬谢。

#include iostream

using namespace std;

double shengmingli=2000;//定义主角初始生命力

int gongjili=150;//定义主角初始攻击力

int fangyuli=200;//定义主角初始防御力

int money=20;//定义主角初始金钱数量

bool guoguan;//定义是否通关判定

void wuqidian();//定义武器店函数

void yaodian();//定义药店函数

void guaiwu1();//定义小怪物函数

void guaiwu2();//定义大怪物函数

int main()

{

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

int xiaozhen;//定义选择项目

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"endl;

cinxiaozhen;

while(xiaozhen!=5)//输入5时退出游戏

{

if(shengmingli=0)//主角生命力小于等于0时游戏结束

{

cout"你死啦!"endl;

break;

}

if(guoguan)

{

cout"恭喜通关!"endl;

break;

}

if(xiaozhen==6)//输入6可检测自己的状态

{

cout"你的生命力:"shengmingliendl;

cout"你的攻击力:"gongjiliendl;

cout"你的防御力:"fangyuliendl;

cout"你拥有的钱:"moneyendl;

}

else

switch(xiaozhen)

{

case 1 : wuqidian();break;

case 2 : yaodian();break;

case 3 : guaiwu1();break;

case 4 : guaiwu2();break;

default : cout"请不要乱选!"endl;break;

}

cinxiaozhen;

}

if(xiaozhen==5)

{

cout"正在退出游戏……"endl;

}

cin.get();

cin.get();

return 0;

}

void wuqidian()

{

cout"欢迎来到武器店!"endl;

cout"1、买小刀(1M加2攻击力)"endl;

cout"2、买短剑(2M加20攻击力)"endl;

cout"3、买大砍刀(5M加40攻击力)"endl;

cout"4、买双节棍(7M加60攻击力)"endl;

cout"5、买盾牌(2M加30防御力)"endl;

cout"6、买铠甲(5M加60防御力)"endl;

cout"7、离开武器店"endl;

int wuqidian;

cinwuqidian;

while(wuqidian!=7)//输入7时结束函数

{

switch(wuqidian)

{

case 1 : if(money10)

cout"你的钱不够"endl;//钱不够时返回Flase

else

cout"购买成功!"endl;//钱足够时返回True

gongjili+=2;

money-=1;

break;

case 2 : if(money80)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

gongjili+=20;

money-=80;

break;

case 3 : if(money140)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

gongjili+=40;

money-=140;

break;

case 4 : if(money200)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

gongjili+=60;

money-=200;

break;

case 5 : if(money60)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

fangyuli+=30;

money-=60;

break;

fangyuli+=60;

money-=100;

break;

default : cout"无"endl;

break;

}

cinwuqidian;

}

if(wuqidian==7)

{ //返回main()主函数

cout"欢迎下次再来!"endl;

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"endl;

}

}

/*

yaodian()的设置与wuqidian()相同,可参照阅读.

*/

void yaodian()

{

cout"欢迎来到药品店!"endl;

cout"1、买1号补血药(10M加200生命)"endl;

cout"2、买2号补血药(50M加1000生命力)"endl;

cout"3、买3号补血药(100M加2200生命力)"endl;

cout"4、离开药品店"endl;

int yaodian;

cinyaodian;

while(yaodian!=4)

{

switch(yaodian)

{

case 1 : if(money10)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

shengmingli+=200;

money-=10;

break;

case 2 : if(money50)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

shengmingli+=1000;

money-=50;

break;

case 3 : if(money100)

cout"你的钱不够"endl;

else

cout"购买成功!"endl;

shengmingli+=2200;

money-=100;

break;

default : cout"无"endl;

break;

}

cinyaodian;

}

if(yaodian==4)

{

cout"欢迎下次再来!"endl;

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"endl;

}

}

/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/

void guaiwu1()

{

cout"开始与小怪物战斗!!!"endl;

double* g_shengmingli=new double;//定义怪物生命

int* g_gongjili=new int;//定义怪物攻击力

int* g_fangyuli=new int;//定义怪物防御力

int* g_money=new int;//定义怪物金钱

*g_shengmingli=100;

*g_gongjili=5;

*g_fangyuli=3;

*g_money=5;

double* tongji1=new double;//用来计算主角对怪物的杀伤

double* tongji2=new double;//用来计算怪物对主角的杀伤

*tongji1=0;

*tongji2=0;

int* huihe=new int;//定义回合数

*huihe=1;

cout"你开始对小怪物进行攻击!"endl;

int* xuanze=new int;

/*

攻击计算公式

杀伤=攻击力*2-防御力

玩家每回合可以选择攻击与逃跑

*/

while((*g_shengmingli)0 shengmingli0 (*xuanze)!=2)

{

cout"现在是""第"*huihe"回合!"endl;

cout"请选择你的动作:\n";

cout"1、攻击\n2、逃跑\n";

cin*xuanze;

switch((*xuanze))

{

case 1 : cout"你对小怪物发动了攻击!"endl;

*g_shengmingli-=gongjili*2-(*g_fangyuli);

*tongji1=gongjili*2-(*g_fangyuli);

cout"你打掉了小怪物"*tongji1"的生命!"endl;

cout"小怪物还剩"(*g_shengmingli)-(*tongji1)"点生命"endl;

shengmingli-=(*g_gongjili)*2-fangyuli;

*tongji2=(*g_gongjili)*2-fangyuli;

cout"小怪物对你发动了攻击!"endl;

cout"小怪物打掉了你"*tongji2"的生命!"endl;

cout"你还剩"shengmingli-(*tongji2)"点生命"endl;break;

case 2 : cout"你决定逃跑!"endl;

cout"逃跑成功!"endl;continue;

default : cout"请不要乱选!"endl;

}

(*huihe)++;

}

if((*g_shengmingli)=0)

{//杀死怪物后的返回

cout"小怪物被你杀死了!你真厉害!!!"endl;

money+=(*g_money);

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"endl;

}

else

if(shengmingli=0)

{//被怪物杀死后的返回

cout"你被小怪物杀死了!游戏结束!!!"endl;

}

else

if((*xuanze)==2)

{//逃跑的返回

cout"你逃回了小镇!"endl;

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"endl;

}

delete g_shengmingli;

delete g_gongjili;

delete g_fangyuli;

delete g_money;

delete tongji1;

delete tongji2;

}

/*

设置均与void函数guaiwu1()相同,可参照上例阅读.

*/

void guaiwu2()

{

cout"开始与大怪物战斗!!!"endl;

double* g_shengmingli=new double;

int* g_gongjili=new int;

int* g_fangyuli=new int;

*g_shengmingli=3600;

*g_gongjili=500;

*g_fangyuli=500;

double* tongji1=new double;

double* tongji2=new double;

*tongji1=0;

*tongji2=0;

int* huihe=new int;

*huihe=1;

cout"你开始对大怪物进行攻击!"endl;

int* xuanze=new int;

while((*g_shengmingli)0 shengmingli0 (*xuanze)!=2)

{

cout"现在是""第"*huihe"回合!"endl;

cout"请选择你的动作:\n";

cout"1、攻击\n2、逃跑\n";

cin*xuanze;

switch((*xuanze))

{

case 1 : cout"你对大怪物发动了攻击!"endl;

*g_shengmingli-=gongjili*2-(*g_fangyuli);

*tongji1=gongjili*2-(*g_fangyuli);

cout"你打掉了大怪物"*tongji1"的生命!"endl;

cout"大怪物还剩"(*g_shengmingli)-(*tongji1)"点生命"endl;

shengmingli-=(*g_gongjili)*2-fangyuli;

*tongji2=(*g_gongjili)*2-fangyuli;

cout"大怪物对你发动了攻击!"endl;

cout"大怪物打掉了你"*tongji2"的生命!"endl;

cout"你还剩"shengmingli-(*tongji2)"点生命"endl;break;

case 2 : cout"你决定逃跑!"endl;

cout"逃跑成功!"endl;continue;

default : cout"请不要乱选!"endl;

}

(*huihe)++;

}

if((*g_shengmingli)=0)

{

cout"大怪物被你杀死了!你真厉害!!!"endl;

guoguan=true;

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"endl;

}

else

if(shengmingli=0)

{

cout"你被大怪物杀死了!游戏结束!!!"endl;

}

else

if((*xuanze)==2)

{

cout"你逃回了小镇!"endl;

cout"欢迎你开始玩打怪物小游戏!\n";

cout"小镇\n";

cout"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。\n有一家药店"endl;

cout"和一家武器店。\n";

cout"1.去武器店"endl;

cout"2.去药品店"endl;

cout"3.去打小怪物"endl;

cout"4.去打大怪物"endl;

cout"5.退出游戏"endl;

cout"6.显示你的状态"en;

}

delete g_shengmingli;

delete g_gongjili;

delete g_fangyuli;

delete tongji1;

delete tongji2;

}

在哪里可以找到免费的VB游戏源代码下载点?

VB在线:

维维软件园:

这几个地方比较不错,你要是想编写Direct接口的游戏那就多看看CSDN和MSDN还有微软的官方资料吧。

关于免费的游戏源代码和免费游戏源码分享的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/7715.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载