**
浙江大学竺可桢学院C程序设计基础(翁恺)行编辑器
**
这次的作业有点难,时间也有点赶。写出来有点乱,可能没时间精校修整了,各位大佬见谅。如果有好的方法,非常欢迎和我交流,谢谢大家!
(要求和使用方法和学在浙大上的是一样的)
#include "acllib.h"
#include <stdio.h>
#include <math.h>
#define width 1200
#define length 300
#define start 20
int cnt_of_words = 0;
int length_of_words = 0;
char state_of_words = 1;//-1是小写,1是大写
char result[100];
double num_of_words = 1;
int state_of_carets = 1;//1是插入,-1是覆盖
double num_of_carets = 1;
int state_of_print = 0;
void mouse(int x, int y, int a, int b)
{
static int ox = -1;
static int oy = -1;
printf("%d %d %d %d \n", x, y, a ,b );
beginPaint();
line(ox, oy, x ,y);
endPaint();
ox = x;
oy = y;
}
void key(int x, int y)
{
if((x == 20)&&(y == 1)) num_of_words = pow(-1,state_of_words++);
if((x == 45)&&(y == 1)) num_of_carets = pow(-1,state_of_carets++);
if((x == 13)&&(y == 0))printf("%s\n",result);//回车输出
int i = 0;
if(num_of_carets == 1)
{
if((x != 37)&&(x != 39)&&(cnt_of_words < length_of_words)\
&&(y == 0)&&(x != 20)&&(x != 45)&&(x != 8)&&(x != 46))//方向准备
{
for(i = length_of_words; i > cnt_of_words; i--)\
result[i] = result[i-1];
result[i] = 32;
}
else if((x != 37)&&(x != 39)&&(cnt_of_words > length_of_words)\
&&(y == 0)&&(x != 20)&&(x != 45)&&(x != 8)&&(x != 46))
{
for(i = length_of_words; i < cnt_of_words; i++)\
result[i] = 32;
length_of_words = cnt_of_words;
}
}
int delete = 0;
if(y == 0)//输入
{
if((x <= 'Z')&&(x >= 'A'))
{
length_of_words++;//字母
if(num_of_words == -1)result[cnt_of_words++] = x - 'A' + 'a';
else if(num_of_words == 1)result[cnt_of_words++] = x;
}
else if(x == 32)
{
result[cnt_of_words++] = x;//空格
length_of_words++;
}
else if((x <= '9')&&(x >= '0'))
{
result[cnt_of_words++] = x;//数字
length_of_words++;
}
else if(x == 8)
{
for( delete = cnt_of_words - 1; delete <= length_of_words; delete++)
{
result[ delete ] = result[ delete + 1];
}//Backspace
length_of_words--;
cnt_of_words--;
}
else if(x == 46)
{
for( delete = cnt_of_words; delete <= length_of_words; delete++)
{
result[ delete ] = result[delete + 1];
}//Delete
length_of_words--;
}
}
if((x == 37)&&(y == 1))cnt_of_words--;//移动
else if((x == 39)&&(y == 1))cnt_of_words++;
beginPaint();
clearDevice();
if(num_of_carets == 1)setCaretSize(1,10);
else if(num_of_carets == -1)setCaretSize(5,10);
SetCaretPos(7 * cnt_of_words,1);
showCaret();
setPenWidth(20);
paintText(0,0,result);
endPaint();
}
int Setup()
{
initWindow("Word", start, start, width, length);
initConsole();
beginPaint();
//registerMouseEvent(mouse);
registerKeyboardEvent(key);
endPaint();
return 0;
}
效果: