我怎么能用向量移动星星

时间:2014-04-04 09:35:25

标签: c++ vector

我想用向量移动星星,我有两个向量,这是我的代码但是当我运行它时我的开始出错,我该如何解决这个问题

代码:

#include <iostream>
#include <vector>
#include <conio.h>
#include <windows.h>
#include <stdio.h>

using namespace std;

void gotoxy(int eex, int eey)
{
  COORD coord;
  coord.X = eex;
  coord.Y = eey;
  SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

int main()
{  
  vector <int> tmp(2);//for x,y location
  vector <vector<int> > main(0);//for relocation of x,y last place
  int x=2,y=2,lx,ly;
  for(int i=2;i<20;i++){
    tmp.at(0)=i;//save the location of x
    tmp.at(1)=y;//save the location o y
    main.push_back(tmp);//push the x,y into this vector
    gotoxy(i,y);//go to location
    cout<<"*";
    Sleep(100);
    lx=main[0][i-1];//relocate the last x
    ly=main[0][1];//lelocate the last y
    gotoxy(lx,ly);//go to the last location of " *"
    cout<<" ";
  }
}

1 个答案:

答案 0 :(得分:0)

您只看main[0],因此忽略推送到矢量上的所有其他元素。

我没有看到将位置推到矢量上然后在相同的循环中直接处理它们之后的点。这是非常困惑的代码。

相关问题