#include <iostream>
#include <Windows.h>
#include <conio.h>
#include <time.h>
#include <thread>
using namespace std;
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
#define space 32
int start_time;
int end_time;
bool timer_start = true;
bool start = true;
int choice;
void move(int x, int y);
int user_count = 0;
int x=10, y =3;
int board_x_index = 0, board_y_index = 0;
int board[5][5] = { 0, };
void number_remove(int x, int y);
void main_ground()
{
cout << endl << endl << endl << endl << endl;
cout << " 1. 게임시작 " << endl;
cout << " 2. 점수보기 " << endl;
cin >> choice;
}
void game_background()
{
cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆" << endl;
cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆ ☆☆" << endl;
cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆" << endl;
cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆" << endl;
}
void user_Timer(int s_time)
{
if (timer_start)
{
start_time = GetTickCount()-s_time;
timer_start = false;
}
else{
end_time = GetTickCount() - start_time;
move(20, 25);
cout << end_time;
}
}
void select_number(int x, int y)
{
COORD pos = { x - 1, y - 1 };
if (start)
{
pos = { x - 1, y };
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
pos = { x*(i + 1), y*(j + 1) };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" -", board[i][j]);
}
cout << endl;
}
start = false;
}
else{
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf("┌─┐");
pos = { x - 1, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf("│-│", board[board_x_index][board_y_index]);
pos = { x - 1, y + 1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf("└─┘");
}
}
void move(int x, int y)
{
COORD pos = { x-1, y-1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void remove(int x, int y)
{
COORD pos = { x - 1, y - 1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" ");
pos = { x - 1, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" - ", board[board_x_index][board_y_index]);
pos = { x - 1, y + 1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" ");
}
void number_remove(int x,int y)
{
COORD pos = { x - 1, y - 1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" ");
pos = { x - 1, y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" ", board[board_x_index][board_y_index]);
pos = { x - 1, y + 1 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
printf(" ");
}
void change_number(int choice,int x,int y)
{
COORD pos = { x - 1, y - 1 };
if (choice == user_count)
{
if (choice > 25)
{
number_remove(x, y);
board[board_x_index][board_y_index] = -1;
user_count++;
}
else
{
board[board_x_index][board_y_index] = user_count + 25;
select_number(x, y);
user_count++;
}
}
}
int main(void)
{
main_ground();
int count = 0;
srand((unsigned)time(NULL));
int temp;
bool check = false;
int rand_num[25] = { 0, };
for (int i = 0; i < 25; i++)
{
while (true)
{
temp = rand() % 25;
for (int j = 0; j < i; j++)
{
if (temp == rand_num[j]){
check = true;
}
}
if (!check)
{
rand_num[i] = temp;
break;
}
else
{
check = false;
}
}
}
if (choice == 1)
{
system("cls");
game_background();
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
board[i][j] = rand_num[count];
//move((j + 1) * 10, 5*(i+1));
//cout << rand_num[count];
count++;
}
}
select_number(x, y);
char key;
int temp1 = GetTickCount();
thread t1(&user_Timer, temp1);
while (1)
{
key = _getch();
switch (key)
{
case LEFT:
if (board_x_index - 1 < 0) break;
remove(x, y);
x -= 10;
board_x_index--;
select_number(x, y);
break;
case RIGHT:
if (board_x_index + 1 > 4) break;
remove(x, y);
x += 10;
board_x_index++;
select_number(x, y);
break;
case UP:
if (board_y_index - 1 < 0) break;
remove(x, y);
y -= 3;
board_y_index--;
select_number(x, y);
break;
case DOWN:
if (board_y_index + 1 > 4) break;
remove(x, y);
y += 3;
board_y_index++;
select_number(x, y);
break;
case space:
change_number(board[board_x_index][board_y_index], x, y);
break;
}
}
t1.join();
}
}
소스 전부인데 스레드를 안배워서 뭐가뭔지모르겟다 끝날때까지 기다린다는게 뭔말이야
으 혐
고갱님여기서싸시면