turbo C 下的打字游戏
在这里贴上最近自己忙活的用turbo C编写的“打字游戏”的源代码:
#include<graphics.h>
#include<conio.h>
#include<STDLIB.h>
#include<dos.h>
#define BK_COLOR BLACK
#define CHAR_COLOR WHITE
#define C_COLOR BLUE
#define num 10
#define SPEED 3000
#define Esc 27
#define MenuX 200
#define MenuY 110
#define MenuWidth 200
#define MenuSinH 40
#define ChoiceX MenuX+15
#define ChoiceY MenuY+10
#define ChoiceWidth 170
#define ChoiceH 25
#define UpKey 72
#define DownKey 80
#define Enter 13
void Choice(int c_x,int c_y,int color)
{
setfillstyle(1,color);
bar(c_x,c_y,c_x+ChoiceWidth,c_y+ChoiceH);
}
void Main_Menu()
{
settextstyle(0,0,2);
outtextxy(MenuX+20,MenuY+15,"Start Game");
outtextxy(MenuX+20,MenuY+MenuSinH+15,"Game Steup");
outtextxy(MenuX+40,MenuY+2*MenuSinH+15,"Exit");
}
void Option_Menu()
{
settextstyle(0,0,2);
outtextxy(MenuX+20,MenuY+15,"beginner");
outtextxy(MenuX+20,MenuY+MenuSinH+15,"advancer");
outtextxy(MenuX+40,MenuY+2*MenuSinH+15,"senior");
}
int ChooseMenu(int flag)
{
int x,y;
char C_key;
x=ChoiceX;y=ChoiceY;
do
{
kbhit();
C_key=getch();
if(C_key==Esc)
return Esc;
else
if(C_key==Enter)
return y;
else
switch(C_key)
{
case UpKey:
if(y==ChoiceY)
break;
else
{
Choice(x,y,BK_COLOR);
y-=MenuSinH;
Choice(x,y,C_COLOR);
}
break;
case DownKey:
if (y==ChoiceY+2*MenuSinH)
break;
else
{
Choice(x,y,BLACK);
y+
相关文档:
今天为了给顶嵌杯做准备又回到linux下开始c编程了。刚开始是练习写一个与矩阵变换有关的程序,为了节省时间有一个函数模块是直接用的以前在windows下编程时所使用的。结果在linux下编译完运行之后很快就崩溃了,由于调试水平不高弄了很久也不知到问题出在哪里。正在百思不得其解时忽然注意到(当然不是自己调试出来的 ......
今天要编个最简单的"hello world"的C程序,算是初步感受下Linux中的编程环境,涉及以下3个步骤:
1. 先在"vim"里编写源文件;
2. 然后再用"gcc"编译生成"hello"的可执行文件;
3. 运行"hello",看看效果。
那么开始吧!
1. vim
vim hello.c
i
#include <stdio.h>
int
main (void)
{
printf ("hello.\n" ......
(1)
数组名的内涵在于其指代实体是一种数据结构,这种数据结构就是数组;
(2)
数组名的外延在于其可以转换为指向其指代实体的指针,而且是一个指针常量;
(3)
指向数组的指针则是另外一种变量类型(在WIN32平台下,长度为4),仅仅意味着数组的存放地址
(4)
数组名作为函数形参时,在函数体内,其失去了本身的内涵 ......
extern "C" 详解
在C++中,为了支持重载机制,在编译生成汇编代码时,函数的名字要加入函数的参数类型或者返回值类型等信息
在C中,因没有重载机制,编译后的代码只是简单的函数名字而已,不加入其他的信息
1. 不加入extern "C"
testexternc.cpp
int mytest(void)
{
int a=10,b=20;
int c=a+b;
ret ......
Q:什么是C风格转换?什么是static_cast, dynamic_cast 以及 reinterpret_cast?区别是什么?为什么要注意?
A:转换的含义是通过改变一个变量的类型为别的类型从而改变该变量的表示方式。为了类型转换一个简单对象为另一个对象你会使用传统的类型转换操作符。比如,为了转换一个类型为doubole的浮点数的指针到整型:
......