如何在直线上移动角色? [英] How to move a character on straight line?
本文介绍了如何在直线上移动角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在c ++上创建一个简单的编码项目。我需要在y = mx + c中移动*字符。我写了一杯编码线来生成直线。现在我必须在这条道路上移动它。 PLZ帮助我.....
我尝试过:
I have to make a simple coding project on c++. i need to move "*" character in y=mx+c. i wrote a cup of coding lines to generate straight lines. now i have to move this in that path. plz help me.....
What I have tried:
#include <iostream>
#include <math.h>
#include<Windows.h>
using namespace std;
int pth (int x) {
return -1*x+1;
}
int main() {
int i,j,y;
for (int x=-10;x <= 10;x++) {
for ( i=-10;i <= x;i++) {
if (i==x) {
y=pth(x);
// cout<<"x=";
//cout<<x;
//cout<<"y=";
//cout<<y;
for(j=-10;j<=y;j++) {
if(j==y)
cout << "*";
else
cout << " ";
}
}
}
cout << "\n";
system("cls");
Sleep(20);
}
cin.get();
return 0;
}
推荐答案
简单:更改pth
函数以便使用新公式而不是-1 * x + 1
- 这是的特殊情况y = mx + c
其中m == -1,c == 1
Simple: Change yourpth
function to use the new formula instead of-1*x+1
- which is a special case ofy = mx + c
where m == -1, and c == 1
可能你需要使用 Windows控制台API [ ^ ]。
Probably you need to use the Windows Console API[^].
这篇关于如何在直线上移动角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文