C++카드 맞 추기 게임 실현
실행 효과
코드
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<Windows.h>
#include<graphics.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")
#define HANG 4
#define LIE 4
#define SIZE 200
int g_matt[HANG][LIE] = { 0 };
int g_matt_time[HANG][LIE] = { 0 };
int g_matt_mask[HANG*LIE] = { 0 };
IMAGE img[10];
void Put(){
char jpg[50];
for (int i = 0; i <10; i++){
sprintf(jpg, "images\\%d.jpg", i);
loadimage(&img[i], jpg, SIZE, SIZE);
//printf("%s
", jpg);
}
}
int getNextNumber()
{
char stat[8] = { 0 };
for (int i = 0; i < HANG; i++){
for (int j = 0; j < LIE; j++){
if (g_matt[i][j]>0 && g_matt[i][j]<9)// 3
stat[g_matt[i][j]-1]++;//
//printf("%c", stat);
}
}
char n = 0;
while (1) {
n = rand() % 8 + 1;// 1 8
if (stat[n-1] >= 2) {// 2 1 8
continue;
} else {
break;
}
}
return n;
}
void Playone(){
for (int i = 0; i < HANG; i++){
for (int j = 0; j < LIE; j++){
g_matt[i][j] = getNextNumber();
printf("%d ", g_matt[i][j]);
}
printf("
");
}
for (int i = 0; i < HANG; i++){
for (int j = 0; j < LIE; j++){
if (g_matt[i][j] >= 1 && g_matt[i][j] <= 8)
g_matt[i][j] += 20;
printf("%d ", g_matt[i][j]);
}
printf("
");
}
}
void Plus(){
for (int i = 0; i < HANG; i++){
for (int j = 0; j < LIE; j++){
if (g_matt[i][j] == 1){
putimage(i*SIZE, j*SIZE, &img[1]);
}
else if (g_matt[i][j] == 2){
putimage(i*SIZE, j*SIZE, &img[2]);
}
else if (g_matt[i][j] == 3){
putimage(i*SIZE, j*SIZE, &img[3]);
}
else if (g_matt[i][j] == 4){
putimage(i*SIZE, j*SIZE, &img[4]);
}
else if (g_matt[i][j] == 5){
putimage(i*SIZE, j*SIZE, &img[5]);
}
else if (g_matt[i][j] == 6){
putimage(i*SIZE, j*SIZE, &img[6]);
}
else if (g_matt[i][j] == 7){
putimage(i*SIZE, j*SIZE, &img[7]);
}
else if (g_matt[i][j] == 8){
putimage(i*SIZE, j*SIZE, &img[8]);
}
else if (g_matt[i][j] >= 20 && g_matt[i][j] <= 28){
putimage(i*SIZE, j*SIZE, &img[0]);
}
else if (g_matt[i][j] > 100){
putimage(i*SIZE, j*SIZE, &img[9]);
}
}
}
}
void Play(){
MOUSEMSG msg = { 0 };
msg = GetMouseMsg();
//if (WM_LBUTTONDOWN == matt[msg.x][msg.y] >= 20 || matt[msg.x][msg.y]<=28){
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
{
int row = msg.y / SIZE;
int col = msg.x / SIZE;
if (g_matt[col][row] >= 20 && g_matt[col][row] <= 28){
g_matt[col][row] -= 20;
//printf("%d ", g_matt[col][row]);
}
//mciSendString("open images\\click.wav", NULL, NULL, NULL);
mciSendString("play images\\click.wav", NULL, NULL, NULL);
Sleep(10);
mciSendString("cloes images\\click.wav", NULL, NULL, NULL);
}
}
//cleardevice();
}
void Over(){
int *p = (int*)g_matt+1;
for (int i = 0; i < HANG*LIE; i++) {
for (int j = i + 1; j < HANG*LIE; j++) {
if(p[i] <= 8 && p[i] >= 1 && p[i] == p[j]){
p[i] += 120;
p[j] += 120;
//mciSendString("open images\\search.wav", NULL, NULL, NULL);
mciSendString("play images\\search.wav", NULL, NULL, NULL);
Sleep(10);
mciSendString("cloes images\\search.wav", NULL, NULL, NULL);
}
}
}
}
void Keep(){
for (int i = 0; i < HANG; i++){
for (int j = 0; j < LIE; j++){
if (g_matt[i][j] >= 1 && g_matt[i][j] <= 8){
g_matt[i][j] += 20;
//printf("%d ", g_matt[i][j]);
}
}
printf("
");
}
}
int main() {
//int *p1;
mciSendString("open images\\ .mp3", NULL, NULL, NULL);
mciSendString("play images\\ .mp3", NULL, NULL, NULL);
srand(time(NULL));
HWND hwnd =initgraph(800, 800);
Put();
Playone();
int frames = 0;
DWORD t1, t2,t3;
t1 = GetTickCount();//
while (1)
{
t2 = GetTickCount();
Plus();//
Play();//
if (t2-t1>=1600){//
Keep();//
//continue;
t1 = t2;//
}
Over();
char ch[16] = { 0 };
char n = 0;
for (int i = 0; i < HANG; i++){
for (int j = 0; j < LIE; j++){
if (g_matt[i][j] >= 120){
ch[g_matt[i][j] - 1]++;
}
}
}
while (n>6) {
if (ch[n - 1] >= 6) {// 2 1 8
MessageBox(hwnd, " ", "", MB_OK);
//continue;
n++;
}
}
}
return 0;
}
더 많은 재 미 있 는 클래식 게임 을 통 해 주 제 를 실현 하고 여러분 에 게 공유 합 니 다.C++클래식 게임 모음
python 클래식 게임 모음
python 러시아 블록 게임 집합
JavaScript 클래식 게임 을 계속 합 니 다.
자바 클래식 게임 모음
javascript 고전 게임 모음
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Visual Studio에서 파일 폴더 구분 (포함 경로 설정)Visual Studio에서 c, cpp, h, hpp 파일을 폴더로 나누고 싶었습니까? 어쩌면 대부분의 사람들이 있다고 생각합니다. 처음에 파일이 만들어지는 장소는 프로젝트 파일 등과 같은 장소에 있기 때문에 파일...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.