2017. 6. 14. 13:30
간단한 콘솔 기반 빙고 게임입니다.
셔플을 활용해서 숫자를 섞어서 넣고 출력하는게 포인트였던..
= _=지금보면 새록새록한 추억이군요.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <time.h> | |
using namespace std; | |
int main(){ | |
srand((unsigned int)time(NULL)); | |
int bingo[5][5]; | |
int count = 1; | |
for (int i = 0; i < 5; i++){ | |
for (int j = 0; j < 5; j++){ | |
bingo[i][j] = count++; | |
} | |
} | |
for (int i = 0; i < 50; i++){ | |
int dest = rand() % 5; | |
int sour = rand() % 5; | |
int temp = bingo[dest][sour]; | |
bingo[dest][sour] = bingo[sour][dest]; | |
bingo[sour][dest] = temp; | |
} | |
int inputNum; | |
int bingoCount = 0; | |
int inputArr[25]; | |
int inputCount = 0; | |
while (true){ | |
//system("cls"); | |
cout << "please input 1 between 25 number" << endl; | |
if (inputCount != 0) cout << "inputNums : "; | |
for (int i = 0; i < inputCount; i++){ | |
cout<<inputArr[i] << " "; | |
} | |
cout << endl; | |
cin >> inputNum; | |
inputArr[inputCount] = inputNum; | |
inputCount++; | |
for (int i = 0; i < 5; i++){ | |
for (int j = 0; j < 5; j++){ | |
if (bingo[i][j] == inputNum) | |
bingo[i][j] = 35; | |
} | |
} | |
for (int i = 0; i < 5; i++){ | |
for (int j = 0; j < 5; j++){ | |
if (bingo[i][j] == 35) cout << (char)bingo[i][j] << "\t"; | |
else cout << bingo[i][j] << "\t"; | |
} | |
cout << endl; | |
} | |
int checkH = 0; | |
int checkV = 0; | |
for (int i = 0; i < 5; i++){ | |
for (int j = 0; j < 5; j++){ | |
if (bingo[i][j] == 35) | |
checkH++; | |
} | |
if (checkH % 5 == 0 && checkH > 0){ | |
bingoCount++; | |
checkH = 0; | |
} | |
else checkH = 0; | |
} | |
for (int i = 0; i < 5; i++){ | |
for (int j = 0; j < 5; j++){ | |
if (bingo[j][i] == 35){ | |
checkV++; | |
} | |
} | |
if (checkV % 5 == 0 && checkV > 0){ | |
bingoCount++; | |
checkV = 0; | |
} | |
else checkV = 0; | |
} | |
if (bingo[0][0] == 35 && bingo[1][1] ==35 && bingo[2][2] == 35 && bingo[3][3] == 35 && bingo[4][4] == 35) | |
bingoCount++; | |
if (bingo[0][4] == 35 && bingo[1][3] ==35 && bingo[2][2] == 35 && bingo[3][1] == 35 && bingo[4][0] == 35) | |
bingoCount++; | |
cout <<"bingoCount : "<< bingoCount << endl; | |
if (bingoCount >= 5) break; | |
else bingoCount = 0; | |
} | |
return 0; | |
} |
'Programming > C++' 카테고리의 다른 글
[C++]간단한 숫자 퍼즐 게임 (0) | 2017.06.14 |
---|---|
[C++]간단한 별찍기 (0) | 2017.06.14 |
[C++]주민등록번호 생성기 (0) | 2017.06.14 |
[C++]문자열 거꾸로 만들기 (0) | 2017.06.14 |
[C++]간단한 strlen, strcmp, strcat, strcpy, strtok (0) | 2017.06.14 |