Ⅰ 用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、进行问题分析与设计,计划实现的功能为,开局选择人机或双人对战,确定之后比赛开始。
2、比赛结束后初始化棋盘,询问是否继续比赛或退出,后续可加入复盘、悔棋等功能。
3、整个过程中,涉及到了棋子和棋盘两种对象,同时要加上人机对弈时的AI对象,即涉及到三个对象。
Ⅱ 游戏软件怎么查看源代码
游戏都是进行过编译,加密的无法看到源代码。如果你想查看的游戏是开源的,可以到游戏的开源网站进行查看。
查看APP应用的源代码的具体方法步骤如下:
1、首先在电脑内下载并安装获取网页源码app。
2、然后单击打开网页源码APP并在APP中的输入框内输入想要查看的网址,再在界面内找到GO选项单并单击。
3、单击后等待APP最后加载3秒就可以成功的获取APP源代码并查看了。
Android 系统源代码多大
是指sdk的源码,还是android操作系统的源码,不过都有10G左右,另外sdk的源码是用git管理的,一次下载后,用git check就可以切换到各个版本。
Android SDK是用于开发Android上java应用程序的,另外发布Android NDK,可以添加一些C语言写的链接库,至于Linux代码,可以在Android源代码中找到(SDK程序中只有编译好的测试映像)。
应用程序开发用不到Linux代码(搞嵌入式开发才会用到,而SDK不负责底层开发)。
Ⅲ 求"贪吃蛇"小游戏JAVA源代码一份
LZ 可以来到 http://www.itcast.cn 下载版块去自下,有视频教程和原代码,说的也不错
Ⅳ 求各种各样的小游戏的源代码,比如:贪吃蛇、推箱子、俄罗斯方块、五子棋等,最好是.NET的,JAVA也行。
我有java的,你可以看看:一个拼图
import java.lang.Math.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class MainFrame extends JFrame implements ActionListener{ //定义整个框架
private JButton[] jb = new JButton[8];
private JButton jbs = new JButton("开 局");
private JButton jbres = new JButton("重新开始");
private JPanel jp1 = new JPanel();
private JPanel jp2 = new JPanel();
private int[] n = new int[9];
private int[] n1 = new int[9];
private int position = 8,p,q;
private boolean bl,startbl=false;
private JLabel jl = new JLabel();
private int count = 0;
private JLabel jl1 = new JLabel(" "+Integer.toString(0));
public MainFrame(){ //框架的构造方法
int i;
for(int j = 0; j < n.length; j++){
n[j] = j;
n1[j] = n[j];
}
for(i = 0; i < jb.length; i++){ //给每个按钮赋相应的值,并注监听器
jb[i] = new JButton(Integer.toString(i+1));
jb[i].setFont(new Font("宋体",Font.BOLD,48));
jp2.add(jb[i]);
jb[i].addActionListener(this);
}
for(i = 0; i < n.length; i++){
if(n[i] == position)
jp2.add(jl);
else
jp2.add(jb[n[i]]);
}
jp2.setLayout(new GridLayout(3,3));//注册监听器
jbs.addActionListener(this);
jbres.addActionListener(this);
jp1.add(jbs);
jp1.add(jbres);
jp1.add(jl1);
jp1.setLayout(new FlowLayout()); //将jp1设置为流布局
setLayout(new BorderLayout()); //整体布局为边界布局
this.add("North",jp1);
this.add("Center",jp2);
this.setTitle("拼图游戏");
this.setBounds(100,100,300,350);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //实现关闭按钮
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){ //实现按钮的事件
if(e.getSource()==jbres){ // 重新开始按钮事件
for(int j = 0; j<n.length;j++)
n[j] = n1[j];
reShow();
startbl=true;
count = 0;
jl1.setText(" "+Integer.toString(0));
}
else if(e.getSource()==jbs) //开局按钮事件
this.Init();
else if(startbl){ //按钮1-8移动事件
for(int i = 0; i < jb.length; i++)
if(e.getSource() == jb[i]){
//System.out.println(i+1);
for(int a=0;a<n.length;a++){
if(n[a]==i)
p=a;
if(n[a]==position)
q=a;
}
}
if(p != 0 && p != 1 && p != 2)
if((p-3) == q)
swap(p,q);
if(p != 0 && p != 3 && p != 6)
if((p-1) == q)
swap(p,q);
if(p != 2 && p != 5 && p != 8)
if((p+1) == q)
swap(p,q);
if(p != 6 && p != 7 && p != 8)
if((p+3) == q)
swap(p,q);
}
}
public void swap(int x,int y){ //按钮1-8与空白图片交换
int z;
z = n[x];
n[x] = n[y];
n[y]=z;
jl1.setText(" "+Integer.toString(++count));
reShow();
win();
}
public void Init(){ //随机产生游戏界面
int i=0,j,x;
boolean bl ;
while(i<9){
bl = true;
x=(int)(Math.random()*9);
for(j=0;j<i;j++)
if(n[j] == x)
bl=false;
if(bl){
n [i++] = x;
n1[i-1] = x;
}
}
reShow();
startbl=true;
count = 0;
jl1.setText(" "+Integer.toString(0));
}
public void reShow(){ //对游戏界面的重写
for(int i = 0; i < n.length; i++){
if(n[i] == position)
jp2.add(jl);
else
jp2.add(jb[n[i]]);
}
jp2.revalidate();
}
public void win(){ //判断是否成功
boolean winbl=true;
for(int i=0;i<n.length;i++)
if(n[i]!=i)
winbl=false;
if(winbl){
JOptionPane.showMessageDialog(this,"祝贺你,你成功了! "+"你用了"+Integer.toString(count)+"步","",JOptionPane.INFORMATION_MESSAGE);
startbl=false;
}
}
}
public class Collage { // 主函数类
public static void main(String[] args){
new MainFrame();
}
}
自已以前编的,不是很好,你就参考参考吧
Ⅳ 求小游戏源代码
猫版超级玛丽游戏しょぼんのアクションBGMcastle.mp3
.......................................
geon.mp3
.......................................field.mp3
.......................................puyo.mp3
.......................................star4.mp3
....................................desktop.ini
....................................loadg.cpp
....................................main.cpp
....................................main.h
....................................RESrock.png
.......................................rock2.png
.......................................haikei.png
.......................................item.png
.......................................omake.png
.......................................omake2.png
.......................................player.png
.......................................syobon3.png
....................................... eki.png
....................................SE4-clear.mp3
......................................allclear.mp3
......................................rockbreak.mp3
......................................rockcoin.mp3
......................................rockkinoko.mp3
......................................coin.mp3
......................................death.mp3
......................................dokan.mp3
......................................gameover.mp3
......................................goal.mp3
......................................hintblock.mp3
......................................humi.mp3
......................................jump.mp3
......................................jumpblock.mp3
......................................kirra.mp3
......................................koura.mp3
......................................powerup.mp3
......................................pswitch.mp3
...................................... ekifire.mp3
.....................................YSapploc.msi
.......................................AppLoc.tmp
....................................しょぼんのアクション.exe
....................................リードミー.txt
....................................点我开始玩.cmd
....................................BGM
....................................RES
....................................SE
....................................SYS
................しょぼんのアクション
http://www.pudn.com/downloads385/sourcecode/game/detail1652652.html
http://www.pudn.com/downloads234/sourcecode/game/detail1099372.html
http://syobon.codeplex.com/releases/62191/download/214890
变态版http://download.csdn.net/download/lc19890326/861250
VF
报表(frx/frt)无法导出成prg格式
菜单(mnx/mnt)编译时已自动生成了prg格式的文件mpr
注意“文件类型”一定要选择“窗体”类型,否则“查看代码”将处于隐藏状态,无法看到原代码,切记!!
1:如果只是想获得网站的样式,使用浏览器的“保存”功能就可以实现!关键是下载到CSS文件就可以了!Ⅵ 基于eclipse开发一个安卓小游戏
你是大学生吧?女生怎么想起学计算机。建议随便下载一个简单的游戏,然后找人反编译一下,修改下,变成你自己的。我是高中毕业生,也在学习Android编程,可是我的能力还不到帮你的地步,我也是初学者。有大神直接建议让我去学C,于是我又开始学C了。爱莫能助,试试我的办法,希望能有帮助。
Ⅶ 求一个Android小游戏消方块的源代码,谢谢了~
两个以上可以点击消失??什么样的?对对碰,连在一起的,还是连连看那样的?