게임프로그래밍

#include using namespace std; int main() { int iNumber[9] = { 1,2,3,4,5,6,7,8,9 };//1부터 9까지있는 배열을 생성한다 int idx1, idx2, temp; int iArr[3]; srand((unsigned int)time(NULL)); for (int i = 0; i < 100; i++)//대략 100번 정도 섞는다. { //인덱스를 임의로 정하고 idx1 = rand() % 9; idx2 = rand() % 9; //두 배열의 값을 바꾼다. temp = iNumber[idx1]; iNumber[idx1] = iNumber[idx2]; iNumber[idx2] = temp; } for(int i = 0; i < 3; i++) iArr[..
게임은 항상 상대(다른 사람, 나 자신, AI, 목표 등)가 있어야 한다. 그렇기에 난수는 컴퓨터의 판단의 기본이 된다. 1) rand() 함수 -rand() 함수는 srand()에서 생성된 값을 바탕으로 난수를 생성하는 함수이다. -rand() 함수로 범위지정 방법 : rand() % (마지막 값 - 시작 값 + 1) + 시작 값 EX) 1 ~ 100의 난수를 얻고 싶을때 #include using namespace std; int main() { srand((unsigned int)time(NULL)); cout 기본 형태(외워두면 좋음) : srand((unsigned int)time(NULL)); #include using namespace std; int main() { cout
준이06
'게임프로그래밍' 카테고리의 글 목록