Note that there are some explanatory texts on larger screens.

plurals
  1. POweird issue in an SDL-based Hanoi Tower Game
    primarykey
    data
    text
    <p>I want to create a SDL-based Hanoi Tower Game, but before I proceed to writing "engine", I wanted to test my Hanoi in a console. Surprisingly, it turned out to be quite buggy.</p> <pre><code>CTower tower[3]; tower[0] = CTower(3); tower[1] = CTower(3); tower[2] = CTower(3); init(&amp;tower[0]); //prepare first tower tower[0].Print(); </code></pre> <p>This piece of code should create 3 arrays (of size 3) and fill 'em with 0 (zeros). Then, in init(), I prepare the first tower (fill it with vaild discs). However simple may it seem, my application halts on printing and doesn't fill the remaining arrays (with 0). What's strange, function init() works just fine.</p> <p>I would appreciate any help. </p> <p>Here's some code to check:</p> <pre><code>class CTower { uint16 *floors, floorsNum; void Init(); public: (...) //definitions, probably of zero importance }; void CTower::Init() { //private member, filling with zeros for (uint16 i = 0; i &lt; floorsNum; i++) floors[i] = 0; } CTower::CTower() { //default initialiazer floors = NULL; floorsNum = 0; } CTower::CTower(uint16 nfloors) { floors = new uint16[nfloors]; floorsNum = nfloors; this-&gt;Init(); } CTower::~CTower() { delete[] floors; floorsNum = 0; } void CTower::Print() { if (floorsNum == 0) printf("EMPTY TOWER!"); else for (uint16 i = 0; i &lt; floorsNum; i++) printf("%d\n", floors[i]); } void init(CTower *tower) { //a friend method of CTower for (uint16 i = 0; i &lt; tower-&gt;floorsNum; i++) tower-&gt;floors[i] = i+1; } </code></pre> <p>My application source: <a href="https://rapidshare.com/files/2229751163/hanoi-tower.7z" rel="nofollow">https://rapidshare.com/files/2229751163/hanoi-tower.7z</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload