heeey guys
i want to make predator and pray simulation and i made the 2d array i just don't know what to do next
i need help !!!!:S

#include <iostream>
using namespace std;
void printGrid(char grid[][20], int w, int h);


int main() {

    // Create a 20 by 20 grid array of chars

    char grid[20][20];

    // Now loop through each row...

    for (int i = 0; i < 20; i++) {

        // ... then each column and set each space to '.'

        for (int j = 0; j < 20; j++) {

            grid[i][j] = '.';

        }

    }

 

    // Print the grid of 20 by 20 dots

    printGrid(grid,20,20);

 

    return 0;
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
   std::cin.get();
}

 

 

// Call this function to print your grid. w = width, h = height

void printGrid(char grid[][20], int w, int h) {

    for (int i = 0; i < w; i++) {

        for (int j = 0; j < h; j++) {

            cout << grid[i][j] << " ";

        }

        cout << endl;

    }

}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Unfortunately, I'm unfamiliar with the game you're speaking of. However, just as a program needs it's main(), a game needs a loop. Hope this can aid you some.

//pseudo

bool quit = false;

while( !quit ) { 
    getInput()
    doSomeThinking()

    if (someone won) quit =true

    printResult()
}

Create the following:

1) PredatorModel class
2) PreyModel class
3) MapView
4) PredatorController
5) PreyController

Your PredatorModel will contain all function necessary for a Predator like move, think, kill and so on.
Your PreyModel will contain all function necessary for a Prey like sleep, eat, and so on
Your MapView will be your Map class, this is what will be on the screen. It will show where there are foods, walkable area, prey position and predator position
The Predator and Prey Controller will control how Predator and Prey moves, respectively. They will utilize the interface provided by Predator and Prey class

Break your problem up into small easily-managed pieces. You're off to a good start, you can create an empty grid, and you can print out your grid. What do you want to do next? Programming can seem overwhelming if you're trying to solve everything all in one step. Pick a step, describe what the step is (if you can't describe it to yourself, or can't code it from your description, break it up into smaller steps!), figure out how to test whether you've coded it correctly, then code-test-repeat until it's working. So what's your next step? Put some predators and prey on your grid? Do that much. Test it by printing out the resulting grid.

This article has been dead for over six months. Start a new discussion instead.