HIII!!! i need to know how to make a random movement for a character??

#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;

char board[20][20];

void setBoard ()
{
    for (int j=0; j<20; j++)
            {
               board[0][j]  = 219;
               board[19][j] = 219;
            }

            for (int i=0; i<20; i++)
            {
               board[i][0]  = 219;
               board[i][19] = 219;
            }
            for (int j=1; j<19; j++)
            {
                for (int i=1; i<19; i++)
                {
                    board[i][j] = ' ';
                }
            }
}

void displayBoard()
{
    for (int i=0; i<20; i++)
    {
        for (int j=0; j<20; j++)
        {
            cout<< board[i][j];
        }
        cout<<endl;
    }
}

struct objects
{
    int  x_coord;
    int  y_coord;
    char z_dep  ;
    int  counter;
};
class Prey
{
 private:
    int  X;
    int  Y;
    char Z;
    int  C;
    int count2;

 public:
    objects prey [200];
    Prey()
    {
        count2 = 0;
        for (int i=0; i<200; i++)
        {
            prey[i].x_coord =  0 ;
            prey[i].y_coord =  0 ;
            prey[i].z_dep   = ' ';
            prey[i].counter =  0 ;
        }
    }

    void setArray (int l, int m, char n, int index1, int cntr)
    {
        prey[index1].x_coord =  l  ;
        prey[index1].y_coord =  m  ;
        prey[index1].z_dep   =  n  ;
        prey[index1].counter = cntr;
    }
};

Recommended Answers

All 3 Replies

You should have a look at the functions srand and rand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.