菜雞游戲源碼
Ⅰ 求C++小游戲源代碼啊~
一個戀愛小測試賊靈驗哦
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,a,b,c,d,e,f,g,h,i,j,k,l,sum;
cout<<"歡迎來到戀愛指數測試器*>-<*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"獨家的哦*^0^*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"以下異性均為合適年齡"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"下列問題如果是則輸入2,如果不是則輸入1,一點也沒感覺輸入0"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"加油,面對你自己!*-o-*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"question one:"<<"你是否面對異性時有莫名心跳?"<<endl;
cin>>n;
cout<<endl;
cout<<"question two:"<<"你是否有看到異性被撩時很憤怒?"<<endl;
cin>>m;
cout<<endl;
cout<<"question three:"<<"你是否懼怕見到一位異性的家長"<<endl;
cin>>a;
cout<<endl;
cout<<"question four:"<<"你是否經常刷一位異性的QQ或其他軟體"<<endl;
cin>>b;
cout<<endl;
cout<<"question five:"<<"想不想真心和Ta用情頭?"<<endl;
cin>>c;
cout<<endl;
cout<<"question six:"<<"和Ta邂逅過嗎?"<<endl;
cin>>d;
cout<<endl;
cout<<"question seven:"<<"吃過同一個飯碗里的東西嗎?"<<endl;
cin>>e;
cout<<endl;
cout<<"question eight:"<<"有過一個人在夢里與Ta相遇嗎?"<<endl;
cin>>f;
cout<<endl;
cout<<"question nine:"<<"有為了等Ta一個人站在風雨中嗎?"<<endl;
cin>>g;
cout<<endl;
cout<<"question ten:"<<"想kissTa不,想摸Ta的頭發嗎?"<<endl;
cin>>h;
cout<<endl;
sum=n+m+a+b+c+d+e+f+g+h;
cout<<"正在測評中,請稍後..."<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
if(sum>=16&&sum<=20)
cout<<"你的戀愛指數為:A。你是一個深深愛著Ta的人,你往往會走到最後^-^。"<<endl;
if(sum<=15&&sum>=12)
cout<<"你的戀愛指數為:B。你是一個矛盾卻又不失愛意的人,你的愛往往一波三折!-!。"<<endl;
if(sum<=11&&sum>=7)
cout<<"你的戀愛指數為:C。你是一個有點點情絲的人,你想表,卻又懼怕現實,你仍須努力o-o。"<<endl;
if(sum<=6&&sum>=0)
cout<<"你的戀愛指數為:D。你是一個無暇無垢,不食人間煙火的人,想一路踏歌,證道路上需佳人陪伴+-+。"<<endl;
if(sum>20||sum<0)
cout<<"你出格了喲ooo.ooo"<<endl;
cout<<"人生在世,恍如昨世,孤獨的身影終難走遠,你的那個Ta就在不遠方,就如漫天繁星,總有一顆屬於你!"<<endl;\
cout<<"快抓緊你身邊的那個Ta^-^oooooo"<<endl;
cout<<endl;
cout<<"作品創造者:yang sky one"<<endl;
cout<<"戀愛指數測試器已關閉,需重啟………………"<<endl;
return 0;
}
Ⅱ J2EE貪吃蛇游戲源代碼
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
/**
*
* @author lenovo
*/
public class TanChiShe extends JFrame implements ActionListener, KeyListener,Runnable{
private JMenuBar menuBar;
private JMenu youXiMenu,nanDuMenu,fenShuMenu,guanYuMenu;
private JMenuItem kaiShiYouXi,exitItem,zuoZheItem,fenShuItem;
private JCheckBoxMenuItem cJianDan,cPuTong,cKunNan;
private int length = 6;
private Toolkit toolkit;
private int i,x,y,z,objectX,objectY,object=0,growth=0,time;//bojectX,Y為食物坐標,z為蛇前進方向
private int difficult=2;
private int m[]=new int[50];
private int n[]=new int[50];
private Thread she = null;
private int life=0;
private int foods = 0;
private int fenshu=0;
public void run()
{
time=500;
for(i=0;i<=length-1;i++)
{
m[i]=90-i*10;n[i]=60;
}
x=m[0];
y=n[0];
z=4;
while(she!=null)
{
check();
try
{
she.sleep(time);
}
catch(Exception ee)
{
System.out.println(z+"");
}
}
}
public TanChiShe()
{
//***************創建新對象**************
setVisible(true);
menuBar = new JMenuBar();
Container con=getContentPane();
toolkit=getToolkit();
//**************游戲菜單對象*****************
youXiMenu = new JMenu("游戲");
kaiShiYouXi = new JMenuItem("開始游戲");
exitItem = new JMenuItem("退出遊戲");
//***************困難程度對象****************
nanDuMenu = new JMenu("困難程度");
cJianDan = new JCheckBoxMenuItem("簡單");
cPuTong = new JCheckBoxMenuItem("普通");
cKunNan = new JCheckBoxMenuItem("困難");
//*****************分數菜單對象****************
fenShuMenu = new JMenu("積分排行");
fenShuItem = new JMenuItem("最高記錄");
//****************關於對象*********************
guanYuMenu = new JMenu("關於");
zuoZheItem = new JMenuItem("關於作者");
//***************設置關於菜單*******************
guanYuMenu.add(zuoZheItem);
//****************設置困難程度菜單**************
nanDuMenu.add(cJianDan);
nanDuMenu.add(cPuTong);
nanDuMenu.add(cKunNan);
//******************設置分數菜單***************
fenShuMenu.add(fenShuItem);
//*****************設置游戲菜單****************
youXiMenu.add(kaiShiYouXi);
youXiMenu.add(exitItem);
//******************設置主菜單********************
menuBar.add(youXiMenu);
menuBar.add(nanDuMenu);
menuBar.add(fenShuMenu);
menuBar.add(guanYuMenu);
//*********************監聽注冊*****************
zuoZheItem.addActionListener(this);
kaiShiYouXi.addActionListener(this);
exitItem.addActionListener(this);
addKeyListener(this);
fenShuItem.addActionListener(this);
//*********************加快捷鍵********************
KeyStroke keyOpen = KeyStroke.getKeyStroke('O',InputEvent.CTRL_DOWN_MASK);
kaiShiYouXi.setAccelerator(keyOpen);
KeyStroke keyExit = KeyStroke.getKeyStroke('X',InputEvent.CTRL_DOWN_MASK);
exitItem.setAccelerator(keyExit);
//*****************設置框架**********************
setJMenuBar(menuBar);
setTitle("貪吃蛇");
setResizable(false);
setBounds(300,200,400,400);
validate();
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[])
{
TanChiShe 高原=new TanChiShe();
}
//******************菜單監聽******************************
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==kaiShiYouXi)
{
length = 6;
life = 0;
foods = 0;
if(she==null)
{
she=new Thread(this);
she.start();
}
else if(she!=null)
{
she=null;
she= new Thread(this);
she.start();
}
}
if(e.getSource()==exitItem)
{
System.exit(0);
}
if(e.getSource()==zuoZheItem)
{
JOptionPane.showMessageDialog(this, "北京java編程愛好者製作"+"\n\n"+" "+"QQ號:860695120"+"\n");
}
if(e.getSource()==fenShuItem)
{
JOptionPane.showMessageDialog(this,"最高記錄為"+fenshu+"");
}
}
//**************檢查一下*******************************
public void check()
{
isDead();
if(she!=null)
{
if(growth==0)
{
reform(); //得到食物
}
else
{
upgrowth(); //生成食物
}
if(x==objectX&&y==objectY)
{
object=0;
growth=1;
toolkit.beep();
}
//****************產生食物坐標**********************
if(object==0)
{
object=1;
objectX=(int)Math.floor(Math.random()*39)*10;
objectY=(int)Math.floor(Math.random()*29)*10+50;
}
this.repaint(); //重繪
}
}
void isDead()
{
//判斷游戲是否結束的方法
if(z==4)
{
x=x+10;
}
else if(z==3)
{
x=x-10;
}
else if(z==2)
{
y=y+10;
}
else if(z==1)
{
y=y-10;
}
if(x<0||x>390||y<50||y>390)
{
she=null;
}
for(i=1;i<length;i++)
{
if(m[i]==x&&n[i]==y)
{
she=null;
}
}
}
public void upgrowth()
{
//當蛇吃到東西時的方法
if(length<50)
{
length++;
}
growth--;
time=time-10;
reform();
life+=100;
if(fenshu<life)
{
fenshu = life;
}
foods++;
}
public void reform()
{
for(i=length-1;i>0;i--)
{
m[i]=m[i-1];
n[i]=n[i-1];
}
if(z==4)
{
m[0]=m[0]+10;
}
if(z==3)
{
m[0]=m[0]-10;
}
if(z==2)
{
n[0]=n[0]+10;
}
if(z==1)
{
n[0]=n[0]-10;
}
}
public void keyPressed(KeyEvent e)
{
if(she!=null)
{
if(e.getKeyCode()==KeyEvent.VK_UP)
{
if(z!=2)
{
z=1;
check();
}
}
else if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
if(z!=1)
{
z=2;
check();
}
}
else if(e.getKeyCode()==KeyEvent.VK_LEFT)
{
if(z!=4)
{
z=3;
check();
}
}
else if(e.getKeyCode()==KeyEvent.VK_RIGHT)
{
if(z!=3)
{
z=4;
check();
}
}
}
}
public void keyReleased(KeyEvent e)
{
// TODO 自動生成方法存根
}
public void keyTyped(KeyEvent e)
{
// TODO 自動生成方法存根
}
public void paint(Graphics g)
{
//*******************畫圖**********************
g.setColor(Color.DARK_GRAY); //設置背景
g.fillRect(0,50,400,400);
g.setColor(Color.pink);
for(i=0;i<=length-1;i++)
{
g.fillRect(m[i],n[i],10,10);
}
g.setColor(Color.green); //蛇的食物
g.fillRect(objectX,objectY,10,10);
g.setColor(Color.white);
g.drawString("當前 分數"+this.life,6,60);
g.drawString("當前已吃食物數"+this.foods,6,72);
}
}
Ⅲ 求一個C++的貪吃蛇游戲源代碼,要標註解釋的。
/*因為當時只考慮到了代碼可通過,沒有考慮代碼的質量,所以重復利用率差,不要隨意改動哦
運行是完全通過的但是會一閃一閃的*/
#include<iostream>
#include<conio.h>
#include<time.h>
#include<windows.h>
#define X 15
#define Y 15
int score=0;
char ch[X][Y];
char lch = 's';
char nch = 's';
class Snake
{
public:
Snake() { nx = 8;ny = 8;lx = 9;ly = 9;next = NULL; }
Snake(Snake&r);//建立蛇身
void input();//把數據輸入到圖像
void control();//控制貪吃蛇
void show();//顯示圖像
void check();//檢測食物是否被吃掉
bool gameover();//檢測游戲是否結束
int nx;
int ny;
int lx;
int ly;
Snake*next;
};
Snake *head;
namespace Food
{
int x;
int y;
void NEW()
{
Snake*p=head;
x = rand() % X;
y = rand() % Y;
while(p!=NULL)
{
if(p->nx==x&&p->ny==y)
{
x = rand() % X;
y = rand() % Y;
p = head;
}
else
p=p->next;
}
ch[x][y]='$';
}
};
Snake::Snake(Snake&r)
{
this->nx = r.lx;
this->ny = r.ly;
r.next = this;
this->next = NULL;
}
void Snake::show()//顯示圖像
{
system("cls");
//std::cout << " ------------------------------ \n";
for (int y = 0; y<Y; ++y)
{
//std::cout << "|";
for (int x = 0; x < X; ++x)
std::cerr << ch[x][y] << " " ;
std::cerr <<"|"<< std::endl;
}
std::cout << " ------------------------------ \n";
printf("x = %d,y = %d\n",nx,ny);
printf("x = %0X,y = %0X\n",&nx,&ny);
printf("score = %d\n",score);
}
void Snake::control()//鍵盤控制
{
if (_kbhit() == 1)
{
nch = _getch();
lx = nx;
ly = ny;
if (nch == 'w' || nch == 's' || nch == 'a' || nch == 'd')
{
lch = nch;
switch (nch)
{
case 'w':if (ny == 0) ny = Y - 1; else --ny; break;
case 's':if (ny == Y - 1) ny = 0; else ++ny; break;
case 'a':if (nx == 0) nx = X - 1; else --nx; break;
case 'd':if (nx == X - 1) nx = 0; else ++nx; break;
}
}
else
{
switch (lch)
{
case 'w':if (ny == 0) ny = Y - 1; else --ny; break;
case 's':if (ny == Y - 1) ny = 0; else ++ny; break;
case 'a':if (nx == 0) nx = X - 1; else --nx; break;
case 'd':if (nx == X - 1) nx = 0; else ++nx; break;
}
}
}
else
{
lx = nx;
ly = ny;
if (nch == 'w' || nch == 's' || nch == 'a' || nch == 'd')
{
lch = nch;
switch (nch)
{
case 'w':if (ny == 0) ny = Y - 1; else --ny; break;
case 's':if (ny == Y - 1) ny = 0; else ++ny; break;
case 'a':if (nx == 0) nx = X - 1; else --nx; break;
case 'd':if (nx == X - 1) nx = 0; else ++nx; break;
}
}
else
{
switch (lch)
{
case 'w':if (ny == 0) ny = Y - 1; else --ny; break;
case 's':if (ny == Y - 1) ny = 0; else ++ny; break;
case 'a':if (nx == 0) nx = X - 1; else --nx; break;
case 'd':if (nx == X - 1) nx = 0; else ++nx; break;
}
}
}
}
void Snake::input()//把對象輸入到圖像
{
Snake*p = head;
ch[p->lx][p->ly] = ' ';
ch[p->nx][p->ny] = '*';
while (p->next != NULL)
{
p->next->lx = p->next->nx;
p->next->ly = p->next->ny;
p->next->nx = p->lx;
p->next->ny = p->ly;
p = p->next;
ch[p->lx][p->ly] = ' ';
ch[p->nx][p->ny] = '*';
}
}
void Snake::check()//檢測食物是否被吃掉
{
Snake*p=head;
if (p->nx == Food::x&&p->ny == Food::y)
{
Snake*p = head;
while (p->next != NULL)
{
p = p->next;
}
p->next = new Snake(*p);
Food::NEW();
++score;
}
}
bool Snake::gameover()//檢測游戲是否結束
{
Snake*p = head;
Snake*pn = head->next;
while (p != NULL)
{
while (pn != NULL)
{
if (p->nx == pn->nx&&p->ny == pn->ny)
{
std::cout << "Game Over\n";
return true;
}
pn = pn->next;
}
p = p->next;
}
return 0;
}
int main()
{
//初始化
srand(time(NULL));
for (int y = 0; y<Y; ++y)
for (int x = 0; x<X; ++x)
ch[x][y] = ' ';
head = new Snake;
Food::NEW();
std::cout<<"游戲規則:\n1.wsad(小寫)控制蛇\n2.若蛇節數超過2,那麼無法反方向運動,\n若反方向運動則GameOver\n3.'*'為蛇,'$'為食物\n";
system("pause");
//開始游戲
while (1)
{
head->control();
head->input();
head->check();
if(head->gameover())
break;
head->show();
Sleep(100);
}
Sleep(1000);
system("pause");
return 0;
}
/*------------------------------------------------------------------------------------
當然你也可以用下面這個,經過一些奇怪的演算法,當然可讀性極差,不閃,但是有時有些莫名其妙的bug的,這是把輸出圖像變成了一個一維數組,用一維數組來模擬直角坐標系
------------------------------------------------------------------------------------*/
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#define X 32
#define Y 17
char ch[544];
char nch = 's';
char lch = 's';
int score = 0;
class Snake
{
public:
Snake();//創建蛇頭
void Add();//添加蛇身
void Show();//顯示圖像
bool GameOver();//檢測游戲是否結束
void Input();//輸入數據
void Check();//檢測食物是否被吃
void Control();//輸入控制
void INIT();
int GetX(){return nx;}
int GetY(){return ny;}
Snake *next;
private:
int lx;
int ly;
int nx;
int ny;
};
Snake*head;
Snake*finally;
namespace Food
{
int x;
int y;
void GetXY()
{
std::cout<<"Food x = "<<x<<"Food y = "<<y<<"\n";
}
void NEW()
{
Snake*p=head;
x = (rand()%15)+1;
y = (rand()%15)+1;
while(p!=NULL)
{
if(p->GetX()==x&&p->GetY()==y)
{
x = (rand()%15)+1;
y = (rand()%15)+1;
p=head;
}
p=p->next;
}
ch[y*32+x*2-1]='$';
}
};
void Snake :: INIT()//初始化
{
for(int n=0;n<=543;++n)
ch[n]=' ';
for(int n=1;n<30;++n)
ch[n]='-';
for(int n=1;n<30;++n)
ch[n+512]='-';
for(int n=0;n<=16;++n)
ch[n*32+31]='\n';
for(int n=1;n<=16;++n)
ch[n*32+30]='|';
for(int n=1;n<=16;++n)
ch[n*32]='|';
ch[543]='\0';
next=NULL;
Food::NEW();
lx = 4;
ly = 4;
nx = 4;
ny = 5;
ch[ly*32+lx*2-1]='*';
}
Snake :: Snake()//創建蛇頭head
{
}
void Snake :: Add()//添加蛇身
{
finally->next = new Snake;
finally->next->nx=finally->lx;
finally->next->ny=finally->ly;
finally->next->next=NULL;
finally=finally->next;
}
void Snake :: Control()//控制輸入
{
if(kbhit()==1){
nch=getch();
if(nch=='w'||nch=='s'||nch=='a'||nch=='d'){
lch=nch;
switch(nch)
{
case 'w':if(ny==1) ny=15;else ny--;break;
case 's':if(ny==15) ny=1;else ny++;break;
case 'a':if(nx==1) nx=15;else nx--;break;
case 'd':if(nx==15) nx=1;else nx++;break;
}
}else{
switch(lch)
{
case 'w':if(ny==1) ny=15;else ny--;break;
case 's':if(ny==15) ny=1;else ny++;break;
case 'a':if(nx==1) nx=15;else nx--;break;
case 'd':if(nx==15) nx=1;else nx++;break;
}
}
}else{
switch(lch)
{
case 'w':if(ny==1) ny=15;else ny--;break;
case 's':if(ny==15) ny=1;else ny++;break;
case 'a':if(nx==1) nx=15;else nx--;break;
case 'd':if(nx==15) nx=1;else nx++;break;
}
}
}
void Snake :: Show()//顯示圖像
{
std::cerr<<ch<<"\nscore = "<<score<<"\t";
}
void Snake :: Input()//輸入數據
{
Snake*p = head;
ch[(p->lx)*2+(p->ly)*32-1] = ' ';
ch[(p->nx)*2+(p->ny)*32-1] = '*';
while (p->next != NULL)
{
p->next->lx = p->next->nx;
p->next->ly = p->next->ny;
p->next->nx = p->lx;
p->next->ny = p->ly;
p = p->next;
ch[(p->lx)*2+(p->ly)*32-1] = ' ';
ch[(p->nx)*2+(p->ny)*32-1] = '*';
}
head->lx=head->nx;
head->ly=head->ny;
}
bool Snake :: GameOver()//檢測游戲是否結束
{
Snake *p = head;
Snake *pl ;
while(p!=NULL)
{
pl=p->next;
while(pl!=NULL)
{
if(p->nx==pl->nx&&p->ny==pl->ny){
std::cout<<"\nGameOver\n";
return true;
}
pl=pl->next;
}
p=p->next;
}
return false;
}
void Snake :: Check()//檢測食物是否被吃掉
{
if(head->nx==Food::x&&head->ny==Food::y)
{
Food::NEW();
head->Add();
score++;
}
}
int main(int argc,char *argv[])
{
srand(time(NULL));
head=new Snake;
head->INIT();
finally = head;
while(1)
{
head->Control();//控制輸出
head->Input();//輸入數據
system("cls");
head->Show();//顯示圖像
Sleep(150);
if(head->GameOver())//檢測游戲是否結束
break;
head->Check();//檢測食物是否被吃
}
Sleep(1000);
printf("請按任意鍵退出\n");
_getch();
return 0;
}
Ⅳ 游戲軟體怎麼查看源代碼
源代碼是看不成的,因為游戲軟體打包好做成app的話,是沒法看源碼的,雖然存在一些特殊情況下,我們可以推測出exe程序是用什麼程序寫的。但是多數情況下,我們是無法只根據一個exe程序就判斷出來的。
根據exe程序我們是無法直接得到程序的源碼的。雖然也有一些用於逆向工程的辦法,但那不可能把已經是exe的程序反回到它原始的源碼情況。而且這些工具都很難用。你可以用「反編譯」搜到很多工具,但是說實話,即便是這方面的專家,要看懂反編譯以後的程序也不是一件輕松的事情。
Ⅳ 用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];
};
(5)菜雞游戲源碼擴展閱讀:
設計思路
1、進行問題分析與設計,計劃實現的功能為,開局選擇人機或雙人對戰,確定之後比賽開始。
2、比賽結束後初始化棋盤,詢問是否繼續比賽或退出,後續可加入復盤、悔棋等功能。
3、整個過程中,涉及到了棋子和棋盤兩種對象,同時要加上人機對弈時的AI對象,即涉及到三個對象。
Ⅵ 跪求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;
cin>>xiaozhen;
while(xiaozhen!=5)//輸入5時退出遊戲
{
if(shengmingli<=0)//主角生命力小於等於0時游戲結束
{
cout<<"你死啦!"<<endl;
break;
}
if(guoguan)
{
cout<<"恭喜通關!"<<endl;
break;
}
if(xiaozhen==6)//輸入6可檢測自己的狀態
{
cout<<"你的生命力:"<<shengmingli<<endl;
cout<<"你的攻擊力:"<<gongjili<<endl;
cout<<"你的防禦力:"<<fangyuli<<endl;
cout<<"你擁有的錢:"<<money<<endl;
}
else
switch(xiaozhen)
{
case 1 : wuqidian();break;
case 2 : yaodian();break;
case 3 : guaiwu1();break;
case 4 : guaiwu2();break;
default : cout<<"請不要亂選!"<<endl;break;
}
cin>>xiaozhen;
}
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;
cin>>wuqidian;
while(wuqidian!=7)//輸入7時結束函數
{
switch(wuqidian)
{
case 1 : if(money<10)
cout<<"你的錢不夠"<<endl;//錢不夠時返回Flase
else
cout<<"購買成功!"<<endl;//錢足夠時返回True
gongjili+=2;
money-=1;
break;
case 2 : if(money<80)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
gongjili+=20;
money-=80;
break;
case 3 : if(money<140)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
gongjili+=40;
money-=140;
break;
case 4 : if(money<200)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
gongjili+=60;
money-=200;
break;
case 5 : if(money<60)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
fangyuli+=30;
money-=60;
break;
fangyuli+=60;
money-=100;
break;
default : cout<<"無"<<endl;
break;
}
cin>>wuqidian;
}
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;
cin>>yaodian;
while(yaodian!=4)
{
switch(yaodian)
{
case 1 : if(money<10)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
shengmingli+=200;
money-=10;
break;
case 2 : if(money<50)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
shengmingli+=1000;
money-=50;
break;
case 3 : if(money<100)
cout<<"你的錢不夠"<<endl;
else
cout<<"購買成功!"<<endl;
shengmingli+=2200;
money-=100;
break;
default : cout<<"無"<<endl;
break;
}
cin>>yaodian;
}
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 && shengmingli>0 && (*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 && shengmingli>0 && (*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;
}
Ⅶ 菜雞游戲安卓系統是多少
早期版本的安卓體統都要低一點,以此類推,越新的版本,要求越高
Ⅷ 游戲源代碼
網路游戲源代碼就是游戲的基礎,在外行人眼裡是無數行的英文和數字,其實就是一組程序。作用當然是開發游戲啦。手上擁有了源代碼就可以製作游戲,當然如果你啥都不改,那功能就和原來的游戲沒什麼兩樣。現在網上你可以搜索一下網路游戲的源代碼還是非常多的,但是大多數都是不完整的,也就是...
Ⅸ 急!!!求大神做份Java作業菜雞做了5天硬是沒做出來
這種源碼網上不是一大堆嗎,自己去找吧。找代做和找源碼沒區別。