嗨,我正在寫一個基本的俄羅斯方塊與ASCII輸出C++中的方法改變局部變量
,我有我想移動塊對象周圍
我將如何改變字符在某個位置在我的領域從我的方法?
但VisualStudio的告訴我
1>------ Build started: Project: Tetris, Configuration: Debug Win32 ------
1>Tetris.cpp
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(48): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(49): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(50): error C2108: subscript is not of integral type
1>e:\dateien\uni\c++\tetris\tetris\tetris.cpp(91): warning C4305: '+=': truncation from 'double' to 'float'
1>Done building project "Tetris.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
代碼:
#include <iostream>
using namespace std;
int main()
{
const int FieldY = 20;
const int FieldX = 11;
char TetrisField[FieldY][FieldX] =
{
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
"__________",
};
class Block {
public:
float posX;
float posY;
char Character = 'A';
void setPos(int x, int y)
{
posX = x;
posY = y;
TetrisField[posY][posX] = Character;
};
};
while (true)
{
Block B1;
B1.setPos(0, 5);
for (int n = 0; n < FieldY; n = n + 1)
{
cout << TetrisField[n][0] << TetrisField[n][1] << TetrisField[n][2] << TetrisField[n][3] << TetrisField[n][4]
<< TetrisField[n][5] << TetrisField[n][6] << TetrisField[n][7] << TetrisField[n][8] << TetrisField[n][9] << endl;
};
};
return 0;
};
我知道的輸出方法是壞但是那只是爲了測試
確定現在即時通訊writig隨機的東西,這樣的堆棧溢出編輯器允許我發佈這個問題,因爲顯然我沒有寫出正常的文字,那不是Code。啊終於;-)
THX
雖然設計有問題,但您提供的代碼沒有任何明顯的錯誤。你可以請發佈[最小,完整和可驗證的例子](https://stackoverflow.com/help/mcve)? – orhtej2
另外,請注意在移動它之前應該如何從先前的位置擦除塊。 – orhtej2
請複製並粘貼整個錯誤消息,而不是重新輸入它。使用輸出窗口,而不是錯誤列表窗口。 – molbdnilo