将一个int变量添加到Label并给它+1

时间:2015-05-01 19:26:48

标签: c# int var counting

我忙于迷宫,我目前正在解决这个问题。我希望当有人碰壁时他使用方法Movetostart,我想让它与var death一起计算。到目前为止我得到了这个。

int death = 0;
private void MoveToStart()
{
    Count.Text = death.ToString();
    Point startingPoint = panel1.Location;
    startingPoint.Offset(301, 543);
    Cursor.Position = PointToScreen(startingPoint);
    ms = 0;
    sec = 0;
    min = 0;
    hour = 0;
    death = +1;
}

现在的问题是死亡只停留在1并且并不重要,它碰到了多少次并不算数。

3 个答案:

答案 0 :(得分:3)

您可能希望在展示之前增加src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::start_for<tbb::blocked_range<int>, tbb::internal::parallel_for_body<ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)::{lambda(int)#1}, int>, tbb::auto_partitioner const>::~start_for()': ComputeSPMV_ref.cpp:(.text+0x3): undefined reference to `vtable for tbb::task' src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::start_for<tbb::blocked_range<int>, tbb::internal::parallel_for_body<ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)::{lambda(int)#1}, int>, tbb::auto_partitioner const>::~start_for()': ComputeSPMV_ref.cpp:(.text+0x23): undefined reference to `vtable for tbb::task' src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::start_for<tbb::blocked_range<int>, tbb::internal::parallel_for_body<ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)::{lambda(int)#1}, int>, tbb::auto_partitioner const>::execute()': ComputeSPMV_ref.cpp:(.text+0x182): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0x1ad): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0x26b): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0x296): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0x43b): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0x470): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0x52c): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const' src/ComputeSPMV_ref.o: In function `ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)': ComputeSPMV_ref.cpp:(.text+0x9d0): undefined reference to `tbb::task_group_context::init()' ComputeSPMV_ref.cpp:(.text+0x9e9): undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned long) const' ComputeSPMV_ref.cpp:(.text+0xa29): undefined reference to `tbb::internal::get_initial_auto_partitioner_divisor()' ComputeSPMV_ref.cpp:(.text+0xa52): undefined reference to `tbb::task_group_context::~task_group_context()' ComputeSPMV_ref.cpp:(.text+0xad4): undefined reference to `tbb::task_group_context::~task_group_context()' ComputeSPMV_ref.cpp:(.text+0xae0): undefined reference to `vtable for tbb::task' ComputeSPMV_ref.cpp:(.text+0xaee): undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const' src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::flag_task::~flag_task()': ComputeSPMV_ref.cpp:(.text._ZN3tbb10interface68internal9flag_taskD2Ev[_ZN3tbb10interface68internal9flag_taskD5Ev]+0x3): undefined reference to `vtable for tbb::task' src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::signal_task::~signal_task()': ComputeSPMV_ref.cpp:(.text._ZN3tbb10interface68internal11signal_taskD2Ev[_ZN3tbb10interface68internal11signal_taskD5Ev]+0x3): undefined reference to `vtable for tbb::task' src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::flag_task::~flag_task()': ComputeSPMV_ref.cpp:(.text._ZN3tbb10interface68internal9flag_taskD0Ev[_ZN3tbb10interface68internal9flag_taskD0Ev]+0x3): undefined reference to `vtable for tbb::task' src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::signal_task::~signal_task()': ComputeSPMV_ref.cpp:(.text._ZN3tbb10interface68internal11signal_taskD0Ev[_ZN3tbb10interface68internal11signal_taskD0Ev]+0x3): undefined reference to `vtable for tbb::task' src/ComputeSPMV_ref.o:(.rodata+0x110): undefined reference to `typeinfo for tbb::task' src/ComputeSPMV_ref.o:(.rodata._ZTIN3tbb10interface68internal11signal_taskE[_ZTIN3tbb10interface68internal11signal_taskE]+0x10): undefined reference to `typeinfo for tbb::task' src/ComputeSPMV_ref.o:(.rodata._ZTIN3tbb10interface68internal9flag_taskE[_ZTIN3tbb10interface68internal9flag_taskE]+0x10): undefined reference to `typeinfo for tbb::task' src/ComputeSPMV_ref.o:(.rodata._ZTVN3tbb10interface68internal9flag_taskE[_ZTVN3tbb10interface68internal9flag_taskE]+0x28): undefined reference to `tbb::task::note_affinity(unsigned short)' src/ComputeSPMV_ref.o:(.rodata._ZTVN3tbb10interface68internal11signal_taskE[_ZTVN3tbb10interface68internal11signal_taskE]+0x28): undefined reference to `tbb::task::note_affinity(unsigned short)' collect2: error: ld returned 1 exit status make: *** [bin/xhpcg] Error 1 Compile instruction look like this: make /usr/bin/g++ -DHPCG_NOMPI -DHPCG_NOOPENMP -I./src -I./src/GCC_TBB -O3 -ltbb -std=c++11 -ffast-math -ftree-vectorize -ftree-vectorizer-verbose=0 -fopenmp testing/main.o src/CG.o src/CG_ref.o .... ,否则它会以1显示:

death

使用private void MoveToStart() { ++death; Count.Text = death.ToString(); Point startingPoint = panel1.Location; startingPoint.Offset(301, 543); Cursor.Position = PointToScreen(startingPoint); ms = 0; sec = 0; min = 0; hour = 0; } 运算符会将计数增加1并将其分配回对象,与++相同。

您的代码存在的实际问题是death += 1;death = +1不同。您正在做的只是将death += 1重新分配给death+1

答案 1 :(得分:0)

我想你想写death += 1;而不是death = +1;

编辑: 此外,与其他人评论一样,您应该在将值增加后将值指定为Count.Text,否则Count.Text上的文字将始终落后一步。

答案 2 :(得分:0)

如果你想在你的&#34;死亡&#34;中添加1变量,你可以像这样写

int death = 0;
private void MoveToStart()
{
    Count.Text = death.ToString();
    Point startingPoint = panel1.Location;
    startingPoint.Offset(301, 543);
    Cursor.Position = PointToScreen(startingPoint);
    ms = 0;
    sec = 0;
    min = 0;
    hour = 0;
    death++;
}

int death = 0;
private void MoveToStart()
{
    Count.Text = death.ToString();
    Point startingPoint = panel1.Location;
    startingPoint.Offset(301, 543);
    Cursor.Position = PointToScreen(startingPoint);
    ms = 0;
    sec = 0;
    min = 0;
    hour = 0;
    death = death + 1;
}
每次调用方法时,

或创建另一个用于添加到死亡的变量

int death = 0;
int _numberToAddEachTime = 1;
private void MoveToStart()
{
    Count.Text = death.ToString();
    Point startingPoint = panel1.Location;
    startingPoint.Offset(301, 543);
    Cursor.Position = PointToScreen(startingPoint);
    ms = 0;
    sec = 0;
    min = 0;
    hour = 0;
    death = death + _numberToAddEachTime;
}