计算机程序设计--24点游戏设计
计算机程序设计
--课程设计(C语言)
题目:速算24点
学院:
专业:
班级:
姓名:
指导教师:
设计日期:
选题背景:
速算24点是一个智力游戏。由1.2.3.4.5.6.7.8.9.10.用+.-.*./.(.).运算求出结果为24的游戏.
二、设计思想:
编程思路:首先在程序开始处,开通语句
#include "time.h" /*系统时间函数*/
#include "graphics.h" /*图形函数*/
#include "alloc.h"/*动态地址分配函数*/
#include "stdlib.h" /*库函数*/
#include "string.h" /*字符串函数*/
#include "ctype.h" /*字符操作函数*/
引入文件。然后定义结构体变量。在main函数中实现对其他函数的调用。通过选择语句对函数进行都次调用。实现游戏的继续性。
三.主要解决问题的方法及技术关键
调用函数。
指针 结构体和公用体的应用。
while循环语句,if else 语句。
数组,字符串的输入和输出。
四.程序流程图
五、程序清单
#define N 20
#define COL 100
#define ROW 40
#include "stdio.h"
#include "time.h" /*系统时间函数*/
#include "graphics.h" /*图形函数*/
#include "alloc.h"/*动态地址分配函数*/
#include "stdlib.h" /*库函数*/
#include "string.h" /*字符串函数*/
#include "ctype.h" /*字符操作函数*/
char p[4][9]={
{'1','2','3','4','5','6','7','8','9'},
{'1','2','3','4','5','6','7','8','9'},
{'1','2','3','4','5','6','7','8','9'},
{'1','2','3','4','5','6','7','8','9'}};
typedef struct node
{
int data;
struct node *link;
}STACK1; /*栈1*/
typedef struct node2
{
char data;
struct node2 *link;
}STACK2; /*栈2*/
void init(void);/*图形驱动*/
void close(void);/*图形关闭*/
void play(void);/*发牌的具体过程*/
void rand1(int j);/*随机发牌函数*/
void change(char *e,char *a); /*中缀变后缀函数*/
int computer(char *s); /*后缀表达式计算函数*/
STACK1 *initstack1(STACK1 *top); /*栈1初始化*/
STACK1 *push(STACK1 *top,int x); /*栈1入栈运算*/
STACK1 *pop(STACK1 *top); /*栈1删除栈顶元素*/
int topx(STACK1 *top); /*栈1读栈顶元素*/
STACK1 *ptop(STACK1 *top,int *x); /*栈1读出栈顶元素值并删除栈顶元素*/
int empty(STACK1 *top); /*判栈1是否为空函数*/
STACK2 *initstack2(STACK2 *top); /*栈2初始化*/
STACK2 *push2(STACK2 *top,char x); /*栈2入栈运算*/
STACK2 *pop2(STACK2 *top); /*栈2删除栈顶元素*/
char topx2(STACK2 *top); /*栈2读栈顶元素*/
STACK2 *ptop2(STACK2 *top,char *x); /*栈2读出栈顶元素值并删除栈顶元素*/
int empty2(STACK2 *top); /*判栈2是否为空函数*
int text1(char *s) ; /*显示文本*/
main()
{
char s[N],s1[N],ch;
int i,result;
int gdriver, gmode;
clrscr(); /*清屏*/
init(); /*初始化函数*/
while(1)
{
setbkcolor(BLACK); /*设置背景颜色*/
cleardevice();/*清屏*/
p