Ⅰ 用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小游戲消方塊的源代碼,謝謝了~
兩個以上可以點擊消失??什麼樣的?對對碰,連在一起的,還是連連看那樣的?