dev-c++小游戏代码,急急急急!!!!!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dev-c++小游戏代码,急急急急!!!!!相关的知识,希望对你有一定的参考价值。

#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;

/*=============== all the structures ===============*/

typedef struct Frame

COORD position[2];
int flag;
Frame;

/*=============== all the functions ===============*/

void SetPos(COORD a)// set cursor

HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);


void SetPos(int i, int j)// set cursor

COORD pos=i, j;
SetPos(pos);


void HideCursor()

CONSOLE_CURSOR_INFO cursor_info = 1, 0;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);


//把第y行,[x1, x2) 之间的坐标填充为 ch
void drawRow(int y, int x1, int x2, char ch)

SetPos(x1,y);
for(int i = 0; i <= (x2-x1); i++)
cout<<ch;


//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
void drawRow(COORD a, COORD b, char ch)

if(a.Y == b.Y)
drawRow(a.Y, a.X, b.X, ch);
else

SetPos(0, 25);
cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等";
system("pause");



//把第x列,[y1, y2] 之间的坐标填充为 ch
void drawCol(int x, int y1, int y2, char ch)

int y=y1;
while(y!=y2+1)

SetPos(x, y);
cout<<ch;
y++;



//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
void drawCol(COORD a, COORD b, char ch)

if(a.X == b.X)
drawCol(a.X, a.Y, b.Y, ch);
else

SetPos(0, 25);
cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等";
system("pause");



//左上角坐标、右下角坐标、用row填充行、用col填充列
void drawFrame(COORD a, COORD b, char row, char col)

drawRow(a.Y, a.X+1, b.X-1, row);
drawRow(b.Y, a.X+1, b.X-1, row);
drawCol(a.X, a.Y+1, b.Y-1, col);
drawCol(b.X, a.Y+1, b.Y-1, col);


void drawFrame(int x1, int y1, int x2, int y2, char row, char col)

COORD a=x1, y1;
COORD b=x2, y2;
drawFrame(a, b, row, col);


void drawFrame(Frame frame, char row, char col)

COORD a = frame.position[0];
COORD b = frame.position[1];
drawFrame(a, b, row, col);


void drawPlaying()

drawFrame(0, 0, 48, 24, '=', '|');// draw map frame;
drawFrame(49, 0, 79, 4, '-', '|');// draw output frame
drawFrame(49, 4, 79, 9, '-', '|');// draw score frame
drawFrame(49, 9, 79, 20, '-', '|');// draw operate frame
drawFrame(49, 20, 79, 24, '-', '|');// draw other message frame
SetPos(52, 6);
cout<<"得分:";
SetPos(52, 7);
cout<<"称号:";
SetPos(52,10);
cout<<"操作方式:";
SetPos(52,12);
cout<<" a,s,d,w 控制战机移动。";
SetPos(52,14);
cout<<" p 暂停游戏。";
SetPos(52,16);
cout<<" e 退出游戏。";
SetPos(52,18);
cout<<" k 发射子弹。";


//在[a, b)之间产生一个随机整数
int random(int a, int b)

int c=(rand() % (a-b))+ a;
return c;


//在两个坐标包括的矩形框内随机产生一个坐标
COORD random(COORD a, COORD b)

int x=random(a.X, b.X);
int y=random(a.Y, b.Y);
COORD c=x, y;
return c;


bool judgeCoordInFrame(Frame frame, COORD spot)

if(spot.X>=frame.position[0].X)
if(spot.X<=frame.position[1].X)
if(spot.Y>=frame.position[0].Y)
if(spot.Y<=frame.position[0].Y)
return true;
return false;


void printCoord(COORD a)

cout <<"( "<<a.X<<" , "<<a.Y<<" )";


void printFrameCoord(Frame a)

printCoord(a.position[0]);
cout <<" - ";
printCoord(a.position[1]);


int drawMenu()

SetPos(30, 1);
cout<<"P l a n e W a r";
drawRow(3, 0, 79, '-');
drawRow(5, 0, 79, '-');
SetPos(28, 4);
cout<<"w 和 s 选择, k 确定";
SetPos(15, 11);
cout<<"1. 简单的敌人";
SetPos(15, 13);
cout<<"2. 冷酷的敌人";
drawRow(20, 0, 79, '-');
drawRow(22, 0, 79, '-');
SetPos(47, 11);
cout<<"简单的敌人:";
SetPos(51, 13);
cout<<"简单敌人有着较慢的移动速度。";
SetPos(24, 21);
cout<<" ☆○☆○☆○☆○☆○☆ ";
int j=11;
SetPos(12, j);
cout<<">>";

//drawFrame(45, 9, 79, 17, '=', '|');

while(1)
if( _kbhit() )

char x=_getch();
switch (x)

case 'w' :

if( j == 13)

SetPos(12, j);
cout<<" ";
j = 11;
SetPos(12, j);
cout<<">>";
SetPos(51, 13);
cout<<"            ";
SetPos(47, 11);
cout<<"简单的敌人:";
SetPos(51, 13);
cout<<"简单敌人有着较慢的移动速度。";

break;

case 's' :

if( j == 11 )

SetPos(12, j);
cout<<" ";
j = 13;
SetPos(12, j);
cout<<">>";
SetPos(51, 13);
cout<<"              ";
SetPos(47, 11);
cout<<"冷酷的敌人:";
SetPos(51, 13);
cout<<"冷酷的敌人移动速度较快。";

break;

case 'k' :

if (j == 8) return 1;
else return 2;






/*
DWORD WINAPI MusicFun(LPVOID lpParamte)

//DWORD OBJ;
sndPlaySound(TEXT("bgm.wav"), SND_FILENAME|SND_ASYNC);
return 0;

*/

/*================== the Game Class ==================*/

class Game

public:
COORD position[10];
COORD bullet[10];
Frame enemy[8];
int score;
int rank;
int rankf;
string title;
int flag_rank;

Game ();

//初始化所有
void initPlane();
void initBullet();
void initEnemy();

//初始化其中一个
//void initThisBullet( COORD );
//void initThisEnemy( Frame );

void planeMove(char);
void bulletMove();
void enemyMove();

//填充所有
void drawPlane();
void drawPlaneToNull();
void drawBullet();
void drawBulletToNull();
void drawEnemy();
void drawEnemyToNull();

//填充其中一个
void drawThisBulletToNull( COORD );
void drawThisEnemyToNull( Frame );

void Pause();
void Playing();
void judgePlane();
void judgeEnemy();

void Shoot();

void GameOver();
void printScore();
;

Game::Game()

initPlane();
initBullet();
initEnemy();
score = 0;
rank = 25;
rankf = 0;
flag_rank = 0;


void Game::initPlane()

COORD centren=39, 22;
position[0].X=position[5].X=position[7].X=position[9].X=centren.X;
position[1].X=centren.X-2;
position[2].X=position[6].X=centren.X-1;
position[3].X=position[8].X=centren.X+1;
position[4].X=centren.X+2;
for(int i=0; i<=4; i++)
position[i].Y=centren.Y;
for(int i=6; i<=8; i++)
position[i].Y=centren.Y+1;
position[5].Y=centren.Y-1;
position[9].Y=centren.Y-2;


void Game::drawPlane()

for(int i=0; i<9; i++)

SetPos(position[i]);
if(i!=5)
cout<<"o";
else if(i==5)
cout<<"|";



void Game::drawPlaneToNull()

for(int i=0; i<9; i++)

SetPos(position[i]);
cout<<" ";



void Game::initBullet()

for(int i=0; i<10; i++)
bullet[i].Y = 30;


void Game::drawBullet()

for(int i=0; i<10; i++)

if( bullet[i].Y != 30)

SetPos(bullet[i]);
cout<<"^";




void Game::drawBulletToNull()

for(int i=0; i<10; i++)
if( bullet[i].Y != 30 )

COORD pos=bullet[i].X, bullet[i].Y+1;
SetPos(pos);
cout<<" ";



void Game::initEnemy()

COORD a=1, 1;
COORD b=45, 15;
for(int i=0; i<8; i++)

enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;



void Game::drawEnemy()

for(int i=0; i<8; i++)
drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|');


void Game::drawEnemyToNull()

for(int i=0; i<8; i++)

drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' ');



void Game::Pause()

SetPos(61,2);
cout<<" ";
SetPos(61,2);
cout<<"暂停中...";
char c=_getch();
while(c!='p')
c=_getch();
SetPos(61,2);
cout<<" ";


void Game::planeMove(char x)

if(x == 'a')
if(position[1].X != 1)
for(int i=0; i<=9; i++)
position[i].X -= 2;

if(x == 's')
if(position[7].Y != 23)
for(int i=0; i<=9; i++)
position[i].Y += 1;

if(x == 'd')
if(position[4].X != 47)
for(int i=0; i<=9; i++)
position[i].X += 2;

if(x == 'w')
if(position[5].Y != 3)
for(int i=0; i<=9; i++)
position[i].Y -= 1;


void Game::bulletMove()

for(int i=0; i<10; i++)

if( bullet[i].Y != 30)

bullet[i].Y -= 1;
if( bullet[i].Y == 1 )

COORD pos=bullet[i].X, bullet[i].Y+1;
drawThisBulletToNull( pos );
bullet[i].Y=30;






void Game::enemyMove()

for(int i=0; i<8; i++)

for(int j=0; j<2; j++)
enemy[i].position[j].Y++;

if(24 == enemy[i].position[1].Y)

COORD a=1, 1;
COORD b=45, 3;
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;




void Game::judgePlane()

for(int i = 0; i < 8; i++)
for(int j=0; j<9; j++)
if(judgeCoordInFrame(enemy[i], position[j]))

SetPos(62, 1);
cout<<"坠毁";
drawFrame(enemy[i], '+', '+');
Sleep(1000);
GameOver();
break;



void Game::drawThisBulletToNull( COORD c)

SetPos(c);
cout<<" ";


void Game::drawThisEnemyToNull( Frame f )

drawFrame(f, ' ', ' ');


void Game::judgeEnemy()

for(int i = 0; i < 8; i++)
for(int j = 0; j < 10; j++)
if( judgeCoordInFrame(enemy[i], bullet[j]) )

score += 5;
drawThisEnemyToNull( enemy[i] );
COORD a=1, 1;
COORD b=45, 3;
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
drawThisBulletToNull( bullet[j] );
bullet[j].Y = 30;



void Game::Shoot()

for(int i=0; i<10; i++)
if(bullet[i].Y == 30)

bullet[i].X = position[5].X;
bullet[i].Y = position[5].Y-1;
break;



void Game::printScore()

if(score == 120 && flag_rank == 0)

rank -= 3;
flag_rank = 1;


else if( score == 360 && flag_rank == 1)

rank -= 5;
flag_rank = 2;

else if( score == 480 && flag_rank == 2)

rank -= 5;
flag_rank = 3;

int x=rank/5;
SetPos(60, 6);
cout<<score;

if( rank!=rankf )

SetPos(60, 7);
if( x == 5)
title="初级飞行员";
else if( x == 4)
title="中级飞行员";
else if( x == 3)
title="高级飞行员";
else if( x == 2 )
title="王牌飞行员";
cout<<title;

rankf = rank;


void Game::Playing()

//HANDLE MFUN;
//MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL);

drawEnemy();
drawPlane();

int flag_bullet = 0;
int flag_enemy = 0;

while(1)

Sleep(8);
if(_kbhit())

char x = _getch();
if ('a' == x || 's' == x || 'd' == x || 'w' == x)

drawPlaneToNull();
planeMove(x);
drawPlane();
judgePlane();

else if ('p' == x)
Pause();
else if( 'k' == x)
Shoot();
else if( 'e' == x)

//CloseHandle(MFUN);
GameOver();
break;



/* 处理子弹 */
if( 0 == flag_bullet )

bulletMove();
drawBulletToNull();
drawBullet();
judgeEnemy();

flag_bullet++;
if( 5 == flag_bullet )
flag_bullet = 0;

/* 处理敌人 */
if( 0 == flag_enemy )

drawEnemyToNull();
enemyMove();
drawEnemy();
judgePlane();

flag_enemy++;
if( flag_enemy >= rank )
flag_enemy = 0;

/* 输出得分 */
printScore();



void Game::GameOver()

system("cls");
COORD p1=28,9;
COORD p2=53,15;
drawFrame(p1, p2, '=', '|');
SetPos(36,12);
string str="Game Over!";
for(int i=0; i<str.size(); i++)

Sleep(80);
cout<<str[i];

Sleep(1000);
system("cls");
drawFrame(p1, p2, '=', '|');
SetPos(31, 11);
cout<<"击落敌机:"<<score/5<<" 架";
SetPos(31, 12);
cout<<"得  分:"<<score;
SetPos(31, 13);
cout<<"获得称号:"<<title;
SetPos(30, 16);
Sleep(1000);
cout<<"继续? 是(y)| 否(n)";
as:
char x=_getch();
if (x == 'n')
exit(0);
else if (x == 'y')

system("cls");
Game game;
int a = drawMenu();
if(a == 2)
game.rank = 20;
system("cls");
drawPlaying();
game.Playing();

else goto as;


/*================== the main function ==================*/
int main()

//游戏准备
srand((int)time(0)); //随机种子
HideCursor(); //隐藏光标

Game game;
int a = drawMenu();
if(a == 2)
game.rank = 20;
system("cls");
drawPlaying();
game.Playing();
参考技术A //你看看行不行?
//贪吃蛇
#include<graphics.h>

#include<stdlib.h>
#include<dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;
int gamespeed=32000;
struct Food /*食物的结构体*/

int x; /*食物的横坐标*/
int y; /*食物的纵坐标*/
int yes; /*食物是否出现的变量*/
food;
struct Snack /*蛇的结构体*/

int x[N];
int y[N];
int node; /*蛇的节数*/
int direction; /*蛇的方向*/
int life; /*蛇的生命,0活着,1死亡*/
snake;
void Init(void); /*图形驱动*/
void Close(void); /*关闭游戏函数*/
void DrawK(void); /*画图函数*/
void GameOver(void);/*输出失败函数*/
void GamePlay(); /*游戏控制函数 主要程序*/
void PrScore(void); /*分数输出函数*/

DELAY(char ch)/*调节游戏速度*/

if(ch=='3')

delay(gamespeed); /*delay是延迟函数*/
delay(gamespeed);

else if(ch=='2')

delay(gamespeed);



Menu()/*游戏开始菜单*/

char ch;
printf("Please choose the gamespeed:\n");
printf("1-Fast 2-Normal 3-Slow\n");
printf("\nPlease Press The numbers..\n");
do
ch=getch();
while(ch!='1'&&ch!='2'&&ch!='3');
clrscr();
return(ch);


/*主函数*/
void main(void)

int ch;
ch=Menu();
Init();
DrawK();
GamePlay(ch);
Close();


void Init(void)

int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();


void DrawK(void)

setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
for(i=50;i<=600;i+=10)

rectangle(i,40,i+10,49); /*画出上边框*/
rectangle(i,451,i+10,460); /*画出下边框*/

for(i=40;i<=450;i+=10)

rectangle(50,i,59,i+10); /*画出左边框*/
rectangle(601,i,610,i+10); /*画出右边框*/



void GamePlay(char ch)

randomize(); /*随机数发生器*/
food.yes=1; /*1代表要出现食物,0表示以存在食物*/
snake.life=0;
snake.direction=1;
snake.x[0]=100;snake.y[0]=100;
snake.x[1]=110;snake.y[1]=100;
snake.node=2;
PrScore();
while(1) /*可以重复游戏*/

while(!kbhit()) /*在没有按键的情况下蛇自己移动*/

if(food.yes==1) /*需要食物*/

food.x=rand()%400+60;
food.y=rand()%350+60; /*使用rand函数随机产生食物坐标*/
while(food.x%10!=0)
food.x++;
while(food.y%10!=0)
food.y++; /*判断食物是否出现在整格里*/
food.yes=0; /*现在有食物了*/

if(food.yes==0) /*有食物了就要显示出来*/

setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);

for(i=snake.node-1;i>0;i--) /*贪吃蛇的移动算法*/

snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1]; /*贪吃蛇的身体移动算法*/


switch(snake.direction) /*贪吃蛇的头部移动算法,以此来控制移动*/

case 1:snake.x[0]+=10;break;
case 2:snake.x[0]-=10;break;
case 3:snake.y[0]-=10;break;
case 4:snake.y[0]+=10;break;

for(i=3;i<snake.node;i++) /*判断是否头部与身体相撞*/

if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])

GameOver();
snake.life=1;
break;


/*下面是判断是否撞到墙壁*/
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||snake.y[0]>455)

GameOver();
snake.life=1;

if(snake.life==1) /*如果死亡就退出循环*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y) /*判断蛇是否吃到食物*/

setcolor(0);
rectangle(food.x,food.y,food.x+10,food.y-10); /*吃的食物后用黑色将食物擦去*/
snake.x[snake.node]=-20;snake.y[snake.node]=-20; /*现把增加的一节放到看不到的地方去*/

snake.node++;
food.yes=1;
score+=10;
PrScore();

setcolor(4); /*每次移动后将后面的身体擦去*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);
delay(gamespeed);
DELAY(ch);
setcolor(0);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);


if(snake.life==1)
break;
key=bioskey(0); /*接受按键*/
if(key==ESC)
break;
else
if(key==UP&&snake.direction!=4)/*判断是否改变方向*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;



void GameOver(void)

cleardevice();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();


void PrScore(void)

char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"scord:%d",score);
outtextxy(55,20,str);

void Close(void)

getch();
closegraph();
参考技术B 就是楼下啦
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int m[20][20];
char a,b,c,d;
int xa=16,ya=4,xb=16,yb=15,fxa=20,fya=20;
int xShang,Tiao,Zuo,You,Quan,fang=1,blood=50,lan=20;
int yShang,Tiaob,Zuob,Youb,Quanb,fangb=-1,bloodb=50,lanb=20;
int Zhao,Fen,zou,zhao,Bao,baox,baoy,Di,diy,Bu;
int Lie,liey,lief,liefy,Ji,jiy,jif,Shun,r,R,s,S,M;
void Yan(int a)

if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);

void Bai()SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
void SetPos(int x,int y)

COORD pos;
pos.X=2*y+8;
pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);

void Xue()

SetPos(0,-4);for(int i=0;i<4;i++) for(int j=0;j<38;j++)cout<<" ";cout<<endl;SetPos(0,-4);if(lan>30) lan=30;
if(lanb>30) lanb=30;cout<<" ";Yan(5);if(lan==30) Yan(3);for(int i=1;i<=lan;i++) printf("▃");Yan(1);printf("\n1p :");for(int i=2;i<=blood;i+=2) printf("█");
if(blood%2==1) printf("▌");cout<<endl<<" ";Yan(5);if(lanb==30) Yan(3);for(int i=1;i<=lanb;i++) printf("▃");Yan(4);printf("\n2p :");for(int i=2;i<=bloodb;i+=2) printf("█");
if(bloodb%2==1) printf("▌");cout<<endl;SetPos(17,0);Yan(2);for(int j=0;j<20;j++) cout<<"■";continue; Bai();Yan(1);printf("\n\n 蓝方:A W D --控制\t\t");Yan(4);
printf("红方:←↑→--控制\n\n"); Yan(1);printf(" J-出拳");if(lan<1) Yan(6);printf(" K-前刺");if(lan<3) Yan(6);printf(" L-分身\t");Yan(4);printf("1-出拳");
if(lanb<1) Yan(6);printf(" 2-上挑");Yan(4);if(lanb<3) Yan(6);printf(" 3-瞬移\n\n");Yan(1);if(lan<3) Yan(6);printf(" U-回血");Yan(1);if(lan<5) Yan(6);printf(" I-裂地");Yan(1);
if(lan<10) Yan(6);printf(" O-炸地\t");Yan(4);if(lanb<3) Yan(6);printf("4-回血");Yan(4);if(lanb<5) Yan(6);printf(" 5-震爆");Yan(4);if(lanb<7) Yan(6);printf(" 6-激光");Bai();

void Wo()Yan(1),SetPos(xa,ya),cout<<"●";Yan(4),SetPos(xb,yb),cout<<"●";if(Fen!=0) Bai(),SetPos(fxa,fya),cout<<"●";
void Hong()Wo();system("color 4F"),Sleep(10),system("color 0F"),Xue();
void Lan()Wo();system("color 1F"),Sleep(10),system("color 0F"),Xue();
void Lv()Wo();system("color 2F"),Sleep(10),system("color 0F"),Xue();
void Zou()

zou=0;
SetPos(xa,ya),cout<<" ";SetPos(xb,yb),cout<<" ";
if(Fen>0) SetPos(fxa,fya),cout<<" ";SetPos(0,-4);
if(fxa<=5||xa<=5) xShang=0;
if(xa==xb&&ya==yb) xa--,zou=1;
if(fxa==xa&&fya==ya) fxa--,zou=1;
if(fxa==xb&&fya==yb) fxa--,zou=1;
if(Fen>0)

if(xa==fxa+1&&ya==fya&&fang==-1)if(fya>0) fya--;else fya+=2;
if(xa==fxa+1&&ya==fya&&fang==1)if(fya<19) fya++;else fya-=2;
if(fxa+1==xb&&fya==yb&&fang==-1)if(fya>0) fya--;else fya+=2;
if(fxa+1==xb&&fya==yb&&fang==1)if(fya<19) fya++;else fya-=2;
if(Tiao>0)

if(fang==-1&&fya>0&&(fxa!=xb||fya-1!=yb)&&(fxa!=xa||fya-1!=ya)) fya--;
if(fang==1&&fya<19&&(fxa!=xb||fya+1!=yb)&&(fxa!=xa||fya+1!=ya)) fya++;

if(xShang>0) m[fxa][fya]=0,fxa-=2;
if(fxa<16) m[fxa][fya]=0,fxa++;

if(xa+1==xb&&ya==yb&&fang==-1)if(ya>0) ya--;else ya+=2;
if(xa+1==xb&&ya==yb&&fang==1)if(ya<19) ya++;else ya-=2;
if(xa+1==fxa&&ya==fya&&fang==-1)if(ya>0) ya--;else ya+=2;
if(xa+1==fxa&&ya==fya&&fang==1)if(ya<19) ya++;else ya-=2;
if(Zuo>0&&ya>0&&Tiao==0&&(xa!=xb||ya-1!=yb)&&(fxa!=xa||fya!=ya-1)) m[xa][ya]=0,ya--;
if(Zuo>0&&fya>0&&Tiao==0&&(fxa!=xb||fya-1!=yb)&&(xa!=fxa||ya!=fya-1)) m[fxa][fya]=0,fya--;Zuo=0;
if(You>0&&ya<19&&Tiao==0&&(xa!=xb||ya+1!=yb)&&(fxa!=xa||fya!=ya+1)) m[xa][ya]=0,ya++;
if(You>0&&fya<19&&Tiao==0&&(fxa!=xb||fya+1!=yb)&&(xa!=fxa||ya!=fya+1)) m[fxa][fya]=0,fya++;You=0;
if(Tiao>0)

if(fang==-1&&ya>0&&(xa!=xb||ya-1!=yb)&&(fxa!=xa||fya!=ya-1)) ya--;
if(fang==1&&ya<19&&(xa!=xb||ya+1!=yb)&&(fxa!=xa||fya!=ya+1)) ya++;

if(xShang>0) m[xa][ya]=0,xShang--,xa-=2;
if(xa<16) m[xa][ya]=0,xa++;
if(xa==16) Tiao=0;
if(xb<=5) yShang=0;
if(xa==xb+1&&ya==yb&&fangb==-1)if(yb>0) yb--;else yb+=2;
if(xa==xb+1&&ya==yb&&fangb==1)if(yb<19) yb++;else yb-=2;
if(xb+1==fxa&&yb==fya&&fangb==-1)if(yb>0) yb--;else yb+=2;
if(xb+1==fxa&&yb==fya&&fangb==1)if(yb<19) yb++;else yb-=2;
if(Zuob>0&&yb>0&&Tiaob==0&&(xa!=xb||ya!=yb-1)&&(fxa!=xb||fya!=yb-1)) m[xb][yb]=0,Zuob=0,yb--;Zuob=0;
if(Youb>0&&yb<19&&Tiaob==0&&(xa!=xb||ya!=yb+1)&&(fxa!=xb||fya!=yb+1)) m[xb][yb]=0,Youb=0,yb++;Youb=0;
if(Tiaob>0&&Bu==0)

if(fangb==-1&&yb>0&&(xa!=xb||ya!=yb-1)&&(fxa!=xb||fya!=yb-1)) yb--;
if(fangb==1&&yb<19&&(xa!=xb||ya!=yb+1)&&(fxa!=xb||fya!=yb+1)) yb++;

if(yShang>0) m[xb][yb]=0,yShang--,xb-=2;
if(xb<16) m[xb][yb]=0,xb++;
if(xb==16) Tiaob=0;
SetPos(0,-4);if(zou==1) Zou();
Sleep(10);

void Xian()

zhao=0;s++;
if(M>=5) Zhao=0;return;
if(s==70) s=0;if(lan<40)lan++;if(lanb<40)lanb++;Xue();
SetPos(0,-4);
if(Bao!=0)

Bao--;Zhao--;
for(int i=baox-3;i<=baox+3;i++)
for(int j=baoy-3;j<=baoy+3;j++) if(i<=16&&j>=0&&j<=19) m[i][j]=9;
for(int i=baox-1;i<=baox+1;i++)
for(int j=baoy-1;j<=baoy+1;j++) if(i<=16&&j>=0&&j<=19) m[i][j]=0;
if(Bao==0) baox=0,baoy=0;
if(Lie!=0)

Lie--;Zhao--;
if(lief==-1) for(int i=1;i<=7-Lie;i++) if(liey+Lie>=0) m[18-i][liey+Lie]=11;
if(lief==1) for(int i=1;i<=7-Lie;i++) if(liey-Lie<=19) m[18-i][liey-Lie]=10;
if(Fen>0)

if(lief==-1) for(int i=1;i<=7-Lie;i++) if(liefy+Lie>=0) m[18-i][liefy+Lie]=11;
if(lief==1) for(int i=1;i<=7-Lie;i++) if(liefy-Lie<=19) m[18-i][liefy-Lie]=10;

if(Lie==0) liey=0,lief=0,liefy=0;
if(Ji!=0)

Ji--;Zhao--;
if(jif==-1) for(int i=jiy;i>=0;i--) m[xb][i]=14;
if(jif==1) for(int i=jiy;i<=19;i++) m[xb][i]=13;
if(Ji==0) jiy=0,jif=0;
if(Di!=0)

Di--;Zhao--;
for(int i=2;i<=16;i++) m[i][diy]=19;
if(Fen>0&&yb!=0&&yb!=19) for(int i=2;i<=16;i++) m[i][diy+fangb]=19;
if(Di==0) diy=0;
if(Shun!=0)

SetPos(Shun,-4);cout<<" ";
Shun=0;

Bu=0;
if(m[xa][ya]==3) Shun=xa,Zuo+=1,xShang+=4,blood-=1,Zhao=0,m[xa][ya]=7,Lan(),lan++,zhao=1;Xue();
else if(m[xa][ya]==4) Shun=xa,You+=1,xShang+=4,blood-=1,Zhao=0,m[xa][ya]=7,Lan(),lan++,zhao=1;Xue();
else if(m[xa][ya]==9) Shun=xa,xShang=7,blood-=2,Zhao=0,m[xa][ya]=7,Lan(),lan+=2,zhao=1;Xue();
else if(m[xa][ya]==13) Shun=xa,You+=1,blood-=2,Zhao=0,m[xa][ya]=7,Lan(),lan+=2,zhao=1;Xue();
else if(m[xa][ya]==14) Shun=xa,Zuo+=1,blood-=2,Zhao=0,m[xa][ya]=7,Lan(),lan+=2,zhao=1;Xue();
else if(m[xa][ya]==15) Shun=xa,You+=1,blood-=1,Zhao=0,m[xa][ya]=7,Lan(),lan+=1,zhao=1;Xue();
else if(m[xa][ya]==16) Shun=xa,Zuo+=1,blood-=1,Zhao=0,m[xa][ya]=7,Lan(),lan+=1,zhao=1;Xue();
else m[xa][ya]=1;
if(m[fxa][fya]==3||m[fxa][fya]==4||m[fxa][fya]==9||m[fxa][fya]==13||m[fxa][fya]==14||m[fxa][fya]==15||m[fxa][fya]==16)
Zhao=0,m[fxa][fya]=7,fxa=20,fya=20,Fen=0,Lan(),zhao=1;Xue();
if(m[xb][yb]==5) Shun=xb,Zuob+=4,yShang+=1,bloodb-=1,Zhao=0,m[xb][yb]=7,Hong(),lanb++,zhao=1;Xue();
else if(m[xb][yb]==6) Shun=xb,Youb+=4,yShang+=1,bloodb-=1,Zhao=0,m[xb][yb]=7,Hong(),lanb++,zhao=1;Xue();
else if(m[xb][yb]==10) Shun=xb,Youb+=1,yShang+=1,bloodb-=2,Zhao=0,m[xb][yb]=7,Hong(),lanb+=2,zhao=1;Xue();
else if(m[xb][yb]==11) Shun=xb,Zuob+=1,yShang+=1,bloodb-=2,Zhao=0,m[xb][yb]=7,Hong(),lanb+=2,zhao=1;Xue();
else if(m[xb][yb]==17) Shun=xb,Youb+=1,bloodb-=1,Zhao=0,m[xb][yb]=7,Hong(),lanb+=1,zhao=1;Xue();
else if(m[xb][yb]==18) Shun=xb,Zuob+=1,bloodb-=1,Zhao=0,m[xb][yb]=7,Hong(),lanb+=1,zhao=1;Xue();
else if(m[xb][yb]==19) Shun=xb,Bu=1,yShang+=3,bloodb-=1,Zhao=0,m[xb][yb]=7,Hong(),lanb+=1,zhao=1;Xue();
else m[xb][yb]=2;
if(Fen>0) m[fxa][fya]=8;
for(int i=5;i<=16;i++)
for(int j=0;j<20;j++)

if(m[i][j]==20) SetPos(i,j);cout<<" ",m[i][j]=0;continue;
if(m[i][j]==1) Yan(1),SetPos(i,j);cout<<"●",m[i][j]=20,Bai();continue;
if(m[i][j]==2) Yan(4),SetPos(i,j);cout<<"●",m[i][j]=20,Bai();continue;
if(m[i][j]==8) Bai(),SetPos(i,j);cout<<"●",m[i][j]=20;continue;
if(m[i][j]==7) Yan(5),SetPos(i,j);cout<<"█",m[i][j]=20,zhao=1;Bai();continue;
if(m[i][j]==12) Bai(),SetPos(i,j);cout<<"●",Shun=xb;continue;
if(m[i][j]>=3&&m[i][j]<=6||(m[i][j]>=9&&m[i][j]<=11)||(m[i][j]>=13))
Bai(),SetPos(i,j);cout<<"■";m[i][j]=20,Zhao=0,zhao=1;continue;

if(zhao>0) M++,Zou(),Xian();M=0;return;
memset(m,0,sizeof(m));M=0;

void Go(char a)

if(a=='j') Quan++; else Quan=0;
if(a=='w'&&Tiao==0) Tiao++,xShang+=3;
if(a=='a'&&Tiao==0) Zuo=1,You=0,fang=-1;
if(a=='d'&&Tiao==0) You=1,Zuo=0,fang=1;
if(a=='j'&&Quan<=3&&fang==-1&&ya-1>=0) m[xa][ya-1]=18;if(Fen>0&&fya-1>=0) m[fxa][fya-1]=18;
if(a=='j'&&Quan<=3&&fang==1&&ya+1<=19) m[xa][ya+1]=17;if(Fen>0&&fya+1<=19) m[fxa][fya+1]=17;
if(a=='k'&&fang==-1&&lan>=1&&ya!=0) lan--,Xue();Zhao++;for(int i=1;i<=3;i++)if(ya-i>=0) m[xa][ya-i]=5;if(Fen>0&&fya-i>=0) m[fxa][fya-i]=5;
if(a=='k'&&fang==1&&lan>=1&&ya!=19) lan--,Xue();Zhao++;for(int i=1;i<=3;i++)if(ya+i<=19) m[xa][ya+i]=6;if(Fen>0&&fya+i<=19) m[fxa][fya+i]=6;
if(a=='l'&&Fen==0&&lan>=3) lan-=3,Xue(),Lan(),fxa=xa-3,fya=rand()%19,Fen=1,Zou(),Xian();
if(a=='u'&&lan>=3) lan-=3,Xue(),Lv(),blood+=2;
if(a=='i'&&lan>=5) lan-=5,Xue(),Zhao+=3,Di+=3,diy=yb;
if(a=='o'&&fang==-1&&lan>=10) lan-=10,Xue();Zhao+=6,Lie=6,liey=ya-6,lief=-1,liefy=0;if(Fen>0) liefy=fya-6;
if(a=='o'&&fang==1&&lan>=10) lan-=10,Xue();Zhao+=6,Lie=6,liey=ya+6,lief=1,liefy=0;if(Fen>0) liefy=fya+6;

if(a=='1') Quanb++; else Quanb=0;
if(a==72&&Tiaob==0) Tiaob++,yShang+=3;
if(a==75&&Tiaob==0) Zuob=1,Youb=0,fangb=-1;
if(a==77&&Tiaob==0) Youb=1,Zuob=0,fangb=1;
if(a=='1'&&Quanb<=3&&fangb==-1&&yb-1>=0) m[xb][yb-1]=16;
if(a=='1'&&Quanb<=3&&fangb==1&&yb+1<=19) m[xb][yb+1]=15;
if(a=='2'&&fangb==-1&&lanb>=1&&yb!=0) lanb--,Xue();Zhao++;for(int i=1;i<=3;i++)if(yb-i>=0) m[xb][yb-i]=3;
if(a=='2'&&fangb==1&&lanb>=1&&yb!=19) lanb--,Xue();Zhao++;for(int i=1;i<=3;i++)if(yb+i<=19) m[xb][yb+i]=4;
if(a=='3'&&fangb==1&&lanb>=3&&yb!=19) lanb-=3;Xue();for(int i=yb;i<=18;i++) m[xb][i]=12;yb=19;Xian();
if(a=='3'&&fangb==-1&&lanb>=3&&yb!=0) lanb-=3;Xue();for(int i=yb;i>0;i--) m[xb][i]=12;yb=0;Xian();
if(a=='4'&&lanb>=3) lanb-=3,Xue(),Lv(),bloodb+=2;
if(a=='5'&&lanb>=5) lanb-=5,Xue(),Zhao+=3,Bao+=3,baox=xb,baoy=yb;
if(a=='6'&&lanb>=7) lanb-=7,Xue(),Zhao+=3,Ji+=3,jiy=yb,jif=fangb;

int main()

x:
system("cls");
srand((unsigned)time(NULL));Bai();
cout<<endl<<" -------------------胎红 VS 胎蓝---------------------"<<endl;
cout<<" ---------------------------作者:胎神---------------"<<endl<<endl;Yan(5);
cout<<" 2.0版本,憾世来袭!"<<endl<<endl;
cout<<" 2大更新:"<<endl<<endl;
cout<<" 1.完美解决“闪”的问题!"<<endl<<endl;
cout<<" 2.单人模式来了!完全电脑AI控制,比双人模式更难!"<<endl<<endl;
cout<<" 3.技能平衡性调整,更合理化的对战体验。"<<endl<<endl;Yan(1);
cout<<" 已开启 闪光功能:当蓝方挨血时,画面闪蓝光,反之闪红光;恢血时闪绿光。"<<endl<<endl;Bai();
cout<<" 请输入: 1.单人模式 2.双人模式"<<endl<<endl;A:a=_getch();
if(a=='1')

cout<<" 你要当谁? 1.小胎蓝 2.小胎红 3.老子不想打了,让他们自己打!"<<endl<<endl;b=_getch();
cout<<" 选择难度: 1.简单的像吃屎 2.一般的像垃圾 3.巨难的像变胎"<<endl<<endl;
cout<<" (难度越简单,对方动作越迟缓。)"<<endl<<endl;d=_getch();
if(d=='1') R=5;
if(d=='2') R=3;
if(d=='3') R=1;
system("cls");
Xue();Xian();
while(blood>0&&bloodb>0)

SetPos(0,-4);M=0;
Zou();Xian();
if(b=='1'||b=='3')

S++;
if(S>=R)

S=0;c=0;int xxa=xa,yya=ya;
if(lanb>=7) r=rand()%6;else if(lanb>=5) r=rand()%7-2;else if(lanb>=3) r=rand()%6-2;else if(lanb>=1) r=rand()%4-1;else r=rand()%3-1;
if(Fen>0) xxa=fxa,yya=fya;
if((xb==16&&yb==0)||(xb==16&&yb==19)) r=0;
if(r==5)if(fangb==-1&&xxa==xb&&yya<=yb) c='6';if(fangb==1&&xxa==xb&&yya>=yb) c='6';else r=0;
if(r==4)if(xxa==xb&&abs(yya-yb)<=1) r=0;if(fangb==-1&&yb-3<=yya&&yya<=yb-1) c='5';if(fangb==1&&yb+3>=yya&&yya>=yb+1) c='5';else r=0;
if(r==3&&bloodb<30&&lan>=3) c='4';
if(r==2)if(fangb==-1&&yb-3<=yya&&yya<=yb) c='2';if(fangb==1&&yb+3>=yya&&yya>=yb) c='2';else r=0;
if(r==1)if(fangb==-1&&yb-1==yya) c='1';else if(fangb==1&&yb+1==yya) c='1';else r=0;
if(yya<=yb&&r==0)int rr=rand()%5;if(fangb==-1&&rr==0) c=72;else if(fangb==-1&&rr==1&&abs(yya-yb)>=5) c='3';else c=75;
if(yya>yb&&r==0)int rr=rand()%5;if(fangb==1&&rr==0) c=72;else if(fangb==1&&rr==1&&abs(yya-yb)>=5) c='3';else c=77;
if(c!=0) Go(c);


if(b=='2'||b=='3')

S++;
if(S>=R)

S=0;c=0;
if(lanb>=10) r=rand()%10;else if(lanb>=5) r=rand()%9-3;else if(lanb>=3) r=rand()%8-3;else if(lanb>=1) r=rand()%6-2;else r=rand()%3-1;
if((xa==16&&ya==0)||(xa==16&&ya==19)) r=0;
if(r>=6)if(fang==-1&&ya>=yb&&abs(ya-yb)<=2) c='o';if(fang==1&&ya<=yb&&abs(ya-yb)<=2) c='o';else r=0;
if(r==5) c='i';
if(r==4&&blood<30&&lan>=3) c='u';
if(r==3&&Fen==0) c='l';
if(r==2)if(fang==1&&yb-3<=ya&&ya<=yb) c='k';if(fang==-1&&yb+3>=ya&&ya>=yb) c='k';else r=0;
if(r==1)if(fang==1&&yb-1==ya) c='j';else if(fang==-1&&yb+1==ya) c='j';else r=0;
if(ya>=yb&&r==0)int rr=rand()%5;if(fang==-1&&rr==0) c='w';else c='a';
if(ya<yb&&r==0)int rr=rand()%5;if(fang==1&&rr==0) c='w';else c='d';
if(c!=0) Go(c);


if(kbhit())

SetPos(0,-4);
if(b=='1')

if(KEY_DOWN(87)) Go('w');if(KEY_DOWN(65)) Go('a');if(KEY_DOWN(68)) Go('d');
if(KEY_DOWN(74)) Go('j');if(KEY_DOWN(75)) Go('k');if(KEY_DOWN(76)) Go('l');
if(KEY_DOWN(85)) Go('u');if(KEY_DOWN(73)) Go('i');if(KEY_DOWN(79)) Go('o');

if(b=='2')

if(KEY_DOWN(38)) Go(72);if(KEY_DOWN(37)) Go(75);if(KEY_DOWN(39)) Go(77);
if(KEY_DOWN(97)) Go('1');if(KEY_DOWN(98)) Go('2');if(KEY_DOWN(99)) Go('3');
if(KEY_DOWN(100)) Go('4');if(KEY_DOWN(101)) Go('5');if(KEY_DOWN(102)) Go('6');

Zou(),Xian();

if(Zhao>0) Zou(),Xian();
Sleep(20);


else if(a=='2')

system("cls");
Xue();Xian();
while(blood>0&&bloodb>0)

SetPos(0,-4);
if(!kbhit()) Zou(),Xian();
if(kbhit())

SetPos(0,-4);
if(KEY_DOWN(87)) Go('w');if(KEY_DOWN(65)) Go('a');if(KEY_DOWN(68)) Go('d');
if(KEY_DOWN(74)) Go('j');if(KEY_DOWN(75)) Go('k');if(KEY_DOWN(76)) Go('l');
if(KEY_DOWN(85)) Go('u');if(KEY_DOWN(73)) Go('i');if(KEY_DOWN(79)) Go('o');
if(KEY_DOWN(38)) Go(72);if(KEY_DOWN(37)) Go(75);if(KEY_DOWN(39)) Go(77);
if(KEY_DOWN(97)) Go('1');if(KEY_DOWN(98)) Go('2');if(KEY_DOWN(99)) Go('3');
if(KEY_DOWN(100)) Go('4');if(KEY_DOWN(101)) Go('5');if(KEY_DOWN(102)) Go('6');
Zou(),Xian();

if(Zhao>0) Zou(),Xian();Sleep(20);


else goto A;
system("cls");
if(blood>0) Yan(1);
if(bloodb>0) Yan(4);
cout<<endl<<endl<<endl;
cout<<" ┌-------------┐"<<endl;
cout<<" ┆ ┆"<<endl;
if(blood>0) cout<<" ┆ 1p WIN!!! ┆"<<endl;
if(bloodb>0) cout<<" ┆ 2p WIN!!! ┆"<<endl;
cout<<" ┆ ┆"<<endl;
cout<<" └-------------┘"<<endl<<endl;
Sleep(2000);Bai();system("cls");
xa=16,ya=4,xb=16,yb=15,fxa=20,fya=20;
xShang=Tiao=Zuo=You,Quan=0,fang=1,blood=50,lan=20;
yShang=Tiaob=Zuob=Youb=Quanb=0,fangb=-1,bloodb=50,lanb=20;
Zhao=Fen=zou=zhao=Bao=baox=baoy=Di=diy=Bu=0;
Lie=liey=lief=liefy=Ji=jiy=jif=Shun=r=R=s=S=M=0;goto x;
return 0;
参考技术C i don't known

JS获取图片宽高,急急急~

我想用js获取本地图片的宽高,然后将宽高赋值给变量,再用变量进行数学运算,请哪位高手帮忙弄一下,希望有说明,谢谢了~如果好会追加分数的~
因为要依次获取几张图片的宽高,我把图片定义为了一个数组,获取的时候可以用var pic[i] = new pic();么?

参考技术A 我这里有个IE下可用的,我以前做过的项目里的:

var tmpObj = new Image();
tmpObj.src = path;
if(tmpObj.width>500)
tmpObj.height = parseInt(500 * tmpObj.height / tmpObj.width);
tmpObj.width = 500;

var imgObj = document.getElementById(targetId);
imgObj.src = path;
imgObj.width = tmpObj.width;
imgObj.height = tmpObj.height;
imgObj.style.display = "block";

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/chenilu/archive/2009/04/10/4062120.aspx
参考技术B var img = new Image();
img.onload = function()
宽度=this.width
高度=this.height

img.src = 图片地址;本回答被提问者采纳

以上是关于dev-c++小游戏代码,急急急急!!!!!的主要内容,如果未能解决你的问题,请参考以下文章

急急急。电脑出现404错误怎么解决 急急急·~~~

正常的xml文件不能正常显示!!急急急~~

c 语言求源代码急急急

请问这个问题怎么解决啊?急急急

在c#中怎么能在一个窗口中设置另一个窗口控件的属性?急急急!!!

ping本机IP不通但是可以上网,有时候掉线。在公司内网上用了proxifier玩网游,可能设置错了求高手指导急急