1.����Դ��
2.ç®å好ç©çç¼ç¨ä»£ç ï¼
3.求一C++小游戏源代码 简单点的超简?!!单源单谢谢
����Դ��
月数不好定,因为每个月天数不一样。源码算到天就行了。超简简搜源码
代码如下:
.版本 2
.支持库 spec
.子程序 _按钮1_被单击
.局部变量 运行时间,单源单前端h 源码 整数型, , , 毫秒
运行时间 = 取启动时间 ()
调试输出 (取毫秒到天 (运行时间))
.子程序 取毫秒到天, 文本型
.参数 参_秒, 整数型
.局部变量 参_秒, 整数型
.局部变量 天, 整数型
.局部变量 小时, 整数型
.局部变量 分钟, 整数型
.局部变量 秒, 整数型
参_秒 = 取启动时间 () ÷
天 = 参_秒 ÷ ÷ ÷
小时 = (参_秒 - 天 × × ) ÷
分钟 = (参_秒 - 天 × × - 小时 × ) ÷
秒 = 参_秒 %
返回 (到文本 (天) + “天” + 到文本 (小时) + “小时” + 到文本 (分钟) + “分钟” + 到文本 (秒) + “秒”)
ç®å好ç©çç¼ç¨ä»£ç ï¼
ç«é ·çç¼ç¨ä»£ç
ç«é ·çç¼ç¨ä»£ç æ¯@echooffmodeconcols=lines=colorsetlocalenabledelayedexpansionsetcode=abcdefsetm=1setv=1ã
ç¼å®ç¨åºï¼ç®ç§°ç¼ç¨ï¼æ¯æ让计ç®æºä»£ä¸ºè§£å³æ个é®é¢ã对æ个计ç®ä½ç³»è§å®ä¸å®çè¿ç®æ¹å¼ï¼ä½¿è®¡ç®ä½ç³»æç §è¯¥è®¡ç®æ¹å¼è¿è¡ï¼å¹¶æç»å¾å°ç¸åºç»æçè¿ç¨ã
ç¼ç¨å°±æ¯ä¸ºäºåå©äºè®¡ç®æºæ¥è¾¾å°æä¸ç®çæ解å³æ个é®é¢ï¼è使ç¨æç§ç¨åºè®¾è®¡è¯è¨ç¼åç¨åºä»£ç ï¼å¹¶æç»å¾å°ç»æçè¿ç¨ã计ç®æºè½ç¶åè½åå强大ï¼å¯ä»¥ä¸ç½ãç©æ¸¸æã管çå ¬å¸äººäºå ³ç³»ççãä½æ¯æ²¡æç¨åºï¼å®å°±çäºæ¯ä¸å åºéï¼ä¸ä¼çä¼æ们对å®ä¸è¾¾çâå½ä»¤âã
ç¼ç¨è¯è¨ä»ç»
使ç¨æ±ç¼è¯è¨ç¼å计ç®æºç¨åºï¼ç¨åºåä»ç¶éè¦ååçæ计ç®æºç³»ç»ç硬件ç»æï¼æ以ä»ç¨åºè®¾è®¡æ¬èº«ä¸æ¥çä»ç¶æ¯ä½æççãç¦ççãä½æ£æ¯ç±äºæ±ç¼è¯è¨ä¸è®¡ç®æºç¡¬ä»¶ç³»ç»å ³ç³»å¯åï¼å¨æäºç¹å®çåºåï¼å¦å¯¹æ¶ç©ºæçè¦æ±å¾é«çç³»ç»æ ¸å¿ç¨åºä»¥åå®æ¶æ§å¶ç¨åºçï¼è¿ä»ä¸ºæ¢æ±ç¼è¯è¨ä»ç¶æ¯ååææçç¨åºè®¾è®¡å·¥å ·ã
使ç¨é«çº§è¯è¨ç¼åç¨åºçä¼ç¹æ¯ï¼ç¼ç¨ç¸å¯¹ç®åãç´è§ãæç解ãä¸å®¹æåºéãé«çº§è¯è¨æ¯ç¬ç«äºè®¡ç®æºçï¼å èç¨é«çº§è¯è¨ç¼åç计ç®æºç¨åºéç¨æ§å¥½ï¼å ·æè¾å¥½ç移æ¤æ§ã
å¨è®¡ç®æºåºç¨çåæï¼ç¨åºå使ç¨æºå¨çæ令系ç»æ¥ç¼å计ç®æºåºç¨ç¨åºï¼è¿ç§ç¨åºç§°ä¸ºæºå¨è¯è¨ç¨åºã
æ±è¡ç®åCè¯è¨ç¨åºä»£ç ï¼åºç¡ç就好
#includestdio.h
#includestdlib.h
#defineNUM
/*runthisprogramusingtheconsolepauseroraddyourowngetch,system("pause")orinputloop*/
//å泡æåºç®æ³
//åºæ¬ææ³ï¼æ¯è¾ç¸é»ç两个æ°ï¼å¦æåè æ¯åè 大ï¼åè¿è¡äº¤æ¢ãæ¯ä¸è½®æåºç»æï¼éåºä¸ä¸ªæªæåºä¸æ大çæ°æ¾å°æ°ç»åé¢ã
voidbubbleSort(int*arr,intn){
inti,j;
for(i=0;in-1;i++)
for(j=0;jn-i-1;j++){
//å¦æåé¢çæ°æ¯åé¢å¤§ï¼è¿è¡äº¤æ¢
if(arr[j]arr[j+1]){
inttemp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
//æå·®æ¶é´å¤æ度为O(n^2),å¹³åæ¶é´å¤æ度为O(n^2)ã稳å®æ§ï¼ç¨³å®ãè¾ å©ç©ºé´O(1)ã
//å级çå泡æåºæ³ï¼éè¿ä»ä½å°é«éåºæ大çæ°æ¾å°åé¢ï¼åä»é«å°ä½éåºæå°çæ°æ¾å°åé¢ï¼
//å¦æ¤åå¤ï¼ç´å°å·¦è¾¹çåå³è¾¹çéåãå½æ°ç»ä¸æå·²æåºå¥½çæ°æ¶ï¼è¿ç§æåºæ¯ä¼ ç»å泡æåºæ§è½ç¨å¥½ã
//å级çå泡æåºç®æ³
voidbubbleSort_1(int*arr,intn){
//设置æ°ç»å·¦å³è¾¹ç
intleft=0,right=n-1;
//å½å·¦å³è¾¹çæªéåæ¶ï¼è¿è¡æåº
while(left=right){
inti,j;
//ä»å·¦å°å³éåéåºæ大çæ°æ¾å°æ°ç»å³è¾¹
for(i=left;iright;i++){
if(arr[i]arr[i+1]){
inttemp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
right--;
//ä»å³å°å·¦éåéåºæå°çæ°æ¾å°æ°ç»å·¦è¾¹
for(j=right;jleft;j--){
if(arr[j+1]arr[j]){
inttemp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
left++;
}
}
intmain(intargc,char*argv[]){
intarr[NUM],i,j,temp;
printf("请è¾å ¥ä¸ªæ°ï¼\n");
for(i=0;iNUM;i++){
printf("请è¾å ¥ç¬¬(%d)个æ°ï¼",i+1);
scanf("%d",arr[i]);
}
printf("\nè¾å ¥å¦ä¸æåï¼\n");
for(i=0;iNUM;i++){
printf("%4d",arr[i]);
}/
*for(i=0;iNUM;i++){
for(j=i+1;jNUM;j++){
if(arr[i]arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}*/
bubbleSort_1(arr,NUM);
/*printf("\nä»å°å°å¤§å¦ä¸æåï¼\n");
for(i=0;iNUM;i++){
printf("%4d",arr[i]);
}*/
printf("\nä»å¤§å°å°å¦ä¸æåï¼\n");
for(i=NUM-1;i=0;i--){
printf("%4d",arr[i]);
}
return0;
}
é便ç»æä¸ä¸ªç¼ç¨ä»£ç 带ææ谢谢main()?
{ ?
inti,j,k;?
printf("\n");?
for(i=1;i5;i++)ï¼*以ä¸ä¸ºä¸é循ç¯*/
for(j=1;j5;j++)
for(k=1;k5;k++)
{
if(i!=ki!=jj!=k)/*ç¡®ä¿iãjãkä¸ä½äºä¸ç¸å*/
printf("%d,%d,%d\n",i,j,k);
}?
}
1ã代ç 解éï¼ä»¥ä¸è¿æ®µä»£ç æ¯ç¨Cè¯è¨ååºæ¥ç代ç ï¼ä»æ解å³çé®é¢æ¯ï¼æ1ã2ã3ã4个æ°åï¼è½ç»æå¤å°ä¸ªäºä¸ç¸åä¸æ éå¤æ°åçä¸ä½æ°ï¼é½æ¯å¤å°ï¼?å¯å¡«å¨ç¾ä½ãåä½ã个ä½çæ°åé½æ¯1ã2ã3ã4ãç»æææçæåååå»?æä¸æ»¡è¶³æ¡ä»¶çæåã
2ãCè¯è¨ä»ç»ï¼Cè¯è¨æ¯ä¸é¨éç¨è®¡ç®æºç¼ç¨è¯è¨ï¼åºç¨å¹¿æ³ãCè¯è¨ç设计ç®æ æ¯æä¾ä¸ç§è½ä»¥ç®æçæ¹å¼ç¼è¯ãå¤çä½çº§åå¨å¨ã产çå°éçæºå¨ç 以åä¸éè¦ä»»ä½è¿è¡ç¯å¢æ¯æ便è½è¿è¡çç¼ç¨è¯è¨ã
3ãCè¯è¨çä¼ç¹ï¼ç®æ´ç´§åãçµæ´»æ¹ä¾¿ãè¿ç®ç¬¦ä¸°å¯ãæ°æ®ç»æ丰å¯ãCæ¯ç»æå¼è¯è¨ãCè¯æ³éå¶ä¸å¤ªä¸¥æ ¼ãç¨åºè®¾è®¡èªç±åº¦å¤§ï¼ä¸è¬çé«çº§è¯è¨è¯æ³æ£æ¥æ¯è¾ä¸¥ï¼è½å¤æ£æ¥åºå ä¹ææçè¯æ³é误ãèCè¯è¨å 许ç¨åºç¼åè æè¾å¤§çèªç±åº¦ãCè¯è¨ç¨åºçæ代ç è´¨éé«ï¼ç¨åºæ§è¡æçé«ï¼ä¸è¬åªæ¯æ±ç¼ç¨åºçæçç®æ 代ç æçä½ã¸%ã
4ãå ¶ä»ç¼ç¨è¯è¨ä»ç»ï¼Python(è±å½åé³:/?pa?θ?n/ç¾å½åé³:/?pa?θÉ?n/),æ¯ä¸ç§é¢å对象ç解éå计ç®æºç¨åºè®¾è®¡è¯è¨ï¼ç±è·å °äººGuidovanRossumäºå¹´åæï¼ç¬¬ä¸ä¸ªå ¬å¼åè¡çåè¡äºå¹´ãPythonæ¯çº¯ç²¹çèªç±è½¯ä»¶ï¼?æºä»£ç å解éå¨CPythonéµå¾ªGPL(GNU?GeneralPublicLicense)åè®®ãPythonè¯æ³ç®æ´æ¸ æ°ï¼ç¹è²ä¹ä¸æ¯å¼ºå¶ç¨ç©ºç½ç¬¦(whitespace)ä½ä¸ºè¯å¥ç¼©è¿ã
pythonæ趣çç¼ç¨ä»£ç class?Point:
row=0col=0def?__init__(self,?row,?col):self.row=row
self.col=col
def?copy(self):return?Point(row=self.row,?col=self.col)
#åå§æ¡æ¶
import?pygame
import?random
#åå§å
pygame.init()
W=
H=
ROW=
COL=
size=(W,H)
window=pygame.display.set_mode(size)
pygame.display.set_caption('è´ªåè')
bg_color=(,,)
snake_color=(,,)
head=Point(row=int(ROW/2),?col=int(COL/2))
head_color=(0,,)
snakes=[
Point(row=head.row,?col=head.col+1),Point(row=head.row,?col=head.col+2),Point(row=head.row,?col=head.col+3)]
#çæé£ç©
def?gen_food():
while?1:pos=Point(row=random.randint(0,ROW-1),?col=random.randint(0,COL-1))
#
is_coll=False
#æ¯å¦è·è碰ä¸äº
if?head.row==pos.row?and?head.col==pos.col:
is_coll=True#è身å
for?snake?in?snakes:
if?snake.row==pos.row?and?snake.col==pos.col:is_coll=True
break
if?not?is_coll:
breakreturn?pos#å®ä¹åæ
food=gen_food()
food_color=(,,0)
direct='left'#left,right,up,down
#
def?rect(point,?color):
cell_width=W/COLcell_height=H/ROWleft=point.col*cell_widthtop=point.row*cell_heightpygame.draw.rect(window,?color,
(left,?top,?cell_width,?cell_height)
)pass#游æ循ç¯
quit=True
clock=pygame.time.Clock()
while?quit:
#å¤çäºä»¶for?event?in?pygame.event.get():if?event.type==pygame.QUIT:
quit=Falseelif?event.type==pygame.KEYDOWN:
if?event.key==?or?event.key==:if?direct=='left'?or?direct=='right':
direct='up'elif?event.key==?or?event.key==:if?direct?==?'left'?or?direct?==?'right':
direct='down'elif?event.key==?or?event.key==:if?direct?==?'up'?or?direct?==?'down':
direct='left'elif?event.key==?or?event.key==:if?direct?==?'up'?or?direct?==?'down':
direct='right'#åä¸è¥¿eat=(head.row==food.row?and?head.col==food.col)#éæ°äº§çé£ç©if?eat:food?=?gen_food()
#å¤ç身å#1.æåæ¥ç头ï¼æå ¥å°snakesç头ä¸snakes.insert(0,?head.copy())#2.æsnakesçæåä¸ä¸ªå æif?not?eat:snakes.pop()
#移å¨if?direct=='left':head.col-=1
elif?direct=='right':head.col+=1
elif?direct=='up':head.row-=1
elif?direct=='down':head.row+=1
#æ£æµdead=False#1.æå¢if?head.col0?or?head.row0?or?head.col=COL?or?head.row=ROW:dead=True
#2.æèªå·±for?snake?in?snakes:if?head.col==snake.col?and?head.row==snake.row:
dead=Truebreakif?dead:print('æ»äº')
quit=False
#渲æââç»åºæ¥#èæ¯pygame.draw.rect(window,?bg_color,?(0,0,W,H))#è头for?snake?in?snakes:rect(snake,?snake_color)
rect(head,?head_color)rect(food,?food_color)#pygame.display.flip()#设置帧é¢ï¼é度ï¼clock.tick(8)#æ¶å°¾å·¥ä½
è¿æ¯ä¸ä¸ªç®æçè´ªåèç代ç ï¼è½ç¶ç»æç®åï¼ä½æ¯è¯¥æçåè½é½æ¯å®æ´çï¼å¯ç©æ§ä¹ä¸é
cè¯è¨ç¼ç¨çè±ä»£ç ç®åcè¯è¨ç¼ç¨çè±ä»£ç ç®åå¦ä¸ï¼
#include"stdlib.h"
#include"graphics.h"
#include"stdio.h"
#include"math.h"
#include"conio.h"
#definePI?3.
main()
{
intgdriver=DETECT,gmode,errorcode;
inta[],b[],x,y,c,r,i,j,t;
doublerad=0.0;
/*initializegraphicsandlocalvariables*/
initgraph(gdriver,gmode,"");
/*readresultofinitialization*/
errorcode=graphresult();
if(errorcode!=grOk)?/*anerroroccurred*/
{
printf("Graphicserror:%s/n",grapherrormsg(errorcode));
printf("Pleaseanykeytohalt:");
getch();
exit(1);?/*terminatewithanerrorcode*/
}
randomize();
for(;!kbhit();)
{
x=rand()%+;/*éæºä¸å¿åæ */
y=rand()%+;
for(r=0;r=8;r++?)?/*çè±ç大å°è®¾å®*/
{
for(i=0,rad=0.0;rad2*PI;rad+=0.)?/*设å®åæ */
{
a[i++]=x+(int)r**cos(rad);
b[i]=y+(int)r**sin(rad);
}
t=i;
for(i=1;it;i++)
{
c=rand()%+1;/*åç¹çé¢è²éæº*/
setcolor(c);/*åè½:å°å½åå¾å½¢å±å¹çå½åç¬ç»é¢è²ç½®ä¸ºcolor.*/
circle(a[i],b[i],1);/*a[i],b[i]为åå¿1为åå¾ç»å*/
}
delay();
delay();
cleardevice();
å½æ°å:cleardevice?
å?è½:æ¸ é¤å¾å½¢å±å¹?
ç¨?æ³:voidfarcleardevice(void);
}
}
getch();
closegraph();
å½æ°å:closegraph
å?è½:å ³éå¾å½¢ç³»ç»
ç¨?æ³:voidfarclosegraph(void);
}
åå§åçè±åæ°
voidInit(inti)
{
//åå«ä¸ºï¼çè±ä¸å¿å°å¾çè¾¹ç¼çæè¿è·ç¦»ãçè±ä¸å¿å°å¾çå·¦ä¸è§çè·ç¦»(xãy)两个åé
intr[]={ ,,,,,,,,,,,,};
intx[]={ ,,,,,,,,,,,,};
inty[]={ ,,,,,,,,,,,,};
/****åå§åçè±*****/
Fire[i].x=0;//çè±ä¸å¿åæ
Fire[i].y=0;
Fire[i].width=;//å¾ç宽
Fire[i].height=;//å¾çé«
Fire[i].max_r=r[i];//æ大åå¾
Fire[i].cen_x=x[i];//ä¸å¿è·å·¦ä¸è§è·ç¦»
Fire[i].cen_y=y[i];
Fire[i].show=false;//æ¯å¦ç»½æ¾
Fire[i].dt=5;//绽æ¾æ¶é´é´é
Fire[i].t1=timeGetTime();
Fire[i].r=0;//ä»0å¼å§ç»½æ¾
/****åå§åçè±å¼¹*****/
Jet[i].x=-;//çè±å¼¹å·¦ä¸è§åæ
Jet[i].y=-;
Jet[i].hx=-;//çè±å¼¹åå°æé«ç¹åæ
Jet[i].hy=-;
Jet[i].height=0;//åå°é«åº¦
Jet[i].t1=timeGetTime();
Jet[i].dt=rand()%;//åå°é度æ¶é´é´é
Jet[i].n=0;//çè±å¼¹éªçå¾çä¸æ
Jet[i].shoot=false;//æ¯å¦åå°
}
求一C++小游戏源代码 简单点的?!!码简谢谢
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#define LEFT 0x4b
#define RIGHT 0x4d
#define DOWN 0x
#define UP 0x
#define ESC 0xb
int i,源码key;
int score=0;
int gamespeed=;
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();
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
for(i=;i<=;i+=)
{
rectangle(i,,i+,); /*画出上边框*/
rectangle(i,,i+,); /*画出下边框*/
}
for(i=;i<=;i+=)
{
rectangle(,i,,i+); /*画出左边框*/
rectangle(,i,,i+); /*画出右边框*/
}
}
void GamePlay(char ch)
{
randomize(); /*随机数发生器*/
food.yes=1; /*1代表要出现食物,0表示以存在食物*/
snake.life=0;
snake.direction=1;
snake.x[0]=;snake.y[0]=;
snake.x[1]=;snake.y[1]=;
snake.node=2;
PrScore();
while(1) /*可以重复游戏*/
{
while(!kbhit()) /*在没有按键的码简情况下蛇自己移动*/
{
if(food.yes==1) /*需要食物*/
{
food.x=rand()%+;
food.y=rand()%+; /*使用rand函数随机产生食物坐标*/
while(food.x%!=0)
food.x++;
while(food.y%!=0)
food.y++; /*判断食物是否出现在整格里*/
food.yes=0; /*现在有食物了*/
}
if(food.yes==0) /*有食物了就要显示出来*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+,food.y-);
}
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]+=;break;
case 2:snake.x[0]-=;break;
case 3:snake.y[0]-=;break;
case 4:snake.y[0]+=;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]<||snake.x[0]>||snake.y[0]<||snake.y[0]>)
{
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+,food.y-); /*吃的食物后用黑色将食物擦去*/
snake.x[snake.node]=-;snake.y[snake.node]=-; /*现把增加的一节放到看不到的地方去*/
snake.node++;
food.yes=1;
score+=;
PrScore();
}
setcolor(4); /*每次移动后将后面的身体擦去*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+,snake.y[i]-);
delay(gamespeed);
DELAY(ch);
setcolor(0);
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],snake.x[snake.node-1]+,snake.y[snake.node-1]-);
}
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(,,"GAME OVER");
getch();
}
void PrScore(void)
{
char str[];
setfillstyle(SOLID_FILL,YELLOW);
bar(,,,);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"scord:%d",score);
outtextxy(,,str);
}
void Close(void)
{
getch();
closegraph();
}
贪吃蛇