Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;并联回路_C++_Loops_Parallel Processing - Fatal编程技术网

C++ C++;并联回路

C++ C++;并联回路,c++,loops,parallel-processing,C++,Loops,Parallel Processing,我正在做一个叫做外星人宇宙飞船的控制台游戏作为家庭作业。应该是这样的。 到目前为止,我不允许使用类或对象=>只使用函数和数组。 我有一个while循环,它检查我在键盘上按下的按钮,并根据按钮应用一些功能。 当我试着发射导弹时,问题来了,因为它是用“for”循环完成的,当我发射时,我不能移动。有没有人能告诉我这个模型应该是什么样子的,我该如何制作这样的东西。我认为不需要发布我的代码,但如果您愿意,我会发布它。我假设您不愿意使用多线程。对于这样一个简单的游戏来说,这不是强制性的,而且会增加一些复杂性

我正在做一个叫做外星人宇宙飞船的控制台游戏作为家庭作业。应该是这样的。 到目前为止,我不允许使用类或对象=>只使用函数和数组。 我有一个while循环,它检查我在键盘上按下的按钮,并根据按钮应用一些功能。
当我试着发射导弹时,问题来了,因为它是用“for”循环完成的,当我发射时,我不能移动。有没有人能告诉我这个模型应该是什么样子的,我该如何制作这样的东西。我认为不需要发布我的代码,但如果您愿意,我会发布它。

我假设您不愿意使用多线程。对于这样一个简单的游戏来说,这不是强制性的,而且会增加一些复杂性

所以单线程游戏的通用循环是:

state new_state = createInitialState();
do
{
  input = readInput(); // non blocking !
  new_state = modifyState(input, new_state);
  updateScreen(new_state);
}
while (!exitCondition(input));
这些函数都不应该长时间循环


在您的情况下,应在
modifyState
中更新导弹位置,并考虑自上次
modifyState
以来的时间

我假设您不愿意使用多线程。对于这样一个简单的游戏来说,这不是强制性的,而且会增加一些复杂性

所以单线程游戏的通用循环是:

state new_state = createInitialState();
do
{
  input = readInput(); // non blocking !
  new_state = modifyState(input, new_state);
  updateScreen(new_state);
}
while (!exitCondition(input));
这些函数都不应该长时间循环


在您的情况下,应在
modifyState
中更新导弹位置,并考虑自上次
modifyState
以来的时间

我假设您使用一个矩阵来存储所有数据,并定期打印矩阵的内容(这就是创建控制台游戏的方式)。 因此,您的代码应该如下所示:

render()
{
   update_position(x,y);
   if(missile_fired)
       update_missile_position();
}

main()
{
for(;;)
{
  read_input(&x,&y);
  render();
  draw_image();
}
}

我假设您使用一个矩阵来存储所有数据,并定期打印矩阵的内容(这就是您创建控制台游戏的方式)。 因此,您的代码应该如下所示:

render()
{
   update_position(x,y);
   if(missile_fired)
       update_missile_position();
}

main()
{
for(;;)
{
  read_input(&x,&y);
  render();
  draw_image();
}
}

“我不允许使用类或对象”-叹气!那些臭名远扬的教授的方法:学习C,而不是C++……“我不允许使用课堂和对象”叹息!臭名昭著的教授们的方法:学习C,而不是C++…