【发布时间】:2015-12-18 19:45:25
【问题描述】:
如何将主方法分解为更小的方法,而不是将主文件分解为三个文件:头文件、客户端和 C 编程中 SFML 中的实现。
我们的主文件中没有函数,只有主方法,你怎么能把主方法分解成更小的,每个特定的任务?您打算为这些方法使用什么名称?这些方法的输入是什么? 根据您将如何将主要方法分解为较小的方法,创建您的接口以包含方法原型 剩下的是客户。连接您的方法并以正确的顺序调用它们以获得我们之前对 main.c 文件的相同行为。 编程时要考虑的事项:
不允许使用全局变量 对于方法参数,只选择需要发送的参数。如果一个参数只有一个方法需要,那么它必须是这个方法的一个局部变量。
//include directive
#include <stdio.h>
#include <SFML/Graphics.h>
//main function
int main(void)
{
// change the size of the window
sfVideoMode mode = {200, 300, 32};
sfRenderWindow* window;
sfCircleShape* circle;
sfSprite* sprite;
sfEvent event;
// Create the main window with my name on the top
window = sfRenderWindow_create(mode, "CSFML", sfResize | sfClose, NULL);
//window is different than return 1.
if (!window)
return 1;
//create a circle to display
circle = sfCircleShape_create();
if(!circle)
return 1;
//changes the radius of the circle
sfCircleShape_setRadius(circle, 100);
//changes the color of the cicrcle
sfCircleShape_setFillColor(circle, sfRed);
// Start the window loop
while (sfRenderWindow_isOpen(window))
{
while (sfRenderWindow_pollEvent(window, &event))
{
// Close window: exit
if (event.type == sfEvtClosed)
sfRenderWindow_close(window);
}
// Clear screen and change the color of the window
sfRenderWindow_clear(window, sfBlack);
sfRenderWindow_drawCircleShape(window, circle, NULL);
//display window
sfRenderWindow_display(window);
}
//destroy the window and the circle
sfCircleShape_destroy(circle);
sfRenderWindow_destroy(window);
return 0;
}
【问题讨论】:
-
我已回滚您的编辑。请不要删除您问题的内容,尤其是在有人好心提供答案之后。
标签: c++ header-files sfml