迷宫源代码:
#include
#include
#include
#include
#include
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define F9 0x43
#define Esc 0x1b
#define Del 0x53
#define Home 0x47
#define End 0x4f
#define Space 0x20
#define Up 0x48
#define Down 0x50
#define Left 0x4b
#define Right 0x4d
#define Enter 0x0d
#define F2 0x3c
#define F3 0x3d
#define STACK_INIT_SIZE 200 #define STACKINCREMENT 10 typedef int Boolean;
typedef int Status;
typedef suct {
int x;
int y;
} PosType;
typedef suct {
int ord;
PosType seat;
int di;
} SElemType;
typedef suct {
int ;
int foot;
int mark;
} MazeType;
typedef suct {
SElemType *base;
SElemType *top;
int stacksize;
} Stack;
int Maze[20][30];
MazeType maze[20][30];
PosType StartPlace;
PosType EndPlace;
int count;
int m,n;
Boolean b_start=FALSE,b_end=FALSE;
void CreatMaze(void);
Status SaveMaze(char *filename);
Status LoadMaze(char *filename);
void Error(char *message);
Status InitStack(Stack *s);
Status DesoyStack(Stack *s);
Status ClearStack(Stack *s);
Boolean StackEmpty(Stack *s);
int StackLength(Stack *s);
Status Push(Stack *s,SElemType e);
SElemType Pop(Stack *s,SElemType e);
Status GetTop(Stack *s,SElemType *e);
Status StackTraverse(Stack *s,Status (* visit)(SElemType *se)); Boolean Pass(PosType curpos);
void MarkPrint(PosType seat);
void FootPrint(PosType curpos);
PosType NextPos(PosType seat,int di);
Status MazePath(PosType start,PosType end);
void CreatMaze(void)
/* Form the maze. */
{
void Error(char *message);
Status SaveMaze(char *filename);
Status LoadMaze(char *filename);
int i,j;
int x,y;
char c;
char savename[12],loadname[12];
Boolean flag=FALSE,load=FALSE;
clrscr();
printf("Menu:\n\n");
printf("1.Load Mazefile:(*.dd)\n\n");
printf("2.Input Maze:\n\n");
printf("Input your choice: ");
do
{
c=getch();
switch(c)
{
case ''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''': putch(''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''); break; case ''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''': putch(''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''); break; case Esc: sleep(1); exit(1);
default: break;
}
}
while(c!=''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''&&c!=''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''') ;
if(c==''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''')
{
printf("\n\nLoadName: ");
scanf("%s",loadname);
if(LoadMaze(loadname))
{
sleep(1); load=TRUE;
}
else { gotoxy(1,9); printf("Load fail! "); }
}
if(!load)
{
printf("\nInput the maze''''''''''''''''''''''''''''''''s size:\n");
printf("\nInput Length :\n");
scanf("%d",&m);
printf("\nInput Width :\n");
scanf("%d",&n);
if(m<4||n<4) Error("Input");
if(m>30||n>20) Error("Maze too large");
for(i=0;i<30;i )
for(j=0;j<20;j )
Maze[j][i]=2;
StartPlace.x=0;
StartPlace.y=0;
EndPlace.x=0;
EndPlace.y=0;
clrscr();BR> for(i=1;i<=n;i )
{
for(j=1;j<=m;j )
{
printf(" #");
Maze[i-1][j-1]=0;
}
printf("\n");
}
}
gotoxy(65,5);
printf("''''''''''''''''''''''''''''''''#'''''''''''''''''''''''''''''''':Wall");
gotoxy(65,7);
printf("Start:Home");
gotoxy(65,9);
printf("End:End");
gotoxy(65,11);
printf("Delete Wall:Del");
gotoxy(65,13);
printf("Enter Wall:Enter");
gotoxy(65,15);
printf("Save Maze:F2");
gotoxy(65,17);
printf("Complete:F9");
gotoxy(65,19);
printf("Exit:Esc");
gotoxy(4,3);
x=4;y=3;
do
{
c=getch();
switch(c)
{
case Up: if(y>3) { y--; gotoxy(x,y); }
break;
case Down: if(y break; case Left: if(x>4) { x-=2; gotoxy(x,y); } break; case Right: if(x<2*m-2) { x =2; gotoxy(x,y); } break; case Del: if(y-2==StartPlace.y&&x/2-1==StartPlace.x) b_start=FALSE; if(y-2==EndPlace.y&&x/2-1==EndPlace.x) b_end=FALSE; putch('''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''); Maze[y-2][x/2-1]=1; gotoxy(x,y); break; case Enter: if(y-2==StartPlace.y&&x/2-1==StartPlace.x) break; if(y-2==EndPlace.y&&x/2-1==EndPlace.x) break; putch(''''''''''''''''''''''''''''''''#''''''''''''''''''''''''''''''''); Maze[y-2][x/2-1]=0; gotoxy(x,y); break; case Home: if(Maze[y-2][x/2-1]&&!b_start) { StartPlace.x=x/2-1; StartPlace.y=y-2; putch(''''''''''''''''''''''''''''''''S''''''''''''''''''''''''''''''''); gotoxy(x,y); b_start=TRUE; } break; case End: if(Maze[y-2][x/2-1]&&!b_end) { EndPlace.x=x/2-1; EndPlace.y=y-2; putch(''''''''''''''''''''''''''''''''E''''''''''''''''''''''''''''''''); gotoxy(x,y); b_end=TRUE; } break; case Esc: gotoxy(2,22); printf("exit"); sleep(1); exit(1); case F9: if(b_start&&b_end) flag=TRUE; break; case F2: gotoxy(2,22); printf("Savename:"); scanf("%s",savename); gotoxy(2,22); if(SaveMaze(savename)) printf("Save OK! "); else printf("Save fail! "); sleep(1); gotoxy(2,22); printf(" "); gotoxy(x,y); break; default: break; } } while(!flag); for(i=0;i<30;i ) for(j=0;j<20;j ) { maze[j][i].=Maze[j][i]; maze[j][i].mark=0; maze[j][i].foot=0; } } Status LoadMaze(char *file) /* The maze has been loaded. */ { FILE *fp; char *buffer; char ch; int i=0,j,k; Boolean len=FALSE,wid=FALSE; if((fp=fopen(file,"r"))==NULL) return ERROR; buffer=(char *)malloc(600*sizeof(char)); ch=fgetc(fp); while(ch!=EOF) { buffer[i]=ch; i ; ch=fgetc(fp); } m=30;n=20; for(i=0;i<600;i ) { j=i/30; k=i0; if(buffer[i]==''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''&&!len){ m=i; len=TRUE; } if(k==0&&buffer[i]==''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''&&!wid){ n=j; wid=TRUE; } switch(buffer[i]) { case ''''''''''''''''''''''''''''''''0'''''''''''''''''''''''''''''''': Maze[j][k]=0; break; case ''''''''''''''''''''''''''''''''1'''''''''''''''''''''''''''''''': Maze[j][k]=1; break; case ''''''''''''''''''''''''''''''''2'''''''''''''''''''''''''''''''': Maze[j][k]=2; break; case ''''''''''''''''''''''''''''''''3'''''''''''''''''''''''''''''''': Maze[j][k]=1; StartPlace.x=k; StartPlace.y=j; b_start=TRUE; break; case ''''''''''''''''''''''''''''''''4'''''''''''''''''''''''''''''''': Maze[j][k]=1; EndPlace.x=k; EndPlace.y=j; b_end=TRUE; break; default : break; } } fclose(fp); clrscr(); for(i=0;i<30;i ) for(j=0;j<20;j ) { maze[j][i].=Maze[j][i]; maze[j][i].foot=0; maze[j][i].mark=0; if(Maze[j][i]==0) { gotoxy(2*i 2,j 2); putch(''''''''''''''''''''''''''''''''#''''''''''''''''''''''''''''''''); } } gotoxy(2*StartPlace.x 2,StartPlace.y 2); putch(''''''''''''''''''''''''''''''''S''''''''''''''''''''''''''''''''); gotoxy(2*EndPlace.x 2,EndPlace.y 2); putch(''''''''''''''''''''''''''''''''E''''''''''''''''''''''''''''''''); return OK; } Status SaveMaze(char *filename) /* The maze has been saved. */ { FILE *fp; char *buffer; int i,j,k; fp=fopen(filename,"wb"); buffer=(char *)malloc(600*sizeof(char)); for(i=0;i<600;i ) { j=i/30; k=i0; switch(Maze[j][k]) { case 0: buffer[i]=''''''''''''''''''''''''''''''''0''''''''''''''''''''''''''''''''; break; case 1: buffer[i]=''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''; break; case 2: buffer[i]=''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''; break; default : Error("Write"); break; } if(k==StartPlace.x&&j==StartPlace.y) buffer[i]=''''''''''''''''''''''''''''''''3''''''''''''''''''''''''''''''''; if(k==EndPlace.x&&j==EndPlace.y) buffer[i]=''''''''''''''''''''''''''''''''4''''''''''''''''''''''''''''''''; } fwrite(buffer,600,1,fp); free(buffer); fclose(fp); return OK; } void Error(char *message) { clrscr(); fprintf(serr,"Error:%s\n",message); exit(1); } /* Error */ Status InitStack(Stack *s) /* The stack s has been created and is initialized to be empty. */ { s->base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!s->base) Error("Overflow"); s->top=s->base; s->stacksize=STACK_INIT_SIZE; return OK; } /* InitStack */ Status DesoyStack(Stack *s) /* The stack s has been desoyed. */ { s->top=NULL; s->stacksize=0; free(s->base); s->base=NULL; return OK; } /* DesoyStack */ Status ClearStack(Stack *s) /* The stack has been clear to be maximum. */ { s->top=s->base; s->stacksize=STACK_INIT_SIZE; return OK; } /* ClearStack */ Boolean StackEmpty(Stack *s) /* Check if the stack s is empty. */ { if(s->top==s->base) return TRUE; else return FALSE; } /* StackEmpty */ int StackLength(Stack *s) /* Gain the length of the stack s. */ { if(s->top>s->base) return (int)(s->top-s->base); else return 0; } /* StackLength */ Status Push(Stack *s,SElemType e) /* The element e has been pushed into the stack s. */ { if(s->top-s->base>=s->stacksize) { s->base=(SElemType *)realloc(s->base, (s->stacksize STACKINCREMENT)*sizeof(SElemType)); if(!s->base) Error("Overflow"); s->top=s->base s->stacksize; s->stacksize =STACKINCREMENT; } *s->top =e; return OK; } /* Push */ SElemType Pop(Stack *s,SElemType e) /* The element e has been removed from the stack s. */ { if(s->top==s->base) Error("Pop"); e=*--s->top; return e; } /* Pop */ Status GetTop(Stack *s,SElemType *e) /* The element e has got to the top of the stack s.*/ { if(s->top==s->base) Error("GetTop"); *e=*(s->top-1); return OK; } /* GetTop */ /* Traverse the stack s using ''''''''''''''''''''''''''''''''visiting'''''''''''''''''''''''''''''''' function. */ /* Status StackTraverse(Stack *s,Status (* visit)(SElemType *se)) { SElemType p; int result; if(s->top==s->base) return ERROR; p=s->base; while(!(p==s->top)) { result=(*visit)(p); p ; } return OK; } */ Boolean Pass(PosType curpos) /* Check if the current position can be passed. */ { if(maze[curpos.x][curpos.y].==1&& maze[curpos.x][curpos.y].foot==0&&maze[curpos.x][curpos.y].mark==0) return TRUE; else return FALSE; } /* Pass */ void MarkPrint(PosType seat) /* Mark the position seat. */ { maze[seat.x][seat.y].mark=-1; /* Marking ''''''''''''''''''''''''''''''''-1'''''''''''''''''''''''''''''''' symbolize the current position cannot be put. */ } /* MarkPrint */ void FootPrint(PosType curpos) /* The foot of the curpos of the maze has been set ''''''''''''''''''''''''''''''''ue''''''''''''''''''''''''''''''''. */ { maze[curpos.x][curpos.y].foot=1; } /* FootPrint */ PosType NextPos(PosType seat,int di) { switch(di) { case 1: seat.y ; return seat; /* Eastward */ case 2: seat.x ; return seat; /* Southward */ case 3: seat.y--; return seat; /* Westward */ case 4: seat.x--; return seat; /* Northward */ default: seat.x=0; seat.y=0; return seat; } } /* NextPos */ /* The key to the program. */ /* Pre: The maze array & the startplace & the endplace. Post: Find the one averse of the maze and perform the mazepath. Uses: The ADT stack class. */ Status MazePath(PosType start,PosType end) { PosType curpos; int curstep; SElemType e; Stack *s,stack; stack.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!stack.base) Error("Overflow"); stack.top=stack.base; stack.stacksize=STACK_INIT_SIZE; s=&stack; curpos=start; curste printf("\n");<'0''''''''''''''''''''''''''''''''; break; case 1: buffer[i]=''''''''''''''''''''''''''''''''1''''''''''''''''''''''''''''''''; break; case 2: buffer[i]=''''''''''''''''''''''''''''''''2''''''''''''''''''''''''''''''''; break; default : Error("Write"); break; } if(k==StartPlace.x&&j==StartPlace.y) buffer[i]=''''''''''''''''''''''''''''''''3''''''''''''''''''''''''''''''''; if(k==EndPlace.x&&j==EndPlace.y) buffer[i]=''''''''''''''''''''''''''''''''4''''''''''''''''''''''''''''''''; } fwrite(buffer,600,1,fp); free(buffer); fclose(fp); return OK; } void Error(char *message) { clrscr(); fprintf(serr,"Error:%s\n",message); exit(1); } /* Error */ Status InitStack(Stack *s) /* The stack s has been created and is initialized to be empty. */ { s->base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!s->base) Error("Overflow"); s->top=s->base; s->stacksize=STACK_INIT_SIZE; return OK; } /* InitStack */ Status DesoyStack(Stack *s) /* The stack s has been desoyed. */ { s->top=NULL; s->stacksize=0; free(s->base); s->base=NULL; return OK; } /* DesoyStack */ Status ClearStack(Stack *s) /* The stack has been clear to be maximum. */ { s->top=s->base; s->stacksize=STACK_INIT_SIZE; return OK; } /* ClearStack */ Boolean StackEmpty(Stack *s) /* Check if the stack s is empty. */ { if(s->top==s->base) return TRUE; else return FALSE; } /* StackEmpty */ int StackLength(Stack *s) /* Gain the length of the stack s. */ { if(s->top>s->base) return (int)(s->top-s->base); else return 0; } /* StackLength */ Status Push(Stack *s,SElemType e) /* The element e has been pushed into the stack s. */ { if(s->top-s->base>=s->stacksize) { s->base=(SElemType *)realloc(s->base, (s->stacksize STACKINCREMENT)*sizeof(SElemType)); if(!s->base) Error("Overflow"); s->top=s->base s->stacksize; s->stacksize =STACKINCREMENT; } *s->top =e; return OK; } /* Push */ SElemType Pop(Stack *s,SElemType e) /* The element e has been removed from the stack s. */ { if(s->top==s->base) Error("Pop"); e=*--s->top; return e; } /* Pop */ Status GetTop(Stack *s,SElemType *e) /* The element e has got to the top of the stack s.*/ { if(s->top==s->base) Error("GetTop"); *e=*(s->top-1); return OK; } /* GetTop */ /* Traverse the stack s using ''''''''''''''''''''''''''''''''visiting'''''''''''''''''''''''''''''''' function. */ /* Status StackTraverse(Stack *s,Status (* visit)(SElemType *se)) { SElemType p; int result; if(s->top==s->base) return ERROR; p=s->base; while(!(p==s->top)) { result=(*visit)(p); p ; } return OK; } */ Boolean Pass(PosType curpos) /* Check if the current position can be passed. */ { if(maze[curpos.x][curpos.y].==1&& maze[curpos.x][curpos.y].foot==0&&maze[curpos.x][curpos.y].mark==0) return TRUE; else return FALSE; } /* Pass */ void MarkPrint(PosType seat) /* Mark the position seat. */ { maze[seat.x][seat.y].mark=-1; /* Marking ''''''''''''''''''''''''''''''''-1'''''''''''''''''''''''''''''''' symbolize the current position cannot be put. */ } /* MarkPrint */ void FootPrint(PosType curpos) /* The foot of the curpos of the maze has been set ''''''''''''''''''''''''''''''''ue''''''''''''''''''''''''''''''''. */ { maze[curpos.x][curpos.y].foot=1; } /* FootPrint */ PosType NextPos(PosType seat,int di) { switch(di) { case 1: seat.y ; return seat; /* Eastward */ case 2: seat.x ; return seat; /* Southward */ case 3: seat.y--; return seat; /* Westward */ case 4: seat.x--; return seat; /* Northward */ default: seat.x=0; seat.y=0; return seat; } } /* NextPos */ /* The key to the program. */ /* Pre: The maze array & the startplace & the endplace. Post: Find the one averse of the maze and perform the mazepath. Uses: The ADT stack class. */ Status MazePath(PosType start,PosType end) { PosType curpos; int curstep; SElemType e; Stack *s,stack; stack.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); if(!stack.base) Error("Overflow"); stack.top=stack.base; stack.stacksize=STACK_INIT_SIZE; s=&stack; curpos=start; curstep=1; { if(Pass(curpos)) { FootPrint(curpos); e.ord=curstep; e.seat=curpos; e.di=1; gotoxy((curpos.y 1)*2,curpos.x 2); putch(''''''''''''''''''''''''''''''''@''''''''''''''''''''''''''''''''); delay(8000); /* pospone time. */ Push(s,e); if(curpos.x==end.x&&curpos.y==end.y) /* Proceed recursively. */ { DesoyStack(s); return TRUE; } curpos=NextPos(curpos,1); /* Try next position. */ curstep ; } else { if(!StackEmpty(s)) { e=Pop(s,e); /* Removed e from s. */ while(e.di==4&&!StackEmpty(s)) /* Four directions have been checked and s is not empty. */ { MarkPrint(e.seat); gotoxy((e.seat.y 1)*2,e.seat.x 2); putch(''''''''''''''''''''''''''''''''@''''''''''''''''''''''''''''''''); delay(8000); /* Pospone time. */ gotoxy((e.seat.y 1)*2,e.seat.x 2); putch('''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''); e=Pop(s,e); /* Remove e from s. */ curstep--; } if(e.di<4) /* The current position hasnot been checked. */ { e.di ; Push(s,e); /* Insert e into s. */ curpos=NextPos(e.seat,e.di); /* Try next position. */ } } } while(!StackEmpty(s)); DesoyStack(s); return FALSE; } /* MazePath */ void main() { PosType start,end; CreatMaze(); start.x=StartPlace.y; start.y=StartPlace.x; end.x=EndPlace.y; end.y=EndPlace.x; if(MazePath(start,end)) { gotoxy(2,22); printf("Path found\n"); } else { gotoxy(2,22); printf("Path not found\n"); } getch(); clrscr(); } 目录1.设计目的 1.1课程设计的目的 2.总体设计 2.1设计思路 2.2设计方法 3.关键技术 4.程序流程 5.主要源代码 6. 运行结果及结论 7.参考文献 1.设计目的 1.1课程设计的目的 随着科技进步,时代发展,计算机走进了大家的生活。计算机程序强大的功能为使用者提供服务,编程语言也变得越来越流行。Java语言是当今流行的网络编程语言,它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法,它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。 为了进一步巩固课堂上所学到的知识,深刻把握Java语言的重要概念及其面向对象的特性,熟练应用面向对象的思想和设计方法解决实际问题的能力,也是为了增加同学们娱乐游戏选择而开发了一个适合学生的,能提升思考力的迷宫冒险游戏,这既锻炼了动手能力,还能进行消遣娱乐,可谓一举两得。 2.总体设计 2.1设计思路 根据对游戏系统进行的需求分析,本系统将分为6个模块:分别是迷宫主界面模块、记时设计模块、迷宫设计模块、道路和障碍设计模块、动漫冒险者设计模块、出入口设计模块。实现的功能有: (1)迷宫的选择 玩家可以根据自身需求来进行选择简单迷宫、中等迷宫、难度迷宫三类中选择一类迷宫进行游戏。 (2)选择道路和障碍的图像 玩家可以根据个人喜好对迷宫中的道路和障碍的图片进行选择,但是图片的格式有规定,必须是“jpg”或“gif”格式的。 (3)游戏记时 当玩家控制迷宫中的动漫人物进行游戏时,计时器就开始进行记时,直到动漫人物到达出口时,记时结束,并在屏幕上显示游戏用时。 (4)开始游戏 玩家将鼠标移动至迷宫中的动漫冒险者,即可看到“单击我然后按键盘方向键”,单击后,游戏开始。玩家即可通过键盘上的方向键进行游戏。 (5)游戏结束 玩家控制动漫冒险者移动至迷宫地图的出口处时,游戏的计时器停止计时,并弹出信息框“恭喜您通关了”,游戏结束。 纯C语言写的一个小型游戏-源代码 /* A simple game*/ /*CopyRight: Guanlin*/ #include C语言游戏源代码 1、简单的开机密码程序 #include "conio.h" #include "string.h" #include "stdio.h" void error() {window(12,10,68,10); textbackground(15); textcolor(132); clrscr(); cprintf("file or system error! you can't enter the system!!!"); while(1); /*若有错误不能通过程序*/ } void look() {FILE *fauto,*fbak; char *pass="c:\\windows\\password.exe"; /*本程序的位置*/ char a[25],ch; char *au="autoexec.bat",*bname="hecfback.^^^"; /*bname 是autoexec.bat 的备份*/ setdisk(2); /*set currently disk c:*/ chdir("\\"); /*set currently directory \*/ fauto=fopen(au,"r+"); if (fauto==NULL) {fauto=fopen(au,"w+"); if (fauto==NULL) error();} fread(a,23,1,fauto); /*读取autoexec.bat前23各字符*/ a[23]='\0'; if (strcmp(a,pass)==0) /*若读取的和pass指针一样就关闭文件,不然就添加*/ fclose(fauto); else {fbak=fopen(bname,"w+"); if (fbak==NULL) error(); fwrite(pass,23,1,fbak); fputc('\n',fbak); rewind(fauto); while(!feof(fauto)) {ch=fgetc(fauto); fputc(ch,fbak);} rewind(fauto); rewind(fbak); while(!feof(fbak)) //Java编程:五子棋游戏源代码 import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; import java.io.PrintStream; import javax.swing.JComponent; import javax.swing.JPanel; /* *main方法创建了ChessFrame类的一个实例对象(cf), *并启动屏幕显示显示该实例对象。 **/ public class FiveChessAppletDemo { public static void main(String args[]){ ChessFrame cf = new ChessFrame(); cf.show(); } } /* *类ChessFrame主要功能是创建五子棋游戏主窗体和菜单**/ class ChessFrame extends JFrame implements ActionListener { private String[] strsize={"20x15","30x20","40x30"}; private String[] strmode={"人机对弈","人人对弈"}; public static boolean iscomputer=true,checkcomputer=true; private int width,height; private ChessModel cm; private MainPanel mp; //构造五子棋游戏的主窗体 public ChessFrame() { this.setTitle("五子棋游戏"); cm=new ChessModel(1); mp=new MainPanel(cm); Container con=this.getContentPane(); con.add(mp,"Center"); this.setResizable(false); this.addWindowListener(new ChessWindowEvent()); MapSize(20,15); JMenuBar mbar = new JMenuBar(); this.setJMenuBar(mbar); JMenu gameMenu = new JMenu("游戏"); 连连看java源代码 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener { JFrame mainFrame; //主面板 Container thisContainer; JPanel centerPanel,southPanel,northPanel; //子面板 JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组 JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮 JLabel fractionLable=new JLabel("0"); //分数标签 JButton firstButton,secondButton; //分别记录两次被选中的按钮 int grid[][] = new int[8][7];//储存游戏按钮位置 static boolean pressInformation=false; //判断是否有按钮被选中 int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标int i,j,k,n;//消除方法控制 public void init(){ mainFrame=new JFrame("JKJ连连看"); thisContainer = mainFrame.getContentPane(); thisContainer.setLayout(new BorderLayout()); centerPanel=new JPanel(); southPanel=new JPanel(); northPanel=new JPanel(); thisContainer.add(centerPanel,"Center"); thisContainer.add(southPanel,"South"); thisContainer.add(northPanel,"North"); centerPanel.setLayout(new GridLayout(6,5)); for(int cols = 0;cols < 6;cols++){ for(int rows = 0;rows < 5;rows++ ){ diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1])); diamondsButton[cols][rows].addActionListener(this); centerPanel.add(diamondsButton[cols][rows]); } } exitButton=new JButton("退出"); exitButton.addActionListener(this); resetButton=new JButton("重列"); resetButton.addActionListener(this); newlyButton=new JButton("再来一局"); newlyButton.addActionListener(this); southPanel.add(exitButton); C语言编写的迷宫游戏源代码 #include c语言课程设计源代码标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N] 学校运动会管理系统问题描述: (1) 初始化输入:N-参赛院系总数,M-男子竞赛项目数,W-女子竞赛项目数; (2) 各项目名次取法有如下几种: 取前5名:第1名得分 7,第2名得分 5,第3名得分3,第4名得分2,第5名得分 1; (3) 由程序提醒用户填写比赛结果,输入各项目获奖运动员的信息。 (4) 所有信息记录完毕后,用户可以查询各个院系或个人的比赛成绩,生成团体总分报表,查看参赛院系信息、获奖运动员、比赛项目信息等。 程序代码: #include<> #include<> #define N 3 #define M 3 #define W 3 char* n_number[3]={"1","院系2","院系3"}; char* m_number[3]={"1","男项2","男项3"}; char* w_number[3]={"女项1","女项2","女项3"}; int size=2; struct student { char num[10]; char name[20]; char xiangmu[20]; int score; char ximing[20]; }stu[100],temp; void input() um,&stu[i].name,&stu[i].xiangmu,&stu[i].score,&stu[i].ximing); iming,n_number[0])==0) iming); iming,n_number[h])==0) for(int s=0;s #include set(); } else if(ch==-32) { switch(getch()) { case 72:upon();break; case 80:down();break; case 75:left();break; case 77:right();break; } } else ahead(); } else { ahead(); } if(head_f->x==food.x&&head_f->y==food.y) { Sleep(100); crate(); food.judge=0; point=point+(6-grade)*10; if(food.x<30||food.y<30||food.x>570||food.y>570) life++; menu(); } if(head_f->x<5||head_f->x>595||head_f->y<5||head_f->y>595) { Sleep(1000); life--; food.judge=0; init_graph(); init_insect(); menu(); } for(p1=head_f->next;p1!=NULL;p1=p1->next) { if(head_f->x==p1->x&&head_f->y==p1->y) { Sleep(1000); life--; food.judge=0; j a v a小游戏源代码 Document number:NOCG-YUNOO-BUYTT-UU986-1986UT Java小游戏 第一个Java文件: import class GameA_B { public static void main(String[] args) { Scanner reader=new Scanner; int area; "Game Start…………Please enter the area:(1-9)" + '\n'+"1,2,3 means easy"+'\n'+"4,5,6 means middle"+'\n'+ "7,8,9 means hard"+'\n'+"Please choose:"); area=(); switch((area-1)/3) { case 0:"You choose easy! ");break; case 1:"You choose middle! ");break; case 2:"You choose hard! ");break; } "Good Luck!"); GameProcess game1=new GameProcess(area); (); } } 第二个Java文件: import class GameProcess { int area,i,arrcount,right,midright,t; int base[]=new int[arrcount],userNum[]=new int[area],sysNum[]=new int[area]; Random random=new Random(); Scanner reader=new Scanner; GameProcess(int a) { area=a; arrcount=10; right=0; midright=0; t=0; base=new int[arrcount]; userNum=new int[area]; sysNum=new int[area]; for(int i=0;i 目录1.设计目的 课程设计的目的 2.总体设计 设计思路 设计方法 3.关键技术 4.程序流程 5.主要源代码 6. 运行结果及结论 7. 参考文献 1.设计目的 课程设计的目的 随着科技进步,时代发展,计算机走进了大家的生活。计算机程序强大的功能为使用者提供服务,编程语言也变得越来越流行。 Java 语言是当今流行的网络编程语言,它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法,它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。 为了进一步巩固课堂上所学到的知识,深刻把握 Java 语言的重要概念及其面向对象的特性,熟练应用面向对象的思想和设计方法解决实际问题的能力,也是为了增加同学们娱乐游戏选择而开发了一个适合学生的,能提升思考力的迷宫冒险游戏,这既锻炼了动手能力,还能进行消遣娱乐,可谓一举两得。 2.总体设计设计思路 根据对游戏系统进行的需求分析,本系统将分为 6 个模块:分别是迷宫 主界面模块、记时设计模块、迷宫设计模块、道路和障碍设计模块、动漫冒险者设计模块、出入口设计模块。实现的功能有: (1)迷宫的选择 玩家可以根据自身需求来进行选择简单迷宫、中等迷宫、难度迷宫三类中选择一类迷宫进行游戏。 (2)选择道路和障碍的图像 玩家可以根据个人喜好对迷宫中的道路和障碍的图片进行选择,但是图片的格式有规定,必须是“ jpg ”或“ gif ”格式的。 (3)游戏记时 当玩家控制迷宫中的动漫人物进行游戏时,计时器就开始进行记时,直 到动漫人物到达出口时,记时结束,并在屏幕上显示游戏用时。 (4)开始游戏 玩家将鼠标移动至迷宫中的动漫冒险者,即可看到“单击我然后按键盘 方向键”,单击后,游戏开始。玩家即可通过键盘上的方向键进行游戏。 (5)游戏结束 玩家控制动漫冒险者移动至迷宫地图的出口处时,游戏的计时器停止计时,并弹出信息框“恭喜您通关了” ,游戏结束 (6)冒险脚步声 玩家单击动漫冒险者后,便可以用键盘方向键进行控制。动漫冒险者每移动一步便会发出一声“嘟”的响声。 语言游戏源代码1、简单地开机密码程序 "" "" "" () {()()()()(" ! ' !!!"); (); *若有错误不能通过程序* } () { *,*; *":\\\\"; *本程序地位置* []; *"",*".^^^"; *是地备份*(); * :*("\\"); * \*(,""); () {(,""); () ();}(); *读取前各字符* []'\'; (()) *若读取地和指针一样就关闭文件,不然就添加*(); {(,""); () ()()('\'); (); (()) {()();} (); (); (()){()();}()(); (); * * } } () { *""; [] ; () {()()()(); ; ()()()()(":"); () {[](); (>) {(); ;} *若字符多于个字符就结束本次输入* ([]) ; ([]> []<) *若字符是数字或字母才算数* {('*'); ;} ([]) *删除键* (>) {("\ \"); []'\'; ;} } []'\'; (()) ; {(); ()()()()(" !")();} } } () {(); (); } 2、彩色贪吃蛇 <> <> ; * 游戏速度*, , ; * 游戏分数* [] { , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , 扫雷游戏Java源代码 import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; import java.awt.GridLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.Timer; public class ScanLei1 extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private Container contentPane; private JButton btn; private JButton[] btns; private JLabel b1; private JLabel b2; private JLabel b3; private Timer timer; private int row=9; private int col=9; private int bon=10; private int[][] a; private int b; private int[] a1; private JPanel p,p1,p2,p3; public ScanLei1(String title){ super(title); contentPane=getContentPane(); Java语言与面向对象技术课程设计报告 ( 2014 -- 2015年度第1 学期) 走迷宫 目录 目录 ...................................................................................................... 错误!未定义书签。 1 概述.................................................................................................. 错误!未定义书签。课程设计目的 ........................................................................... 错误!未定义书签。课程设计内容 ........................................................................... 错误!未定义书签。 2 系统需求分析 .......................................................................................... 错误!未定义书签。系统目标 ................................................................................... 错误!未定义书签。主体功能 ................................................................................... 错误!未定义书签。开发环境 ................................................................................... 错误!未定义书签。 3 系统概要设计 .......................................................................................... 错误!未定义书签。系统的功能模块划分 ............................................................... 错误!未定义书签。系统流程图 ............................................................................... 错误!未定义书签。4系统详细设计 ........................................................................................... 错误!未定义书签。系统的主界面设计 ..................................................................... 错误!未定义书签。 MAZE的设计.................................................................... 错误!未定义书签。 PERSONINMAZE的设计................................................... 错误!未定义书签。 WALLORROAD的设计 ..................................................... 错误!未定义书签。 MAZEPOINT的设计 ......................................................... 错误!未定义书签。 SOUND的设计 ................................................................. 错误!未定义书签。 RECORD的设计................................................................ 错误!未定义书签。 5 测试........................................................................................................... 错误!未定义书签。测试方案 ................................................................................... 错误!未定义书签。测试结果 ................................................................................... 错误!未定义书签。 6 小结........................................................................................................... 错误!未定义书签。参考文献....................................................................................................... 错误!未定义书签。 /* A simple game*/ /*CopyRight: Guanlin*/ #include /************************************ * Desc: 俄罗斯方块游戏 * By: hoodlum1980 :30 ************************************/ #include <> #include <> #include <> #include <> #include <> #include <> #define true 1 #define false 0 #define BoardWidth 12 #define BoardHeight 23 #define _INNER_HELPER /*inner helper method */ /*Scan Codes Define*/ enum KEYCODES { K_ESC =0x011b, K_UP =0x4800, /* upward arrow */ K_LEFT =0x4b00, K_DOWN =0x5000, K_RIGHT =0x4d00, K_SPACE =0x3920, K_P =0x1970 }; /* the data structure of the block */ typedef struct tagBlock { char c[4][4]; /* cell fill info array, 0-empty, 1-filled */ int x; /* block position cx [ 0,BoardWidht -1] */ int y; /* block position cy [-4,BoardHeight-1] */ char color; /* block color */ char size; /* block max size in width or height */ char name; /* block name (the block's shape) */ } Block; /* game's global info */ int FrameTime= 1300; int CellSize= 18; int BoardLeft= 30; int BoardTop= 30; /* next block grid */ int NBBoardLeft= 300; 本世纪70年代,人们曾疯魔一种被称作“生命游戏”的小游戏,这种游戏相当简单。假设有一个像棋盘一样的方格网,每个方格中放置一个生命细胞,生命细胞只有两种状态:“生”或“死”。游戏规则如下: 1. 如果一个细胞周围有3个细胞为生(一个细胞周围共有8个细胞),则该细胞为生,即该细胞若原先为死,则转为生,若原先为生,则保持不变; 2. 如果一个细胞周围有2个细胞为生,则该细胞的生死状态保持不变; 3. 在其它情况下,该细胞为死,即该细胞若原先为生,则转为死,若原先为死,则保持不变。 依此规则进行迭代变化,使细胞生生死死,会得到一些有趣的结果。该游戏之所以被称为“生命游戏”,是因为其简单的游戏规则,反映了自然界中的生存规律:如果一个生命,其周围的同类生命太少的话,会因为得不到帮助而死亡;如果太多,则会因为得不到足够的资源而死亡。 用计算机模拟这个“生命游戏”也相当简单,可以用一个M×N像素的图像来代表M×N个细胞,其中每一个像素,代表一个细胞,像素为黑色表示细胞为生,像素为白色代表细胞为死。 设定图像中每个像素的初始状态后依据上述的游戏规则演绎生命的变化,由于初始状态和迭代次数不同,将会得到令人叹服的优美图案。 下面给出的小程序是用TC2.0编写。演示100×100个生命细胞初始状态全为生时的变代情况,变化时边缘细胞不参与变化。随着迭代次数的不同,在屏幕显示的图案精彩纷呈,像万花筒般引人入胜。 #include **** 届毕业设计Java小游戏俄罗斯方块 ┊┊┊┊┊┊┊┊┊┊┊┊┊装┊┊┊┊┊订┊┊┊┊┊线┊┊┊┊┊┊┊┊┊┊┊┊┊ 摘要 在现今电子信息高速发展的时代,电子游戏已经深入人们的日常生活,成为老少皆宜的娱乐方式。但是游戏设计结合了日新月异的技术,在一个产品中整合了复杂的设计、艺术、声音和软件,所以并不是人人皆知。直到今天,在中国从事游戏设计的人仍然很少,但是游戏行业的发展之快,远超如家电、汽车等传统行业,也正因为如此,游戏人才的教育、培养远落后于产业的发展。 俄罗斯方块是个老幼皆宜的小游戏,它实现由四块正方形的色块组成,然后存储在一个数组的四个元素中,计算机随机产生不同七种类型的方块,根据计算机时钟控制它在一定的时间不停的产生,用户根据键盘的四个方向键控制翻转、向左、向右和向下操作,(控制键的实现是由键盘的方向键的事件处理实现)。然后程序根据这七种方块堆叠成各种不同的模型。 论文描述了游戏的历史,开发此游戏的环境,游戏开发的意义。遵循软件工程的知识,从软件问题定义开始,接着进行可行性研究、需求分析、概要设计、详细设计,最后对软件进行了测试,整个开发过程贯穿软件工程的知识体系。 此次设计在Microsoft Windows 7系统下,以Java为开发语言,在eclipse开发平台上进行游戏的设计与实践。从游戏的基本玩法出发,主要就是俄罗斯方块的形状和旋转,我在设计中在一个图片框中构造了一些的网状小块,由这些小块组合成新的形状,每四个小块连接在一起就可以构造出一种造型,因此我总共设计了7中造型,每种造型又可以通过旋转而变化出2到4种形状,利用随机函数在一个欲览窗体中提前展示形状供用户参考,在游戏窗体中用户就可以使用键盘的方向键来控制方块的运动,然后利用递归语句对每一行进行判断,如果有某行的方块是满的,则消除这行的方块,并且使上面的方块自由下落,最后就可以得出用户的分数。 关键词:游戏设计,算法,数组,事件 #include 006*/ else puke[i][j]=1+rand()%12; //A……K } for(k=0; k<8; k++) outputacard(puke[k][0],puke[k][1]); //随机输出8张扑克 printf("\n"); int puke2[8][2]; int puke0[2]; intt,rh; for(t=0; t<8; t++) { puke2[t][0]=puke[t][0]; puke2[t][1]=puke[t][1]; } for(t=0; t<8; t++) /*把上面的8张扑克打乱顺序存入另一个数组*/ { rh=rand()%7; if(rh!=t) { puke0[0]=puke2[t][0]; puke0[1]=puke2[t][1]; puke2[t][0]=puke2[rh][0]; puke2[t][1]=puke2[rh][1]; puke2[rh][0]=puke0[0]; puke2[rh][1]=puke0[1]; } } for(k=0; k<8; k++) outputacard(puke2[k][0],puke2[k][1]); /*打乱顺序后重新输出8张扑克*/ printf("\n"); int puke3[8][2],puke4[8][2]; for(i=0; i<8; i++) /*为把上面代表两组扑克的数组puke,puke2复制到另外*/ for(j=0; j<2; j++) /*两个数组puke3、puke4中,以方便后面输出*/ for(j=0; j<2; j++) { puke3[i][j]=88; puke4[i][j]=88; } system("pause"); system("CLS");java课设走迷宫含代码
纯C语言写的一个小型游戏-源代码
C语言游戏源代码最新版
Java五子棋游戏源代码(人机对战)
java小游戏源码
C语的迷宫小游戏_源代码
c语言课程设计源代码
一个C语言写的简单贪吃蛇源代码
java小游戏源代码
java课设走迷宫(含代码)
C语言游戏源代码
扫雷游戏Java源代码
Java课程设计走迷宫
纯C语言写的一个小型游戏-源代码
小游戏源代码
C语言实现生命游戏
Java小游戏俄罗斯方块附完整源代码_毕业设计
纸牌记忆小游戏C语言源代码