You are viewing our Forum Archives. To view or take place in current topics click here.
Game Of Life Help
Posted:
Game Of Life HelpPosted:
Status: Offline
Joined: Jul 06, 201212Year Member
Posts: 1,398
Reputation Power: 510
Status: Offline
Joined: Jul 06, 201212Year Member
Posts: 1,398
Reputation Power: 510
I am creating my own Conway's Game of Life program for my systems programming class. I have the main functions working but I am trying to get the universe to wrap around, it can tell that a cell is there, but it wont draw to it. Like if I do 2 squares on the left horizontal and one on the same line on the far right (same line), the program will make 3 vertical on the far left but it wont do the same vice versa.
My function that draws it it:
And my function that checks to see if they are touching is:
Thanks for any help
My function that draws it it:
private void Timer_Tick(object sender, EventArgs e)
{
for (int i = 0; i < universe.GetLength(1); i++)
{
for (int k = 0; k < universe.GetLength(0); k++)
{
bool result = false;
int n;
n = neighbors(i, k);
if (universe[i, k])
{
if (n < 2)
result = false;
if (n > 3)
result = false;
if (n == 2 || n == 3)
result = true;
}
else if (!universe[i, k])
if (n == 3)
result = true;
pad[i, k] = result;
}
}
bool[,] temp = universe;
universe = pad;
pad = temp;
And my function that checks to see if they are touching is:
private int neighbors(int x, int y)
{
bool lwall = true, uwall = true, rwall = true, dwall = true;
if (x + 1 == 50)
rwall = false;
if (x - 1 == -1)
lwall = false;
if (y - 1 == -1)
uwall = false;
if (y + 1 == 50)
dwall = false;
int count = 0;
if (rwall && universe[x + 1, y])
count++;
if (dwall && universe[x, y + 1])
count++;
if (lwall && universe[x - 1, y])
count++;
if (uwall && universe[x, y - 1])
count++;
if (dwall && rwall && universe[x + 1, y + 1])
count++;
if (uwall && rwall && universe[x + 1, y - 1])
count++;
if (dwall && lwall && universe[x - 1, y + 1])
count++;
if (uwall && lwall && universe[x - 1, y - 1])
count++;
if (!rwall && universe[x - 49, y])
count++;
if (!lwall && universe[x + 49, y])
count++;
if (!dwall && universe[x, y - 49])
count++;
if (!uwall && universe[x, y + 49])
count++;
if (!dwall && !rwall && universe[x - 49, y - 49])
count++;
if (!uwall && !rwall && universe[x - 49, y + 49])
count++;
if (!dwall && !lwall && universe[x + 49, y - 49])
count++;
if (!uwall && !lwall && universe[x + 49, y + 49])
count++;
return count;
}
Thanks for any help
#2. Posted:
Status: Offline
Joined: Oct 09, 201014Year Member
Posts: 2,358
Reputation Power: 106
Status: Offline
Joined: Oct 09, 201014Year Member
Posts: 2,358
Reputation Power: 106
Not 100% sure what the problem youre having is, any way you could explain it better?
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Jul 06, 201212Year Member
Posts: 1,398
Reputation Power: 510
Status: Offline
Joined: Jul 06, 201212Year Member
Posts: 1,398
Reputation Power: 510
Xaldin wrote Not 100% sure what the problem youre having is, any way you could explain it better?
Basically what I need to happen is when it reaches the end of the screen, it needs to loop around back to the other side.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.