當前位置:首頁 » 操作系統 » 稀有游戲源碼

稀有游戲源碼

發布時間: 2022-07-30 10:07:21

㈠ 急!!求用C++做的小游戲的源代碼!! 能運行的,做好有解說!!謝謝啦!!

我剛發了一個文檔,俄羅斯方塊的源代碼是c++的,
如你需要,我可以給你再發一個,還有許多其它的游戲源代碼。

㈡ 我有一套游戲的源碼 求高人指導開發架設


마슲

㈢ 求用C語言編寫小游戲的源代碼,不管什麼小游戲,源代碼簡單些,適合初學者,3Q。

/*21點游戲*/
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main(void )
{
int a,b,c,d,s,x,t,i,n,k;
s=200,k=1000;
x=t=i=1,a=b=c=d=n=0;
srand((int)time(0));
printf(" 21點游戲
★游戲規則: \n 游戲開始後系統將隨機產生1到10之間的數並累加.
1.在點數不大於21時,點數大者贏,點數相等算平局;
2.若一方點數大於21,一方點數小於21,小於21的一方贏;
3.若兩方均大於21,則算平局;
4.獲勝者獲得相應賭注金幣,金幣到零則結束游戲 .\n (注:繼續加點選1,不繼續加點選任意非1數)\n\n##########################\n\n") ;
do {
while(x==1)
{

if(t==1)
{
c=rand()%8+3;
a=rand()%10+1;
}
if(t==2)
{
a=rand()%5+1;
c=rand()%4+1;
}
if(t==3)
{
c=rand()%3+1;
a=rand()%3+1;
}
if(t==4)
{
a=rand()%2+1;
c=rand()%3+1;
}
if(t==5)
a=rand()%8+1;
if(t==6)
a=rand()%3+1;

b+=a,d+=c;

if(d>16)
t=2;
if(d==19&&b==19)
t=3;
if(d==20&&b==20)
t=3;
if(b==20&&d==19)
t=4;
if(d==19&&(d-b)>3)
t=5;
if(d==20&&d>b)
t=6;
if(d==21)
t=6;

if(i==1)
{
do
{
printf(" 您現在還有%d個金幣,系統有%d個,請輸入賭注: ",s,k);
scanf("%d",&n);
}
while(s<n);
i++;
}

if(b>21&&d<22)
{
printf(" 你%d點,系統%d點,你輸了!\n\n\n\n",b,d);
s-=n;
k+=n;
t=i=1,b=d=0;
break;
}
if(d>21&&b<22)
{
printf(" 你%d點,系統%d點,你贏了!\n\n\n\n",b,d);
s+=n;
k-=n;
t=i=1,b=d=0;
break;
}
if(d>21&&b>21)
{
printf(" 你%d點,系統%d點,平局!
\n\n\n",b,d);
t=i=1,b=d=0;
break;
}

printf(" 您加%d點,系統加%d點!\n 您現在共 %d點,系統現在共 %d點!\n 是否繼續加點 ",a,c,b,d);
scanf(" %d",&x);
a=c=0;
if(x!=1)
{
if(d<b&&d<18)
{
c=rand()%4+2;
d=d+c;
printf("您不加點,系統加%d點",c);
}
if(d<b&&d==20)
{
c=rand()%2+1;
d=d+c;
printf("您不加點,系統加%d點",c);
}
if(d<b&&d==19)
{
c=rand()%4+1;
d=d+c;
printf("您不加點,系統加%d點",c);
}
if(d<b&&d==18)
{
c=rand()%5+1;
d=d+c;
printf("您不加點,系統加%d點",c);
}
if(d>b)
printf("您不加點,系統不加點");

if(d<22&&d>b)
{
printf(" 你%d點,系統%d點,你輸了!\n\n\n\n",b,d);
s-=n;
k+=n;
t=x=i=1,b=d=0;
break;
}
if(b>d&&b<22||b<22&&d>21)
{
printf(" 你%d點,系統%d點,你贏了!\n\n\n\n",b,d);
s+=n;
k-=n;
t=x=i=1,b=d=0;
break;
}
if(b==d)
{
printf(" 你%d點,系統%d點,平局!
\n\n\n\n",b,d);
t=x=i=1,b=d=0;
break;
}
}
}
}
while(s>0&&k>0);
printf("您有%d個金幣,系統有%d個金幣!\n\n" ,s,k);
if(s>k)
printf("太棒了,你把系統打敗了!!!\n");else if(k>s)
printf(" 您的金幣不足,挑戰系統失敗!\n");
return 0;
}

㈣ 怎樣獲取小游戲的源碼

看3366源碼是2867785235

㈤ 怎樣獲得一款游戲的源代碼

源碼可以找游戲公司要,比如夢幻誅仙為什麼那麼多私服,就是源碼搭出來的

㈥ 誰能給我一個手機游戲的源代碼啊

這個地址也有,不過直接給你吧,這樣比較好
先給你看看主要的類吧

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

看不明白的可以隨時來問我哦,還可以當時傳給你撒

㈦ 什麼軟體可以看到游戲的源代碼

軟體游戲都是封裝好了再交付用戶使用的,一般不會透露源代碼。現在只有一些反編軟體可以看到很低級的機器語言和匯編語言,想看高級語言的話應該是看不到的,你想啊,那麼容易讓你看到了,人家的版權利益怎麼保障啊

㈧ 求小游戲網站源碼

源碼是什麼

㈨ 用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];

};

(9)稀有游戲源碼擴展閱讀:

設計思路

1、進行問題分析與設計,計劃實現的功能為,開局選擇人機或雙人對戰,確定之後比賽開始。

2、比賽結束後初始化棋盤,詢問是否繼續比賽或退出,後續可加入復盤、悔棋等功能。

3、整個過程中,涉及到了棋子和棋盤兩種對象,同時要加上人機對弈時的AI對象,即涉及到三個對象。

熱點內容
md5加密後的密碼是什麼意思 發布:2025-01-18 15:50:16 瀏覽:192
如何qq空間訪問許可權 發布:2025-01-18 15:49:30 瀏覽:531
matlab遺傳演算法約束 發布:2025-01-18 15:31:33 瀏覽:909
果凍java 發布:2025-01-18 15:25:59 瀏覽:695
電腦與時間伺服器同步間隔 發布:2025-01-18 15:21:28 瀏覽:54
蘋果手機apple登錄密碼在手機哪裡 發布:2025-01-18 15:13:43 瀏覽:380
吃雞去哪裡下手游安卓 發布:2025-01-18 15:10:59 瀏覽:668
東方財富dk指標源碼 發布:2025-01-18 14:45:53 瀏覽:435
陌陌登陸密碼是什麼 發布:2025-01-18 14:36:54 瀏覽:848
海龜編譯器代碼 發布:2025-01-18 14:16:51 瀏覽:34