C课设拯救计划 | 轻流扇
0%

C课设拯救计划

C课设拯救计划

前言:为什么要专门耗费时间来写这么一个东西呢?如果你有幸考入了华中柯基大学,又在填志愿的时候阴差阳错的选择了人工智能或者自动化专业,那么你就马上会听闻只存在于传说中的C课设。不仅仅是用了一种已经消失数十年的编译器: 爆烂的C(Borland C3.1,又简称为BC)。不仅其自身使用起来十分的麻烦,令人恼火,而且你几乎找不到任何什么学习BC编程的途径。虽然有学长学姐代代相传的帮忙,但这种事是学院默许的,亦可以说是学院支持的。故,从中也难以学到什么。所以对于大部分而言,结果往往是到deadline的时候,抄写,篡改前人留下来的代码,或者求助选同样题目的同学……

所以,特此写一份较为详细的拯救计划。

BC下载链接

点击下载爆烂的C

BC最基本的用法

首先,不会真的有人会用BC这种东西来编写C课设吧?就其作用而言,不建议给自己找痛苦。

先上BC的图片(建议在电脑上食用,手机可能排版会出问题)



  • 建立工程:意思就是把你写的代码变成一个.exe文件。如何建立?点击Project 有个open,直接输入新建的pgi(?)的名字(就是把那个*.pgi改成 1.pgi等等),这样就可以add 你自己编写的.c文件了。全部添加进去后,点Run,success就行,最终编写完成,就点Compile (?)。

  • 其他:其他的东西自己慢慢摸索,差不多就能搞懂了。BC我目前用过的东西有: Edit中的 复制粘贴,主要是修改错误时会用BC直接修改(一些简单的问题)。注意在BC中修改后一定要点File中的save(BC没编译成功不会自动保存)。还有一个就是Window中的Output,可以查看文本窗口的输出,但基本没用(基本都是图形化窗口,用不到)

  • 关于环境配置,其实没什么,所谓环境配置,就是一个简单的设置Options中的Output,和什么什么的。这些东西自己看看就会慢慢理解的。而且,群里都有配置好了的BC,直接用就行。也可以找我要。至于什么纯净的BC,就是没有学长学姐的工程。但大部分你只要把他们写的东西删掉就行了(除非有人自己改BC)。

  • 你用别的编译器写的汉字,在BC中是无法显示的,原因是汉字编码方式的不同,具体可参考https://www.bilibili.com/video/BV1BT421a7N6/?spm_id_from=333.999.0.0。

  • 自此,我相信你已经学会了使用BC建立工程。虽然你可能还不会编写。



如果还是不会使用BC,可以去看看别人怎么用的。

头文件的编写

(三月16日更新)

头文件编写还是有固定的套路的,一般你自己直接复制粘贴就行。

这里介绍通用的模板:

1
2
3
4
5
6
#ifndef _COMMON_H_  // 这里的意思是if not define 
#define _COMMON_H_ //则define; common.h,是你自己命名的头文件名字,注意文件后缀
//这里就是函数声明,和一些struct的引用,或者define a 1;什么什么的
void hanshu();

#endif

那么这个的原理就是条件编译,其目的在于水代码 防止头文件重复包含(?。有兴趣自己检索就行。

当然一般而言我们还会编写一个总头文件,一般命名为common.h; 你可以发现它就是如同这样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef _COMMON_H_
#define _COMMON_H_
/*
----------------------------
包含所有的头文件,
以后引用头文件只需要 include "common.h";
更加方便,代码简洁
----------------------------
*/
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<bios.h>
#include<string.h>
#include<dos.h>
#include<math.h>
#include<time.h>
#include <conio.h>
//上面是BC自带的头文件,下面为自己编写的

//----必备
#include"mouse.h"//鼠标库
#include"hz.h"//汉字库

//--界面
#include "welcome.h"//开屏动画
#include "mainpage.h"//主界面
#include "mainfunc.h"//农田界面
#include "history.h"//历史记录界面
#include "usehelp.h"//系统说明界面

//---func:功能文件
#include "move.h"//配合鼠标使用的鼠标move函数
#include "showtime.h"//显示时间函数
#include "shuju.h"//数据库

#endif

当然,这是我编写的尚未完成品。注意自己编写的 头文件最好用”” ,爆烂的C自带的用<>,具体原因有兴趣自己查找。

那么关于头文件的全部暂且就到这里了。当然你建立工程的时候如果把头文件不需要手动添加。

拜拜了~



贴图的工厂化实现(已完善)

怎么贴图?很简单。爆烂的C可以用祖传的代码,批量化贴图。你根本不需要理解,你只需要CTRL C, CTRL V。n张图片便已经贴上去了。

废话不多说,直接上代码。这是一个使用例子。(?

1
2
3
bmp_convert("1.bmp", "1.dbm");
open_display();
show_dbm(100,100, "1.dbm", 0);

其中,你只需要操作的部分如下:

  • 将1.bmp改成你要贴的图片的名字。不要告诉我你不知道文件后缀是什么。

  • 当然还有所有的1.

  • 其中show_dbm(100,100,…..),前两个是贴图的位置,左上角坐标。

  • 注意,这种只能贴bmp,而且还要用到ps修改。具体有祖传文件教学。这里我就不提供下载方式了。因为我日后会以图文形式补充,想必大家都能在救助群里找到。

    就是这么多了。当然,要#include .h文件。笑

    注意,你的贴图文件放在source文件夹内,即和你的.c文件放一起。

    为防止还有人不会,上代码(???)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

    #include <stdio.h>
    #include <graphic.h>
    #include <image.h>

    void main()
    {
    int gd=VGA;//graphdriver
    int gm=VGAHI;//graphmode
    initgraph(&gd,&gm,"C: \\BORLANDC\\BGI");//这里后面的C:什么的看放的BGI文件路径

    bmp_convert("1.bmp", "1.dbm");
    open_display();
    show_dbm(100,100, "1.dbm", 0);

    bmp_convert("2.bmp", "2.dbm");
    open_display();
    show_dbm(300, 200, "2.dbm", 0);

    getch();//鼠标按键后退出
    closegraph();
    delay(100)
    }

    虽然不知道有没有问题,但还是暂且认为该代码有问题吧(doge)

附件:贴图祖传代码下载(已经修改,完美适配VGA模式 即640X480下的贴图)

点击下载



1
2
3
4
5
6
7
8
9
10
11
if(ImageW==0||ImageH==0||ImageW>641||ImageH>481)/////注意注意!!根据实际修改/
{
printf("The image is too large!Please input image below 640*480.");
fclose(fbmp);
return 1;
}
if((fdbm=fopen(dbm,"wb"))==NULL)
{
printf("Creat \"%s\" error!",dbm);
return 1;
}

上述的头文件和.c文件经过了修改,至于.c文件,我们无需看懂原理。上面是.c文件大约40-50行部分代码。这里的Imagew 和ImangHI 要根据实际值修改。否则就会出现 The image is too… 然后贴图失败。。

*这里的贴图的重要一点就是对 图片的处理, 首先要下个VS PS, 然后根据文件中的食用方法来便可。 当然其中有些东西不必在意。如:调用 show_dbm(int x,int y,char dbm,int nowpage)即可在在(x,y)输出图片(x 需为 8 的倍数),char * dbm 处填入的 dbm 文件地址。 这里的X并不需要为8的倍数。当然,也许只是我们没有理解其原因。但是只要能贴上图就行。

贴图的工厂化实现就是这样了。请低调使用,勿宣传(.jpg) —4.21.2024



报告的借鉴以及验收过程

在4月的27日,也是极其幸运的过了C课设。原因主要是抽到了好的验收老师。喜提A-。也是上演了一出抽卡现场。验收其实报告几乎不看(所以用的全局变量也是根本没看,当然据说这个看老师,有老师似乎喜欢看??),所以没必要过于精细。代码分配部分,要把.c谁写的都写明。

报告直接借鉴即可食用。

验收过程实际上也很简单。就是要把你的CODE文件夹,复制到机房电脑的C盘(不是桌面)上,然后找到C盘中的Borlandc/bin/bc.exe。打开那个BC,然后自己改下路径即可。实际上手后十分简单。路径就是文件路径。所以我们在编写的过程中,最好用相对路径。比如文件的打开啥的。

老师是听我们讲了我们的程序功能。因为设计了梯田,被认为是相对一个创新的点,所以老师就简单的要我们加个功能。就是让无人机高度在农药喷洒时也显示,也就是一个调用函数的问题。当然,还要调调参数,总之十分简单。但也有老师很考验心态和能力。只能说,验收就是看抽卡。文件操作必须要掌握。验收时许多老师都重视,甚至要你改登录注册的代码。(而许多人是直接照搬的…)

就说这么多吧,愿世上再无C课设 –5.5

报告下载



英文输入法

输入法是登陆注册界面必不可少的。那么这里直接提供代码,来源不明。具体如何使用请看编写的原作者(未知)的注释。

这里的输入法明显要和文件操作结合起来比较方便。或者数组之类。但还是用文件操作更好。

这里面呢,就两个函数,对应两种输入法。可视与不可视。调用即可。建议登录注册不必太过高级。基本功能实现即可,因为要么老师根本不看,要么老师要你加这里的功能。比如忘记密码、让输入的密码可视什么的。(而这些都容易实现(所以就有人故意不把程序搞完美,预判老师会要求加的功能…

源文件下载

那么就说这么多吧。虽然更新速度慢,但不是还早着吗?-5.19



编程的开始

水了这么久,终于来到了激动人心的编程环节。其实主要是因为不知道该水什么了)那么为了节省一些时间,所以编程开始的讲解主要就是按照 我们那一组编写的代码的顺序来,毕竟,与其自己盲目的学这学那,不如完整的看一遍往届的代码。当然我自己尝试过,不过由于看不懂,所以收获不多。但还是收获良多。(比如时间显示就是看往届代码,贴图实现一开始也是看着写的)当然由于种种原因,不开放源代码,毕竟是个人劳动成果,白嫖有害身心健康,可通过邮件询问获取)

——5.23

思路历程

为什么C课设选题时选到了这道题目? 答:C课设选题,其实就是开一个大会,许多班的人坐在一个大教室。然后出题老师会分别讲题目的要求(当然,我是一点没听,大多数人也是),然后呢,不知道什么时候,班长就突然说来选题,其实就是在一张打印好的纸上,有题目的序号,填写你和你的队友的名字,学号。而且因为我们班是30个人,有15道题目,所以题目不能重复,就靠抢?(除非你们班班长很公平,想到了用抽签的方式决定选题的先后顺序。)

所以这里建议选题的时候,坐的离班长近一点。最好坐旁边。

我当时连队友都没找,听到说选题开始,才问谁还没组队。结果发现,所有人都早早组好了队伍(当然除了队友(他也是比较内向吧,与班里的人没交流。于是乎,一坨人为了选题乱挤。所以到我选题的时候,已经是最后了。幸而找到一道22级的题目,也就是这道题。于是乎,便莫名其妙的选好了题目。

 总结:

  1. 开那个选题大会时,坐班长旁边比较好。

  2. 选题靠抢的话一定不要顾及什么面子啥的,直接乱挤,先到先得。不要有所谓的高尚,因为别人可不会管你,当你选到了一个痛苦的题目而无从下手时。。。。

  3. 队友尽量提前找好,而且尽量找负责的吧,行动力强。拖到deadline赶C课设,或者只有你一个人急,抑或是你一个人做了一堆事。。没必要,本来就是团队合作。

  4. 这个选题序号代表了验收的顺序,所以如果选的靠前(1-5的样子)那么就是第一天晚上验收。太靠后(10-15)就是最后一天了。所以选中间比较好。我选的是8。。因为第一天必有zcj,开局必有下马威吗,所以挂的可能性蛮大的,到后面也能有经验,你能问老师的验收风格,比如是加啥啥功能。最后验收就有点痛苦了。毕竟早死早超生。

  5. 还有聪明的人直接随便搞,挂科。如果不想保研确实可以如此。C课设重修只要程序能运行就过,所以可以借鉴代码。当还是别吧,当作锻炼自己的机会。

  6. 多问问往届学长,如果是往届的题目。不是的话自求多福。

  7. 程序没必要太过注重细节。比如什么精美啥的。老师看重的思路(我的就是因为那个梯田贴图让老师赞赏了),拿我的作为例子,两种农田,小农田的地形,农作物种类。。。(都是学长建议的。连夜加的。但梯田,高度显示是自己想到的。但是预验收时,学长也说到了许多没考虑到的点,比如多架无人机,无人机电量,无人机扫描农田(就是说,不是哪里有病就喷农药到哪里),无人机喷农药到一半就返航……

    这些确实我基本没考虑,但万幸最后过了。现在看来还是验收老师好。

    思路目前就这么多了,再见/ ——6.14.2024

后补

经过我的询问,也是终于找到了课设选题的文件:

2023级C语言课程设计

课程设计共同要求:

1. 用C语言编程实现,编译环境采用BC3.1,掌握C语言编写较复杂程序的一些基本技巧;

2. 要求在图形化界面下操作,界面要友好,不提倡使用贴图,贴图软件实现的功能必须控制在总代码量的5%以内;

3. 注意程序的结构,必须采用工程化的思想来组织程序;

4. 要求画流程图(没有流程图的不给评分);

5. 两人一组,每班最多只出现一个三人组,小组个人代码和实现功能分工合理,每人程序不得少于1000行(登录、注册、开机欢迎动画界面、程序结束动画代码不计入);

6. 每组提供一份报告,报告内容应包含数据结构设计、程序流程图、程序功能介绍、源代码等,并注明每人的工作量;

7. 原则上,不得使用全局变量;

8. 注意程序的可读性和可维护性;

评分标准

  1. 软件系统需求分析、系统分析与设计报告 15%
  2. 编程工作量 10%
  3. 人机界面及接口 10%
  4. 软件功能、软件结构、编码规范 30%
  5. 排错与调试技巧 25%
  6. 团队协作 10%
  7. 技术难度附加分 (0-10分)

特别提醒:出现下列情况,不予通过。

(1)个人有效代码量不足1000行;

(2)被2个老师认定代码抄袭的;

(3)不按指定时间进行验收的

(4)所选题目核心功能不能稳定运行的;

l 参考文献

  1. 王士元. C高级实用程序设计. 北京: 清华大学出版社. 1996
  2. 周纯杰,刘正林等. 标准C语言程序及应用. 武汉: 华中科技大学出版社. 2005
  3. 周纯杰,何顶新等. 程序设计教程—用C/C++语言编程. 北京: 机械工业出版社, 2016
  4. 姚远. 高级C语言程序设计技巧与实例. 北京: 机械工业出版社, 1995
  5. 陈清华, 朱红. C语言课程设计. 南京: 东南大学出版社, 2003
  6. 潭浩强. C语言程序设计. 北京: 清华大学出版社, 2000

等等……

指导教师:周纯杰,何顶新,左峥嵘,高常鑫,汪国有,彭刚,周凯波,陈忠

C语言课程设计可选题目

  1. 简历辅助设计系统

主要功能说明:实现一个简历辅助设计系统。支持模板制作与模板选择;支持内容选择(比如,学习经历、实践经历等);支持导入文本后自动排版;支持文本修改和简历修改。

  1. 武汉欢乐谷旅游模拟系统

主要功能说明:为武汉欢乐谷设计并实现一个旅游模拟系统。支持地图查看和列表查看两种方式查看项目;支持在线门票相关业务、特殊项目在线预约、预约提醒、路线推荐等。

3.小区物业管理app模拟

主要功能说明:完成一款典型小区物业管理app的各项功能仿真模拟。比如,华润物业的朝昔app。

  1. 夺岛军演游戏

主要功能说明:模拟攻占岛屿军演作战系统,场景自主设定,兵力申请与调派,后勤物资补给等功能。

5.智能家居app模拟

主要功能说明:完成包括空调、空气净化器、扫地机器人、冰箱、监控设备等至少5种联网设备的管理功能,具备家用设备的接入、设备启动、状态检测与显示,设备记录数据的分析等功能。

  1. 火星家园建设规划系统

主要功能说明:模拟火星宜居家园部署规划、进行就地取材,建设人类家园生活设施,并提供演练展示。

  1. 林果自动采摘系统模拟

主要功能说明:根据果园面积进行采摘路径规划、模拟智能农机进行采摘作业、对采摘林果进行统计、并运输林果到集中站进行储存、盘点等功能。

  1. 农田无人机喷洒农药模拟系统

主要功能说明:利用无人机进行农作物生长监测,针对不同病害进行农药配制,对农药喷洒路径进行规划,模拟无人机喷洒过程等功能。

  1. 家庭看护机器人模拟仿真系统

主要功能说明:根据家庭成员的需求,陪伴机器人进行家庭服务,包括人机交互、端茶倒水、炒菜做饭、开窗关窗、浇花扫地、健康监测、突发状况报警。

10.酒店服务机器人模拟仿真系统

主要功能说明:某酒店多服务机器人的服务全过程模拟,包括根据酒店的订单分配以及机器人送餐、送水、送快递等服务的全过程。

  1. 人工智能学院大楼智慧建造系统

主要功能说明:

实现场地平整、地基建设、楼房建设、外墙装饰的施工过程管理功能,包括图形化模拟显示、施工建材调度、施工进度管控等模块。

  1. 家用婴童陪伴神器

主要功能说明:能识别婴童的状态(翻身、睡着、睡醒、口鼻被捂、呼吸频率、跟踪爬行过程)、电子围栏越过预警、典型过程抓拍形成成长相册。

  1. 学院50年院庆组织过程模拟

主要功能说明:

模拟学院50周年的庆典的全过程,包括院友的接待、组织、院庆当天活动的全过程。

  1. 学生选课模拟系统

主要功能说明:

参考HUB系统功能,以菜单方式模拟选课,包括后台课程管理和前端选课全过程,具有课程信息浏览、选课信息查询等功能。

  1. 东湖水质无人艇检测系统

主要功能说明:

模拟无人艇进行东湖水质检测的全过程,包括采集标本的无人艇航迹规划、水质态势分析及预测、治理措施及建议。

  1. 仿windows资源管理器系统

主要功能说明:

实现windows资源管理器的主要功能。

  1. 模拟BC的汉化文本编辑器

主要功能说明:

模拟BC的编辑器,界面需要汉字显示,至少包括BC编辑器的文件和编辑的相关功能。

  1. 无人驾驶汽车中控仪表系统模拟

主要功能说明:

具有无人驾驶汽车中控仪表系统主要功能的模拟。

19. 图书馆信息管理系统模拟

主要功能:参考学校图书馆,模拟图书馆的主要核心功能。

  1. FIFA世界杯2022淘汰赛模拟系统

主要功能说明:

模拟FIFA世界杯2022淘汰赛全过程。包括各场比赛的集锦及技术统计、颁奖仪式、十佳进球模拟等功能。

源代码逐文件分析

当然,我和我队友的代码基本完全独立,这样做十分有必要,尤其是你和队友不熟或者不能总是在同一个地方编写代码时。分工明确非常重要,否则到了ddl,你会十分的痛苦。而且,验收老师也基本有这个要求。一个人编写一个文件,最好互不干涉。

我编写的部分

其实主要的框架都是由我一人编写,因为队友实在难以沟通,但这样的好处是我自己对于整个程序的流程十分清楚,免去了必须看懂队友代码的麻烦。所以变成了队友必须看我的代码才能编写。下面列举出文件分析。

commom.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef _COMMON_H_
#define _COMMON_H_
/*
----------------------------
包含所有的头文件,
以后引用头文件只需要 include "common.h";
更加方便,代码简洁
----------------------------
*/
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<bios.h>
#include<string.h>
#include<dos.h>
#include<math.h>
#include<time.h>
#include <conio.h>
//上面是BC自带的头文件,下面为自己编写的
//这里的头文件直接复制粘贴即可,不需要管太多。

//----必备,这里主要是往届祖传文件
#include"mouse.h"//鼠标库
#include"hz.h"//汉字库
#include "IMAGE.h"//贴图

//--界面
#include "welcome.h"//开屏动画
#include "mainpage.h"//主界面
#include "mainfunc.h"//农田界面
#include "elsetian.h"//另一个农田界面
#include "usehelp.h"//系统说明界面
#include "growlook.h"//生长检测动画
#include "outcome.h"//大农田的结果查看界面
//---func:功能文件
#include "move.h"//配合鼠标使用的鼠标move函数
#include "showtime.h"//显示时间函数
#include "shuju.h"//数据库
#include "drzhiwu.h"
#include "abdrone.h"
#include"illness.h"
#include "recover.h"

//这下面的都是队友编写的。
#include "pensa.h"
#include "pensadh.h"
#include "pssj.h"
#include "zpjm.h"

#endif

为了方便,我的所有的解释会全放到代码里面。

设置common.h其实是我看了几个往届代码从而发现的一个共性。作用经过检验发现是:把所有编写的.h文件放到这个.h文件中,以后编写.c文件只要#include "common.h"就可以了。免去了各种麻烦。当然,如果你想水代码可以不这样做,但是实在毫无必要。

这里其实含金量不大。头文件编写上面已经说过,因此就不再赘述了。可以发现,我们的编写其实并不规范,只是按照个人习惯罢了。比如头文件的命名,都是为了自己理解方便。当然我又不是码农,而且英语也不太好,所以基本用中文,英文,啥的。

还有一个建议:写代码的时候多写写注释,方便自己和队友看懂。

welcome

1
2
3
4
5
6
#ifndef _WELCOM_H_
#define _WELCOM_H_

int welc(int *a);//函数声明

#endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
----------------------------------------
欢迎界面
----------------------------------------
*/
#include "common.h"
int welc(int *a)//欢迎页
{
if (*a == 1)
{
setbkcolor(WHITE);//background color
setcolor(GREEN);//边界color
setfillstyle(1, GREEN);//
puthz(40, 150, "农田无人机喷洒农药系统", 32, 50, GREEN);
puthz(100, 250, "你最好的选择!", 32, 50, GREEN);
*a = 0;
}
////-------------加载动画
setfillstyle(1, RED);
bar(110, 300, 530, 380);
puthz(125, 322, "加载中", 32, 50, YELLOW);
setfillstyle(1, YELLOW);
bar(265, 320, 305, 360);
delay(400);
bar(315, 320, 355, 360);
delay(400);
bar(365, 320, 405, 360);
delay(400);
bar(415, 320, 455, 360);
delay(400);
bar(465, 320, 505, 360);
delay(400);//这里就是实现了一个动画的过程,原理十分简单。。。。。。
return 1;
}

这里为了方便,直接把.c和.h文件放到一个标题中了。毕竟在算代码量的时候也会剔除头文件,而且似乎那个课程报告里也不用?但我加了。可以看到,头文件编写就只要Ctrl c + Ctrl v 就可以了。

我应该先讲讲main.c文件的,但晚了。

*这里的*a有什么用呢?其实就是我在调用函数的时候是 welc(&a),而a在main.c那里赋值了初始值1。这样welc函数就运行了一次,之后在函数内部 a=0,所以这样之后就不再调用。实现了调用一次的作用。这个还是要先看main.c了解总体框架。

main.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "common.h"
//程序控制台:负责页面跳转。
//实现各个函数的跳转,调用
void main(void)
{
int a1 = 1;
int a2 = 1;
int a3 = 1;
int a4 = 1;
int a5 = 1;
int a6 = 1;
int a7 = 1;
int a8 = 1;
int a9 = 1;
int a10 = 1;
int i, j;
int page;//页面值
//初始化VGA模式
int gd=VGA;//graphdriver
int gm=VGAHI;//graphmode
initgraph(&gd,&gm,"C:\\BORLANDC\\BGI");//这里后面的C:什么的看放的BGI文件路径
page=0;//初始化为0;
mouseinit();//这里是祖传代码里面的,初始化鼠标,就是生成一个鼠标。

while (1)
{
switch (page)
{
case 0:
page = moveint(welc, &a1);//欢迎界面,return:welc中的1//可参考 move.c。
break;

case 1:
page = moveint(hello, &a2);//主界面,return各种数字。
for (i = 0; i < 5; i++)
{
nongyao[i] = 0;
}//这里是队友后面加的,修bug。不用管
break;

case 2:
page = moveint1(mainfunc, &a3,diannian_bitmap,dianbai_bitmap,dianmian_bitmap);//大农田界面。简单农田。
nongyao[5] = 0;
//这里本质就是调用了mainfunc这个函数,后面这一坨是当时没想好,懒得改了。

break;

case 3:
page = moveint( elsetian, &a4);//另一个奇怪的农田。进阶农田,
nongyao[5] = 1;//队友加的,修bug,农药配置那的,这里是直接用了全局变量

break;

case 4:
page = moveint(usepage, &a5);//系统说明界面,主要介绍了本系统的使用方法

break;

case 5:
page = moveint(elseoutcome, &a6);//小农田的结果查看界面。。

break;


case 6:
page = moveint(outcome, &a7);//查看大农田,说明农作物具体的生长状况,,

break;


case 7:
page = moveint2(zhuzhan, &a8, nongyao);

break;


case 8:
page = moveint2(zpjiemian, &a9, nongyao);//装配农药

break;


case 9:
page = moveint3(psdonghua, &a10, nongyao, diannian_bitmap, dianbai_bitmap, dianmian_bitmap, rount, &amtjudge);//喷洒动画

break;


case -1://-1是点了 退出 框框;直接关闭BC
break;
default :break;
}
if (page==-1)
break;
}

delay(1000);//程序结束运行
closegraph();
}

这里总体就是用了switch page模式。调用的函数代表不同的界面,函数通过改变返回值来实现界面的跳转。这里的moveint什么的是一个我编写的中转的函数,功能就是防止鼠标留痕啥的。具体后面会说到。

这里只需要学到这个界面跳转的基本框架即可。



这次更新就到这里吧。bye~

——6.28

函数介绍(1)

setbkcolor

即:set background color,设置背景颜色十分通俗易懂。用法:就是setbkcolor( ); 括号里面加颜色的英文大写。但是颜色也是有种类的,并不是可以随心所欲的调色。颜色具体有如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#define	BLACK//黑色			0
#define BLUE//蓝色 0xAA0000
#define GREEN //绿色 0x00AA00
#define CYAN //青绿 0xAAAA00
#define RED //红色 0x0000AA
#define MAGENTA //紫红 0xAA00AA
#define BROWN //棕色 0x0055AA
#define LIGHTGRAY//浅灰 0xAAAAAA
#define DARKGRAY //深灰 0x555555
#define LIGHTBLUE //淡蓝 0xFF5555
#define LIGHTGREEN //浅绿 0x55FF55
#define LIGHTCYAN//浅青 0xFFFF55
#define LIGHTRED //浅红 0x5555FF
#define LIGHTMAGENTA//浅紫 0xFF55FF
#define YELLOW //黄色 0x55FFFF
#define WHITE //白色 0xFFFFFF

setcolor

也就是设置颜色,主要是边框的颜色,setcolor(GREEN); 之后你用的各种绘图函数所绘制出来的图形,点,线的边框颜色就是绿色。就像画图这个软件一样。bar, rectangle, line, putpixel. 其颜色与上面的表一致。

setfillstyle

设置填充颜色。setfillstyle所设置的填充颜色只对于一些特定的函数有用。比如bar.bar与rectangle的区别是,前者含义是画实心矩形,后者不是。这也就意味这,setfillstyle之后,bar的边框颜色还是由setcolor决定的,但内部的颜色是setfillstyle的颜色。rectangle内部颜色还是背景色。

用法:setfillstyle( 1, GREEN);第二个参数是要填充的颜色,第一个参数代表了填充的方式。具体见下表

1
2
3
4
5
6
7
8
9
10
11
12
13
EMPTy_FILL               0         用背景色填充区域(空填)
SOLID_FILL 1 用实填充色填充(实填)
LINE_FILL 2 ----填充
LTSLASH_FILL 3 ///填充
SLASH_FILL 4 ///用粗线填充
BKSLASH_FILL 5 用粗线填充
LTBKSLASH_FILL 6 填充
HATCH_FILL 7 网格线填充
xHATCH_FILL 8 斜网格线填充
INTEREAVE_FILL 9 间隔点填充
WIDE_DOT_FILL 10 大间隔点填充
CLOSE_DOT_FILL 11 小间隔点填充
USER_FILL 12 用户定义图样填充

正确性我并没有确定,一般而言,在使用bc过程中,我只用到了setfillstyle(1, );其中数字和英文是等效的。其实如果聪明的话,你也许已经想到,可以用数字代表颜色,这样可以用一个数组把颜色给储存起来,从而实现颜色的改变。当然我本人是没有尝试过的。

bar

用法: bar(a,b ,c,d); 四个参数分别代表左上角和右下角的坐标x,y。十分简单。只需要注意界面的坐标系是怎么建的即可。这个要看图形化的模式,也就是下面的initgraph中会讲到的。意义为画实心矩形。颜色由setcolor和setfillstyle决定。

delay

十分简单,就是delay( 1000); 数字代表毫秒。一般的用途是防止鼠标的连续点击(就是说点一次但实际效果是多次),还有界面跳转时用用防止跳转频繁导致bc崩。加上总没事。

initgraph和closegraph

图形化界面必用。只需要main函数里用一次就行。用法如下:

1
2
3
4
5
6
7
8
int gd=VGA;//graphdriver
int gm=VGAHI;//graphmode
initgraph(&gd,&gm,"C:\\BORLANDC\\BGI");//这里后面的C:什么的看放的BGI文件路径

//省略。。。。。


closegraph();

这里就是直接复制粘贴即可。唯一要注意的就是initgraph中的“ ”这里的文件路径要根据bgi文件夹的路径来。所以验收的时候就要注意了,最好把你的文件放到那个C盘里。具体验收的流程我以后记得会补充。

原理可以自行上网搜索。

——7.17

usehelp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "common.h"
/*========================
用户说明界面
简单的操作说明书
=========================*/
int usepage(int* a5)
{
if (*a5 == 1)
{
cleardevice();
setbkcolor(WHITE);//background color
setcolor(RED);//边界color
setfillstyle(1, RED);//意思:设置绿色的填充模式为1(完全填充)
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);
rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);
puthz(250,10, "系统说明", 32, 30,GREEN);
setcolor(GREEN);//边界color
rectangle(10, 50, 635, 470);
puthz(10+5, 50+5, "该系统模拟了两个不同的农田,代表了两种不同的用户。平坝田地势平坦,一览无余,适用于种植大户,设置了小麦与玉米间种。小农田地势多样、具有障碍物,植物多种分布不匀杂乱。操作流程:首先进入农田,点击生长检测,此时无人机运行开始检测。结束后,可以在结果查看界面查看农作物的患病情况,并根据需要,选择配置相应的农药。农药装配到无人机后,无人机会自动进行最优路径规划,并进行农药喷洒。", 32, 30, GREEN);
*a5 = 0;
}
showbiankuang(0, 0, 80, 40);//showbiankuang是自己编写的一个函数,作用为鼠标移动到那里会标亮矩形边框提示。实际意义不大,因为验收老师不会关注这个。但闲的时候可以直接套用。
showbiankuang(600, 0, 640, 40);
//界面的跳转
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a5 = 1;//注意这里要把a5还原。
return 1;//
}
return 4;
}

为了方便和效率,没有特殊列出,头文件只有源文件里面的函数声明。所以这里的usehelp.h就略去了。这里巧妙的一点就是函数传入了a5这个参数,这样使得if(a5==1)这里面的代码只调用一次,能够很好的防止各种bug,界面更加稳定。我这里所有的界面跳转都用到了这个基本的思想。

move

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "common.h"
/*--------------
解决了鼠标的闪动问题,
解决了鼠标被 图像遮挡的问题
--------------*/
//适用于 int类型函数。可参考 welcome.h中的使用
int moveint(int (*hanshu)(int*), int* a)
{
int b;
if (*a == 1)
{
clrmous(MouseX, MouseY);
}
b= hanshu(a);//顺序有严格要求,不能颠倒,否则出问题
if (*a != -10)//注意只能if,不能while,而且,这里的*a!=-10是为了消除warning
{
newmouse(&MouseX, &MouseY, &press);
}
return b;
}
int moveint1(int (*hanshu)(int*, unsigned char(*)[49], unsigned char(*)[49], unsigned char(*)[49]), int* a, unsigned char b[384][49], unsigned char c[192][49], unsigned char d[192][49])//这个不用看,这么复杂是因为当时不知道文件操作怎么用。。
{
int bbb;
if (*a == 1)
{
clrmous(MouseX, MouseY);
}
bbb = hanshu(a,b,c,d);
if (*a!=-10)
{
newmouse(&MouseX, &MouseY, &press);

}
return bbb;
}
void showbiankuang(int x1, int y1, int x2, int y2)//用于显使得鼠标在 矩形中显示边框
{//矩形的内部颜色都是白色
if (mouse_press( x1, y1, x2, y2)==2|| mouse_press(x1, y1, x2, y2) == 1)
{//鼠标在框内,而且不处于左键点击状态。其实也可以不这么写。
setcolor(BLUE);
rectangle(x1 + 1, y1 + 1, x2 - 1, y2 - 1);//内部标亮为蓝色
}
else
{
setcolor(WHITE);
rectangle(x1 + 1, y1 + 1, x2 - 1, y2 - 1);//覆盖标亮
}

}

这里总共就三个函数,第一个和第二个的原理一模一样,只不过是能调用的函数类型不一样。moveint这个函数就是智能调用函数形式为 int hanshu(int *a);这种定义类型的。同理你可以根据实际情况改成,比如movevoid(void (*hanshu)(int ),int *a)。这个原理就是把函数作为参数传递。唯一作用就是解决历代流传下来的界面跳转时的鼠标留痕问题。

showtime

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "common.h"
#include "shuju.h"
#include "showtime.h"
/*-----------------------------------------------------
展示时间,具体时间可以自行修改,显示的坐标也可以。
注意这里实现了时间每秒刷新一次。
------------------------------------------------------*/
void displayCurrentTime(void)
{
int currenttime = 1;//设定现在时间,初始化。
int pasttime = 0;//参考时间

////////////////////////////////
time_t timep;
struct tm* p;
char timeString[20]; // 获取当前时间的秒数
time(&timep); // 转换为协调世界时的时间结构体
p = localtime(&timep);
//这一段是通用代码,就是直接复制即可,就是把时间的信息放到了timep这个结构里面
//////////////////////////////

currenttime = p->tm_sec;//赋值
getshijian1(&pasttime);//实现一段时间内(1s)pasttime=currenttime.
//get...这个函数就是把文件里面的数字传给pasttime,相当于赋值。。
if (pasttime != currenttime)//利用这个实现每过一秒中就刷新一个,具体自己理解)
{
clearTimeArea();// 清除时间显示区域
pasttime = currenttime;
setshijian1(pasttime);//把文件里面的数字改成pattime的数字
}
// 在窗口中显示转换后的时间信息
setcolor(LIGHTGREEN);//outtextxy的颜色
settextstyle(1, HORIZ_DIR, 1);//HOR...表示横向显示,第二个1表是字体大小。1为小,0默认。2,3..大
outtextxy(10, 10, "Local Time");
settextstyle(1, HORIZ_DIR, 1);
sprintf(timeString, "%d-%02d-%02d- %02d:%02d:%02d",//图形化下的数据显示函数。sprintf将这些储存到timestring字符串中
p->tm_year + 1900, p->tm_mon + 1, p->tm_mday,
p->tm_hour, p->tm_min, p->tm_sec);//这里要加1900和1的原因感兴趣自己可以去查。
outtextxy(10, 30, timeString);//显示字符串
}
/*-----------------------------------------------------
用一个实心矩形(注意改背景色),遮挡。
并不断刷新,实现部分cleardevice()的效果。 c=bioskey(0); //读取键盘输入内容
------------------------------------------------------*/
void clearTimeArea(void) {
setcolor(WHITE);
setfillstyle(SOLID_FILL, WHITE);
bar(10, 30, 300, 55); // 清除时间显示区域
}

这里实现了一个时钟的显示吧,意义不大,主要是让界面看起来更丰富一点。clearTimeArea就是用一个矩形覆盖上一秒的数字,然后重新outtexty,这样就实现了时间的更新。但是要实现每秒更新一次时间,就要引入pasttime了。否则实际情况是clearTimeArea一直在执行,导致时钟一直在闪烁。原理用到了文件操作。但其实,我一开始是直接用结构(struct)然后直接全局变量。。在shuju.h中你也会见到全局变量的用法。

这个的原理还是比较简单的。但仍然存在的bug是鼠标放到时钟显示的地方会被遮挡,这个小细节还没想到如果优化,但其实意义不大,老师不会注重这些与选题无关的细节,就比如室友还加了买门票提醒出现小红点功能,碰到cj还不是直接挂?管你做的多细节?只要有一些核心的东西没到点就是寄。

mainpage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "common.h"
/*-----------------------------------------------------
主界面的编写,实现不同功能界面的跳转
可以一览本程序的功能。
------------------------------------------------------*/
int hello(int* a2)
{
//绘图,只画一次,绘制主界面
if (*a2 == 1)
{
int i = -1;
clrmous(MouseX, MouseY);
cleardevice();
setbkcolor(WHITE);//background color
setcolor(RED);
setfillstyle(1,RED );
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);//右上角画 退出
setcolor(GREEN);
puthz(80, 60, "无人机喷洒农药系统", 32, 50, GREEN);
line(80, 100, 520, 100);//画标题
rectangle(220, 120, 420, 200);
rectangle(220, 240, 420, 320);
rectangle(220, 360, 420, 440);
puthz(230, 140, "进入平坝田", 32, 38, GREEN);
puthz(230, 260, "进入小农田", 32, 38, GREEN);
puthz(230, 380, "系统说明", 32, 50, GREEN);
//画三个框框,代表三种功能。
*a2 = 0;
setshijian1(i);//初始化 time.dat文件
}
//else---------------------------------------------------
displayCurrentTime();//左上角显示时间
showbiankuang(220,120,420,200);//用于显使得鼠标在 矩形中显示边框
showbiankuang(220, 240, 420, 320);
showbiankuang(220, 360, 420, 440);
showbiankuang( 600 ,0 ,640 ,40 );

//-------------------------------------------------------
//界面的跳转
if( mouse_press(600,0,640,40) == 1)
{
*a2 = 1;//使得函数参数重置,为了能够实现返回界面
return -1;//关闭BC。
}
else if (mouse_press(220,120,420,200) == 1)
{
*a2 = 1;
return 2;//进入大农田
}
else if (mouse_press(220, 240, 420, 320)== 1)
{
*a2 = 1;
return 3;//小农田
}
else if (mouse_press(220, 360, 420, 440) == 1)
{
*a2=1;
return 4 ;//系统说明
}
return 1;
}

此界面就是初始界面了。十分简单。绘图部分完全不用看,界面跳转也是一个通用模板了。

drzhiwu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 #include"common.h"

/*========================================
functions: 画植物,包括小麦,玉米,棉花。
=========================================*/
//=============
// 画棉花,透视图
//==============
void mianhua(int x, int y)//x,y为其的左上角坐标。20*35
{
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
bar(x + 10, y + 15, x + 12, y + 35);
line(x + 7, y + 14, x + 10, y + 17);
line(x + 10, y + 17, x + 16, y + 14);
ellipse(x+18, y+17,10, 360, 2, 4);//画椭圆函数
ellipse(x + 5, y +16 , 20, 360, 3, 4);
floodfill(x + 5, y + 16, GREEN);
floodfill(x + 18, y + 17, GREEN);
line(x+10, y+15, x+10, y+9);
line(x+11, y+15, x+11, y+9);
line(x+10, y+9, x+3, y+7);
line(x+3, y+7, x+9, y+5);
line(x+9, y+5, x+6, y+1);
line(x+6, y+1, x+10, y+2);
line(x+10, y+2, x+12, y+5);
line(x+12, y+5, x+15, y+1);
line(x+15, y+1, x+16, y+5);
line(x+16, y+5, x+19, y+6);
line(x+19, y+6, x+19, y+9);
line(x+19, y+9, x+13, y+10);
line(x+13, y+10, x+13, y+13);
line(x+13, y+13, x+11, y+10);
floodfill(x + 9, y + 3, GREEN);
setcolor(WHITE);
line(x+10, y+9, 6+x, y+8);
line(x+11,y+ 9, 10+x, 4+y);
line(11+x, y+9, x+15, y+2);
line(x+12, y+8, x+14, y+7);
}
//=============
// 画玉米,透视图
//==============
void yumi(int x, int y) //xy为左上角35*35
{
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
bar(x + 12, y + 3, x + 16, y + 35);
arc(x+14, y+4, 0, 180, 2);
floodfill(x + 13, y + 3, GREEN);
line(x + 12 , y +4 , x +5 , y +4 );
line(x +5 , y + 4, x +2 , y +10 );
line(x +2 , y +10 , x +6 , y +8 );
line(x + 6, y +8 , x +12 , y +7 );
line(x + 12, y +18 , x +9 , y + 17);
line(x + 9, y + 17, x +7 , y + 28);
line(x +7 , y +28 , x +12 , y + 22);
line(x + 16, y +24 , x + 21, y +20 );
line(x + 21, y + 20, x +27 , y +25 );
line(x + 27, y +25 , x +23 , y +17 );
line(x +23 , y +17 , x + 16, y + 20);
floodfill(x + 20, y + 19, GREEN);
floodfill(x + 10, y + 20, GREEN);
floodfill(x + 5, y + 7, GREEN);
line(x + 16, y +17 , x + 20, y +15 );
line(x +20 , y +15 , x +20 , y +4 );
line(x + 20, y +4 , x +16 , y +12 );
floodfill(x + 19, y + 19, GREEN);
line(x + 16, y + 13, x + 20, y + 6);
line(x +12 , y +10 , x + 7, y +8 );
line(x + 7, y + 8, x +12 , y + 12);
line(x + 7, y +8 , x +6 , y +10 );
line(x + 6, y + 10, x +12 , y + 17);
line(x + 6, y +10 , x +12 , y +12 );
setfillstyle(SOLID_FILL, YELLOW);
floodfill(x + 10, y + 12, GREEN);
floodfill(x + 18, y + 12, GREEN);
}
//=======
//小麦块
//=======
void xiaomaikuai(int x, int y)
{
xiaomai(x, y);
xiaomai(x+5, y);
xiaomai(x-5, y);
}
//画小麦透视图,,,其大小为 20*19.
void xiaomai(int x, int y)
{
x = x +10;//修正小麦坐标
//xy是最顶点
setcolor(GREEN);
putpixel(x, y, GREEN);
line(x, y, x, y + 19);
line(x, y + 6, x + 5, y + 6 - 5);
line(x, y + 6, x - 5, y + 6 - 5);
line(x, y + 12, x - 5, y + 6);
line(x, y + 12, x + 5, y + 6 );
}
//画小麦俯视图
void fxiaomai(int x, int y)//xy是最左边的点//25*25
{
setcolor(GREEN);
line(x + 2, y + 10 + 6 + 4 + 3, x + 6, y + 2 + 6 + 4 + 3);
line(x + 2, y + 6 + 6 + 4 + 3, x + 10, y + 6 + 6 + 4 + 3);
line(x + 6, y + 12 + 6 + 4 + 3, x + 3, y + 3 + 6 + 4 + 3);
line(x + 10, y + 9 + 6 + 4 + 3, x + 7, y + 12 + 6 + 4 + 3);
line(x + 11, y + 10 + 6 + 4 + 3, x + 8, y + 7 + 6 + 4 + 3);
line(x + 13, y + 10 + 6 + 3, x + 6 + 12, y + 2 + 6 + 3 + 3);
line(x + 2 + 12, y + 6 + 6 + 3, x + 10 + 12, y + 6 + 6 + 3 + 3);
line(x + 6 + 12, y + 12 + 5 + 4, x + 3 + 12, y + 3 + 6 + 3 + 3);
line(x + 10 + 12, y + 9 + 6 + 3, x + 7 + 12, y + 12 + 4);
line(x + 11 + 12, y + 10 + 3 + 3, x + 8 + 12, y + 7 + 4 + 3);
line(x + 6 + 10, y + 12, x + 8 + 10, y + 12 + 2);
line(x + 6 + 10, y + 12, x + 6 - 2 + 10, y + 12 + 2);
line(x + 6 + 10, y + 12, x + 6 + 10, y + 12 - 4);
line(x + 6 + 10, y + 12, x + 6 - 2 + 10, y + 12 - 4);
line(x + 4, y + 2, x + 8, y + 10);
line(x + 8, y + 6, x + 8, y + 2);
line(x + 8, y + 10, x + 12, y + 2);
line(x + 4, y + 10, x + 8, y + 18);
line(x + 8, y + 14, x + 8, y + 10);
line(x + 8, y + 18, x + 12, y + 10);
line(x + 8, y + 2, x + 16, y + 10);
line(x + 16, y + 6, x + 16, y + 2);
line(x + 16, y + 10, x + 24, y + 2);
line(x + 8, y + 10, x + 16, y + 18);
line(x + 16, y + 14, x + 16, y + 10);
line(x + 16, y + 18, x + 24, y + 10);
}
//=============
// 画玉米,俯视图
//==============
void fyumi(int x, int y)
{
setcolor(GREEN);
circle(x + 12, y + 12, 2);
line(x + 12, y + 10, x + 20, y + 2);
line(x + 20, y + 2, x + 16, y + 9);
line(x + 16, y + 9, x + 13, y + 11);
line(x + 14, y + 9, x + 20, y + 13);
line(x + 20, y + 13, x + 13, y + 13);
putpixel(x + 13, y + 13, GREEN);
putpixel(x + 13, y + 14, GREEN);
putpixel(x + 14, y + 14, GREEN);
putpixel(x + 14, y + 15, GREEN);
putpixel(x + 15, y + 15, GREEN);
putpixel(x + 15, y + 16, GREEN);
putpixel(x + 14, y + 17, GREEN);
putpixel(x + 15, y + 17, GREEN);
putpixel(x + 16, y + 17, GREEN);
putpixel(x + 17, y + 17, GREEN);
putpixel(x + 18, y + 17, GREEN);
line(x + 18, y + 17, x + 20, y + 23);
line(x + 20, y + 23, x + 13, y + 20);
line(x + 13, y + 20, x + 12, y + 15);
line(x + 11, y + 11, x + 2, y + 10);
line(x + 2, y + 10, x + 2, y + 12);
line(x + 2, y + 12, x + 5, y + 13);
line(x + 5, y + 13, x + 11, y + 14);
line(x + 7, y + 14, x + 3, y + 21);
line(x + 3, y + 21, x + 12, y + 18);
line(x + 5, y + 10, x + 13, y + 7);
setfillstyle(SOLID_FILL, GREEN);
floodfill(x + 12, y + 12, GREEN); // 遇到边界颜色停止
setfillstyle(SOLID_FILL, YELLOW);
floodfill(x + 15, y + 18, GREEN);
}

完全没有技术含量,仅仅是画图而已。

那今天的更新就到这里吧,大概不久就要去练科三了,时间也变的紧张起来。考驾照无非就是67个人围着一辆车子,一个人10多min,一天下来基本在太阳底下站。。。早七晚六不用说。大二上学期更没时间,课表全满,双休也有课,每天早八晚九了。。。


abdrone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "common.h"
/*===========================================
无人机所有函数,包括运动,画图
=============================================*/
//俯视图 的无人机
//用于大农田
void drfdrone(int x, int y)//xy是左上角坐标
{
setcolor(DARKGRAY);
setfillstyle(1, DARKGRAY); //circle(x + 12, y + 12, 4);
fillellipse(x + 12, y + 12, 4, 4);
rectangle(x + 8, y + 9, x + 15, y + 15);// floodfill(x + 12, y + 12, DARKGRAY);
line(x + 5, y + 4, x + 9, y + 8);
line(x + 3, y + 4, x + 9, y + 9);
line(x + 3, y + 5, x + 8, y + 10);
line(x + 9, y + 1, x + 1, y + 9);
line(x + 8, y + 1, x + 0, y + 9);
line(x + 7, y + 1, x + 0, y + 8);
line(x + 15, y + 8, x + 19, y + 4);
line(x + 15, y + 9, x + 20, y + 4);
line(x + 15, y + 10, x + 20, y + 5);
line(x + 15, y + 0, x + 24, y + 9);
line(x + 16, y + 0, x + 24, y + 8);
line(x + 14, y + 1, x + 23, y + 9);
line(x + 16, y + 15, x + 21, y + 20);
line(x + 15, y + 15, x + 20, y + 20);
line(x + 14, y + 16, x + 20, y + 21);
line(x + 24, y + 15, x + 15, y + 24);
line(x + 24, y + 16, x + 16, y + 24);
line(x + 24, y + 14, x + 14, y + 24);
line(x + 9, y + 15, x + 3, y + 21);
line(x + 8, y + 15, x + 3, y + 20);
line(x + 9, y + 16, x + 4, y + 21);
line(x + 0, y + 15, x + 9, y + 24);
line(x + 0, y + 16, x + 8, y + 24);
line(x + 0, y + 14, x + 10, y + 24);
}
//==================================================
//动画实现代码。建议自己理解。。。。。详细调用在growlook.c里面的大农田里面有。
//原理大概就是视觉停留(?,
void move11(int* x, int* y, int* buffer1)
{
for (; *x < 620 - 25; *x = *x + 2)//运动到了最左端。。
{
getimage(*x, *y, *x + 25, *y + 25, buffer1);//保存image到buffer
drfdrone(*x, *y);
delay(8);
putimage(*x, *y, buffer1, COPY_PUT);//恢复图像
}
}
void move12(int* x, int* y, int* buffer1, int* judge)
{
for (; *y < *judge + 25; (*y)++)
{
getimage(*x, *y, *x + 25, *y + 25, buffer1);
drfdrone(*x, *y);
delay(10);
putimage(*x, *y, buffer1, COPY_PUT);
}
*judge = *y;
}
void move13(int* x, int* y, int* buffer1)
{
for (; *x > 20; *x = *x - 2)
{
getimage(*x, *y, *x + 25, *y + 25, buffer1);
drfdrone(*x, *y);
delay(8);
putimage(*x, *y, buffer1, COPY_PUT);
}
}
//=============================================
//无人机透视图,用于小农田
void drtdrone(int xx, int y)//xy是左上角坐标 75*44
{
int x;
x = xx - 25;
setcolor(DARKGRAY);
setfillstyle(1, DARKGRAY);
bar(0 + x, 4 + y, 24 + x, 5 + y);
bar(49 + x, 4 + y, 73 + x, 5 + y);
bar(x + 4, y + 6, x + 5, y + 10);
bar(x + 6, y + 9, x + 20, y + 10);
bar(x + 19, y + 6, x + 20, y + 10);
bar(x + 53, y + 6, x + 54, y + 10);
bar(x + 54, y + 10, x + 69, y + 9);
bar(x + 68, y + 6, x + 69, y + 9);
bar(x + 7, y + 11, x + 9, y + 14);
bar(x + 16, y + 11, x + 18, y + 13);
bar(x + 8, y + 16, x + 22, y + 17);
bar(x + 55, y + 11, x + 57, y + 13);
bar(x + 64, y + 14, x + 66, y + 11);
bar(x + 51, y + 16, x + 65, y + 17);
bar(x + 24, y + 11, x + 49, y + 13);
bar(x + 21, y + 20, x + 51, y + 22);
bar(x + 23, y + 24, x + 50, y + 25);
line(x + 11, y + 18, x + 13, y + 18);
line(x + 60, y + 18, x + 62, y + 18);
line(x + 9, y + 15, x + 23, y + 15);
line(x + 50, y + 15, x + 64, y + 15);
line(x + 10, y + 14, x + 17, y + 14);
line(x + 10, y + 13, x + 15, y + 13);
line(x + 10, y + 12, x + 10, y + 14);
line(x + 15, y + 12, x + 15, y + 13);
line(x + 57, y + 14, x + 63, y + 14);
line(x + 58, y + 13, x + 63, y + 13);
line(x + 58, y + 12, x + 58, y + 13);
line(x + 63, y + 12, x + 63, y + 13);
line(x + 23, y + 12, x + 23, y + 14);
line(x + 50, y + 12, x + 50, y + 14);
line(x + 8, y + 2, x + 10, y + 0);
line(x + 8, y + 3, x + 11, y + 0);
line(x + 14, y + 0, x + 16, y + 2);
line(x + 13, y + 0, x + 16, y + 3);
line(x + 12, y + 0, x + 9, y + 3);
line(x + 13, y + 1, x + 15, y + 3);
line(x + 12, y + 1, x + 10, y + 3);
line(x + 12, y + 1, x + 14, y + 3);
line(x + 21, y + 18, x + 21, y + 19);
line(x + 20, y + 18, x + 20, y + 21);
line(x + 52, y + 18, x + 52, y + 21);
line(x + 53, y + 18, x + 53, y + 20);
line(x + 23, y + 23, x + 25, y + 23);
line(x + 48, y + 23, x + 50, y + 23);
line(x + 57, y + 2, x + 59, y + 0);
line(x + 57, y + 3, x + 60, y + 0);
line(x + 58, y + 3, x + 61, y + 0);
line(x + 62, y + 0, x + 59, y + 3);
line(x + 63, y + 0, x + 65, y + 2);
line(x + 63, y + 1, x + 65, y + 3);
line(x + 62, y + 1, x + 64, y + 3);
line(x + 62, y + 2, x + 63, y + 2);
line(x + 23, y + 26, x + 23, y + 32);
line(x + 24, y + 26, x + 24, y + 30);
line(x + 22, y + 32, x + 22, y + 42);
line(x + 21, y + 32, x + 21, y + 42);
line(x + 20, y + 37, x + 20, y + 41);
line(x + 21, y + 41, x + 25, y + 41);
line(x + 21, y + 42, x + 24, y + 42);
line(x + 49, y + 26, x + 53, y + 37);
line(x + 49, y + 27, x + 53, y + 38);
line(x + 51, y + 34, x + 51, y + 42);
line(x + 48, y + 41, x + 53, y + 41);
line(x + 49, y + 42, x + 52, y + 42);
line(x + 53, y + 37, x + 53, y + 41);
line(x + 51, y + 34, x + 51, y + 42);
line(x + 52, y + 42, x + 52, y + 34);
bar(x + 41, y + 28, x + 43, y + 36);
bar(x + 41, y + 26, x + 42, y + 36);
line(x + 38, y + 36, x + 43, y + 36);
line(x + 31, y + 26, x + 29, y + 30);
line(x + 32, y + 26, x + 29, y + 31);
line(x + 34, y + 36, x + 30, y + 36);
line(x + 30, y + 36, x + 30, y + 27);
line(x + 29, y + 30, x + 29, y + 35);
setcolor(LIGHTGRAY);
setfillstyle(1, LIGHTGRAY);
floodfill(x + 12, y + 3, DARKGRAY);
floodfill(x + 61, y + 3, DARKGRAY);
floodfill(x + 13, y + 12, DARKGRAY);
floodfill(x + 60, y + 11, DARKGRAY);
line(x +26 , y +23 , x +47 , y + 23);
bar(x +6 , y + 6, x +18 , y + 8);
bar(x +55 , y +6, x +67 , y +8 );
bar(x + 24, y +14 , x + 49, y +19 );
line(x +23 , y + 16, x +23 , y + 19);
line(x +50 , y + 16, x +50 , y + 19);
setcolor(DARKGRAY);
setfillstyle(1, DARKGRAY);
bar(x +26 , y + 17, x + 27, y +18 );
bar(x + 29, y + 17, x + 30, y + 18);
}

这个文件就是画无人机(两种形式),写了一段实现简单动画平移的函数,目前关于如何实现斜线运动我那时就没想到,之后也就没想了(只想到了循线这种)。比较简单,不需要多看。。

shuju.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "shuju.h"
#include "common.h"

//==============================================================
//控制时间间隔。原理请配合showtime.c使用//这里和时间那里有关,其实可以直接搞个全局变量就OK,
//但当时怕被发现,换成了文件操作,当时也是刚刚学这东西,所以就当练练手了
void setshijian1(int cankaotime)//这个函数的作用就是把传进的 cankaotime这个东西写入到time.dat文件
//中(这种文件都能直接用记事本打开好像,还是比较方便检查错误的)
{
FILE* filePointer1;
filePointer1 = fopen("data//time.dat", "w"); //具体用法建议问chatgpt或者上网搜
if (filePointer1 == NULL) {
printf("Unable to open the file.\n");
getch();
exit(1);
}
fprintf(filePointer1, "%d\n", cankaotime);//设置使得time.dat 储存cankaotime的数字
fclose(filePointer1);
}//上面那一串都是直接复制粘贴的,原理我不太懂。。套路就是这样吧,那里的if那一大段要不要其实无所谓了,我后面
//自己编写的时候也基本没加,但加上还是好的,便于检查内存分配的问题。
void getshijian1(int *cankaotime)
{
FILE* filePointer1;
filePointer1 = fopen("data//time.dat", "r");
if (filePointer1 == NULL) {
printf("Unable to open the file.\n");
getch();
exit(1);
}
fscanf(filePointer1, "%d", cankaotime);//设置使得cankaotime获得time.dat 储存的数字,注意这里用了指针。。
fclose(filePointer1); //fscanf用&,fprintf不用&
}//这里只需要掌握fscanf和fprintf的用法就行,靠这两个函数就能基本实现储存和读取数据了。
//====================================================
//这一堆都是偷偷藏起来的全局变量,后面想改,但时间不够,而且难度高,所以索性摆烂了,全都是大农田用的,因为
//大农田搞了个植物自愈,自愈不完全,病情加深的功能,虽然验收老师并没有感到十分的赞赏。。。。。。无用功吧属
//实是。
unsigned char dianmian_bitmap[192][49];//这三个就是储存点的坐标,就是植物生病会随机出现颜色点,点的
//坐标就储存到了这个数组里面,现在想来就是纯纯折磨自己。搞了个点的随机显示。如果你仔细观察大农田就会发现了
unsigned char dianbai_bitmap[192][49];
unsigned char diannian_bitmap[384][49];//,棉铃虫,白粉病,黏虫。
//下面这三个是储存生病植物的坐标,用了全局变量,当然可以用文件操作(小农田就是这样,但要重写实在太麻烦
dbfxy bai = { 0 };//小麦地得白粉病 的坐标。 注意当x,y均为0时,表示该区域不得病。
dbfxy mian = { 0 };//得棉铃虫病的坐标。 注意当x,y均为0时,表示该区域不得病。
niang nian = { 0 };//黏虫的坐标,左上角坐标, 注意当x,y均为0时,表示该区域不得病。
//下面三个是队友写的全局变量。。看不太懂
int nongyao[6];//氟铃胺,甲胺磷,氯氰菊酯,甲维盐,菌酯, nongyao[6]用于判断大小农田 0:大 1:小
int rount[386][2];//储存需要喷洒农药的植物坐标
int amtjudge;//判断需要喷洒的植物的棵数
//=================================================================================
//获得所有植物的坐标,把植物坐标传入到 plantPostions里面。
void getxtxiao(int plantPositions3[][2])//小农田的代码,就是把植物坐标传入文件xt是小田的意思
{//小麦
int row = 0;
FILE* filePointer3;
filePointer3 = fopen("data//xtxiao.dat", "r"); // 以读取模式打开文件
for (row = 0; row < 104; row++)//画植物的数量为坐标数
{
fscanf(filePointer3, "%d %d", &plantPositions3[row][0], &plantPositions3[row][1]);
}
fclose(filePointer3);
}
void getxtyumi(int plantPositions3[][2])
{//玉米
int row = 0;
FILE* filePointer3;
filePointer3 = fopen("data//xtyumi.dat", "r"); // 以读取模式打开文件

for (row = 0; row < 68; row++)//画植物的数量为坐标数
{
fscanf(filePointer3, "%d %d", &plantPositions3[row][0], &plantPositions3[row][1]);
}
fclose(filePointer3);
}
void getxtmianhua(int plantPositions3[][2])
{//棉花
int row = 0;
FILE* filePointer3;
filePointer3 = fopen("data//xtmianhua.dat", "r"); // 以读取模式打开文件
for (row = 0; row < 68; row++)//画植物的数量为坐标数
{
fscanf(filePointer3, "%d %d", &plantPositions3[row][0], &plantPositions3[row][1]);
}
fclose(filePointer3);
}
//=================================================
//下面的三个文件对文件进行初始化定义。
//这个函数就是起到初始化文件的作用,就是重新生成一般xtyumi.dat等三个文件(储存了植物坐标),清空记录的作用吧。
void setxtzhiwu(int plantPositions1[][2], int plantPositions2[][2], int plantPositions3[][2])
{
int j;
FILE* filePointer1; // 文件指针
FILE* filePointer2;
FILE* filePointer3;
filePointer1 = fopen("data//xtyumi.dat", "w"); // 以写入模式打开文件
filePointer2 = fopen("data//xtmianhua.dat", "w");
filePointer3 = fopen("data//xtxiao.dat", "w");
if (filePointer1 == NULL) {
printf("Unable to open the file.\n");
getch();
exit(1);
}
if (filePointer2 == NULL) {
printf("Unable to open the file.\n");
getch();
exit(1);
}
if (filePointer3 == NULL) {
printf("Unable to open the file.\n");
getch();
exit(1);
}
for (j = 0; j < 68; j++)
{
fprintf(filePointer1, "%d %d\n", plantPositions1[j][0], plantPositions1[j][1]);
}
for (j = 0; j < 68; j++)
{
fprintf(filePointer2, "%d %d\n", plantPositions2[j][0], plantPositions2[j][1]);
}
for (j = 0; j < 104; j++)
{
fprintf(filePointer3, "%d %d\n", plantPositions3[j][0], plantPositions3[j][1]);
}
fclose(filePointer1);
fclose(filePointer2);
fclose(filePointer3);
}
//下面是大农田里用到的
//就是清空全局变量的值,全部归零,防止退出到主界面时,上一次的检测结果影响。
void zero(void)//重置储存。。
{
int i, j;
for (i = 0, j = 192; i < 192, j < 384; i++, j++)
{
bai.bfzuobiao[i][0] = 0;
bai.bfzuobiao[i][1] = 0;
mian.bfzuobiao[i][0] = 0;
mian.bfzuobiao[i][0] = 0;
nian.bfzuobiao[i][0] = 0;
nian.bfzuobiao[i][0] = 0;
nian.bfzuobiao[j][0] = 0;
nian.bfzuobiao[j][0] = 0;
}
}
//下面这两个函数都是gpt生成的,当时出现了内存爆炸的问题,心里也很慌,gpt说位图能减少内存使用,所以
//阴差阳错之下就用到了这东西,反正我看不懂,但还是会用的。具体使用好像是在illness.c和recover.c里面
// 设置位图中的某个像素值,具体原理我当时也没去了解,过了C课设之后更不学了。。
void setshu(unsigned char bitmap[49], int x, int value)
{
if (value) {
bitmap[x / 8] |= (1 << (x % 8)); // 设置为 1
}
else {
bitmap[x / 8] &= ~(1 << (x % 8)); // 设置为 0
}
}
// 获取位图中的某个像素值
int getshu(unsigned char bitmap[49], int x)
{
return (bitmap[x / 8] >> (x % 8)) & 1;
}

shuju.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef _SHUJU_H
#define _SHUJU_H
/*--------------
作为数据库,实现一次定义
--------------*/
typedef struct
{
int bfzuobiao[384][2];//
} niang; //储存黏虫的坐标信息;
typedef struct
{
int bfzuobiao[192][2];//
} dbfxy;//储存小麦的白粉病信息以及玉米的棉铃虫信息
//引用全局变量,
extern dbfxy bai;
extern dbfxy mian;
extern niang nian;
extern unsigned char dianmian_bitmap[192][49];//位图,储存颜色点的信息
extern unsigned char dianbai_bitmap[192][49];
extern unsigned char diannian_bitmap[384][49];
//初始化位图和获取位图的0,1.
void setshu(unsigned char bitmap[49], int x, int value);
int getshu(unsigned char bitmap[49], int x);
extern int nongyao[6];//氟铃胺,甲胺磷,氯氰菊酯,甲维盐,菌酯, nongyao[5]用于判断大小农田 0:大 1:小
extern int rount[386][2];//储存需要喷洒农药的植物坐标
extern int amtjudge;//判断需要喷洒的植物的棵数

//初始化小农田里的各种植物坐标。以及从文件中获取各个植物的坐标到数组中
void setxtzhiwu(int plantPositions1[][2], int plantPositions2[][2], int plantPositions3[][2]);
void getxtmianhua(int plantPositions3[][2]);
void getxtyumi(int plantPositions3[][2]);
void getxtxiao(int plantPositions3[][2]);
//=====================
//time.dat
//function:控制时间间隔,每隔一秒刷新
void setshijian1(int cankaotime);
void getshijian1(int* cankaotime);
//=====================
void zero(void);//重置大农田的患病植物坐标储存
#endif

这两个文件基本涉及到了所有的文件操作的相关函数(我是指我编的程序里面用到的),对于看懂整个代码有很大作用。比较复杂,因为是后面边写便堆砌上去的。毕竟文件操作都是差不多距离验收一个月前加上去的。虽然我们用到的文件操作仅仅限于储存数组,但毫无争议的是,还是要学更多,毕竟画图没有什么含金量,你也可以发现,其实整个程序抛弃画图,我现在看来,C课设编写的程序也就那样。。。详细解释看新加的注释

——7.28


mainfunc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
 #include "common.h"
/*===========================================
实现了分工,其中准备喷洒会进入另外一个新界面。
绘制了农田和植物的基本样子。
=============================================*/
int mainfunc(int* a3, unsigned char diannian[384][49], unsigned char dianbai[192][49], unsigned char dianmian[192][49])
{
//大农田的绘制
int i;
srand(time(NULL));
//================================
//这里是绘制大农田界面
if (*a3 == 1)
{
cleardevice();
clrmous(MouseX, MouseY);
setbkcolor(WHITE);//background color
drawBackground();//画通用背景
farmfield();//绘制农田
*a3 = 0;
}
//===========================
if (*a3 ==- 1)//实现界面跳转后,返回改界面的重新绘图
{
cleardevice();
clrmous(MouseX, MouseY);
setbkcolor(WHITE);//background color
drawBackground();
farmfield();
for (i = 0; i < 192; i++)//小麦区域的发病率
{
if (nian.bfzuobiao[i][0] != 0 && nian.bfzuobiao[i][1] != 0)
{
nianchong(nian.bfzuobiao[i][0], nian.bfzuobiao[i][1],diannian[i]);
}
}
for (i=192; i < 384; i++)//玉米区域的发病率
{
if (nian.bfzuobiao[i][0] != 0 && nian.bfzuobiao[i][1] != 0)
{
nianchong(nian.bfzuobiao[i][0], nian.bfzuobiao[i][1],diannian[i]);
}
}
for (i = 0; i< 192; i++)//玉米区域的发病率.
{
if (mian.bfzuobiao[i][0] != 0 && mian.bfzuobiao[i][1] != 0)
{
mianling(mian.bfzuobiao[i][0], mian.bfzuobiao[i][1],dianmian[i]);
}
}
for (i = 0;i < 192; i++)
{
if (bai.bfzuobiao[i][0] != 0 && bai.bfzuobiao[i][1] != 0)
{
baifen(bai.bfzuobiao[i][0], bai.bfzuobiao[i][1],dianbai[i]);
}
}
*a3 = 2;
}
//上面这一段是重新绘图,因为结果查看后要返回到大农田界面,所以要这样
//====================ELSE
//鼠标显示边框
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);
showbiankuang(100, 5, 100 + 140, 50);
//===================下面是界面的跳转
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a3 = 1;
zero();//重置病虫坐标
delay(100);
return 1;//返回前一个界面
}
else if (mouse_press(100, 5,240, 50) == 1)//连续点击生长检测
{
*a3 = 2;
clrmous(MouseX, MouseY);
grow();//无人机动画的实现
recover();//再次点击生长检测,部分区域恢复
//显示三种病
showbaifen(dianbai);
shownianchong(diannian);
showmianling(dianmian);
}
if (*a3 == 2 || *a3 == -1)//这里实现了必须先点击一次生长检测,才能点击结果查看和准备喷洒的功能
{
if (mouse_press(100 + 140 + 30, 5, 100 + 140 + 30 + 140, 50) == 1)
{
*a3 = -1;
delay(100);
return 6;//结果查看部分
}
else if (mouse_press(100 + 140 + 140 + 30 + 30, 5, 100 + 140 + 140 + 30 + 30 + 140, 50) == 1)
{
*a3 = -1;
delay(100);
return 7;//准备喷洒部分
}
showbiankuang(100 + 140 + 30, 5, 100 + 140 + 30 + 140, 50);
showbiankuang(100 + 140 + 140 + 30 + 30, 5, 100 + 140 + 140 + 30 + 30 + 140, 50);
}
return 2;
}
//绘制通用背景
void drawBackground(void)
{
setcolor(RED);//边界color
setfillstyle(1, GREEN);//意思:设置绿色的填充模式为1(完全填充)
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);//关闭按钮
rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);
setfillstyle(1, GREEN);
bar(100, 5, 100 + 140, 50);
bar(100 + 140 + 30, 5, 100 + 140 + 30 + 140, 50);
bar(100 + 140 + 140 + 30 + 30, 5, 100 + 140 + 140 + 30 + 30 + 140, 50);
puthz(100 + 10, 5 + 5, "生长检测", 32, 30, WHITE);
puthz(100 + 140 + 30 + 10, 5 + 5, "结果查看", 32, 30, WHITE);
puthz(100 + 140 + 140 + 30 + 30 + 10, 5 + 5, "准备喷洒", 32, 30, WHITE);
}
//绘制农田
void farmfield(void)
{
int x = 0, y = 0;
int j;
int jia1[] = { 25,75,25,75,25,75,25,75 };
setfillstyle(1, BROWN);
setcolor(BROWN);
bar(20, 60+5, 640-20, 480-15);//边框,即农田大小
for (x = 20; x < 620 - 25 + 1; x = x + 25)//小麦区域,
{
j = -1;
for (y = 65; y < 465; y = y + jia1[j])
{
j++;
fxiaomai(x, y);
}
}
for (y = 0; y <= 300; y = y + 100)//玉米的绘制
{
for (x = 20; x <= 620 - 25; x = x + 25)
{
fyumi(x, 65+50 + y);
fyumi(x, 65 +25+50 + y);
}
}
}

这一个文件是实现了大农田的农田绘制和植物的生长检测功能(包括无人机动画,病虫害显示)这段代码个人认为有用的包括那个 必须得先点击一个按键,之后便可点击其他。也许你有其他的方法,但我暂时还没思路。

illness.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef _ILLNESS_H_
#define _ILLNESS_H_
//大农田显示
void showbaifen(unsigned char abc[192][49]);
void baifen(int x, int y, unsigned char abc[49]);
void ifbaifen(unsigned char abc[49]);
void nianchong(int x, int y, unsigned char aaa[49]);//画黏虫
void ifnianchong(unsigned char aaa[49]);//随机点列
void shownianchong(unsigned char aaa[384][49]);
void ifmianling(unsigned char aaa[49]);//随机显示
void mianling(int x, int y, unsigned char aaa[49]);
void showmianling(unsigned char aaa[192][49]);
int randill(int j);//控制不同的病的不同的发病率。就是使得一种病,每次检测时,的发病率不同
//小农田显示
void showxtbaifen(void);
void xtbaifen(int x, int y, FILE* filePointer5);//画出白粉病,适用于俯视图。25*25大小
void showxtnianchong(void);
void xtnianchong(int x, int y, FILE* filePointer5);//画出白粉病,适用于俯视图。25*25大小
void xtymmian(int x, int y, FILE* filePointer5);
void showxtymmian(void);
void showxtymnian(void);
void xtymnian(int x, int y, FILE* filePointer5);
void showxtmhmian(void);
void xtmhmian(int x, int y, FILE* filePointer5);
void showxtmhxiu(void);
void xtmhxiu(int x, int y, FILE* filePointer5);
#endif

illness.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
#include "common.h"
/*==========================
植物患病的概率
===========================*/
int randill(int k)//这里j代表系数,注意0,1,2,3.
{//随机显示 点
int judge;
int i, j;
int a[4][60] = //这一堆控制的是显示点数量的比例啥的,没什么大用。。。建议不用看
{
//棉铃虫对于玉米的
{40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40, 40,40,40,40,5,5,5,5,7,7,7,7,7,8,8,8,8,10,10,10,10,11,11,11,12,13,13,14,14,14,14,14,15,15,16,17,18,19,20,20,20,20,20,20 },
//黏虫对于小麦的
{40,40,40,40,40,40,40,40,40,40,40,40,40,40,40, 40, 40,40,40,40,5,5,5,6,6,6,6,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,12,12,12,13,14,14,15,16,17,18,19,20,21,22,22,22,22,22 },
//黏虫对于玉米的
{40,40,40,40,40,40,40,40,40,40,40,40,40,40,40, 40, 40,40,40,40,5,5,6,6,6,6,7,7,7,9,9,9,10,10,10,11,11,11,12,12,12,13,13,13,13,13,14,14,15,16,16,17,18,19,20,21,22,22,22,22 },
//白粉对于小麦的
{40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40, 40,40,40,40,5,5,5,5,5,5,7,7,7,7,7,8,8,8,8,10,10,10,10,11,11,11,12,13,13,14,14,14,14,14,16,17,18,19,20,20,20,20,20,20 },
};
int b[4][60] = { 0 };
judge = rand() % 8;
if (judge != 0)//有8分之一的概率全部是正常
{
for (i = 0; i < 4; i++)
{
for (j = 0; j < 60; j++)
{
b[i][j] = a[i][j];
}
}
}
else
{
for (i = 0; i < 4; i++)
{
for (j = 0; j < 60; j++)
{
b[i][j] = 999;
}
}
}
i = rand() % 60;
return b[k][i];
}
/*==========================
显示棉铃虫,大农田
===========================*/
void showmianling(unsigned char aaa[192][49])//棉铃虫。感染玉米和棉花。
{
// int aaa[49] = { 0 };//
int temp;
int judge = 0;
int j;
int jia2[] = { 25,75,25,75,25,75,25,75 };//控制y的加的数,使其跳过小麦区域。
int x;
int y;
int i;
x = 0;
y = 0;
i = 0;
temp = randill(0);//控制发病率的调整比例
for (x = 20; x < 620 - 25 + 1; x = x + 25)//玉米区域的发病率
{
j = -1;
for (y = 65 + 50; y < 465; y = y + jia2[j])//3行
{
ifmianling(aaa[i]);//控制点的形成
j++;
judge = rand() % temp;
if (judge == 0)//
{
mianling(x, y,aaa[i]);
mian.bfzuobiao[i][0] = x;
mian.bfzuobiao[i][1] = y;
i++;
}
else
{
i++;
}
}
}
}
/*==========================
显示棉铃虫点列
===========================*/
void mianling(int x, int y, unsigned char aaa[49])//
{
int i;
int j;
int jjj;
int mlxy[49][2] =
{
//蓝色点所有可能的位置...49个点
{ 7 , 3 },
{ 19 , 1 },
{ 20 ,1 },
{ 6 , 5 },
{ 9, 5 },
{ 18 , 4},
{ 18 , 5},
{ 11 , 6 },
{ 14 , 6 },
{ 5 ,7 },
{ 2 , 8 },
{ 7 ,8 },
{ 13 ,7 },
{ 17 , 7 },
{ 22 ,7 },
{ 19 , 8 },
{ 20 , 8 },
{ 6 , 10 },
{ 4 , 11 },
{ 1 ,13 },
{ 3 , 16 },
{ 1 ,17 },
{ 1 , 18 },
{ 2 , 18 },
{ 7 , 19 },
{ 7 , 20 },
{ 5 ,23 },
{ 7 , 23 },
{ 10 , 12 },
{ 10 , 13 },
{ 9 , 17 },
{ 11 , 15 },
{ 12 , 14 },
{ 19 , 12 },
{ 22 , 12 },
{ 22 ,13 },
{ 22 , 15 },
{ 18 , 15 },
{ 19 , 16 },
{ 13 , 17 },
{ 15 , 16 },
{ 15 , 19 },
{ 16 , 19 },
{ 14 , 21 },
{ 15 , 23 },
{ 16 , 22 },
{ 17 , 24},
{ 19 , 21 },
{ 21 , 23 },
};
for (i = 0; i < 49; i++)
{
mlxy[i][0] = mlxy[i][0] + x;
mlxy[i][1] = mlxy[i][1] + y;
}
for (j = 0; j < 49; j++)
{
jjj = getshu(aaa, j);
if ( jjj== 1)
{
setcolor(BLUE);
putpixel(mlxy[j][0], mlxy[j][1], BLUE);
}
}
}
/*==========================
使得能够随机显示棉铃虫点列
===========================*/
void ifmianling(unsigned char aaa[49])//随机显示
{
int judge[49];
int i;
for (i = 0; i < 49; i++)
{
judge[i] = rand() % 2;//显示的概率为 1/2..
if (judge[i] == 1)
{
setshu(aaa, i, 0);//不显示
}
else
{
setshu(aaa, i, 1);//显示
}
}
}
void shownianchong(unsigned char aaa[384][49])//黏虫。两者均患
{
int judge = 0;
int j;
int jia1[] = { 25,75,25,75,25,75,25,75 };
int jia2[] = { 25,75,25,75,25,75,25,75 };
int x;
int y;
int i;
int temp1, temp2;
temp1 = randill(1);
temp2 = randill(2);
x = 0;
y = 0;
i = 0;
for (x = 20; x < 620 - 25 + 1; x = x + 25)//小麦区域的发病率
{
j = -1;
for (y = 65; y < 465; y = y + jia1[j])
{
ifnianchong(aaa[i]);
j++;
judge = rand() % temp1;//
if (judge == 0)//
{
nianchong(x, y,aaa[i]);
nian.bfzuobiao[i][0] = x;
nian.bfzuobiao[i][1] = y;
i++;
}
else
{
i++;
}
}
}
i = 192;//就是说,nian.bfzuobiao[i][],第1--192个是小麦区域的得了黏虫病的坐标,第193-384个是玉米的
//注意, 进行了农药喷洒后,请注意把对应的坐标 重新赋值为0
for (x = 20; x < 620 - 25 + 1; x = x + 25)//玉米区域的发病率
{
j = -1;
for (y = 65+50; y < 465; y = y + jia2[j])//3行
{
ifnianchong(aaa[i]);
j++;
judge = rand() % temp2;// 1/4的发病率
if (judge == 0)//
{
nianchong(x, y,aaa[i]);
nian.bfzuobiao[i][0] = x;
nian.bfzuobiao[i][1] = y;
i++;
}
else
{
i++;
}
}
}
}
void nianchong(int x, int y, unsigned char aaa[49])//
{
int i;
int j;
int jjj;
int ncxy[43][2] =
{
//洋红色点所有可能的位置...43个点
{ 1 , 2 },
{ 1 , 5 },
{ 3 , 3 },
{ 2 ,20 },
{ 2 , 22 },
{ 4 , 20 },
{ 6 , 13 },
{ 6 , 14 },
{ 6 , 16 },
{ 7 , 14 },
{ 10 , 9 },
{ 10 , 11 },
{ 11 , 10 },
{ 13 ,11 },
{ 15 , 9 },
{ 16 , 10 },
{ 16 , 11 },
{ 17 , 10 },
{ 18 , 9 },
{ 11 , 18 },
{ 11 ,19 },
{ 11 , 20 },
{ 10 ,19 },
{ 10 , 21 },
{ 17 , 17},
{ 16 , 18 },
{ 17 , 18 },
{ 18 , 18 },
{ 22 ,17 },
{ 22 , 19 },
{ 21 , 18 },
{ 21 , 19 },
{ 21 , 20 },
{ 11 , 2 },
{ 13 , 2 },
{ 13 , 3 },
{ 15 , 3 },
{ 16 , 2 },
{ 20 , 3},
{ 20 , 4 },
{ 21 , 5 },
{ 22 , 3 },
{ 22 , 4 }
};
for (i = 0; i < 43; i++)
{
ncxy[i][0] = ncxy[i][0] + x;
ncxy[i][1] = ncxy[i][1] + y;
}
for (j = 0; j < 43; j++)
{
jjj = getshu(aaa, j);
if (jjj == 1)
{
setcolor(YELLOW);
putpixel(ncxy[j][0], ncxy[j][1], YELLOW);
}
}
}
void ifnianchong(unsigned char aaa[49])//随机显示
{
int judge[43];
int i;
for (i = 0; i < 43; i++)
{
judge[i] = rand() % 2;//显示的概率为 1/2.
if (judge[i] == 1)
{
setshu(aaa, i, 0);//不显示
}
else
{
setshu(aaa, i, 1);//显示
}
}
}
void showbaifen(unsigned char abc[192][49])//白粉病的发病率
{
int judge = 0;
int j;
int jia[] = { 25,75,25,75,25,75,25,75 };//控制y的加的数,使其跳过玉米区域。
int x;
int y;
int i;
int temp;
temp = randill(3);
x = 0;
y = 0;
i = 0;
for (x = 20; x < 620 - 25 + 1; x = x + 25)//96*2片区域,,这是24列
{
j = -1;
for (y = 65; y < 465; y = y + jia[j])//6行
{
ifbaifen(abc[i]);
j++;
judge = rand() % temp;
if (judge == 0)// 1/4的概率得病
{
baifen(x, y,abc[i]);
bai.bfzuobiao[i][0] = x;////储存区域生病的坐标;
bai.bfzuobiao[i][1] = y;
i++;
}
else
{
i++;
}
}
}
}
void baifen(int x, int y, unsigned char abc[49])//画出白粉病,适用于俯视图。25*25大小
{
int i;
int j;
int jjj;
int bfxy[34][2] =
{
//白色点所有可能的位置
{5, 5},
{ 7, 4},
{ 9, 5},
{ 7, 9},
{ 4, 9},
{ 4, 14},
{ 3, 14},
{ 8, 18},
{ 8, 19},
{ 9, 14},
{ 13, 5},
{ 13, 6},
{ 13, 7},
{ 13, 8},
{ 13, 14},
{ 14, 14},
{ 14, 17},
{ 14, 20},
{ 18, 21},
{ 19, 15},
{ 20, 11},
{ 16, 6},
{ 17, 6},
{ 18, 3},
{ 5, 1 },
{ 21 , 1 },
{ 21 , 23 },
{ 5 ,22 },
{ 10 ,22 },
{ 1 , 13 },
{ 1 , 18 },
{ 3 , 11 },
{22 , 9 },
{ 23 , 19}//34个点
};
for (i = 0; i < 34; i++)
{
bfxy[i][0] = bfxy[i][0] + x;
bfxy[i][1] = bfxy[i][1] + y;

}
for (j = 0; j < 34; j++)
{
jjj = getshu(abc, j);
if (jjj == 1)
{
setcolor(WHITE);
putpixel(bfxy[j][0], bfxy[j][1], WHITE);
}
}
}
void ifbaifen(unsigned char abc[49])//使得白粉病 设置白点的随机显示
{
int judge[34];
int i;
for (i = 0; i < 34; i++)
{
judge[i] = rand() % 3;//显示的概率为 2/3.。。
if (judge[i] == 1)
{
setshu(abc, i, 0);//不显示
}
else
{
setshu(abc, i, 1);
}
}
}
//============================================================================================================
//============================================================================================================
//下面为小农田
void showxtbaifen(void)//小农田显示白粉病
{
FILE* filePointer4;
FILE* filePointer5;
int plantPositions3[104][2];
int judge = 0;
int j;
int x;
int i;
int temp;
temp = randill(3);
x = 0;
i = 0;
filePointer4 = fopen("data//xtxmbai.dat", "w");
filePointer5 = fopen("data//xmbfdian.dat", "w");
getxtxiao(plantPositions3);//使得小麦坐标到了plantpositions3
for (x = 0; x < 104; x++)
{
judge = rand() % temp;
if (judge == 0)
{
xtbaifen(plantPositions3[i][0], plantPositions3[i][1], filePointer5);
fprintf(filePointer4, "%d %d\n", plantPositions3[i][0], plantPositions3[i][1]);
i++;
}
else
{
i++;
}
}
fclose(filePointer4); //
fclose(filePointer5); // 关闭文件
}
void xtbaifen(int x, int y, FILE* filePointer5)
{
int i;
int j;
int bfxy[31][2] =
{
//白色点所有可能的位置 31
{ 1 , 2 },
{ 2 , 6 },
{ 2 , 10 },
{ 2 , 13 },
{ 1 , 15 },
{ 3 , 8 },
{ 3 , 18 },
{ 4 , 12 },
{ 5 , 4 },
{ 5 , 8 },
{ 5 , 14 },
{ 5 , 16 },
{ 5 , 17 },
{ 7 , 9 },
{ 10 , 2 },
{ 10 , 3 },
{ 10 , 8 },
{ 10 , 13 },
{ 10 , 17 },
{ 12 , 8 },
{ 12 , 10 },
{ 14 , 6 },
{ 14 , 13 },
{ 15 , 2 },
{ 15 , 16 },
{ 18 , 3 },
{ 17 , 8 },
{ 17 , 13 },
{ 18 , 11 },
{ 19 , 11 },
{ 19 , 17 }
};
int ttemp;
for (i = 0; i < 31; i++)
{
bfxy[i][0] = bfxy[i][0] + x;
bfxy[i][1] = bfxy[i][1] + y;
}
for (j = 0; j < 31; j++)
{
ttemp = rand() % 2;
if (ttemp == 1)
{
setcolor(WHITE);
putpixel(bfxy[j][0], bfxy[j][1], WHITE);
fprintf(filePointer5, "%d %d\n", bfxy[j][0], bfxy[j][1]);
}
}
}
void showxtnianchong(void)//小农田
{
FILE* filePointer4;
FILE* filePointer5;
int plantPositions3[104][2];
int judge = 0;
int j;
int x;
int i;
int temp;
temp = randill(3);
x = 0;
i = 0;
filePointer4 = fopen("data//xtxmnian.dat", "w"); // 以读取模式打开文件
filePointer5 = fopen("data//xmncdian.dat", "w"); // 以读取模式打开文件
getxtxiao(plantPositions3);//使得小麦坐标到了plantpositions3
for (x = 0; x < 104; x++)//
{
judge = rand() % temp;
if (judge == 0)
{
xtnianchong(plantPositions3[i][0], plantPositions3[i][1], filePointer5);
fprintf(filePointer4, "%d %d\n", plantPositions3[i][0], plantPositions3[i][1]);
i++;
}
else
{
i++;
}
}
fclose(filePointer4); // 关闭文件
fclose(filePointer5);
}
void xtnianchong(int x, int y, FILE* filePointer5)
{
int i;
int j;
int bfxy[27][2] =
{
//黄色点所有可能的位置 27
{ 4, 1 },
{ 1 , 4 },
{ 1 , 8 },
{ 1 , 12 },
{ 2 , 16 },
{ 3 , 15 },
{ 7 , 3 },
{ 7 , 7 },
{ 5 , 11 },
{ 7 , 13 },
{ 7 , 16 },
{ 8 , 16 },
{ 7 , 18 },
{ 9 , 6 },
{ 10 , 6 },
{ 9 , 11 },
{ 12 , 4 },
{ 12 , 15 },
{ 12 , 18 },
{ 13, 12 },
{ 15 , 8 },
{ 15 , 10 },
{ 17 , 2 },
{ 17 , 6 },
{ 16, 18 },
{ 17 , 18 },
{ 18 , 15 }

};
int ttemp;
for (i = 0; i < 27; i++)
{
bfxy[i][0] = bfxy[i][0] + x;
bfxy[i][1] = bfxy[i][1] + y;
}
for (j = 0; j < 27; j++)
{
ttemp = rand() % 2;
if (ttemp == 1)
{
setcolor(YELLOW);
putpixel(bfxy[j][0], bfxy[j][1], YELLOW);
fprintf(filePointer5, "%d %d\n", bfxy[j][0], bfxy[j][1]);
}
}
}
void showxtymmian(void)//小农田玉米的棉虫病坐标
{
FILE* filePointer4;
FILE* filePointer5;
int plantPositions3[68][2];
int judge = 0;
int j;
int x;
int i;
int temp;
temp = randill(2);
x = 0;
i = 0;
filePointer4 = fopen("data//xtymmian.dat", "w");
filePointer5 = fopen("data//ymmldian.dat", "w");
getxtyumi(plantPositions3);
for (x = 0; x < 68; x++)
{
judge = rand() % temp;
if (judge == 0)
{
xtymmian(plantPositions3[i][0], plantPositions3[i][1], filePointer5);
fprintf(filePointer4, "%d %d\n", plantPositions3[i][0], plantPositions3[i][1]);
i++;
}
else
{
i++;
}
}
fclose(filePointer4); // 关闭文件
fclose(filePointer5); // 关闭文件
}
void xtymmian(int x, int y,FILE* filePointer5)//画出
{
int i;
int j;
int bfxy[27][2] =
{
//蓝色点所有可能的位置 27
{ 5 , 6 },
{ 5 , 8 },
{ 8 , 6 },
{ 10 ,5 },
{ 12 , 6 },
{ 14 , 5 },
{ 15 , 7 },
{ 14 , 9 },
{ 13 , 12 },
{ 13 , 14 },
{ 10 , 19 },
{ 11 , 20 },
{ 9 , 23 },
{ 14 , 18 },
{ 14 , 23 },
{ 14 , 26 },
{ 13 , 29 },
{ 13 , 34 },
{ 16 , 29 },
{ 16 , 34 },
{ 17 , 11 },
{ 17 , 22 },
{ 19 , 20 },
{ 21 , 19 },
{ 23 , 18 },
{ 24 , 21 },
{ 25 , 23 }
};
int ttemp;
for (i = 0; i < 27; i++)
{
bfxy[i][0] = bfxy[i][0] + x;
bfxy[i][1] = bfxy[i][1] + y;
}
for (j = 0; j < 27; j++)
{
ttemp = rand() % 2;
if (ttemp == 1)
{
setcolor(BLUE);
putpixel(bfxy[j][0], bfxy[j][1], BLUE);
fprintf(filePointer5, "%d %d\n", bfxy[j][0], bfxy[j][1]);
}
}
}
void showxtymnian(void)
{
FILE* filePointer4;
FILE* filePointer5;
int plantPositions3[68][2];
int judge = 0;
int j;
int x;
int i;
int temp;
temp = randill(2);
x = 0;
i = 0;
filePointer4 = fopen("data//xtymnian.dat", "w");
filePointer5 = fopen("data//ymncdian.dat", "w");
getxtyumi(plantPositions3);
for (x = 0; x < 68; x++)
{
judge = rand() % temp;
if (judge == 0)
{
xtymnian(plantPositions3[i][0], plantPositions3[i][1], filePointer5);
fprintf(filePointer4, "%d %d\n", plantPositions3[i][0], plantPositions3[i][1]);
i++;
}
else
{
i++;
}
}
fclose(filePointer4);
fclose(filePointer5);
}
void xtymnian(int x, int y, FILE* filePointer5)
{
int i;
int j;
int bfxy[26][2] =
{
//蓝色点所有可能的位置 26
{ 3 , 10 },
{ 4 , 7 },
{ 6 , 4 },
{ 6 , 6 },
{ 8 , 8 },
{ 11 , 5 },
{ 10, 6 },
{ 14 , 3 },
{ 16 , 5 },
{ 13 , 8 },
{ 12 , 10 },
{ 24 , 19 },
{ 23 , 20 },
{ 26 , 24 },
{ 16 , 20 },
{ 17 , 20 },
{ 14 , 20 },
{ 9 , 21 },
{ 9 , 26 },
{ 13 , 25 },
{ 15 , 27 },
{ 15 , 32 },
{ 13 , 31 },
{ 14 , 21 },
{ 15 , 23 },
{ 11 , 21 }
};
int ttemp;
for (i = 0; i < 26; i++)
{
bfxy[i][0] = bfxy[i][0] + x;
bfxy[i][1] = bfxy[i][1] + y;
}
for (j = 0; j < 26; j++)
{
ttemp = rand() % 2;
if (ttemp == 1)
{
setcolor(YELLOW);
putpixel(bfxy[j][0], bfxy[j][1], YELLOW);
fprintf(filePointer5, "%d %d\n", bfxy[j][0], bfxy[j][1]);
}
}
}
void showxtmhmian(void)//小农田 棉花的棉铃虫病坐标
{
FILE* filePointer4;
FILE* filePointer5;
int plantPositions3[68][2];
int judge = 0;
int j;
int x;
int i;
int temp;
temp = randill(1);
x = 0;
i = 0;
filePointer4 = fopen("data//xtmhmian.dat", "w");
filePointer5 = fopen("data//mhmldian.dat", "w");
getxtmianhua(plantPositions3);
for (x = 0; x < 68; x++)
{
judge = rand() % temp;
if (judge == 0)
{
xtmhmian(plantPositions3[i][0], plantPositions3[i][1],filePointer5);
fprintf(filePointer4, "%d %d\n", plantPositions3[i][0], plantPositions3[i][1]);
i++;
}
else
{
i++;
}
}
fclose(filePointer4);
fclose(filePointer5);
}
void xtmhmian(int x, int y, FILE* filePointer5)
{
int i;
int j;
int bfxy[33][2] =
{
// 33
{ 9 , 2 },
{ 9 , 5 },
{ 8 , 6 },
{ 11 , 3 },
{ 12 , 6 },
{ 11 , 9 },
{ 5 , 12 },
{ 4 , 14 },
{ 6 , 15 },
{ 9 , 15 },
{ 5 , 18 },
{ 11 , 16 },
{ 12 , 13 },
{ 13 , 20 },
{ 12 , 23 },
{ 11 , 25 },
{ 13 , 25 },
{ 12 , 27 },
{ 12 , 29 },
{ 16 , 2 },
{ 16 , 4 },
{ 14 , 5 },
{ 15 , 8 },
{ 13 , 9 },
{ 13 , 11 },
{ 17 , 6 },
{ 19 , 6 },
{ 20 , 8 },
{ 19 , 12 },
{ 18 , 15 },
{ 20 , 15 },
{ 19 , 18 },
{ 21 , 18 }
};
int ttemp;
for (i = 0; i < 33; i++)
{
bfxy[i][0] = bfxy[i][0] + x-1;
bfxy[i][1] = bfxy[i][1] + y+1;
}
for (j = 0; j < 33; j++)
{
ttemp = rand() % 2;
if (ttemp == 1)
{
setcolor(BLUE);
putpixel(bfxy[j][0], bfxy[j][1], BLUE);
fprintf(filePointer5, "%d %d\n", bfxy[j][0], bfxy[j][1]);
}
}
}
void showxtmhxiu(void)
{
FILE* filePointer4;
FILE* filePointer5;
int plantPositions3[68][2];
int judge = 0;
int j;
int x;
int i;
int temp;
temp = randill(1);
x = 0;
i = 0;
filePointer4 = fopen("data//xtmhxiu.dat", "w");
filePointer5 = fopen("data//mhxbdian.dat", "w");
getxtmianhua(plantPositions3);
for (x = 0; x < 68; x++)
{
judge = rand() % temp;
if (judge == 0)
{
xtmhxiu(plantPositions3[i][0], plantPositions3[i][1], filePointer5);
fprintf(filePointer4, "%d %d\n", plantPositions3[i][0], plantPositions3[i][1]);
i++;
}
else
{
i++;
}
}
fclose(filePointer4);
fclose(filePointer5);
}
void xtmhxiu(int x, int y, FILE* filePointer5)//
{
int i;
int j;
int bfxy[35][2] =
{
//洋红色点所有可能的位置 35
{ 8 , 0 },
{ 6 , 5 },
{ 5 , 6 },
{ 4 , 16 },
{ 6 , 13 },
{ 8 , 14 },
{ 7 , 17 },
{ 11 , 1 },
{ 10 , 2 },
{ 10 , 8 },
{ 10 , 7 },
{ 11 , 12 },
{ 11 , 15 },
{ 11 , 18 },
{ 11 , 20 },
{ 11 , 22 },
{ 11 , 31 },
{ 12 , 32 },
{ 12 , 10 },
{ 13 , 15 },
{ 13 , 16 },
{ 13 , 18 },
{ 13 , 22 },
{ 13 , 30 },
{ 14 , 10 },
{ 16 , 9 },
{ 18 , 4 },
{ 18 , 8 },
{ 20 , 6 },
{ 17 , 13 },
{ 18 , 17 },
{ 19 , 14 },
{ 19 , 16 },
{ 21 , 14 },
{ 21 , 17 }
};
int ttemp;
for (i = 0; i < 35; i++)
{
bfxy[i][0] = bfxy[i][0] + x-1;
bfxy[i][1] = bfxy[i][1] + y+1;
}
for (j = 0; j < 35; j++)
{
ttemp = rand() % 2;
if (ttemp == 1)
{
setcolor(LIGHTRED);
putpixel(bfxy[j][0], bfxy[j][1], LIGHTRED);
fprintf(filePointer5, "%d %d\n", bfxy[j][0], bfxy[j][1]);
}
}
}

其实这里有很多重复的代码和东西,一个农田只看一种植物的一种病就可以了。。其他都是复制粘贴的,说实话。建议不用细看,因为颜色点的随机显示,老师根本不注重,而且不会细看。。。现在让我自己看,我也看不懂 。

recover

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "common.h"

//===========================
//大农田里面的部分植物自愈
//===========================
void recover(void)//完全随机重新刷新;;
{
int j;//跳过区域用
int jia1[] = { 25,75,25,75,25,75,25,75 };//跳过玉米区域。
int jia2[] = { 25,75,25,75,25,75,25,75 };//跳过小麦区域。
int x, y;//循环
int i = 0;//调用患病植株坐标
int ii;//同上
int judge = 0;//恢复比例的分子
int temp1, temp2;//自愈比例分母
temp1 = randrecover(0);//小麦自愈比例
temp2 = randrecover(1);//玉米自愈比例
for (x = 20; x < 620 - 25 + 1; x = x + 25)//小麦区域,
{
j = -1;
for (y = 65; y < 465; y = y + jia1[j])//
{
j++;
judge = rand() % temp1;//
if (judge == 0)//
{
setcolor(BROWN);
setfillstyle(1, BROWN);
bar(x, y, x + 25, y + 25);//矩形覆盖原生病植物。再画健康植物
fxiaomai(x, y);
nian.bfzuobiao[i][0] = 0;
nian.bfzuobiao[i][1] = 0;
bai.bfzuobiao[i][0] = 0;
bai.bfzuobiao[i][1] = 0;//使其为0;表示其恢复健康。
i++;
}
else i++;
}
}
i = 192;
ii = 0;
for (x = 20; x < 620 - 25 + 1; x = x + 25)//玉米区域
{
j = -1;
for (y = 65 + 50; y < 465; y = y + jia2[j])//
{
j++;
judge = rand() % temp2;//
if (judge == 0)//
{
setcolor(BROWN);
setfillstyle(1, BROWN);
bar(x, y, x + 25, y + 25);
fyumi(x,y);
mian.bfzuobiao[ii][0] = 0;
mian.bfzuobiao[ii][1] = 0;//使其为0,表示健康
nian.bfzuobiao[i][0] = 0;
nian.bfzuobiao[i][1] = 0;//
i++;
ii++;
}
else
{
i++;//表示仍然患病,跳过
ii++;
}
}
}
}
int randrecover(int k)//恢复比例分配
{
int i;
int a[2][10] =
{
{1,1,2,2,2,2, 2,3,3,4},//小麦

{1,1,2,2,2,2, 2,3,3,4}//玉米的
};
i = rand() % 10;
return a[k][i];
}

这里的生病、自愈都是完全用随机数搞的,但实际上验收老师就看了一两遍无人机扫描结果,所以根本没有用。。。

elsetian

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
#include "common.h"
// 画植物,均为左上角坐标。
void drawPlants(void)
{
// 绘制固定位置的植物
int i;
//玉米的坐标30*35
int plantPositions1[][2] =//直接穷举法列举出植物坐标
{
//梯田那部分。11个
{100,100},
{ 3 , 92 },
{ 73 , 89 },
{ 46 , 171 },
{ 138 , 213 },
{ 99 , 154 },
{ 120 , 151 },
{ 9 , 120 },
{ 65 , 140 },
{ 158 , 156 },
{ 89 , 199 },
//最右上角一块 5
{ 501 , 238 },
{ 598 , 265 },
{ 598 , 227 },
{ 574 , 144 },
{ 544 ,132 },
// 第三块 18
{ 350 , 95 },
{ 356 , 132 },
{ 366 , 168 },
{ 379 , 204 },
{ 392 , 243},
{ 469 , 100},
{ 470 , 139 },
{ 470 , 215 },
{ 470 , 175 },
{ 470 , 254 },
{ 473 , 294 },
{ 416 , 265 },
{ 447 , 291 },
{ 405 , 197 },
{ 416 , 231 },
{ 445 , 254 },
{ 438 , 220 },
{ 452 , 191 },
// 最上面区域 6个
{ 0,256 },
{ 31 , 283 },
{ 66 , 291 },
{ 149 , 281 },
{ 120 , 289 },
{ 94 , 293 },
{ 105 , 330 },
{ 108 , 367 },
{ 118 , 437 },
{ 111 , 402 },
{ 55 , 326 },
{ 69 , 421 },
{ 67 , 358 },
{ 177 , 321 },
{ 181 , 349 },
{ 188, 414 },
{ 195 , 380 },
{ 207 , 329 },
{ 212 , 365 },
{ 212, 411 },
{ 232 , 330 },
{ 236 , 366 },
{ 236 , 443 },
{ 236 , 405 },
{ 608 , 380 },
{ 592 , 411 },
{ 611 , 442 },
{ 328 , 443 },
{ 371 , 406 },
{ 376 , 369 },
{ 379 , 332 },
{ 337 , 406 },
{ 337 , 369 },
{ 346 , 332 }
};
//棉花的20*35
int plantPositions2[][2] =
{
//梯田那部分。12个
{ 31 , 89 },
{ 53 , 85 },
{ 123 , 111 },
{ 75 , 182 },
{ 115 , 193 },
{ 165 , 198 },
{ 147 , 136 },
{ 45 , 117 },
{ 28 , 145 },
{ 90 , 123 },
{ 141 , 176 },
{ 502 , 90 },
{ 502 , 305 },
{ 502 , 129 },
{ 502 , 157 },
{ 502 , 199 },
{ 502 , 278 },
{ 530 , 315 },
{ 605 , 305 },
{ 582 , 308 },
{ 556 , 311 },
{ 521 , 103 },
{ 585 , 123 },
{ 605 , 129 },
//中间 23
{ 283 , 87 },
{ 304 , 87 },
{ 284, 128 },
{ 271 , 153 },
{ 306 , 125 },
{ 316 , 156 },
{ 259 , 181 },
{ 249 , 218},
{ 326, 194 },
{ 283 , 181 },
{ 305 , 188 },
{ 279 , 222 },
{ 305 , 227 },
{ 335 , 228 },
{ 364 , 271 },
{ 340, 284 },
{ 317, 290 },
{ 296 , 293 },
{ 443 , 155 },
{ 416, 148 },
{ 427 , 177},
{ 320 , 252 },
{ 264 , 331 },
{ 265 , 369 },
{ 264 , 443 },
{ 264, 406 },
{ 286 , 331 },
{ 287 , 369 },
{ 286 , 406 },
{ 285 , 443 },
{ 314 , 332 },
{ 309 , 443 },
{ 310 , 405 },
{ 308 , 368 },
{ 583 , 365 },
{ 517 , 406 },
{ 493 , 439 },
{ 517 , 442 },
{ 574 , 440 },
{ 547 , 442 },
{ 538 , 403 },
{ 565 , 403 },
{ 550 , 366 },
{ 360 , 443 }
};
//小麦占地.20*19 总共104个
int plantPositions3[][2] =
{
//最右上角一块
{ 607 , 166 },
{ 609 , 189 },
{ 604 , 210 },
{ 525 , 144 },
{ 532 , 167 },
{ 524 , 189 },
{ 544 , 189 },
{ 562 , 189 },
{ 586 , 183},
{ 556 , 170 },
{ 526 , 212 },
{ 548 , 212 },
{ 569 , 212 },
{ 584 , 204 },
{ 534 , 237 },
{ 559 , 236 },
{ 532 , 265 },
{ 527 , 290 },
{ 555 , 285 },
{ 579 , 283 },
{ 553 , 259 },
{ 576 , 262 },
{ 581 , 240 },
// 中间
{ 260 , 104 },
{ 257 , 128 },
{ 249 , 153 },
{ 242 , 178 },
{ 234 , 202 },
{ 227 , 226 },
{ 220 , 250 },
{ 213 , 274 },
{ 230 , 275 },
{ 230 , 299},
{ 327 , 104 },
{ 330 , 128 },
{ 336 , 151 },
{ 344 , 174 },
{ 351 , 198 },
{ 357 , 222 },
{ 364 , 247 },
//第三块 8
{ 385 , 106 },
{ 410 , 108 },
{ 434 , 108 },
{ 389 , 133 },
{ 415 , 134 },
{ 445 , 135 },
{ 393, 161 },
// 整个上区域 20
{231 , 107 },
{ 228 , 130 },
{ 222 , 152 },
{ 215 , 173 },
{ 207 , 197 },
{ 200 , 223 },
{ 190 , 249 },
{ 182 , 271 },
{ 194 , 288 },
{ 204 , 108 },
{ 176 , 108 },
{ 150 , 107 },
{ 169 , 132 },
{ 196 , 132 },
{ 188 , 154 },
{ 192 , 176 },
{ 33 , 261 },
{ 59 , 272 },
{ 83 , 275 },
{ 2 , 235 },
//所有下方区域 32
{ 131 , 330 },
{ 133 , 353 },
{ 137, 377 },
{ 142 , 401 },
{ 146 , 425 },
{ 146 , 450 },
{ 157 , 331 },
{ 159 , 353 },
{ 162 , 378 },
{ 167 , 402 },
{ 170 , 425},
{ 168 , 455 },
{ 10 , 342 },
{ 22 , 365 },
{ 29 , 392 },
{ 21 , 437 },
{ 28 , 415 },
{ 36 , 337 },
{ 47 , 361 },
{ 53 , 387 },
{ 54 , 411 },
{ 52 , 434 },
{ 465 , 378 },
{ 470 , 406 },
{ 469 , 432 },
{ 469 , 456 },
{ 443 , 391 },
{ 445 , 415 },
{ 443 , 444 },
{ 420 , 412},
{ 419 , 447 },
{ 393 , 455 },
{ 88 , 341 },
{90,384 },
{72 ,399 },
{93 ,413 },
{ 97,437 }
};
for (i = 0; i < sizeof(plantPositions1) / sizeof(plantPositions1[0]); i++)//画植物
{
yumi(plantPositions1[i][0], plantPositions1[i][1]);
}
for (i = 0; i < sizeof(plantPositions2) / sizeof(plantPositions2[0]); i++)//
{
mianhua(plantPositions2[i][0], plantPositions2[i][1]);
}
for (i = 0; i < sizeof(plantPositions3) / sizeof(plantPositions3[0]); i++)
{
xiaomaikuai(plantPositions3[i][0], plantPositions3[i][1]);
}
setxtzhiwu(plantPositions1, plantPositions2, plantPositions3);//记录植物的坐标
}
//============================================================
//小农田主界面
int elsetian(int* a5)
{
srand(time(NULL));
if (*a5 == 1)//绘图
{
cleardevice();
clrmous(MouseX, MouseY);
drawBackground();
//梯田
bmp_convert("5.bmp", "5.dbm");
open_display();
show_dbm(0, 100, "5.dbm", 0);//208*180
tian();//画农田。
bmp_convert("stone.bmp", "stone.dbm");
open_display();
drawPlants();//画植物
drawdxg(250, 240);
show_dbm(194, 447, "stone.dbm", 0);//石头
drawScarecrow(570, 61);//稻草人1
drawScarecrow(500, 325);//稻草人2
*a5 = 0;
}
//=============
//恢复农田
if (*a5 == -1)
{
cleardevice();
clrmous(MouseX, MouseY);
drawBackground();
bmp_convert("5.bmp", "5.dbm");
open_display();
show_dbm(0, 100, "5.dbm", 0);//208*180
tian();//画农田。
bmp_convert("stone.bmp", "stone.dbm");
open_display();
drawPlants();//画植物
drawdxg(250, 240);
show_dbm(194, 447, "stone.dbm", 0);//石头
drawScarecrow(570, 61);//稻草人1
drawScarecrow(500, 325);//稻草人2
binghai();
*a5 = 2;
}
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);
showbiankuang(100, 5, 100 + 140, 50);
//界面的跳转
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a5 = 1;
return 1;//返回前一个界面
}
else if (mouse_press(100, 5, 240, 50) == 1)
{
delay(100);
clrmous(MouseX, MouseY);
grow();//无人机动画的实现
if (*a5 == 2 || *a5 == -1)
{
delay(200);
cleardevice();
clrmous(MouseX, MouseY);
drawBackground();
bmp_convert("5.bmp", "5.dbm");
open_display();
show_dbm(0, 100, "5.dbm", 0);//208*180
tian();//画农田。
bmp_convert("stone.bmp", "stone.dbm");
open_display();
drawPlants();//画植物
drawdxg(250, 240);
show_dbm(194, 447, "stone.dbm", 0);//石头
drawScarecrow(570, 61);//稻草人1
drawScarecrow(500, 325);//稻草人2
}
showxtbaifen();
showxtnianchong();
showxtymmian();
showxtymnian();
showxtmhxiu();
showxtmhmian();
*a5 = 2;
}
if (*a5 == 2 || *a5 == -1)
{
showbiankuang(100 + 140 + 30, 5, 100 + 140 + 30 + 140, 50);
showbiankuang(100 + 140 + 140 + 30 + 30, 5, 100 + 140 + 140 + 30 + 30 + 140, 50);
if (mouse_press(100 + 140 + 30, 5, 100 + 140 + 30 + 140, 50) == 1)
{
*a5 = -1;
delay(100);
return 5;//结果查看部分
}
else if (mouse_press(100 + 140 + 140 + 30 + 30, 5, 100 + 140 + 140 + 30 + 30 + 140, 50) == 1)
{
*a5 = -1;
delay(100);
return 7;//准备喷洒部分
}
}
return 3;
}
// 画稻草人
void drawScarecrow(int x, int y)
{
setcolor(BROWN);
setfillstyle(SOLID_FILL, YELLOW);
fillellipse(x, y, 10, 10);
setfillstyle(SOLID_FILL, DARKGRAY);
fillellipse(x, y - 5, 15, 5);
setfillstyle(SOLID_FILL, BLACK);
fillellipse(x - 3, y + 2, 2, 2);
fillellipse(x + 3, y + 2, 2, 2);
setfillstyle(SOLID_FILL, YELLOW);
bar(x - 5, y + 10, x + 5, y + 60);
bar(x - 20, y + 10, x - 5, y + 15);
bar(x + 5, y + 10, x + 20, y + 15);
bar(x - 2, y + 60, x + 2, y + 80);
}
void drawdxg(int x, int y)//电线杆
{
setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
bar(14 + x, y, 18 + x, 83 + y);
line(x + 0, y +26 , x +25 , y +18 );
line(x +25 , y +18 , x +25 , y +21 );
line(x + 25, y + 21, x +0 , y +29 );
line(x + 0, y +29 , x +0 , y +26 );
floodfill(x+8, y+25, LIGHTGRAY);
floodfill(x+21,y+ 20, LIGHTGRAY);
line(x + 3, y +6 , x + 27, y + 13);
line(x + 27, y +13 , x +27 , y +17 );
line(x + 27, y +17 , x +1 , y +9 );
line(x + 1, y +9 , x + 2, y + 6);
line(x + 2, y +6 , x + 3, y + 6);
floodfill(x + 10, y + 9, LIGHTGRAY);
floodfill(x + 20, y + 13, LIGHTGRAY);
}
// 画不规则形状的农田
void tian(void)
{
int points1[] = { 150,480,130,335, 285,480 - 130,405,335,400,430,500,370,640,405,640,480 };//最下面中间的
int points2[] = { 400,280,500,360, 640,340,640,116,200,116,200,280 };//上面的
setcolor(BROWN);
setfillstyle(1, BROWN);
arc(-62, 420, 0, 360, 90);
arc(70, 560, 0, 360, 105);
line(140, 480, 125, 335);
line(125, 335, 0, 352);
floodfill(100, 420, BROWN);//左下角的
fillpoly(8, points1);//多边形绘制
fillpoly(6, points2);//多边形绘制
line(0, 280, 210, 280);
ellipse(100, 280, 180, 360, 100, 50);//椭圆
floodfill(100, 290, BROWN);
line(0 + 200, 280, 210 + 200 - 10, 280);
ellipse(100 + 200, 280, 180, 360, 100, 50);//椭圆
floodfill(100 + 200, 290, BROWN);
line(150, 280 + 20 + 10, 280, 300 + 10);
floodfill(200, 290, BROWN);
line(400, 280, 500, 360);
line(500, 360, 640, 340);
line(640, 340, 640, 116);
line(110, 116, 640, 116);
line(200, 116, 200, 280);
line(200, 280, 400, 280);
line(400, 280, 500, 360);
line(500, 360, 640, 340);
line(640, 340, 640, 116);
line(110, 116, 640, 116);
line(200, 116, 200, 280);
line(200, 280, 400, 280);
setfillstyle(1, BLUE);
floodfill(630, 350, BROWN);
floodfill(10, 400, BROWN);
floodfill(100, 470, BROWN);
setcolor(WHITE);
line(208, 280, 258, 116);
line(400, 280 + 1, 350, 116);
line(500, 360 - 1, 500, 116);
setfillstyle(1, GREEN);
setcolor(GREEN);
line(0, 98, 640, 98);//分割线
line(630, 116, 640, 116);
line(640, 116, 640, 340);
line(640, 340, 630, 342);
line(630, 342, 630, 116);
floodfill(632, 120, GREEN);
}

void binghai(void)//画病害
{
int row;
FILE* filePointer1;
FILE* filePointer2;
FILE* filePointer3;
FILE* filePointer4;
FILE* filePointer5;
FILE* filePointer6;
int a22[68 * 35][2] = { 0 };
int a11[103 * 31][2] = { 0 };
filePointer1 = fopen("data//xmbfdian.dat", "r");
for (row = 0; row < 103 * 31; row++)
{
fscanf(filePointer1, "%d %d", &a11[row][0], &a11[row][1]);
}
fclose(filePointer1);
for (row = 0; row < 103 * 31; row++)//
{
setcolor(WHITE);
putpixel(a11[row][0], a11[row][1], WHITE);
}
for (row = 0; row < 103 * 31; row++)
{
a11[row][0] = 0;
a11[row][1] = 0;
}
filePointer2 = fopen("data//xmncdian.dat", "r");
for (row = 0; row < 103 * 31; row++)
{
fscanf(filePointer2, "%d %d", &a11[row][0], &a11[row][1]);
}
for (row = 0; row < 103 * 31; row++)
{
setcolor(YELLOW);
putpixel(a11[row][0], a11[row][1], YELLOW);
}
fclose(filePointer2);
filePointer3 = fopen("data//ymncdian.dat", "r");
for (row = 0; row < 68 * 35; row++)
{
fscanf(filePointer3, "%d %d", &a22[row][0], &a22[row][1]);
}
for (row = 0; row < 68 * 35; row++)
{
setcolor(YELLOW);
putpixel(a22[row][0], a22[row][1], YELLOW);
}
fclose(filePointer3);
for (row = 0; row < 68 * 35; row++)
{
a22[row][0] = 0;
a22[row][1] = 0;
}
filePointer4 = fopen("data//ymmldian.dat", "r");
for (row = 0; row < 68 * 35; row++)
{
fscanf(filePointer4, "%d %d", &a22[row][0], &a22[row][1]);
}
for (row = 0; row < 68 * 35; row++)
{
setcolor(BLUE);
putpixel(a22[row][0], a22[row][1], BLUE);
}
fclose(filePointer4);
for (row = 0; row < 68 * 35; row++)
{
a22[row][0] = 0;
a22[row][1] = 0;
}
filePointer5 = fopen("data//mhmldian.dat", "r");
for (row = 0; row < 68 * 35; row++)
{
fscanf(filePointer5, "%d %d", &a22[row][0], &a22[row][1]);
}
for (row = 0; row < 68 * 35; row++)
{
setcolor(BLUE);
putpixel(a22[row][0], a22[row][1], BLUE);
}
fclose(filePointer5);
for (row = 0; row < 68 * 35; row++)
{
a22[row][0] = 0;
a22[row][1] = 0;
}
filePointer6 = fopen("data//mhxbdian.dat", "r");
for (row = 0; row < 68 * 35; row++)
{
fscanf(filePointer6, "%d %d", &a22[row][0], &a22[row][1]);
}
for (row = 0; row < 68 * 35; row++)
{
setcolor(LIGHTRED);
putpixel(a22[row][0], a22[row][1], LIGHTRED);
}
fclose(filePointer6);
}

类似大农田,实现的功能类似。加了个显示高度的功能。好累啊,自己看吧

outcome.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef _OUTCOME_H_
#define _OUTCOME_H_
//=大农田的 结果查看
int outcome(int* a3);//核心
void draw111(void);//普通绘图
void xiaomaioutcome(void);//小麦结果
void yumioutcome(void);//玉米结果
//=====================================
int elseoutcome(int* a3);
void draw222(void);
void elseyumioutcome(void);
void elsexiaomaioutcome(void);
void elsemianhuaoutcome(void);
#endif

outcome.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
#include"common.h"
/*=========================
大农田小麦结果查看
===========================*/
void xiaomaioutcome(void)
{
int y2, y3, y4;
int i;
double yt;
char string[20];
yt = 0;
y2 = 0;
y3 = 0;
y4 = 0;
draw111();
setcolor(GREEN);
line(64, 419, 563, 419);
line(556-5, 406, 563, 419);
line(563, 419, 556-5, 432);
line(64, 419, 64, 76);
line(64, 76, 53, 88);
line(64, 76, 72, 88);
puthz(200, 50, "小麦生长状况柱形图", 16, 15, GREEN);
puthz(400, 50, "总体:", 16, 15, GREEN);
puthz(70, 80, "占总小麦面积比例", 16, 15, GREEN);
puthz(200, 50, "小麦生长状况柱形图", 16, 15, GREEN);
line(63, 119, 65, 119);
settextstyle(1, HORIZ_DIR, 1);
outtextxy(15, 110, "100%");
line(63, 419-150, 65, 419 - 150);
outtextxy(15, 419 - 150-9, "50%");
line(63, 419-75, 65, 419 - 75);
outtextxy(15, 419 - 75-9, "25%");
line(63, 419 - 225, 65, 419 - 225);
outtextxy(15, 419 - 225-9, "75%");
line(84, 418, 84, 420);
line(84+70, 418, 84+70, 420);
puthz(84+20, 430, "健康", 16, 15, GREEN);
line(84+70+30, 418, 84+70+30, 420);
line(84 + 70 + 30+70, 418,84 + 70 + 30+70, 420);
puthz(84+70+30+5, 430, "患白粉病", 16, 15, GREEN);
line(84 + 70 + 30 + 70+30, 418, 84 + 70 + 30 + 70+30, 420);
line(84 + 70 + 30 + 70 + 30+70, 418, 84 + 70 + 30 + 70+70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30+5, 430, "感染黏虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30 + 70+30, 418, 84 + 70 + 30 + 70 +30+ 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70+70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 +70+ 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 70 + 30, 430, "两种均感染", 16, 15, GREEN);
for (i = 0; i < 192; i++)
{
if (bai.bfzuobiao[i][0] == 0 && bai.bfzuobiao[i][1] == 0&& nian.bfzuobiao[i][0] == 0 && nian.bfzuobiao[i][1]==0)
{
yt+=1;
}
if (bai.bfzuobiao[i][0] != 0 && bai.bfzuobiao[i][1] != 0)
{
y2++;
}
if (nian.bfzuobiao[i][0] != 0 && nian.bfzuobiao[i][1] != 0)
{
y3++;
}
if(bai.bfzuobiao[i][0] != 0 && bai.bfzuobiao[i][1] != 0&& nian.bfzuobiao[i][0] != 0 && nian.bfzuobiao[i][1] != 0)
{
y4++;
}
}
setcolor(RED);
settextstyle(1, HORIZ_DIR, 1);
bar(84, 419 - (yt * 300) / 192, 84 + 70, 419);
sprintf(string, "%.lf/192", yt);
outtextxy(84, 419 - (yt * 300) / 192-20, string);
bar(84 + 100 + 70,419 - (y2 * 300) / 192, 84 + 100, 419 );
sprintf(string, "%d/192", y2);
outtextxy(84 + 100 , 419 - (y2 * 300) / 192-20, string);
bar( 84 + 270, 419 - (y3 * 300) / 192, 84 + 200, 419);
sprintf(string, "%d/192", y3);
outtextxy(84 + 200, 419 - (y3 * 300) / 192-20, string);
bar(84 +370, 419 - (y4 * 300) / 192,84 + 300, 419 );
sprintf(string, "%d/192", y4);
outtextxy(84 + 300, 419 - (y4 * 300) / 192-20, string);
if (yt >= 192 - 8)
{
puthz(370 + 84, 50, "健康", 16, 15, GREEN);//
}
else if (yt >= 192 - 15)
{
puthz(370 + 84, 50, "正常", 16, 15, GREEN);//
}
else if (yt >= 192 - 25)
{
puthz(370 + 84, 50, "病虫预防", 16, 15, GREEN);//
}
else if (yt >= 192 - 35)
{
puthz(370 + 84, 50, "急需喷洒", 16, 15, GREEN);//
}
else if (yt >= 192 - 60)
{
puthz(370 + 84, 50, "严重病害", 16, 15, GREEN);//
}
else
{
puthz(370 + 84, 50, "重大病害", 16, 15, GREEN);//
}
}
/*=========================
大农田结果查看
===========================*/
int outcome(int* a3)
{
if (*a3 == 1)
{
cleardevice();
draw111();
*a3 = 0;
}
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);
showbiankuang(311 - 25, 3, 421, 37);
showbiankuang(442, 3, 546 + 25, 37);
//界面的跳转
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a3 = 1;
delay(100);
return 2;//返回前一个界面
}
else if (mouse_press(311 - 25, 3, 421, 35) == 1&&( *a3==0 || *a3== 3))
{
*a3 = 2;
cleardevice();
delay(100);
xiaomaioutcome();
//小麦的
}
else if (mouse_press(442, 3, 546 + 25, 35) == 1 && (*a3 == 0 || *a3 == 2))
{
*a3 = 3;
cleardevice();
delay(100);
yumioutcome();
//玉米的
}
return 6;
}
/*=========================
小农田结果查看
===========================*/
int elseoutcome(int* a3)
{
if (*a3 == 1)
{
cleardevice();
draw222();
*a3 = 0;
}
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);
showbiankuang(197, 3, 325, 37);
showbiankuang(329, 3, 455, 37);
showbiankuang(461, 3, 586, 37);
//界面的跳转
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a3 = 1;
delay(100);
return 3;//返回前一个界面
}
else if (mouse_press(197, 3, 325, 37) == 1 && (*a3 == 0 || *a3 == 3 || *a3 == 4))
{
*a3 = 2;
cleardevice();
delay(100);
elsexiaomaioutcome();
//小麦的
}
else if (mouse_press(329, 3, 455, 37) == 1 && (*a3 == 0 || *a3 == 2 || *a3 == 4))
{
*a3 = 3;
cleardevice();
delay(100);
elseyumioutcome();
//玉米的
}
else if (mouse_press(461, 3, 586, 37) == 1 && (*a3 == 0 || *a3 == 2 || *a3 == 3))
{
*a3 = 4;
cleardevice();
delay(100);
elsemianhuaoutcome();
//棉花的
}
return 5;
}
/*=========================
小农田小麦结果查看
===========================*/
void elsexiaomaioutcome(void)
{
int y2, y3, y4;
int i, j;
double yt;
char string[20];
int baifen[103][2];
int nianchong[103][2] ;
FILE* filePointer11;
FILE* filePointer12;
filePointer11 = fopen("data//xtxmbai.dat", "r"); // 以读取模式打开文件
filePointer12 = fopen("data//xtxmnian.dat", "r"); // 以读取模式打开文件
yt = 0;
y2 = 0;
y3 = 0;
y4 = 0;
draw222();
//坐标轴绘制
setcolor(GREEN);
line(64, 419, 563, 419);
line(556 - 5, 406, 563, 419);
line(563, 419, 556 - 5, 432);
line(64, 419, 64, 76);
line(64, 76, 53, 88);
line(64, 76, 72, 88);
puthz(200, 50, "小麦生长状况柱形图", 16, 15, GREEN);
puthz(400, 50, "总体:", 16, 15, GREEN);
puthz(70, 80, "占总小麦面积比例", 16, 15, GREEN);
puthz(200, 50, "小麦生长状况柱形图", 16, 15, GREEN);
line(63, 119, 65, 119);
settextstyle(1, HORIZ_DIR, 1);
outtextxy(15, 110, "100%");
line(63, 419 - 150, 65, 419 - 150);
outtextxy(15, 419 - 150 - 9, "50%");
line(63, 419 - 75, 65, 419 - 75);
outtextxy(15, 419 - 75 - 9, "25%");
line(63, 419 - 225, 65, 419 - 225);
outtextxy(15, 419 - 225 - 9, "75%");
line(84, 418, 84, 420);
line(84 + 70, 418, 84 + 70, 420);
puthz(84 + 20, 430, "健康", 16, 15, GREEN);
line(84 + 70 + 30, 418, 84 + 70 + 30, 420);
line(84 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70, 420);
puthz(84 + 70 + 30 + 5, 430, "患白粉病", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 5, 430, "感染黏虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 70 + 30, 430, "两种均感染", 16, 15, GREEN);
//统计植物病虫害情况。
for (i = 0; i < 103; i++)
{
int a, b;
a=fscanf(filePointer11, "%d %d", &baifen[i][0], &baifen[i][1]) ;
b=fscanf(filePointer12, "%d %d", &nianchong[i][0], &nianchong[i][1]) ;
if (a==2)
{
y2++;
}
if ( b== 2)
{
y3++;
}
}
for (i = 0; i <y2; i++)
{
for (j = 0; j < y3; j++)
{
if (baifen[i][0] == nianchong[j][0] && baifen[i][1] == nianchong[j][1])
{
y4++;
}
}
}
yt = 103 - y2 - y3 + y4;
fclose(filePointer11);
fclose(filePointer12);
//坐标轴。柱形图
setcolor(RED);
settextstyle(1, HORIZ_DIR, 1);
bar(84, 419 - (yt * 300) / 103, 84 + 70, 419);
sprintf(string, "%.lf/103", yt);
outtextxy(84, 419 - (yt * 300) / 103 - 20, string);
bar(84 + 100 + 70, 419 - (y2 * 300) / 103, 84 + 100, 419);
sprintf(string, "%d/103", y2);
outtextxy(84 + 100, 419 - (y2 * 300) / 103 - 20, string);
bar(84 + 270, 419 - (y3 * 300) / 103, 84 + 200, 419);
sprintf(string, "%d/103", y3);
outtextxy(84 + 200, 419 - (y3 * 300) / 103 - 20, string);
bar(84 + 370, 419 - (y4 * 300) / 103, 84 + 300, 419);
sprintf(string, "%d/103", y4);
outtextxy(84 + 300, 419 - (y4 * 300) / 103 - 20, string);
//显示总体评价
if (yt >= 103 - 7)
{
puthz(370 + 84, 50, "健康", 16, 15, GREEN);//
}
else if (yt >= 103 - 13)
{
puthz(370 + 84, 50, "正常", 16, 15, GREEN);//
}
else if (yt >= 103 - 20)
{
puthz(370 + 84, 50, "病虫预防", 16, 15, GREEN);//
}
else if (yt >= 103 - 30)
{
puthz(370 + 84, 50, "急需喷洒", 16, 15, GREEN);//
}
else if (yt >= 103 - 50)
{
puthz(370 + 84, 50, "严重病害", 16, 15, GREEN);//
}
else
{
puthz(370 + 84, 50, "重大病害", 16, 15, GREEN);//
}
}
/*=========================
小农田玉米结果查看
===========================*/
void elseyumioutcome(void)
{
int y2, y3, y4;
int i, j;
double yt;
char string[20];
int baifen[103][2];
int nianchong[103][2];
FILE* filePointer11;
FILE* filePointer12;
filePointer11 = fopen("data//xtymnian.dat", "r"); // 以读取模式打开文件
filePointer12 = fopen("data//xtymmian.dat", "r");
yt = 0;
y2 = 0;
y3 = 0;
y4 = 0;
draw222();
setcolor(GREEN);
line(64, 419, 563, 419);
line(556 - 5, 406, 563, 419);
line(563, 419, 556 - 5, 432);
line(64, 419, 64, 76);
line(64, 76, 53, 88);
line(64, 76, 72, 88);
puthz(200, 50, "玉米生长状况柱形图", 16, 15, GREEN);
puthz(400, 50, "总体:", 16, 15, GREEN);
puthz(70, 80, "占总玉米株数比例", 16, 15, GREEN);
line(63, 119, 65, 119);
settextstyle(1, HORIZ_DIR, 1);
outtextxy(15, 110, "100%");
line(63, 419 - 150, 65, 419 - 150);
outtextxy(15, 419 - 150 - 9, "50%");
line(63, 419 - 75, 65, 419 - 75);
outtextxy(15, 419 - 75 - 9, "25%");
line(63, 419 - 225, 65, 419 - 225);
outtextxy(15, 419 - 225 - 9, "75%");
line(84, 418, 84, 420);
line(84 + 70, 418, 84 + 70, 420);
puthz(84 + 20, 430, "健康", 16, 15, GREEN);
line(84 + 70 + 30, 418, 84 + 70 + 30, 420);
line(84 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70, 420);
puthz(84 + 70 + 30 + 5, 430, "感染黏虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 5, 430, "感染棉铃虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 70 + 30, 430, "两种均感染", 16, 15, GREEN);
for (i = 0; i < 68; i++)
{
int a, b;
a = fscanf(filePointer11, "%d %d", &baifen[i][0], &baifen[i][1]);
b = fscanf(filePointer12, "%d %d", &nianchong[i][0], &nianchong[i][1]);
if (a == 2)
{
y2++;
}
if (b == 2)
{
y3++;
}
}
for (i = 0; i < y2; i++)
{
for (j = 0; j < y3; j++)
{
if (baifen[i][0] == nianchong[j][0] && baifen[i][1] == nianchong[j][1])
{
y4++;
}
}
}
yt = 68 - y2 - y3 + y4;
fclose(filePointer11);
fclose(filePointer12);
setcolor(RED);
settextstyle(1, HORIZ_DIR, 1);
bar(84, 419 - (yt * 300) / 68, 84 + 70, 419);
sprintf(string, "%.lf/68", yt);
outtextxy(84, 419 - (yt * 300) / 68 - 20, string);
bar(84 + 100 + 70, 419 - (y2 * 300) / 68, 84 + 100, 419);
sprintf(string, "%d/68", y2);
outtextxy(84 + 100, 419 - (y2 * 300) / 68 - 20, string);
bar(84 + 270, 419 - (y3 * 300) / 103, 84 + 200, 419);
sprintf(string, "%d/68", y3);
outtextxy(84 + 200, 419 - (y3 * 300) / 68 - 20, string);
bar(84 + 370, 419 - (y4 * 300) / 103, 84 + 300, 419);
sprintf(string, "%d/68", y4);
outtextxy(84 + 300, 419 - (y4 * 300) / 68 - 20, string);
if (yt >= 68 -5)
{
puthz(370 + 84, 50, "健康", 16, 15, GREEN);//
}
else if (yt >= 68 - 10)
{
puthz(370 + 84, 50, "正常", 16, 15, GREEN);//
}
else if (yt >= 68 - 14)
{
puthz(370 + 84, 50, "病虫预防", 16, 15, GREEN);//
}
else if (yt >= 68 - 20)
{
puthz(370 + 84, 50, "急需喷洒", 16, 15, GREEN);//
}
else if (yt >= 68 - 40)
{
puthz(370 + 84, 50, "严重病害", 16, 15, GREEN);//
}
else
{
puthz(370 + 84, 50, "重大病害", 16, 15, GREEN);//
}
}
/*=========================
小农田棉花结果查看
===========================*/
void elsemianhuaoutcome(void)
{
int y2, y3, y4;
int i, j;
double yt;
char string[20];
int baifen[103][2];
int nianchong[103][2];
FILE* filePointer11;
FILE* filePointer12;
filePointer11 = fopen("data//xtmhmian.dat", "r");
filePointer12 = fopen("data//xtmhxiu.dat", "r");
yt = 0;
y2 = 0;
y3 = 0;
y4 = 0;
draw222();
setcolor(GREEN);
line(64, 419, 563, 419);
line(556 - 5, 406, 563, 419);
line(563, 419, 556 - 5, 432);
line(64, 419, 64, 76);
line(64, 76, 53, 88);
line(64, 76, 72, 88);
puthz(200, 50, "棉花生长状况柱形图", 16, 15, GREEN);
puthz(400, 50, "总体:", 16, 15, GREEN);
puthz(70, 80, "占总棉花株数比例", 16, 15, GREEN);
line(63, 119, 65, 119);
settextstyle(1, HORIZ_DIR, 1);
outtextxy(15, 110, "100%");
line(63, 419 - 150, 65, 419 - 150);
outtextxy(15, 419 - 150 - 9, "50%");
line(63, 419 - 75, 65, 419 - 75);
outtextxy(15, 419 - 75 - 9, "25%");
line(63, 419 - 225, 65, 419 - 225);
outtextxy(15, 419 - 225 - 9, "75%");
line(84, 418, 84, 420);
line(84 + 70, 418, 84 + 70, 420);
puthz(84 + 20, 430, "健康", 16, 15, GREEN);
line(84 + 70 + 30, 418, 84 + 70 + 30, 420);
line(84 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70, 420);
puthz(84 + 70 + 30 + 5, 430, "感染棉铃虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 5, 430, "患上锈病", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 70 + 30, 430, "两种均感染", 16, 15, GREEN);
for (i = 0; i < 68; i++)
{
int a, b;
a = fscanf(filePointer11, "%d %d", &baifen[i][0], &baifen[i][1]);
b = fscanf(filePointer12, "%d %d", &nianchong[i][0], &nianchong[i][1]);
if (a == 2)
{
y2++;
}
if (b == 2)
{
y3++;
}
}
for (i = 0; i < y2; i++)
{
for (j = 0; j < y3; j++)
{
if (baifen[i][0] == nianchong[j][0] && baifen[i][1] == nianchong[j][1])
{
y4++;
}
}
}
yt = 68 - y2 - y3 + y4;
fclose(filePointer11);
fclose(filePointer12);
setcolor(RED);
settextstyle(1, HORIZ_DIR, 1);
bar(84, 419 - (yt * 300) / 68, 84 + 70, 419);
sprintf(string, "%.lf/68", yt);
outtextxy(84, 419 - (yt * 300) / 68 - 20, string);
bar(84 + 100 + 70, 419 - (y2 * 300) / 68, 84 + 100, 419);
sprintf(string, "%d/68", y2);
outtextxy(84 + 100, 419 - (y2 * 300) / 68 - 20, string);
bar(84 + 270, 419 - (y3 * 300) / 103, 84 + 200, 419);
sprintf(string, "%d/68", y3);
outtextxy(84 + 200, 419 - (y3 * 300) / 68 - 20, string);
bar(84 + 370, 419 - (y4 * 300) / 103, 84 + 300, 419);
sprintf(string, "%d/68", y4);
outtextxy(84 + 300, 419 - (y4 * 300) / 68 - 20, string);
if (yt >= 68 - 5)
{
puthz(370 + 84, 50, "健康", 16, 15, GREEN);//
}
else if (yt >= 68 - 9)
{
puthz(370 + 84, 50, "正常", 16, 15, GREEN);//
}
else if (yt >= 68- 15)
{
puthz(370 + 84, 50, "病虫预防", 16, 15, GREEN);//
}
else if (yt >= 68 - 25)
{
puthz(370 + 84, 50, "急需喷洒", 16, 15, GREEN);//
}
else if (yt >= 68 - 34)
{
puthz(370 + 84, 50, "严重病害", 16, 15, GREEN);//
}
else
{
puthz(370 + 84, 50, "重大病害", 16, 15, GREEN);//
}
}
/*=========================
绘制大农田普适背景
===========================*/
void draw111(void)
{
setbkcolor(WHITE);
setcolor(RED);
setfillstyle(1, GREEN);
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);//关闭按钮
rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);
line(0, 40, 640, 40);
setfillstyle(1, WHITE);
bar(90, 1, 140, 22);
setcolor(GREEN);
puthz(90 + 2, 1 + 2, "白粉病", 16, 15, GREEN);
setfillstyle(1, BLUE);
bar(145, 1, 195, 22);
puthz(145 + 2, 1 + 2, "棉铃虫", 16, 15, GREEN);
setfillstyle(1, YELLOW);
bar(200, 1, 250, 22);
puthz(200 + 2, 1 + 2, "黏虫病", 16, 15, GREEN);
setfillstyle(1, GREEN);
bar(311 - 25, 3, 421, 37);
bar(442, 3, 546 + 25, 37);
puthz(311 - 25 + 2, 3, "小麦情况", 32, 30, WHITE);
puthz(442 + 2, 3, "玉米情况", 32, 30, WHITE);
}
/*=========================
绘制小农田普适背景
===========================*/
void draw222(void)
{
setbkcolor(WHITE);
setcolor(RED);
setfillstyle(1, GREEN);
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);//关闭按钮
rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);
line(0, 40, 640, 40);
setfillstyle(1, WHITE);
bar(90, 0, 140, 19);
setcolor(GREEN);
puthz(90 + 2, 0 + 2, "白粉病", 16, 15, GREEN);
setfillstyle(1, BLUE);
bar(145, 0, 195, 19);
puthz(145 + 2, 0 + 2, "棉铃虫", 16, 15, GREEN);
setfillstyle(1, YELLOW);
bar(90, 19, 140, 38);
puthz(90 + 2, 19 + 2, "黏虫病", 16, 15, GREEN);
setfillstyle(1, LIGHTRED);
bar(145, 19, 195, 38);
puthz(145 + 2, 19 + 2, "锈病", 16, 15, GREEN);
setfillstyle(1, GREEN);
bar(197, 3, 325, 37);
bar(329, 3, 455, 37);
bar(461, 3, 586, 37);
puthz(197 + 2, 3, "小麦情况", 32, 30, WHITE);
puthz(329 + 2, 3, "玉米情况", 32, 30, WHITE);
puthz(461 + 2, 3, "棉花情况", 32, 30, WHITE);
}
/*=========================
大农田玉米结果查看
===========================*/
void yumioutcome(void)
{
int y2, y3, y4;
int i;
double y1;
char string[20];
int j;
y1 = 0;
y2 = 0;
y3 = 0;
y4 = 0;
draw111();
setcolor(GREEN);
line(64, 419, 563, 419);
line(556 - 5, 406, 563, 419);
line(563, 419, 556 - 5, 432);
line(64, 419, 64, 76);
line(64, 76, 53, 88);
line(64, 76, 72, 88);
puthz(200, 50, "玉米生长状况柱形图", 16, 15, GREEN);
puthz(400, 50, "总体:", 16, 15, GREEN);
puthz(70, 80, "占玉米总株数比例", 16, 15, GREEN);
line(63, 119, 65, 119);
settextstyle(1, HORIZ_DIR, 1);
outtextxy(15, 110, "100%");
line(63, 419 - 150, 65, 419 - 150);
outtextxy(15, 419 - 150 - 9, "50%");
line(63, 419 - 75, 65, 419 - 75);
outtextxy(15, 419 - 75 - 9, "25%");
line(63, 419 - 225, 65, 419 - 225);
outtextxy(15, 419 - 225 - 9, "75%");
line(84, 418, 84, 420);
line(84 + 70, 418, 84 + 70, 420);
puthz(84 + 20, 430, "健康", 16, 15, GREEN);
line(84 + 70 + 30, 418, 84 + 70 + 30, 420);
line(84 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70, 420);
puthz(84 + 70 + 30, 430, "感染棉铃虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70, 418, 84 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 5, 430, "感染黏虫", 16, 15, GREEN);
line(84 + 70 + 30 + 70 + 30 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 30, 420);
line(84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 418, 84 + 70 + 30 + 70 + 30 + 70 + 70 + 30, 420);
puthz(84 + 70 + 30 + 70 + 30 + 70 + 30, 430, "两种均感染", 16, 15, GREEN);
//统计各个植物的患病情况
for (i = 0, j = 192; i < 192, j < 384; i++, j++)
{
if (mian.bfzuobiao[i][0] == 0 && mian.bfzuobiao[i][1] == 0 && nian.bfzuobiao[j][0] == 0 && nian.bfzuobiao[j][1] == 0)
{
y1 += 1;//无病
}
if (mian.bfzuobiao[i][0] != 0 && mian.bfzuobiao[i][1] != 0)
{
y2++;
}
if (nian.bfzuobiao[j][0] != 0 && nian.bfzuobiao[j][1] != 0)
{
y3++;
}
if (mian.bfzuobiao[i][0] != 0 && mian.bfzuobiao[i][1] != 0 && nian.bfzuobiao[j][0] != 0 && nian.bfzuobiao[j][1] != 0)
{
y4++;//二者均患
}
}
//绘制坐标轴,以及显示柱形图
setcolor(RED);
settextstyle(1, HORIZ_DIR, 1);
bar(84, 419 - (y1 * 300) / 192, 84 + 70, 419);
sprintf(string, "%.lf/192", y1);
outtextxy(84, 419 - (y1 * 300) / 192 - 20, string);
bar(84 + 100 + 70, 419 - (y2 * 300) / 192, 84 + 100, 419);
sprintf(string, "%d/192", y2);
outtextxy(84 + 100, 419 - (y2 * 300) / 192 - 20, string);
bar(84 + 270, 419 - (y3 * 300) / 192, 84 + 200, 419);
sprintf(string, "%d/192", y3);
outtextxy(84 + 200, 419 - (y3 * 300) / 192 - 20, string);
bar(84 + 370, 419 - (y4 * 300) / 192, 84 + 300, 419);
sprintf(string, "%d/192", y4);
outtextxy(84 + 300, 419 - (y4 * 300) / 192 - 20, string);
//显示生长状态
if (y1 >= 192 - 8)//8
{
puthz(370 + 84, 50, "健康", 16, 15, GREEN);
}
else if (y1 >= 192 - 15)//15
{
puthz(370 + 84, 50, "正常", 16, 15, GREEN);
}
else if (y1 >= 192 - 25)//25
{
puthz(370 + 84, 50, "病虫预防", 16, 15, GREEN);
}
else if (y1 >= 192 - 35)//35
{
puthz(370 + 84, 50, "急需喷洒", 16, 15, GREEN);
}

else if (y1 >= 192 - 60)//60
{
puthz(370 + 84, 50, "严重病害", 16, 15, GREEN);
}
else
{
puthz(370 + 84, 50, "重大病害", 16, 15, GREEN);
}
}

看起来很复杂,其实很简单,就是一个画柱形图的功能。。。。

好累,你自己看吧

growlook

无人机动画核心

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
#include "common.h"
/*===========================================
生长检测部分1。这里仅仅只是实现了动画效果。
如,无人机的动画,植物范围的变色,不同的颜色代表了
不同的病虫害。
具体数据要到结果查看部分。
=============================================*/
void grow(void)//将两个农田的无人机运动合为一体化
{

if (getpixel(20, 65) == BROWN)//根据这个判断两个农田.这个是平地农田
{
dronemove1();
}

else// (getpixel(20,65) == WHITE) //这个是小农田
{
dronemove2();
}
}
//小农田无人机动画
void move21(int points[][2], int num_points, int x, int y, int* buffer)
{

int i;
int barrier[2][2] = { 0 };//障碍物
int barrier1[2][2] = { 0 };
int barrier2[2][2] = { 0 };
int xiao[103][2];
int yu[68][2];
int mian[68][2];
getxtxiao(xiao);
getxtyumi(yu);
getxtmianhua(mian);
barrier[0][0] = 249;
barrier[0][1] = 239;
barrier[1][0] = 278;
barrier[1][1] = 324;
barrier1[0][0] = 480;
barrier1[0][1] = 326 - 10;
barrier1[1][0] = 519;
barrier1[1][1] = 415 ;
barrier2[0][0] = 549;
barrier2[0][1] = 49;
barrier2[1][0] = 589;
barrier2[1][1] = 141;
srand(time(NULL)); // 初始化随机种子
for (i = 0; i < num_points; i++)
{
int target_x = points[i][0]; // 获取当前目标点的x坐标
int target_y = points[i][1]; // 获取当前目标点的y坐标
int j;
int dx = 0;
int dy = 0;
int xxx = 2;
int yyy = 2;
int judge;
int xmax, ymax, xmin, ymin;
int randx[400] = { 0 };
int randy[400] = { 0 };
int randfuzhi;
int rand_numbers[400] = { 0 }; // 数组用于存储生成的随机数
int canshu1;
int canshu2;
int judgee;
int movebar[2][2] = { 0 };
if ((target_x - x) >= 0)//判断目标点
{
xxx = 0;
}
else if ((target_x - x) < 0)
{
xxx = 1;
}
if ((target_y - y) >= 0)
{
yyy = 0;
}
else if ((target_y - y) < 0)
{
yyy = 1;
}
if (abs(target_x - x) >= abs(target_y - y))
{
for (randfuzhi = 0; randfuzhi < abs((target_x - x) / 2); randfuzhi++)
{
randx[randfuzhi] = 2;//控制速度 ======================================
randy[randfuzhi] = 0;
}
for (randfuzhi = 0; randfuzhi < abs((target_y - y) / 2); randfuzhi++)
{
while (1)
{
judgee = 1;
canshu1 = rand() % (abs(target_y - y) / 2) + 1;
for (j = 0; j < randfuzhi; j++)
{
if (rand_numbers[j] == canshu1)
{
judgee = 0;
}
}
if (judgee == 1)
{
break;
}
}
rand_numbers[randfuzhi] = canshu1; // 将生成的随机数标记为已使用
randy[canshu1 - 1] = 2;
}
}
else if (abs(target_x - x) < abs(target_y - y))
{
for (randfuzhi = 0; randfuzhi < abs((target_y - y) / 2); randfuzhi++)
{
randx[randfuzhi] = 0;//控制速度 ======================================
randy[randfuzhi] = 2;
}
for (randfuzhi = 0; randfuzhi < abs((target_x - x) / 2); randfuzhi++)
{
while (1)
{
judgee = 1;

canshu2 = rand() % (abs(target_x - x) / 2) + 1;
for (j = 0; j < randfuzhi; j++)
{
if (rand_numbers[j] == canshu2)
{
judgee = 0;
}
}
if (judgee == 1)
{
break;
}
}
rand_numbers[randfuzhi] = canshu2; // 将生成的随机数标记为已使用
randx[canshu2 - 1] = 2;
randx[randfuzhi] = 2;
}
}

while (x != target_x || y != target_y)
{
int jj = 0;
int aa, bb, cc, dd;
judge = rand() % 2;
movebar[0][0] = x - 25;
movebar[0][1] = y - 44;
movebar[1][0] = x + 50;
movebar[1][1] = y;
if (abs(target_x - x) < 10 || abs(target_y - y) < 10)
{
if (x != target_x)//
{
if (judge == 0)
{
dx = 1;
dy = 0;
}
}
if (y != target_y)//
{
if (judge == 1)
{
dx = 0;
dy = 1;
}
}
}
else
{
dx = randx[jj];
dy = randy[jj];
jj++;
}
if (x != target_x && y == target_y && abs(target_x - x) < 10)
{
dx = 1;
dy = 0;
}
else if (x != target_x && y == target_y && abs(target_x - x) >= 10)
{
dx = 2;
dy = 0;
}
if (y != target_y && x == target_x && abs(target_y - y) < 10)
{
dx = 0;
dy = 1;
}
else if (y != target_y && x == target_x && abs(target_y - y) >= 10)
{
dx = 0;
dy = 2;
}
aa = skipthing(barrier, movebar, &dx, &dy);
bb = skipthing(barrier1, movebar, &dx, &dy);
cc = skipthing(barrier2, movebar, &dx, &dy);
if (aa == 1 && bb == 1 && cc == 1)
{
if ((target_x - x) >= 0)
{
xxx = 0;
}
else if ((target_x - x) < 0)
{
xxx = 1;
}
if ((target_y - y) >= 0)
{
yyy = 0;
}
else if ((target_y - y) < 0)
{
yyy = 1;
}
}
xmax = (x + 50) > 639 ? 639 : (x + 50);
ymax = (y + 0) > 479 ? 479 : (y + 0);
xmin = (x - 25) < 0 ? 0 : (x - 25);
ymin = (y - 44) < 20 ? 0 : (y - 44);
showheight(x, y, xiao, yu, mian);
getimage(xmin, ymin, xmax, ymax, buffer);
drtdrone(x, y - 44);
//无人机速度控制
delay(15);//15
if (abs(x - target_x) < 2 && abs(y - target_y) < 2)
{
delay(50);//100
}
putimage(xmin, ymin, buffer, COPY_PUT);
if (xxx == 0)
{
x += dx; // 更新x坐标
}
else if (xxx == 1)
{
x -= dx; // 更新x坐标
}
if (yyy == 0)
{
y += dy; // 更新y坐标
}
else if (yyy == 1)
{
y -= dy; // 更新y坐标
}
}
}
}
int skipthing(int barrier[][2], int movebar[][2], int* dx, int* dy)
{
//barrier 储存的是障碍物坐标,movebar 是无人机坐标。dx,dy是运动的 值。targetxy是终点坐标。
if (barrier[0][0] - 5 <= movebar[1][0] &&
barrier[1][0] - 5 >= movebar[0][0] &&
barrier[0][1] + 5 <= movebar[1][1] &&
barrier[1][1] + 5 >= movebar[0][1]
)//障碍物与无人机 相交:::判断两矩形是否相交。,这里扩充了障碍物,边界+10
{
if (abs(movebar[0][1] - barrier[1][1]) < 4)//无人机 上边与 障碍物下边 相交
{//无人机从 上方碰见障碍物
*dy = 0;// 1;
*dx = 1;
}
else if (abs(movebar[1][1] - barrier[0][1]) < 4)//无人机 下边与 障碍物上边 相交
{//无人机从 下方碰见障碍物
*dy = 0;// 1;
*dx = 1;
}
else if (abs(movebar[0][0] - barrier[1][0]) < 4)//无人机 左边与 障碍物右边 相交
{//无人机从 右方碰见障碍物
*dx = 0;// 1;
*dy = -1;
}
else if (abs(movebar[1][0] - barrier[0][0]) < 4)//无人机 右边与 障碍物左边 相交
{//无人机从 左方碰见障碍物
*dx = 0; // -1;
*dy = 1;
}
return 0;
}
return 1;
}
void dronemove2(void)
{
void* buffer1 = malloc(imagesize(0, 0, 75, 44));//定义缓存区
int x1, y1;
int a[239][2];
int i, j, k;
int temp[2];
int quyu[12] = { 77,110,137,157,185,219,265,316,355,384,417,480 };//将农田分成11区域,有12个分界线无人机扫描11次
int count[11] = { 0 };//计算每个区域有多少植物
int ii[11] = { 0 };
int barrier[2][2] = { 0 };
int barrier1[2][2] = { 0 };
int barrier2[2][2] = { 0 };
getxtxiao(a);
getxtyumi(&a[103]);
getxtmianhua(&a[171]);
barrier[0][0] = 249;
barrier[0][1] = 239;
barrier[1][0] = 278;
barrier[1][1] = 324;
barrier1[0][0] = 480;
barrier1[0][1] = 326 - 10;
barrier1[1][0] = 519;
barrier1[1][1] = 415 - 10;
barrier2[0][0] = 549;
barrier2[0][1] = 49;
barrier2[1][0] = 589;
barrier2[1][1] = 141;
paipai(a, barrier2);
paipai(a, barrier1);
paipai(a, barrier);
for (i = 0; i < 238; i++)
{
for (j = i + 1; j < 239; j++)
{
if (a[i][1] > a[j][1])
{
temp[0] = a[i][0];
temp[1] = a[i][1];
a[i][0] = a[j][0];
a[i][1] = a[j][1];
a[j][0] = temp[0];
a[j][1] = temp[1];
}
}
}
for (i = 0; i < 239; i++)
{
for (k = 0; k < 11; k++)
{
if (a[i][1] >= quyu[k] && a[i][1] < quyu[k + 1])//判断植物在第几区域内部
{
count[k]++;
}
}
}
for (i = 1; i < 11; i++)
{
for (j = 0; j < i; j++)
{
ii[i] += count[j];
}
}
ii[0] = 0;
i = 0;
for (k = 0; k < 11; k++)
{
if ((k % 2) == 0)//向右移动,x小的 在前
{
for (i = ii[k]; i < ii[k] + count[k] - 1; i++)
{
for (j = i + 1; j < ii[k] + count[k]; j++)
{
if (a[i][0] > a[j][0])
{
temp[0] = a[i][0];
temp[1] = a[i][1];
a[i][0] = a[j][0];
a[i][1] = a[j][1];
a[j][0] = temp[0];
a[j][1] = temp[1];
}
}
}
}
else
{
for (i = ii[k]; i < ii[k] + count[k] - 1; i++)
{
for (j = i + 1; j < ii[k] + count[k]; j++)
{
if (a[i][0] < a[j][0])
{
temp[0] = a[i][0];
temp[1] = a[i][1];
a[i][0] = a[j][0];
a[i][1] = a[j][1];
a[j][0] = temp[0];
a[j][1] = temp[1];
}
}
}
}
}
x1 = 0;//初始化无人机坐标
y1 = 60;
move21(a, 239, x1, y1, buffer1);
free(buffer1);
setcolor(WHITE);
setfillstyle(SOLID_FILL, WHITE);
bar(100, 56, 250, 88); // 清除时间显示区域
delay(100);
}
void paipai(int a[][2], int barrier2[][2])//排序
{
int i;
for (i = 0; i < 238; i++)
{
if (a[i][0] >= barrier2[0][0] - 52 && a[i][0] <= barrier2[1][0] + 26 && a[i][1] >= barrier2[0][1] && a[i][1] <= barrier2[1][1] + 46)
{
if (a[i][0] <= ((barrier2[1][0] + barrier2[0][1]) / 2))
{
a[i][0] = barrier2[1][0] - 53;
a[i][1] = barrier2[0][1];
}
else
{
a[i][0] = barrier2[1][0] + 27;
a[i][1] = barrier2[1][1];
}
}
}
}
//大农田的无人机运动
void dronemove1(void)
{
//-========================================================
void* buffer1 = malloc(imagesize(0, 0, 25, 25));
int* x1 = malloc(sizeof(int));
int* y1 = malloc(sizeof(int));
int* judge = malloc(sizeof(int));
int i;
*x1 = 0;
*judge = 65;
*y1 = 65;
//====================================
//整个运动的实现
for (i = 0; i < 7; i++)
{
move11(x1, y1, buffer1);
move12(x1, y1, buffer1, judge);
move13(x1, y1, buffer1);
move12(x1, y1, buffer1, judge);
//这三个运动为一个循环。。。
}
move11(x1, y1, buffer1);
move12(x1, y1, buffer1, judge);
for (; *x1 > 0; *x1 = *x1 - 2)//运动到了最左端。。
{
getimage(*x1, *y1, *x1 + 25, *y1 + 25, buffer1);//保存image到buffer
drfdrone(*x1, *y1);
delay(8);
putimage(*x1, *y1, buffer1, COPY_PUT);//恢复图像
}
for (; *y1 > 65; *y1 = *y1 - 1)//运动到了最左端。。
{
getimage(*x1, *y1, *x1 + 25, *y1 + 25, buffer1);//保存image到buffer
drfdrone(*x1, *y1);
delay(5);
putimage(*x1, *y1, buffer1, COPY_PUT);//恢复图像
}
free(buffer1);
free(x1);
free(y1);
free(judge);
delay(100);
}
void showheight(int x, int y, int xiao[][2], int yu[][2], int mian[][2])//显示无人机高度
{
char string[20];
int high = 0;
int i;
int judge = 0;
int randshu;

if (x > 1 && x < 203 && y < 278 && y>76)//梯田区域
{
for (i = 0; i < 103; i++)
{
if (abs(x - xiao[i][0]) < 4 && abs(y - xiao[i][1]) < 4)
{
high = rand() % 30 + 150 + 300;
judge = 1;
}
}
for (i = 0; i < 68; i++)
{
if (abs(x - yu[i][0]) < 4 && abs(y - yu[i][1]) < 4)
{
high = rand() % 50 + 330 + 300;
judge = 1;
}
if (abs(x - mian[i][0]) < 4 && abs(y - mian[i][1]) < 4)
{
high = rand() % 50 + 210 + 300;
judge = 1;
}
}
}
else
{
for (i = 0; i < 103; i++)
{
if (abs(x - xiao[i][0]) < 4 && abs(y - xiao[i][1]) < 4)
{
high = rand() % 30 + 150;
judge = 1;
}
}
for (i = 0; i < 68; i++)
{
if (abs(x - yu[i][0]) < 4 && abs(y - yu[i][1]) < 4)
{
high = rand() % 50 + 330;
judge = 1;
}
if (abs(x - mian[i][0]) < 4 && abs(y - mian[i][1]) < 4)
{
high = rand() % 50 + 210;
judge = 1;
}
}
}
if (judge == 0)
{
randshu = rand() % 100;
if (randshu == 1)
{
if (getpixel(x, y) == BLUE)
{
high = rand() % 40 + 300;
}

else if (x > 1 && x < 203 && y < 278 && y>76)//梯田区域
{
high = rand() % 40 + 100+300;
}

else if (high < 150)
{
high = rand() % 40 + 200;
}
}
else high = 0;
}
if (high >= 150)
{
setcolor(WHITE);
setfillstyle(SOLID_FILL, WHITE);
bar(177, 56, 230, 88); // 清除高度
setcolor(GREEN);
settextstyle(1, HORIZ_DIR, 1);
sprintf(string, "height: %d cm", high);
outtextxy(107, 57, string);//显示字符串
}
}

这段代码小农田的不用细看,因为这个避障和斜线运动功能确实很难做,所以当时也是乱凑,凑出来了个半成品。。。。显示高度可以看看。自己看吧,打算一口气结束这个C课设拯救计划了。太累了了了了了

队友写的

反正我当时没看多久,也没看懂,现在更加不想看了,有兴趣可以自己分析。

zpjm.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef _ZPJM_H_
#define _ZPJM_H_

int zpjiemian(int* a9, int nongyao[6]);
void chejian(void);//绘画车间图像
void nongdu(int judge);//浓度显示
void jizhan(void);//无人机基站图像
void xiangzi(int x, int y , int num,int judge2);//农药储存箱图像
void drcar(int x, int y,int judge1);//小车
void nydrone(int x, int y ,int judge4);//车间内无人机图像
void fushitu(int x, int y);//小农田农药无人机图
void suofangtu(int x, int y , int judge4);//大农田农药无人机缩放图
void zpdh(int judge3);//农药装配动画
void moveps0(int judge1, int* x, int* y, int* buffer2);//向左特殊运动
void moveps1(int judge1, int* x, int* y, int* buffer2);//向右特殊运动
void moveps2(int judge1, int* x, int* y, int* buffer2);//向右进一区
void moveps3(int judge1, int* x, int* y, int* buffer2);//向上进一区
void moveps4(int judge1, int* x, int* y, int* buffer2);//向下进一区
void moveps6(int judge1, int* x, int* y, int* buffer2);//向左进一区
void moveps7(int judge1, int* x, int* y, int* buffer2);//向下取药
void moveps8(int judge1, int* x, int* y, int* buffer2);//向上回位
void moveps9(int judge1, int* x, int* y, int* buffer2);//向上装药
#endif

zpjm.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
 #include "common.h"

int zpjiemian(int* a9, int nongyao[6])
{
if (*a9 == 1)
{
chejian();
*a9 = 0;
}
if (*a9 == 0 || (*a9 > 1 && *a9 < 10))
if (mouse_press(20, 95, 110, 135) == 1)
{
if (*a9 == 0)
*a9 = 2;
else if (*a9 > 1 && *a9 < 10)
*a9 = *a9 + 1;
nongdu(*a9);
delay(400);
}
if (*a9 > 1 && *a9 < 11)
if (mouse_press(130, 95, 220, 135) == 1)
{
if (*a9 == 2)
*a9 = 0;
else if (*a9 > 2 && *a9 < 11)
*a9 = *a9 - 1;
nongdu(*a9);
delay(400);
}

if (mouse_press(220, 200, 370, 300) == 1)
{
if (nongyao[0] == 1)
{
nongyao[0] = 2;
zpdh(0);
*a9 = 1;
return 9;
}
if (nongyao[0] == 0)
{
return 8;
}
}

else if (mouse_press(420, 200, 570, 300) == 1)
{
if (nongyao[1] == 1)
{
nongyao[1] = 2;
zpdh(1);
*a9 = 1;
return 9;
}
if (nongyao[1] == 0)
{
return 8;
}
}
else if (mouse_press(20, 350, 170, 450) == 1)
{
if (nongyao[2] == 1)
{
nongyao[2] = 2;
zpdh(2);
*a9 = 1;
return 9;
}
if (nongyao[2] == 0)
{
return 8;
}
}

else if (mouse_press(220, 350, 370, 450) == 1)
{
if (nongyao[3] == 1)
{
nongyao[3] = 2;
zpdh(3);
*a9 = 1;
return 9;
}
if (nongyao[3] == 0)
{
return 8;
}
}

else if (mouse_press(420, 350, 570, 450) == 1)
{
if (nongyao[4] == 1)
{
nongyao[4] = 2;
zpdh(4);
*a9 = 1;
return 9;
}
if (nongyao[4] == 0)
{
return 8;
}
}
else if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a9 = 1;
return 7;//返回前一个界面
}
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);

return 8;
}

void chejian(void)//绘画车间图像
{
cleardevice();
clrmous(MouseX, MouseY);
setcolor(RED);
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);

rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);

setfillstyle(1, LIGHTGRAY);
bar(20, 150, 620, 200);
bar(20, 300, 620, 350);
bar(170, 200, 220, 450);
bar(370, 200, 420, 450);
bar(570, 200, 620, 450);
bar(370, 20, 420, 150);
setcolor(DARKGRAY);
line(370, 20, 370, 150);
line(420, 20, 420, 150);
line(20, 150, 370, 150);
line(20, 200, 170, 200);
line(420, 150, 620, 150);
line(620, 150, 620, 450);
line(170, 200, 170, 300);
line(20, 300, 170, 300);
jizhan();

xiangzi(220, 200, 0, nongyao[0]);
xiangzi(420, 200, 1, nongyao[1]);
xiangzi(20, 350, 2, nongyao[2]);
xiangzi(220, 350, 3, nongyao[3]);
xiangzi(420, 350, 4, nongyao[4]);
drcar(20, 150,0);
nydrone(265, 40, 0);
setfillstyle(1, YELLOW);
bar(20, 55, 220, 135);
setfillstyle(1, RED);
bar(20, 95, 220, 135);
setfillstyle(1, WHITE);
bar(60, 95, 70, 135);
bar(45, 110, 85, 120);
bar(150, 108, 200, 122);
rectangle(20, 55, 220, 135);
line(20, 95, 220, 95);
setfillstyle(1, DARKGRAY);
bar(110, 95, 130, 135);
puthz(25, 60, "浓度", 24, 30, GREEN);
settextstyle(1, HORIZ_DIR, 2);
setcolor(GREEN);
outtextxy(85, 56, ":");
setcolor(RED);
outtextxy(140, 58, "%");
nongdu(0);
}
void nongdu(int judge)//浓度显示
{
char a[3];
setcolor(RED);
setfillstyle(1, YELLOW);
bar(100, 58, 138, 94);
if(judge==0)
sprintf(a, "%d", 10);
if (judge == 2)
sprintf(a, "%d", 20);
if (judge == 3)
sprintf(a, "%d", 30);
if (judge == 4)
sprintf(a, "%d", 40);
if (judge == 5)
sprintf(a, "%d", 50);
if (judge == 6)
sprintf(a, "%d", 60);
if (judge == 7)
sprintf(a, "%d", 70);
if (judge == 8)
sprintf(a, "%d", 80);
if (judge == 9)
sprintf(a, "%d", 90);
if (judge == 10)
sprintf(a, "%d", 100);

outtextxy(100, 58, a);

}

void jizhan(void)//无人机基站图像
{
setcolor(DARKGRAY);
setfillstyle(1, DARKGRAY);
bar(290, 45, 370, 50);
bar(330, 55, 335, 80);
bar(320, 80, 345, 82);
setfillstyle(1, LIGHTGRAY);
bar(320, 40, 345, 55);
rectangle(320, 40, 345, 55);
}

void xiangzi(int x, int y ,int num,int judge2)//农药储存箱图像
{
setcolor(DARKGRAY);
setfillstyle(1,LIGHTGRAY);
bar(x, y, x + 150, y + 100);
bar(x+125, y-10, x+145 , y);
rectangle(x + 125, y - 10, x + 145, y);
rectangle(x, y, x + 150, y + 100);
line(x, y + 1, x + 150, y + 1);
line(x, y + 99, x + 150, y + 99);
line(x + 149, y, x + 149, y + 100);
setfillstyle(1, DARKGRAY);
bar(x + 125, y -10, x + 150, y - 4);

if (judge2 == 1)
{
if (num == 0)
{
puthz(x + 5, y + 35, "氯铃胺", 24, 30, DARKGRAY);
}
else if (num == 1)
{
puthz(x + 5, y + 35, "甲胺磷", 24, 30, DARKGRAY);
}
else if (num == 2)
{
puthz(x + 5, y + 35, "氯氰菊酯", 24, 30, DARKGRAY);
}
else if (num == 3)
{
puthz(x + 5, y + 35, "甲维盐", 24, 30, DARKGRAY);
}
else if (num == 4)
{
puthz(x + 5, y + 35, "菌酯", 24, 30, DARKGRAY);
}
}
else
{
line(x, y, x + 150, y + 100);
line(x+150, y, x , y + 100);
line(x+1, y, x + 151 ,y + 100);
line(x + 151, y, x+1, y + 100);
}
}
void drcar(int x, int y,int judge1)//小车
{
setcolor(DARKGRAY);
setfillstyle(1, LIGHTGRAY);
bar(x, y + 20, x + 50, y + 40);
rectangle(x, y + 20, x + 50, y + 40);
setfillstyle(1, DARKGRAY);
bar(x + 35, y, x + 45, y + 20);
bar(x, y, x + 40, y + 6);
bar(x + 5, y + 35, x + 20, y + 50);
bar(x + 30, y + 35, x + 45, y + 50);
setfillstyle(1, WHITE);
bar(x + 10, y + 40, x + 15, y + 45);
bar(x + 35, y + 40, x + 40, y + 45);
if (judge1 == 0)
{
setfillstyle(1, RED);
bar(x + 35, y + 25, x + 40, y + 30);
rectangle(x + 35, y + 25, x + 40, y + 30);
}
else if (judge1 == 1)
{
setfillstyle(1, GREEN);
bar(x + 35, y + 25, x + 40, y + 30);
rectangle(x + 35, y + 25, x + 40, y + 30);
}
}

void nydrone(int x , int y , int judge4)//车间内无人机图像
{
setcolor(DARKGRAY);
setfillstyle(1, LIGHTGRAY);
bar(x, y - 5, x + 25, y + 30);
rectangle (x, y - 5, x + 25, y + 30);
line(x + 5, y - 5, x + 5, y + 30);
line(x + 6, y - 5, x + 6, y + 30);
line(x + 20, y - 5, x + 20, y + 30);
line(x + 19, y - 5, x + 19, y + 30);
setfillstyle(1, DARKGRAY);
bar(x - 5, y - 5, x, y);
bar(x - 10, y - 10, x - 5, y - 5);
bar(x + 25, y - 5, x + 30, y);
bar(x + 30, y - 10, x + 35, y-5);
bar(x - 5, y +25, x, y+30);
bar(x - 10, y + 30, x-5, y + 35);
bar(x + 25, y + 25, x + 30, y + 30);
bar(x + 30, y + 30, x + 35, y + 35);
bar(x - 15, y - 20, x - 10, y + 45);
bar(x + 35 , y - 20, x + 40, y + 45);

if (judge4 == 0)
{
setfillstyle(1, RED);
bar(x + 10,y+10 , x + 15, y+15);
}
else if (judge4 == 1)
{
setfillstyle(1, GREEN);
bar(x + 10, y + 10, x + 15, y + 15);
}
}

void fushitu(int x, int y)//小农田农药无人机图
{
setcolor(DARKGRAY);
setfillstyle(1, BLUE);
bar(x+6, y, x + 14, y + 10);
rectangle(x+6 , y, x + 14, y + 10);
setfillstyle(1, DARKGRAY);
bar(x , y, x + 20, y + 2);
bar(x , y, x +2, y + 5);
bar(x + 18, y, x + 20, y + 5);
setfillstyle(1, LIGHTGRAY);
bar(x+5, y, x + 15, y + 5);
rectangle(x+5, y, x + 15, y + 5);
}
void suofangtu(int x, int y, int judge4)//大农田农药无人机缩放图
{
setcolor(DARKGRAY);
setfillstyle(1, LIGHTGRAY);
bar(x, y - 2, x + 10, y + 12);
rectangle(x, y - 2, x + 10, y + 12);
line(x + 2, y - 2, x + 2, y + 12);
line(x + 3, y - 2, x + 3, y + 12);
line(x + 8, y - 2, x + 8, y + 12);
line(x + 7, y - 2, x + 7, y + 12);
setfillstyle(1, DARKGRAY);
bar(x - 2, y - 2, x, y);
bar(x - 4, y - 4, x - 2, y - 2);
bar(x + 10, y - 2, x + 12, y);
bar(x + 12, y - 4, x + 14, y - 2);
bar(x - 2, y + 10, x, y + 12);
bar(x - 4, y + 12, x - 2, y + 14);
bar(x + 10, y + 10, x + 12, y + 12);
bar(x + 12, y + 12, x + 14, y + 14);
bar(x - 6, y - 8, x - 4, y + 18);
bar(x + 14, y - 8, x + 16, y + 18);

if (judge4 == 0)
{
setfillstyle(1, RED);
bar(x + 4, y + 4, x + 6, y + 6);
}
else if (judge4 == 1)
{
setfillstyle(1, GREEN);
bar(x + 4, y + 4, x + 6, y + 6);
}
}

void zpdh(int judge3)//农药装配动画
{
void* buffer2 = malloc(imagesize(0, 0, 50, 50));
int* x2 = malloc(sizeof(int));
int* y2 = malloc(sizeof(int));
int i;
*x2 = 20;
*y2 = 150;
setcolor(DARKGRAY);
setfillstyle(1, LIGHTGRAY);
bar(20, 150, 70, 200);
line(20, 150, 370, 150);
line(20, 200, 170, 200);
moveps1(0, x2, y2, buffer2);
if (judge3 == 0)
{
moveps2(0, x2, y2, buffer2);
moveps7(0, x2, y2, buffer2);
moveps8(1, x2, y2, buffer2);
moveps9(1, x2, y2, buffer2);
moveps0(0, x2, y2, buffer2);
}
else if (judge3 == 1)
{
moveps2(0, x2, y2, buffer2);
moveps2(0, x2, y2, buffer2);
moveps7(0, x2, y2, buffer2);
moveps8(1, x2, y2, buffer2);
moveps6(1, x2, y2, buffer2);
moveps9(1, x2, y2, buffer2);
moveps0(0, x2, y2, buffer2);
}
else if (judge3 == 2)
{
moveps4(0, x2, y2, buffer2);
moveps7(0, x2, y2, buffer2);
moveps8(1, x2, y2, buffer2);
moveps3(1, x2, y2, buffer2);
moveps2(1, x2, y2, buffer2);
moveps9(1, x2, y2, buffer2);
moveps0(0, x2, y2, buffer2);
}
else if (judge3 == 3)
{
moveps4(0, x2, y2, buffer2);
moveps2(0, x2, y2, buffer2);
moveps7(0, x2, y2, buffer2);
moveps8(1, x2, y2, buffer2);
moveps3(1, x2, y2, buffer2);
moveps9(1, x2, y2, buffer2);
moveps0(0, x2, y2, buffer2);
}
else if (judge3 == 4)
{
moveps4(0, x2, y2, buffer2);
moveps2(0, x2, y2, buffer2);
moveps2(0, x2, y2, buffer2);
moveps7(0, x2, y2, buffer2);
moveps8(1, x2, y2, buffer2);
moveps3(1, x2, y2, buffer2);
moveps6(1, x2, y2, buffer2);
moveps9(1, x2, y2, buffer2);
moveps0(0, x2, y2, buffer2);
}
drcar(20, 150, 0);

free(buffer2);
free(x2);
free(y2);
delay(100);
}

void moveps0(int judge1, int* x, int* y, int* buffer2)//向左特殊运动
{
for (; *x >20; *x = *x - 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps1(int judge1, int* x, int* y, int* buffer2)//向右特殊运动
{
for (; *x <170; *x = *x + 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y,judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps2(int judge1, int* x, int* y, int* buffer2)//向右进一区
{
int xx;
xx = *x;
for (; *x-xx < 200; *x = *x + 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps3(int judge1, int* x, int* y, int* buffer2)//向上进一区
{
int yy;
yy = *y;
for (; yy - *y < 150; *y = *y - 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps4(int judge1, int* x, int* y, int* buffer2)//向下进一区
{
int yy;
yy = *y;
for (; *y - yy < 150; *y = *y + 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps6(int judge1, int* x, int* y, int* buffer2)//向左进一区
{
int xx;
xx = *x;
for (; xx - *x < 200; *x = *x - 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps7(int judge1, int* x, int* y, int* buffer2)//向下取药
{
int yy;
yy = *y;
for (; *y - yy < 40; *y = *y + 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(20);
putimage(*x, *y, buffer2, COPY_PUT);
}
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(200);
drcar(*x, *y, 1);
delay(200);
putimage(*x, *y, buffer2, COPY_PUT);
}

void moveps8(int judge1, int* x, int* y, int* buffer2)//向上回位
{
int yy;
yy = *y;
for (; yy-*y < 40; *y = *y - 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(8);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

void moveps9(int judge1, int* x, int* y, int* buffer2)//装药,回位
{
int yy;
yy = *y;
for (; yy - *y < 50; *y = *y - 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(16);
putimage(*x, *y, buffer2, COPY_PUT);
}

for (; yy - *y < 105; *y = *y - 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(20);
putimage(*x, *y, buffer2, COPY_PUT);
}
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, judge1);
delay(200);
drcar(*x, *y, 0);
nydrone(265, 40, 1);
delay(200);
putimage(*x, *y, buffer2, COPY_PUT);

for (; yy - *y >50; *y = *y + 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, 0);
delay(20);
putimage(*x, *y, buffer2, COPY_PUT);
}

for (; yy - *y >0; *y = *y + 2)
{
getimage(*x, *y, *x + 50, *y + 50, buffer2);
drcar(*x, *y, 0);
delay(16);
putimage(*x, *y, buffer2, COPY_PUT);
}
}

pssj.h

1
2
3
4
5
#ifndef _PSSJ_H
#define _PSSJ_H
int moveint2(int (*hanshu)(int*, int*), int* a, int b[6]);
int moveint3(int (*hanshu)(int*, int*, unsigned char(*)[49], unsigned char(*)[49], unsigned char(*)[49], int(*)[2], int*), int* a, int b[6], unsigned char c[384][49], unsigned char d[192][49], unsigned char e[192][49], int f[386][2], int* g);
#endif

pssj.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "pssj.h"
#include "common.h"


int moveint2(int (*hanshu)(int*,int* ), int* a, int b[6])
{
int bbbb;

if (*a == 1)
{
clrmous(MouseX, MouseY);
}

bbbb = hanshu(a, b);

if (*a != -10)
{
newmouse(&MouseX, &MouseY, &press);
}

return bbbb;
}

int moveint3(int (*hanshu)(int*, int*, unsigned char(*)[49], unsigned char(*)[49], unsigned char(*)[49], int(*)[2], int*), int* a, int b[6], unsigned char c[384][49], unsigned char d[192][49], unsigned char e[192][49],int f[386][2], int* g)
{
int bbbbbb;

if (*a == 1)
{
clrmous(MouseX, MouseY);
}

bbbbbb = hanshu(a, b, c, d, e,f,g);

if (*a != -10)
{
newmouse(&MouseX, &MouseY, &press);
}

return bbbbbb;
}

pensadh.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef _PENSADH_H_
#define _PENSADH_H_

int psdonghua(int *a10,int nongyao[6], unsigned char diannian[384][49], unsigned char dianbai[192][49], unsigned char dianmian[192][49], int rount[386][2],int* amtjudge);
void ljgh(int grandjudge, int *judge, int ny0[384][2], int ny1[192][2], int ny2[192][2], int ny3[192][2], int ny4[192][2], int rount[386][2]);//路径规划
void therount(int rount[386][2], int *amtjudge);//路径画面
void huigui(void);//未发现病害,回归
void huigui2(int i);//喷洒农药后回归
void nyphoto(int x, int y);//农药图像
void anima1(int rount[386][2], int* amtjudge);//大农田路径动画
void anima2(int rount[386][2], int* amtjudge);//小农田路径动画
int linemove1(int* x, int* y, int* buffer1);//大农田沿线段运动
int linemove21(int judge1 ,int* x, int* y, int* buffer1);//小农田沿线段运动(顺时针) 21,22合并后,动画卡顿且容易把系统卡爆
int linemove22(int judge1 ,int* x, int* y, int* buffer1);//小农田沿线段运动(逆时针)

#endif

pensadh.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
#include "common.h"

int psdonghua(int* a10, int nongyao[6], unsigned char diannian[384][49], unsigned char dianbai[192][49], unsigned char dianmian[192][49], int rount[386][2],int* amtjudge)
{
FILE* filePointer1;
FILE* filePointer2;
FILE* filePointer3;
FILE* filePointer4;
FILE* filePointer5;
FILE* filePointer6;
int i,j;
int grandjudge = 0, jg0=0, jg1 = 0, jg2 = 0, jg3 = 0, jg4 = 0;//granjudge:确定农药使用,jg用于贮存相应得病植株数量
int ny0[384][2] = {0};//ny用于贮存坐标
int ny1[192][2] = { 0 };
int ny2[192][2] = { 0 };
int ny3[192][2] = { 0 };
int ny4[192][2] = { 0 };
if (*a10==1)
{
rount[0][0] = 20;
rount[0][1] = 465;
cleardevice();
clrmous(MouseX, MouseY);
setcolor(RED);
setfillstyle(1, GREEN);
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);
bar(260, 5, 400, 50);
puthz(270, 10, "喷洒农药", 32, 30, WHITE);
bar(100, 5, 240, 50);
puthz(110, 10, "路径规划", 32, 30, WHITE);
rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);
if (nongyao[5] == 0)//大农田,已经排除了棉花用的农药,关注0,2,4
{
farmfield();
for (i = 0; i < 192; i++)//小麦,黏虫
{
if (nian.bfzuobiao[i][0] != 0 && nian.bfzuobiao[i][1] != 0)
{
nianchong(nian.bfzuobiao[i][0], nian.bfzuobiao[i][1], diannian[i]);
ny0[jg0][0] = nian.bfzuobiao[i][0];
ny0[jg0][1] = nian.bfzuobiao[i][1];
jg0++;
}
}
for (i = 192; i < 384; i++)//玉米,黏虫
{
if (nian.bfzuobiao[i][0] != 0 && nian.bfzuobiao[i][1] != 0)
{
nianchong(nian.bfzuobiao[i][0], nian.bfzuobiao[i][1], diannian[i]);
ny2[jg2][0] = nian.bfzuobiao[i][0];
ny2[jg2][1] = nian.bfzuobiao[i][1];
jg2++;
}
}
for (i = 0; i < 192; i++)//玉米,棉铃虫
{
if (mian.bfzuobiao[i][0] != 0 && mian.bfzuobiao[i][1] != 0)
{
mianling(mian.bfzuobiao[i][0], mian.bfzuobiao[i][1], dianmian[i]);
ny0[jg0][0] = mian.bfzuobiao[i][0];
ny0[jg0][1] = mian.bfzuobiao[i][1];
jg0++;
}
}
for (i = 0; i < 192; i++)//小麦,白粉病
{
if (bai.bfzuobiao[i][0] != 0 && bai.bfzuobiao[i][1] != 0)
{
baifen(bai.bfzuobiao[i][0], bai.bfzuobiao[i][1], dianbai[i]);
ny4[jg4][0] = bai.bfzuobiao[i][0];
ny4[jg4][1] = bai.bfzuobiao[i][1];
jg4++;
}
}
}
else if (nongyao[5] == 1)//小农田
{
bmp_convert("5.bmp", "5.dbm");
open_display();
show_dbm(0, 100, "5.dbm", 0);
tian();
bmp_convert("stone.bmp", "stone.dbm");
open_display();
drawPlants();
drawdxg(250, 240);
show_dbm(194, 447, "stone.dbm", 0);
drawScarecrow(570, 61);
drawScarecrow(500, 325);
binghai();

filePointer1 = fopen("data//xtxmnian.dat", "r");
for (i = 0; i < 192; i++)
{
if (fscanf(filePointer1, "%d %d", &ny0[jg0][0], &ny0[jg0][1]) != -1)
jg0++;
else
break;
}
fclose(filePointer1);

filePointer2 = fopen("data//xtymmian.dat", "r");
for (i = 0; i < 192; i++)
{
if (fscanf(filePointer2, "%d %d", &ny0[jg0][0], &ny0[jg0][1]) != -1)
jg0++;
else
break;
}
fclose(filePointer2);

filePointer3 = fopen("data//xtmhmian.dat", "r");
for (i = 0; i < 192; i++)
{
if (fscanf(filePointer3, "%d %d", &ny1[jg1][0], &ny1[jg1][1]) != -1)
jg1++;
else
break;
}
fclose(filePointer3);

filePointer4 = fopen("data//xtymnian.dat", "r");
for (i = 0; i < 192; i++)
{
if (fscanf(filePointer4, "%d %d", &ny2[jg2][0], &ny2[jg2][1]) != -1)
jg2++;
else
break;
}
fclose(filePointer4);

filePointer5 = fopen("data//xtmhxiu.dat", "r");
for (i = 0; i < 192; i++)
{
if (fscanf(filePointer5, "%d %d", &ny3[jg3][0], &ny3[jg3][1]) != -1)
jg3++;
else
break;
}
fclose(filePointer5);

filePointer6 = fopen("data//xtxmbai.dat", "r");
for (i = 0; i < 192; i++)
{
if (fscanf(filePointer6, "%d %d", &ny4[jg4][0], &ny4[jg4][1]) != -1)
jg4++;
else
break;
}
fclose(filePointer6);
}
if (nongyao[0] == 2)
{
if (jg0 == 0)
{
nongyao[0] = 0;
huigui();
return 7;
}
if (jg0 > 0)
{
grandjudge = 0;
*amtjudge = jg0;
}
}
if (nongyao[1] == 2)
{
if (jg1 == 0)
{
nongyao[1] = 0;
huigui();
return 7;
}
if (jg1 > 0)
{
grandjudge = 1;
*amtjudge = jg1;
}
}
if (nongyao[2] == 2)
{
if (jg2 == 0)
{
nongyao[2] = 0;
huigui();
return 7;
}
if (jg2 > 0)
{
grandjudge = 2;
*amtjudge = jg2;
}
}
if (nongyao[3] == 2)
{
if (jg3 == 0)
{
nongyao[3] = 0;
huigui();
return 7;
}
if (jg3 > 0)
{
grandjudge = 3;
*amtjudge = jg3;
}
}
if (nongyao[4] == 2)
{
if (jg4 == 0)
{
nongyao[4] = 0;
huigui();
return 7;
}
if (jg4 > 0)
{
grandjudge = 4;
*amtjudge = jg4;
}
}
ljgh(grandjudge, amtjudge, ny0, ny1, ny2, ny3, ny4, rount);
*a10 = 0;
}
if (*a10 == 2)
{
therount(rount, amtjudge);
*a10 = 3;
}
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a10 = 1;
for (i = 0; i < 5; i++)
{
if (nongyao[i] > 1)
{
nongyao[i] = 0;
}
}
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);
return 8;//返回农药选择界面
}


if (*a10 == 0)
{
if (mouse_press(100, 5, 240, 50) == 1)
{
*a10 = 2;
}
showbiankuang(100, 5, 240, 50);
}

if (*a10 == 3)
{
if (mouse_press(260, 5, 400, 50) == 1)
{
if (nongyao[5] == 0)
{
clrmous(MouseX, MouseY);
anima1(rount, amtjudge);
*a10 = 4;
}
else if (nongyao[5] == 1)
{
clrmous(MouseX, MouseY);
anima2(rount, amtjudge);
*a10 = 5;
}
}
showbiankuang(260, 5, 400, 50);
}

if (*a10 == 4)
{
for (i = 0; i < 5; i++)
if (nongyao[i] == 2)
break;
if (i == 0)
for (j = 0; j < 192; j++)
{
nian.bfzuobiao[j][0] = 0;
nian.bfzuobiao[j][1] = 0;
mian.bfzuobiao[j][0] = 0;
mian.bfzuobiao[j][1] = 0;
}
if (i == 2)
{
for (j =192; j < 384; j++)
{
nian.bfzuobiao[j][0] = 0;
nian.bfzuobiao[j][1] = 0;
}
}
if (i == 4)
{
for (j = 0; j < 192; j++)
{
bai.bfzuobiao[j][0] = 0;
bai.bfzuobiao[j][1] = 0;
}
}
nongyao[i] = 0;
*a10 = 1;
huigui2(i);
return 2;
}
if(*a10==5)
{
for (i = 0; i < 5; i++)
if (nongyao[i] == 2)
break;
if (i == 0)
{
filePointer1 = fopen("data//xtxmnian.dat", "w");
fclose(filePointer1);
filePointer1 = fopen("data//xmncdian.dat", "w");
fclose(filePointer1);

filePointer2 = fopen("data//xtymmian.dat", "w");
fclose(filePointer2);
filePointer2 = fopen("data//ymmldian.dat", "w");
fclose(filePointer2);
}
if (i == 1)
{
filePointer3 = fopen("data//xtmhmian.dat", "w");
fclose(filePointer3);
filePointer3 = fopen("data//mhmldian.dat", "w");
fclose(filePointer3);
}
if (i == 2)
{
filePointer4 = fopen("data//xtymnian.dat", "w");
fclose(filePointer4);
filePointer4 = fopen("data//ymncdian.dat", "w");
fclose(filePointer4);
}
if (i == 3)
{
filePointer5 = fopen("data//xtmhxiu.dat", "w");
fclose(filePointer5);
filePointer5 = fopen("data//mhxbdian.dat", "w");
fclose(filePointer5);
}
if (i == 4)
{
filePointer6 = fopen("data//xtxmbai.dat", "w");
fclose(filePointer6);
filePointer6 = fopen("data//xmbfdian.dat", "w");
fclose(filePointer6);

}
nongyao[i] = 0;
*a10 = 1;
huigui2(i);
return 3;
}
return 9;
}

void ljgh(int grandjudge, int *judge, int ny0[384][2], int ny1[192][2], int ny2[192][2], int ny3[192][2], int ny4[192][2],int rount[386][2])//路径规划
{
int i = 0, j = 0, k = *judge-1,K = 1 + *judge;
int len1 = 0, len2 = 0;
int dist1 = 0, dist2 = 0;
int temp0 = 0, temp1 = 0;
if (grandjudge == 0)
{
for (i = 0; i < *judge; i++)
{
j = i + 1;
rount[j][0] = ny0[i][0];
rount[j][1] = ny0[i][1];
}
}
if (grandjudge == 1)
{
for (i = 0; i < *judge; i++)
{
j = i + 1;
rount[j][0] = ny1[i][0];
rount[j][1] = ny1[i][1];
}
}
if (grandjudge == 2)
{
for (i = 0; i < *judge; i++)
{
j = i + 1;
rount[j][0] = ny2[i][0];
rount[j][1] = ny2[i][1];
}
}
if (grandjudge == 3)
{
for (i = 0; i < *judge; i++)
{
j = i + 1;
rount[j][0] = ny3[i][0];
rount[j][1] = ny3[i][1];
}
}
if (grandjudge == 4)
{
j = 1;
for (i = 0; i < *judge; i++)
{
j = i + 1;
rount[j][0] = ny4[i][0];
rount[j][1] = ny4[i][1];
}
}
rount[K][0] = rount[0][0];
rount[K][1] = rount[0][1];
for (i = 0; i < k; i++)
{
len1 = rount[i + 1][0] - rount[i][0];
len2 = rount[i + 1][1] - rount[i][1];
len1 = len1 / 25;
len2 = len2 / 25;
dist1 = len1 * len1 + len2 * len2;
for (j = i + 2; j < K; j++)
{
len1 = rount[j][0] - rount[i][0];
len2 = rount[j][1] - rount[i][1];
len1 = len1 / 25;
len2 = len2 / 25;
dist2 = len1 * len1 + len2 * len2;
if (dist2 < dist1)
{
dist1 = dist2;
temp0 = rount[j][0];
temp1 = rount[j][1];
rount[j][0] = rount[i + 1][0];
rount[j][1] = rount[i + 1][1];
rount[i+1][0] = temp0;
rount[i+1][1] = temp1;
}
}
}

}
void therount(int rount[386][2], int * amtjudge)//路径画面
{
int i = 0;

for (i=0;i<* amtjudge+1;i++)
{
setcolor(RED);
line(rount[i][0], rount[i][1], rount[i + 1][0], rount[i + 1][1]);
}
line(rount[*amtjudge][0], rount[*amtjudge][1], rount[0][0], rount[0][1]);
}
void huigui(void)//回归
{
cleardevice();
clrmous(MouseX, MouseY);
puthz(150, 200, "未发现相关病状", 32, 40, RED);
setcolor(BLUE);
rectangle(110, 300, 530, 380);
puthz(125, 322, "回归中", 32, 50, RED);
setfillstyle(1, BLUE);
bar(265, 320, 305, 360);
delay(400);
bar(315, 320, 355, 360);
delay(400);
bar(365, 320, 405, 360);
delay(400);
bar(415, 320, 455, 360);
delay(400);
bar(465, 320, 505, 360);
delay(1000);
}

void huigui2(int i)//喷洒农药后回归
{
cleardevice();
clrmous(MouseX, MouseY);
puthz(100, 150, "已清除下列植物的下列病状", 32, 40, BLUE);
if (i == 0)
{
puthz(100, 250, "小麦黏虫", 32, 40, RED);
puthz(300, 250, "玉米棉铃虫", 32, 40, RED);
}
if (i == 1)
puthz(100, 250, "棉花棉铃虫", 32, 40, RED);
if (i == 2)
puthz(100, 250, "玉米黏虫", 32, 40, RED);
if (i == 3)
puthz(100, 250, "棉花锈病", 32, 40, RED);
if (i == 4)
puthz(100, 250, "小麦白粉病", 32, 40, RED);

setcolor(BLUE);
rectangle(90, 350, 550, 430);
puthz(100, 372, "回归农田", 32, 50, RED);
setfillstyle(1, BLUE);
bar(285, 370, 325, 410);
delay(400);
bar(335, 370, 375, 410);
delay(400);
bar(385, 370, 425, 410);
delay(400);
bar(435, 370, 475, 410);
delay(400);
bar(485, 370, 525, 410);
delay(1000);
}

void nyphoto(int x, int y)//农药图像
{
setfillstyle(1, LIGHTBLUE);
bar(x, y+2, x + 3, y + 5);
bar(x + 10, y + 7, x + 13, y + 10);
bar(x + 20, y+3, x + 23, y + 6);
bar(x, y + 10, x + 3, y + 13);
bar(x + 20, y + 5, x + 23, y + 8);
bar(x + 20, y+15, x + 23, y + 18);
bar(x, y + 19, x + 3, y + 22);
bar(x + 12, y + 22, x + 15, y + 25);
}

void anima1(int rount[386][2], int* amtjudge)//大农田路径动画
{
void* buffer1 = malloc(imagesize(0, 0, 22, 26));
int* x1 = malloc(sizeof(int));
int* y1 = malloc(sizeof(int));
int i,k;
*x1 = rount[0][0];
*y1 = rount[0][1];
for (i = 0; i < *amtjudge+1; i++)
{
setcolor(CYAN);
line(rount[i][0], rount[i][1], rount[i + 1][0], rount[i + 1][1]);
do
{
k = linemove1(x1, y1, buffer1);
} while (k == 1);
getimage(*x1 - 6, *y1 - 8, *x1 + 16, *y1 + 18, buffer1);
suofangtu(*x1, *y1, 1);
delay(100);
putimage(*x1 - 6, *y1 - 8, buffer1, COPY_PUT);
if (i < *amtjudge)
nyphoto(rount[i + 1][0], rount[i + 1][1]);
}
getimage(*x1 - 6, *y1 - 8, *x1 + 16, *y1 + 18, buffer1);
suofangtu(*x1, *y1, 1);
delay(500);
putimage(*x1 - 6, *y1 - 8, buffer1, COPY_PUT);
free(buffer1);
free(x1);
free(y1);
}
void anima2(int rount[386][2], int* amtjudge)//小农田路径动画
{
void* buffer1 = malloc(imagesize(0, 0, 20, 10));
int* x1 = malloc(sizeof(int));
int* y1 = malloc(sizeof(int));
int i, k ;
for (i = 0; i < *amtjudge + 1; i++)
{
*x1 = rount[i][0];
*y1 = rount[i][1];
setcolor(CYAN);
rectangle(185, 443, 233, 480);
rectangle(184, 444, 234, 479);
rectangle(245, 225, 287, 323);
rectangle(244, 226, 288, 322);
rectangle(553, 43, 582, 136);
rectangle(552, 44, 583, 135);
rectangle(483, 307, 512, 400);
rectangle(482, 308, 513, 399);
line(rount[i][0], rount[i][1], rount[i + 1][0], rount[i + 1][1]);
setcolor(BLUE);
rectangle(185, 444, 233, 479);
rectangle(245, 226, 287, 322);
rectangle(553, 44, 582, 135);
rectangle(483, 308, 512, 399);

if (rount[i][0] < rount[i + 1][0]&& rount[i][1] >= rount[i + 1][1])//第一象限
{
do
{
k = linemove21(6,x1, y1, buffer1);
} while (k == 1);
}
else if (rount[i][0] >= rount[i + 1][0] && rount[i][1] > rount[i + 1][1])//第二象限
{
do
{
k = linemove22(6, x1, y1, buffer1);
} while (k == 1);
}
else if (rount[i][0] > rount[i + 1][0] && rount[i][1] <= rount[i + 1][1])//第三象限
{
do
{
k = linemove22(0, x1, y1, buffer1);
} while (k == 1);
}
else if (rount[i][0] <= rount[i + 1][0] && rount[i][1] < rount[i + 1][1])//第三象限
{
do
{
k = linemove21(0, x1, y1, buffer1);
} while (k == 1);
}


getimage(*x1, *y1, *x1 + 20, *y1 + 10, buffer1);
fushitu(*x1, *y1);
delay(100);
putimage(*x1 , *y1 , buffer1, COPY_PUT);
setcolor(RED);
line(rount[i][0], rount[i][1], rount[i + 1][0], rount[i + 1][1]);
if (i < *amtjudge)
nyphoto(rount[i + 1][0], rount[i + 1][1]);
}
getimage(*x1, *y1, *x1 + 20, *y1 +10, buffer1);
fushitu(*x1, *y1);
delay(500);
putimage(*x1 , *y1, buffer1, COPY_PUT);
free(buffer1);
free(x1);
free(y1);
}

int linemove1( int* x, int* y, int* buffer1)//大农田沿线段运动
{
int a[10][2] = { {-1,0}, {-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0}, {-1,-1} };
int b, judge = 0;
int i;
int x0 = 0, y0 = 0;
for (i = 1; i < 9; i++)
{
b = getpixel(a[i][0] + *x, a[i][1] + *y);
if (b == CYAN)
{
x0 = a[i][0];
y0 = a[i][1];
judge = 1;
break;
}
}
getimage(*x-6, *y-8, *x + 16, *y + 18, buffer1);
suofangtu(*x, *y,1);
delay(8);
putimage(*x-6, *y-8, buffer1, COPY_PUT);
if (judge == 1)
{
putpixel(*x + a[i-1][0], *y + a[i-1][1], RED);
putpixel(*x + a[i][0], *y + a[i][1], RED);
putpixel(*x + a[i+1][0], *y + a[i+1][1], RED);
putpixel(*x , *y , RED);

*x = *x + x0;
*y = *y + y0;
putpixel(*x,*y, RED);
}
return judge;
}

int linemove21(int judge1, int* x, int* y, int* buffer1)//小农田沿线段运动(顺时针)
{
int a[17][2] = { {0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0}, {-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0}, {-1,-1},{0,-1} };
int b, judge = 0;
int i;
int x0 = 0, y0 = 0;
for (i = judge1; i < judge1+8; i++)
{
b = getpixel(a[i][0] + *x, a[i][1] + *y);
if (b == CYAN)
{
x0 = a[i][0];
y0 = a[i][1];
judge = 1;
break;
}
}
getimage(*x, *y, *x + 20, *y + 10, buffer1);
fushitu(*x, *y);
delay(8);
putimage(*x, *y, buffer1, COPY_PUT);
if (judge == 1)
{
putpixel(*x + a[i][0], *y + a[i][1], RED);
putpixel(*x + a[i+1][0], *y + a[i+1][1], RED);
putpixel(*x , *y , RED);

*x = *x + x0;
*y = *y + y0;
putpixel(*x,*y, RED);
}
return judge;
}

int linemove22(int judge1, int* x, int* y, int* buffer1)//小农田沿线段运动(逆时针)
{
int a[17][2] = { {0,-1}, {-1,-1}, {-1,0}, {-1,1}, {0,1} , {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}, {0,1} , {1,1}, {1,0}, {1,-1},{0,-1} };
int b, judge = 0;
int i;
int x0 = 0, y0 = 0;
for (i = judge1; i < judge1+8; i++)
{
b = getpixel(a[i][0] + *x, a[i][1] + *y);
if (b == CYAN)
{
x0 = a[i][0];
y0 = a[i][1];
judge = 1;
break;
}
}
getimage(*x, *y, *x + 20, *y + 10, buffer1);
fushitu(*x, *y);
delay(8);
putimage(*x, *y, buffer1, COPY_PUT);
if (judge == 1)
{
putpixel(*x + a[i][0], *y + a[i][1], RED);
putpixel(*x + a[i+1][0], *y + a[i+1][1], RED);
putpixel(*x, *y, RED);

*x = *x + x0;
*y = *y + y0;
putpixel(*x, *y, RED);
}
return judge;
}

pensa.h

1
2
3
4
5
6
7
8
9
10
#ifndef _PENSA_H_
#define _PENSA_H_

int zhuzhan(int* a8,int nongyao[6]);
void peizhi(void);
void drhook(int x, int y);
void cross(int x, int y);
void drline(int x, int y);

#endif

pensa.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
 #include "common.h"

int zhuzhan(int* a8,int nongyao[6])
{
int i;
if (*a8 == 1)
{
peizhi();
*a8 = 0;
}
showbiankuang(600, 0, 640, 40);
showbiankuang(0, 0, 80, 40);
showbiankuang(370, 0, 580, 60);
if (mouse_press(600, 0, 640, 40) == 1)
{
return -1;//关闭BC。
}
else if (mouse_press(0, 0, 80, 40) == 1)
{
*a8 = 1;
if (nongyao[5] == 0)
return 2;
else if (nongyao[5] == 1)
return 3;
}
if (nongyao[0] == 0)
{
if (mouse_press(300, 145, 440, 225) == 1 || mouse_press(160, 225, 300, 305) == 1)//氟铃脲
{
*a8 = 1;
nongyao[0] = 1;

}
}
if (nongyao[2] == 0)
{
if (mouse_press(300, 225, 440, 305) == 1)//氯氰菊酯
{
*a8 = 1;
nongyao[2] = 1;
}
}
if (nongyao[4] == 0)
{
if (mouse_press(160, 305, 300, 385) == 1)//菌酯
{
*a8 = 1;
nongyao[4] = 1;
}
}
if (nongyao[5] == 1)
{
if (nongyao[1] == 0)
{
if (mouse_press(440, 145, 580, 225) == 1)//甲胺磷
{
*a8 = 1;
nongyao[1] = 1;
}
}
if (nongyao[3] == 0)
{
if (mouse_press(440, 385, 580, 465) == 1)//甲维盐
{
*a8 = 1;
nongyao[3] = 1;
}
}
}

if (nongyao[0] == 1)
{
if (mouse_press(410, 145, 440, 175) == 1 || mouse_press(270, 225, 300, 255) == 1)//氟铃脲
{
*a8 = 1;
nongyao[0] = 0;
delay(400);

}
}
if (nongyao[2] == 1)
{
if (mouse_press(410, 225, 440, 255) == 1)//氯氰菊酯
{
*a8 = 1;
nongyao[2] = 0;
delay(400);
}
}
if (nongyao[4] == 1)
{
if (mouse_press(270, 305, 300, 335) == 1)//菌酯
{
*a8 = 1;
nongyao[4] = 0;
delay(400);
}
}
if (nongyao[5] == 1)
{
if (nongyao[1] == 1)
{
if (mouse_press(550, 145, 580, 175) == 1)//甲胺磷
{
*a8 = 1;
nongyao[1] = 0;
delay(400);
}
}
if (nongyao[3] == 1)
{
if (mouse_press(550, 385, 580, 415) == 1)//甲维盐
{
*a8 = 1;
nongyao[3] = 0;
delay(400);
}
}
}


if (mouse_press(370, 0, 580, 60) == 1)//装配农药
{
*a8 = 1;
return 8;
}
return 7;
}

void peizhi(void)//配置界面绘画
{
int i;
int x,y;
cleardevice();
clrmous(MouseX, MouseY);
setcolor(RED);
rectangle(600, 0, 640, 40);
line(600, 0, 640, 40);
line(640, 0, 600, 40);//关闭按钮

rectangle(0, 0, 80, 40);
puthz(5, 5, "返回", 32, 40, GREEN);
setfillstyle(1, BLUE);
bar(20, 65, 580, 465);
bar(370, 0, 580, 60);
puthz(390, 10, "装配农药", 32, 40, WHITE);
puthz(100, 10, "选择配置农药", 32, 40, BLUE);
setcolor(LIGHTGRAY);
rectangle(370, 0, 580, 60);
line(20, 65, 160, 145);
for (i = 0; i < 6; i++)
{
x = 20 + 140 * i;
line(x, 65, x, 465);
line(x+1, 65, x+1, 465);
y = 65 + 80 * i;
line(20, y, 580, y);
line(20, y+1, 580, y+1);
}
puthz(80, 70, "植株种类", 16, 20, WHITE);
puthz(30, 120, "病害种类", 16, 20, WHITE);
puthz(25, 170, "棉铃虫", 24, 30, WHITE);
puthz(25, 250, "黏虫", 24, 30, WHITE);
puthz(25, 330, "白粉病", 24, 30, WHITE);
puthz(25, 410, "锈病", 24, 30, WHITE);
puthz(165, 90, "小麦", 24, 30, WHITE);
puthz(165, 255, "氟铃脲", 24, 30, WHITE);
puthz(165, 335, "菌酯", 24, 30, WHITE);
puthz(305, 90, "玉米", 24, 30, WHITE);
puthz(305, 175, "氟铃脲", 24, 30, WHITE);
puthz(305, 255, "氯氰菊酯", 24, 30, WHITE);
puthz(445, 90, "棉花", 24, 30, WHITE);
puthz(445, 175, "甲胺磷", 24, 30, WHITE);
puthz(445, 415, "甲维盐", 24, 30, WHITE);
drline(160, 145);
drline(160, 385);
drline(300, 305);
drline(300, 385);
drline(440, 225);
drline(440, 305);

if (nongyao[0] == 1)
{
setfillstyle(1, WHITE);
bar(300, 145, 440, 225);
bar(160, 225, 300, 305);
puthz(165, 255, "氟铃脲", 24, 30, BLUE);
puthz(305, 175, "氟铃脲", 24, 30, BLUE);
drhook(300, 145);
drhook(160, 225);
setfillstyle(1, RED);
bar(410, 145, 440, 175);
bar(270, 225, 300, 255);
cross(410, 145);
cross(270, 225);
rectangle(300, 145, 440, 225);
rectangle(160, 225, 300, 305);
}
if (nongyao[1] == 1)
{
setfillstyle(1, WHITE);
bar(440, 145, 580, 225);
puthz(445, 175, "甲胺磷", 24, 30, BLUE);
drhook(440, 145);
setfillstyle(1, RED);
bar(550, 145, 580, 175);
cross(550, 145);
rectangle(440, 145, 580, 225);
}
if (nongyao[2] == 1)
{
setfillstyle(1, WHITE);
bar(300, 225, 440, 305);
puthz(305, 255, "氯氰菊酯", 24, 30, BLUE);
drhook(300, 225);
setfillstyle(1, RED);
bar(410, 225, 440, 255);
cross(410, 225);
rectangle(300, 225, 440, 305);
}
if (nongyao[3] == 1)
{
setfillstyle(1, WHITE);
bar(440, 385, 580, 465);
puthz(445, 415, "甲维盐", 24, 30, BLUE);
drhook(440, 385);
setfillstyle(1, RED);
bar(550, 385, 580, 415);
cross(550, 385);
rectangle(440, 385, 580, 465);
}
if (nongyao[4] == 1)
{
setfillstyle(1, WHITE);
bar(160, 305, 300, 385);
puthz(165, 335, "菌酯", 24, 30, BLUE);
drhook(160, 305);
setfillstyle(1, RED);
bar(270, 305, 300, 335);
cross(270, 305);
rectangle(160, 305, 300, 385);
}
if (nongyao[5] == 0)
{
setfillstyle(1, BLUE);
bar(442, 147, 578, 223);
bar(442, 387, 578, 463);
drline(440, 145);
drline(440, 385);
}
}

void drhook(int x, int y)
{
setcolor(RED);
line(x + 110, y + 70, x + 125, y + 80);
line(x + 111, y + 70, x + 126, y + 80);
line(x + 124, y + 80, x + 139, y + 50);
line(x + 125, y + 80, x + 140, y + 50);
}

void cross(int x, int y)
{
setcolor(WHITE);
line(x, y, x + 30, y + 30);
line(x, y + 1, x + 29, y + 30);
line(x + 1, y, x + 30, y + 29);
line(x, y + 30, x + 30, y);
line(x, y + 29, x + 29, y);
line(x + 1, y + 30, x + 30, y + 1);
}

void drline(int x, int y)
{
setcolor(LIGHTGRAY);
line(x, y, x + 140, y + 80);
line(x+1, y, x + 141, y + 80);
}

借用祖传

hz.h

1
2
3
4
5
6
#ifndef __HZ_H__
#define __HZ_H__

void puthz(int x, int y,char *s,int flag,int part,int color);
#endif

hz.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"hz.h"

void puthz(int x, int y,char *s,int flag,int part,int color)
{
FILE *hzk_p=NULL; //定义汉字库文件指针
unsigned char quma,weima; //定义汉字的区码和位码
unsigned long offset; //定义汉字在字库中的偏移量
unsigned char mask[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; //功能数组,用于显示汉字点阵中的亮点
int i,j,pos;


switch(flag) //不同的flag对应不同的汉字库,实现了汉字的大小可根据需要改变
{
case 16 :
{
char mat[32]; //16*16的汉字需要32个字节的数组来存储
int y0=y;
int x0=x;
hzk_p = fopen("HZK\\HZ16","rb"); //使用相对路径
if(hzk_p==NULL)
{
settextjustify(LEFT_TEXT,TOP_TEXT); //左部对齐,顶部对齐
settextstyle(GOTHIC_FONT,HORIZ_DIR,1); //黑体笔划输出,水平输出,24*24点阵
outtextxy(10,10,"Can't open hzk16 file!Press any key to quit...");
getch();
exit(1);

}
while(*s!=NULL)
{
while (x<640-flag && (*s!=NULL))
{
y=y0;
quma=s[0]-0xa0; //求出区码
weima=s[1]-0xa0; //求出位码
offset=(94*(quma-1)+(weima-1))*32L; //求出要显示的汉字在字库文件中的偏移
fseek(hzk_p,offset,SEEK_SET); //重定位文件指针
fread (mat,32,1,hzk_p); //读出该汉字的具体点阵数据,1为要读入的项数

for(i=0;i<16;i++)
{
pos=2*i; //16*16矩阵中有每一行有两外字节
for(j=0;j<16;j++) //一行一行地扫描,将位上为了1的点显示出来
{
if((mask[j%8]&mat[pos+j/8])!=NULL) //j%8只能在0—8之间循环,j/8在0,1之间循环
{
putpixel(x+j,y,color);

}

}
y++;


}
/*====================================================
以上是一个汉字显示完
====================================================*/
x+=part; //给x 一个偏移量part
s+=2; //汉字里存放的是内码,2个字节,所以要加2

}
x=x0;y0+=flag+10; //一行汉字显示完后,重新从左侧开始输出汉字,给y一个偏移量
}

break;

}


case 24 :
{
char mat[72]; //24*24矩阵要72个字节来存储
int y0=y;
int x0=x;
hzk_p = fopen("HZK\\Hzk24k","rb");
if (hzk_p==NULL)
{
settextjustify(LEFT_TEXT,TOP_TEXT); //左部对齐,顶部对齐
settextstyle(GOTHIC_FONT,HORIZ_DIR,3); //黑体笔划输出,水平输出,24*24点阵
outtextxy(10,10,"Can't open hzk24 file!Press any key to quit...");
getch();
exit(1);

}
while(*s!=NULL)
{
while(x<640-flag && (*s!=NULL))
{
y=y0;
quma=s[0]-0xa0; //求出区码
weima=s[1]-0xa0; //求出位码
offset=(94*(quma-1)+(weima-1))*72L;
fseek(hzk_p,offset,SEEK_SET);
fread (mat,72,1,hzk_p);
for (i=0;i<24;i++)
{
pos=3*i; //矩阵中每一行有三个字节
for (j=0;j<24;j++) // 每一行有24位
{
if ((mask[j%8]&mat[pos+j/8])!=NULL)
putpixel(x+j,y,color);

}
y++;

}
x+=part;
s+=2;
}
x=x0;y0+=flag+10;
}
break;
}

case 32 :
{
char mat[128]; //32*32的汉字需要128个字节的数组来存储
int y0=y;
int x0=x;
hzk_p = fopen("HZK\\HZK32S","rb");
if(hzk_p==NULL)
{
settextjustify(LEFT_TEXT,TOP_TEXT); //左部对齐,顶部对齐
settextstyle(GOTHIC_FONT,HORIZ_DIR,3); //黑体笔划输出,水平输出,24*24点阵
outtextxy(10,10,"Can't open hzk32 file!Press any key to quit...");
getch();
exit(1);

}
while(*s!=NULL)
{
while (x<640-flag && (*s!=NULL))
{
y=y0;
quma=s[0]-0xa0; //求出区码
weima=s[1]-0xa0; //求出位码
offset=(94*(quma-1)+(weima-1))*128L;
fseek(hzk_p,offset,SEEK_SET);
fread (mat,128,1,hzk_p);
for(i=0;i<32;i++)
{
pos=4*i; //32*32矩阵中有每一行有两外字节
for(j=0;j<32;j++)
{
if((mask[j%8]&mat[pos+j/8])!=NULL)
{
putpixel(x+j,y,color);

}

}
y++;


}
//以上是一个汉字显示完
x+=part; //给x 一个偏移量part
s+=2; //汉字里存放的是内码,2个字节,所以要加2

}
x=x0;y0+=flag+10; //一行汉字显示完后,给y一个偏移量
}
break;

}


case 48:
{
char mat[288]; //48*48的汉字需要288个字节的数组来存储
int y0=y;
int x0=x;
hzk_p = fopen("HZK\\Hzk48k","rb");
if(hzk_p==NULL)
{
settextjustify(LEFT_TEXT,TOP_TEXT); //左部对齐,顶部对齐
settextstyle(GOTHIC_FONT,HORIZ_DIR,3); //黑体笔划输出,水平输出,24*24点阵
outtextxy(10,10,"Can't open hzk48 file!Press any key to quit...");
getch();
exit(1);

}
while(*s!=NULL)
{
while (x<640-flag && (*s!=NULL))
{
y=y0;
quma=s[0]-0xa0; //求出区码
weima=s[1]-0xa0; //求出位码
offset=(94*(quma-1)+(weima-1))*288L; //求出要显示的汉字在字库文件中的偏移
fseek(hzk_p,offset,SEEK_SET); //重定位文件指针
fread (mat,288,1,hzk_p); //读出该汉字的具体点阵数据,1为要读入的项数

for(i=0;i<48;i++)
{
pos=6*i;
for(j=0;j<48;j++) //一行一行地扫描,将位上为了1的点显示出来
{
if((mask[j%8]&mat[pos+j/8])!=NULL) //j%8只能在0—8之间循环,j/8在0,1之间循环
{
putpixel(x+j,y,color);

}

}
y++;
}
//以上是一个汉字显示完
x+=part; //给x 一个偏移量part
s+=2; //汉字里存放的是内码,2个字节,所以要加2

}
x=x0;y0+=flag+10; //一行汉字显示完后,给y一个偏移量
}
break;

}

default:
break;

}

fclose(hzk_p);
}

IMAGE.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef IMAGE_H
#define IMAGE_H

int bmp_convert(char *bmp,char *dbm); //将 *.bmp 变为 *.dbm,字符串bmp中为bmp所在地址,字dbmp为输出地址
int show_dbm(int x,int y,char *dbm,int nowpage); //输入dbmp的路径,在(x,y)输出图片(x需为8的倍数)
void cir_bar(int x1,int y1,int x2,int y2,int color); //在指定位置画出一个圆角矩形框
void movetopage(int x1, int y1, int x2, int y2,int page1);
void set_color(int color_no,int red,int green,int blue); //指定颜色编号,修改其对应的rgb值
int quick_move_2(int Start, int End, int Size);
int quick_move_1(int Start, int End, int Size);
void close_display(void); //关闭屏幕显示
void open_display(void); //打开屏幕显示

#endif

IMAGE.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/***********************

该图像转换及输出函数,要求输入的图片分辨率在640*480之内

***********************/
#include <stdio.h>
#include <dos.h>
#include "image.h"
#include <graphics.h>
#include <conio.h>

int bmp_convert(char *bmp,char *dbm) //将 *.bmp 变为 *.dbm,字符串bmp中为bmp所在地址,字dbmp为输出地址
{
// static int color[16]={0,4,2,6,1,5,3,7,8,12,10,14,9,13,11,15}; 上win下ps
static int color[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//索引与bc内颜色序号对应转换(建议用win画图转化)
unsigned char dbmline[640],bmpline[640],pixel[8],Vbyte;
int ImageW,ImageH,i,j,k,n,now,bmpcom,gg ;
long hangsize;
FILE *fbmp,*fdbm;
union {
unsigned char val;
struct {
unsigned cl:4;
unsigned ch:4;
}color; //用位域储存颜色信息,分拆颜色信息
}MyColor;
if((fbmp=fopen(bmp,"rb"))==NULL)
{
printf("%s\n",bmp);
printf("Open bmp error!");
return 1;
}
fseek(fbmp,18,SEEK_SET); //bmp图像的宽高在文件头18字节后
fread(&gg,4,1,fbmp);
// fread(&ImageW,4,1,fbmp);
fread(&ImageH,4,1,fbmp);
ImageW=gg;
// ImageH*=2;
// printf("%d ",ImageW);
// printf("%d",ImageH);
if(ImageW==0||ImageH==0||ImageW>641||ImageH>481)/////注意注意!!根据实际修改/
{
printf("The image is too large!Please input image below 640*480.");
fclose(fbmp);
return 1;
}
if((fdbm=fopen(dbm,"wb"))==NULL)
{
printf("Creat \"%s\" error!",dbm);
return 1;
}
bmpcom=(ImageW-1)/8+1; //行处理单元数
hangsize=bmpcom*4; //每行字节数(DIB数据要求每行字节为4整数倍,已计算补零)
fwrite(&ImageW,sizeof(int),1,fdbm);
fwrite(&ImageH,sizeof(int),1,fdbm);
fseek(fbmp,-hangsize,SEEK_END);
for(i=0;i<ImageH;i++)
{
now=0;
fread(bmpline,hangsize,1,fbmp);
fseek(fbmp,-hangsize*2,SEEK_CUR);
for(n=3;n>=0;n--) //每行拆成四个位面的数据输出
// for(n=0;n<=3;n++)
{
for(j=0;j<bmpcom;j++)
{
Vbyte=0;
for(k=0;k<4;k++)
{
MyColor.val=bmpline[j*4+k];
pixel[k*2]=color[MyColor.color.ch];
pixel[k*2+1]=color[MyColor.color.cl];
}
for(k=0;k<8;k++)
{
Vbyte+=(pixel[k]>>n&1)<<(7-k);
}
dbmline[now++]=Vbyte;
}
}
fwrite(dbmline,hangsize,1,fdbm);
}
fclose(fdbm);
fclose(fbmp);
return 0;
}

int show_dbm(int x,int y,char *dbm,int nowpage) //输入dbmp的路径,在(x,y)输出图片(x需为8的倍数)
{
int ImageW,ImageH,n,i,j;
long hangsize;
FILE * fdbm;
char far * per;

if(nowpage==0)
per=(char far *)0xA0000000L;
else
per=(char far *)0xA8000000L;

// _VideoBusy=YES; //hanenv系统内的显示寄存器保护变量

if((fdbm=fopen(dbm,"rb"))==NULL)
{
// printf("%s",dbm);
// getchar();
// printf("Open Error!");
return 1;
}
fread(&ImageW,sizeof(int),1,fdbm);
fread(&ImageH,sizeof(int),1,fdbm);
// printf("%d %d",ImageW,ImageH);
hangsize=(ImageW-1)/8;
per=per+x/8+y*80;
if((ImageH+y)>480) ImageH=480-y; //VGAMED 640*480
for(i=0;i<ImageH;i++)
{
for(n=8;n>=1;n>>=1) //从第三位颜色平面写到第0
{
outportb(0x3c4,2);
outportb(0x3c5,n);
fread(per,hangsize,1,fdbm);
fseek(fdbm,1,SEEK_CUR);
}
// fseek(fdbm,hangsize*2,SEEK_CUR);
per+=80;
}
fclose(fdbm);

// _VideoBusy=NO;

outportb(0x3c5,0xf);
return 0;
}

void cir_bar(int x1,int y1,int x2,int y2,int color) //在指定位置画出一个圆角矩形框
{
int w=x2-x1,h=y2-y1;
setcolor(color);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);
ellipse(5+x1,10+y1,90,180,5,10);
line(0+x1,10+y1,0+x1,10+h-20+y1);
ellipse(5+x1,10+h-20+y1,180,270,5,10);
line(5+x1,0+y1,5+w-10+x1,0+y1);
ellipse(5+w-10+x1+1,10+y1,0,90,5,10);
line(w+x1,10+y1,w+x1,y2-10);
ellipse(w-5+x1+1,10+h-20+y1,270,360,5,10);
line(5+x1,h+y1,5+w-10+x1,h+y1);
}

void movetopage(int x1, int y1, int x2, int y2,int page1) //显示页间局部图像数据传输,输入左上角坐标及右上角坐标,从page1移动到page2
{
int per1, per2;
int hangsize = (x2 - x1) / 8;
int high = y2 - y1 + 1;
register int i, p1, p2;
if (page1 == 0)
{
per2 = 0xA0000000L;
per1 = 0xA8000000L;
}
else
{
per1 = 0xA0000000L;
per2 = 0xA8000000L;
}



per1 = per1 + (x1) / 8 + (y1 ) * 80;
per2 = per2 + (x1) / 8 + (y1 ) * 80;
for (i = 0; i <high; i++) //传输视频图像
{
for (p1 = 8, p2 = 3; p1 >= 1; p1 >>= 1, p2--) //从第三位颜色平面写到第0
{
outportb(0x3c4, 2); //颜色位面写寄存器
outportb(0x3c5, p1);
outportb(0x3ce, 4); //颜色位面读寄存器
outportb(0x3cf, p2);
if (page1 == 0)
{
quick_move_2(per2, per1, hangsize);
}
else
{
quick_move_1(per2, per1, hangsize);
}
}
per1 += 80;
per2 += 80;
}
outportb(0x3cf,0); //恢复设置
outportb(0x3c5,0xf);
}

void set_color(int color_no,int red,int green,int blue) //指定颜色编号,修改其对应的rgb值
{
if(color_no<16)
{
_AX=0x1007; //选择10H显示中断中的第7号功能
_BL=color_no;
geninterrupt(0x10);
color_no=_BH;
}
else
color_no = 0xff; //将屏幕边缘色指向调色板255

//修改调色板寄存器
_DH=red;
_CH=green;
_CL=blue;
_BX=color_no;
_AX=0x1010;
geninterrupt(0x10);

//处理屏幕边缘颜色
if(color_no==0xff)
{
_BH=0xff;
_AX=0x1001;
geninterrupt(0x10);
}
}

/*此为用汇编编写的支持跨段寻址的数据传输函数,来自《VGA页面图形数据移动技术在特殊显示效果中的应用》一文*/
int quick_move_1(int Start,int End,int Size) //Start为原处首地址,End为目标位置首地址 (1 to 0)
{
asm{
push es
push ds
push di
push si
push ax
push cx
push dx
mov ax,0a800h
mov ds,ax
mov ax,Start
mov si,ax
mov ax,0a000h
mov es,ax
mov ax,End
mov di,ax
mov cx,Size
rep movsb
pop dx
pop cx
pop ax
pop si
pop di
pop ds
pop es
}
return 0;
}

int quick_move_2(int Start,int End,int Size) //Start为原处首地址,End为目标位置首地址 (0 to 1)
{
asm{
push es
push ds
push di
push si
push ax
push cx
push dx
mov ax,0a000h
mov ds,ax
mov ax,Start
mov si,ax
mov ax,0a800h
mov es,ax
mov ax,End
mov di,ax
mov cx,Size
rep movsb
pop dx
pop cx
pop ax
pop si
pop di
pop ds
pop es
}
return 0;
}

void close_display(void) //关闭屏幕显示
{
_BL=0x32;
_AH=0x12;
_AL=0x01;
geninterrupt(0x10);
}

void open_display(void) //打开屏幕显示
{
_BL=0x32;
_AH=0x12;
_AL=0x00;
geninterrupt(0x10);
}

mouse.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef _mouse_h_
#define _mouse_h_
int mouse_press(int x1, int y1, int x2, int y2);//如果在框中点击,则返回1;在框中未点击,则返回2;不在框中则返回0
void mouse(int,int);//设计鼠标
void mouseinit(void);//初始化
void mou_pos(int*,int*,int*);//更改鼠标位置
void mread(int *,int *,int*);//改坐标不画
void save_bk_mou(int x,int y);//存鼠标背景
void clrmous(int x,int y);//清除鼠标
void drawmous(int x,int y);//画鼠标
void newmouse(int *nx,int *ny,int *nbuttons); //更新鼠标

extern int MouseX;
extern int MouseY;
extern int MouseS;
extern int press;
extern union REGS regs;
#endif

mouse.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdio.h>
#include<stdlib.h>
#include "mouse.h"


/**************************
MOUSE.c
UPDATER: dengshuumin
FUNCTION: mouse action
ABSTRACT:
A.mread
B.newmouse
VERSION: 3.0
***************************/
int MouseX;
int MouseY;
int MouseS;
int press;//形状用 &press
void *buffer;//
union REGS regs;
int flag=0;


void mouseinit()//初始化
{
int retcode;
int xmin,xmax,ymin,ymax,x_max=625,y_max=480;
int size;

xmin=2;
xmax=x_max-1;
ymin=8;
ymax=y_max-2;
regs.x.ax=0;
int86(51,&regs,&regs);
retcode=regs.x.ax;
if(retcode==0)
{
printf("Mouse or Mouse Driver Obsent,Please Install!");
delay(5000);
}
else
{
regs.x.ax=7;
regs.x.cx=xmin;
regs.x.dx=xmax;
int86(51,&regs,&regs);
regs.x.ax=8;
regs.x.cx=ymin;
regs.x.dx=ymax;
int86(51,&regs,&regs);
}
MouseS = 0;
MouseX=320,MouseY=240;
save_bk_mou(320,240);
mouse(MouseX,MouseY);
flag=1;
}

/*****************************
FUNCTION: mouse
DESCRIPTION: 画不同形态的鼠标
INPUT: x,y
RETURN: 无
******************************/
void mouse(int x,int y)
{

switch(MouseS)
{
case 1: //手势鼠标
{
setcolor(WHITE);
setlinestyle(0,0,1);
line(x-1,y+9,x-1,y+8);
line(x,y+7,x,y+11);
line(x+1,y+6,x+1,y+13);
line(x+2,y+8,x+2,y+14);
line(x+3,y-1,x+3,y+15);
arc(x+4,y-1,0,180,1);
line(x+4,y-2,x+4,y+15);
line(x+5,y-1,x+5,y+16);
arc(x+6,y+3,0,180,1);
line(x+6,y+2,x+6,y+16);
line(x+7,y+3,x+7,y+17);
arc(x+8,y+5,0,180,1);
line(x+8,y+4,x+8,y+17);
line(x+9,y+5,x+9,y+16);
arc(x+10,y+7,0,180,1);
line(x+10,y+6,x+10,y+16);
line(x+11,y+7,x+11,y+13);

setcolor(DARKGRAY);
line(x-1,y+9,x-1,y+8);
line(x-1,y+8,x+1,y+6);
line(x+1,y+6,x+3,y+10);
line(x+3,y+10,x+3,y-1);
arc(x+4,y-1,0,180,1);
line(x+5,y-1,x+5,y+5);
arc(x+6,y+3,0,180,1);
line(x+7,y+3,x+7,y+7);
arc(x+8,y+5,0,180,1);
line(x+9,y+5,x+9,y+9);
arc(x+10,y+7,0,180,1);
line(x+11,y+7,x+11,y+13);
arc(x+7,y+13,-90,0,4);
line(x+7,y+17,x+3,y+15);
line(x+3,y+15,x+1,y+13);
line(x+1,y+13,x-1,y+9);
}
break;
case 2: //光标
{
setcolor(DARKGRAY);
setlinestyle(0,0,1);
line(x+1,y-1,x+9,y-1);
line(x+1,y+15,x+9,y+15);
line(x+5,y-1,x+5,y+15);
}
break;
case 3: //十字
{
setcolor(WHITE);
setlinestyle(0,0,1);
line(x-1,y+7,x+11,y+7);
line(x+5,y-1,x+5,y+15);
}
break;
default: //默认鼠标
{
setlinestyle(0,0,1);
setcolor(WHITE);
line(x,y,x,y+13);
line(x+1,y+1,x+1,y+12);
line(x+2,y+2,x+2,y+11);
line(x+3,y+3,x+3,y+10);
line(x+4,y+4,x+4,y+12);
line(x+5,y+5,x+5,y+9);
line(x+5,y+11,x+5,y+14);
line(x+6,y+6,x+6,y+9);
line(x+6,y+13,x+6,y+15);
line(x+7,y+7,x+7,y+9);
line(x+8,y+8,x+8,y+9);
line(x+9,y+9,x+9,y+9);
setcolor(DARKGRAY);
line(x-1,y-1,x-1,y+14);
line(x-1,y+14,x+3,y+11);
line(x+3,y+11,x+3,y+12);
line(x+3,y+12,x+4,y+13);
line(x+4,y+13,x+4,y+14);
line(x+4,y+14,x+7,y+17);
line(x+7,y+17,x+7,y+13);
line(x+7,y+13,x+6,y+12);
line(x+6,y+12,x+6,y+11);
line(x+6,y+11,x+5,y+10);
line(x+5,y+10,x+11,y+10);
line(x+11,y+10,x-1,y-2);
}
break;
}
}

void mou_pos(int *nx,int *ny,int*nbuttons)//更改鼠标位置
{
int x0=*nx,y0=*ny;

mread(nx,ny,nbuttons);
clrmous(x0,y0);
save_bk_mou(*nx,*ny);
drawmous(*nx,*ny);
}

void mread(int *nx,int *ny,int*nbuttons)//改坐标不画
{
int x0=*nx,y0=*ny,buttons0=*nbuttons;
int xnew,ynew,buttonsnew;

do{
regs.x.ax=3;
int86(51,&regs,&regs);
buttonsnew=regs.x.bx;
delay(10);
regs.x.ax=3;
int86(51,&regs,&regs);
if(regs.x.bx==buttonsnew)
*nbuttons=regs.x.bx;
else
*nbuttons=buttons0;
xnew=regs.x.cx;
ynew=regs.x.dx;
}while(xnew==x0&&ynew==y0&&*nbuttons==0);
*nx=xnew;
*ny=ynew;
}


/***************************************
FUNCTION: mread
DESCRIPTION: 获取新的寄存器信息
INPUT: nx,ny,nbuttons
RETURN: 无
****************************************/
//void mread(int *nx,int *ny,int *nbuttons)
//{
// regs.x.ax=3;
// int86(51,&regs,&regs);
// *nx = regs.x.cx;
// *ny = regs.x.dx;
// *nbuttons = regs.x.bx;
//}

/*******************************************
FUNCTION: newmouse
DESCRIPTION: 鼠标状态发生变化则更新鼠标
INPUT: nx,ny,nbuttons
RETURN: 无
********************************************/
void newmouse(int *nx,int *ny,int *nbuttons)
{
int xn,yn,buttonsn;
int x0=*nx,y0=*ny,buttons0=*nbuttons;
mread(&xn,&yn,&buttonsn);
*nx = xn;
*ny = yn;
*nbuttons = buttonsn;
if(buttons0 == *nbuttons)
*nbuttons = 0; //使得能连续按键
if(xn == x0 && yn == y0 && buttonsn == buttons0)
return; //鼠标状态不变则直接返回S
clrmous(x0,y0); //说明鼠标状态发生了改变
save_bk_mou(*nx,*ny);
drawmous(*nx,*ny);
}

void save_bk_mou(int nx,int ny)//存鼠标背景
{
int size;

size=imagesize(nx-1,ny-2,nx+11,ny+17);
buffer=malloc(size);
if(buffer!=NULL)
getimage(nx-1,ny-2,nx+11,ny+17,buffer);
else
printf("Error");
}

void clrmous(int nx,int ny)//清除鼠标
{
if(flag==1)
{
setwritemode(XOR_PUT);
mouse(nx,ny);
putimage(nx-1,ny-2,buffer,COPY_PUT);
free(buffer);
flag=0;
setwritemode(COPY_PUT);
}
}
void drawmous(int nx,int ny)
{
if(flag==0)
{
setwritemode(COPY_PUT);
mouse(nx,ny);
flag=1;
}
}



//如果在框中点击,则返回1;在框中未点击,则返回2;不在框中则返回0
int mouse_press(int x1, int y1, int x2, int y2)
{
//在框中点击,则返回1
if(MouseX > x1
&&MouseX < x2
&&MouseY > y1
&&MouseY < y2
&&press == 1)
{
return 1;
}

//在框中未点击,则返回2
else if(MouseX > x1
&&MouseX < x2
&&MouseY > y1
&&MouseY < y2
&&press == 0)
{
return 2;
}

//在框中点击右键,则返回3
else if(MouseX > x1
&&MouseX < x2
&&MouseY > y1
&&MouseY < y2
&&press == 2)
{
return 3;
}

else
{
return 0;
}
}

后续补充(完结撒花

整个程序的源代码。需要解压密码,可以通过邮件获取,或者自己蒙。什么?你问我为什么要解压密码,当然是因为知识产权了,毕竟不是我一个编写的,还是不能随意传播,而且用处不大,你只需要学习就可以了,而且❀可A院这个爆烂的C应该不久会淘汰吧?或许会换新的爆烂。

点击下载源代码

如果不出意外,这个系列更新应该是无了。如果以后有幸帮学妹学弟搞这玩意,又有了新的东西和新的羁绊,我或许会再加一点东西。现在已经不想更了,因为这一切都和我没关系了(doge),我写的时候可没有像我这么好的人专门花大量时间搞这个。。。

愿世上再无C课设——7.29.2024

完结散花



10.26.2024——最终删减修改。(这种东西,过了就行,没必要花过多时间在这上面

留下万分之一点,采得孤人所笑言