|
-
August 30th, 2009, 09:44 AM
#1
Allegro - C++ - Conway's game of life
Hi, this is my first post here. I've been programming C++ for quite a while, I'm not that good but hey we all try our best right?
Anyway at the moment I'm writing a kind of copy of Conway's game of life. For those of you not familiar with the game, it is a kind of simulation, where each box behaves acording to the boxes around it. You can Wiki it if you like, its very interesting.
Anyway I've been writing a version of this, and I can't figure out why it isn't working, can anyone help?
#include <allegro.h>
int main(){
allegro_init();
install_keyboard();
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
int Cellnum = 1;
int Cellcx = -5;
int Cellcy = 0;
int Cells [2500];
int Cellx [2500];
int Celly [2500];
int Cellsn [2500];
int Cellnc;
Cells[410] = 1;
Cells[411] = 1;
Cells[412] = 1;
while ( !key[KEY_ESC] ){
for (Cellnum; Cellnum <= 2500; Cellnum++) {
if (Cells[(Cellnum - 1)] == 1) {
Cellnc = Cellnc + 1;
}
if (Cells[(Cellnum + 1)] == 1) {
Cellnc = Cellnc + 1;
}
if (Cells[(Cellnum - 51)] == 1) {
Cellnc = Cellnc + 1;
}
if (Cells[(Cellnum - 50)] == 1) {
Cellnc = Cellnc + 1;
}
if (Cells[(Cellnum - 49)] == 1) {
Cellnc = Cellnc + 1;
}
if (Cellnc > 3) {
Cellsn[Cellnum] = 0;
}
if (Cellnc < 2) {
Cellsn[Cellnum] = 0;
}
if (Cellnc = 3) {
Cellsn[Cellnum] = 1;
}
Cellnc = 0;
}
Cellnum = 1;
for (Cellnum; Cellnum <= 2500; Cellnum++) {
Cells[Cellnum] = Cellsn[Cellnum];
Cellcx = Cellcx + 5;
if (Cellcx >= 250) {
Cellcy = Cellcy + 5;
Cellcx = 0;
}
if (Cells[Cellnum] = 1) {
rectfill( screen, Cellcx, Cellcy, (Cellcx + 5), (Cellcy + 5), makecol( 255, 0, 0));
}
if (Cells[Cellnum] = 0) {
rectfill( screen, Cellcx, Cellcy, (Cellcx + 5), (Cellcy + 5), makecol( 255, 255, 255));
}}
Cellnum = 1;
Cellcx = -5;
Cellcy = 0;
}
return 0;
}
END_OF_MAIN();
Now im more than aware that my code often makes no sense to anyone else, so ask if you don't understand something, but any help anyone could give me would be heartily appreciated.
Yours, ninetailsgangster
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|