菜鸡游戏源码
Ⅰ 求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天硬是没做出来
这种源码网上不是一大堆吗,自己去找吧。找代做和找源码没区别。