C++ 테트리스 3차

pwy9679·2022년 5월 25일
0

CPP Tetris

목록 보기
3/4

구현기능

  1. 블록 움직임을 자연스럽게 만듬 (조작감 개선)
  2. 블록을 돌릴때 벽에서 돌리면 오류나는걸 고침
  3. 블록이 바로 쌓이지않고 바닥에 닿이더라도 조금 움직일 수 있게함
  4. 블록 한줄을 가득 채우면 사라지게 만듬
  5. 점수시스템을 만듬(한번에 많은 블록을 없애면 많은 점수를 줌)

실행화면

메인코드

//main.cpp

#include "system.h"
#include "screen.h"
#include "game.h"
using std::thread;

int main() {
	int sel = 0;
	int a = 0;
	int stack = 6;
	CursorView(false); //커서 안보이게하기
	system("mode con cols=130 lines=40 | title C++ Tetris"); //상태창 설정
	Screen screen; //메인화면 설정
	Game game; //게임에 필요한 요소 설정
	while (sel != 1) {
		sel = screen.MainMenu();
		if (sel == 2) {
			screen.how();//게임방법 출력
		}
		else if (sel == 3) {
			exit(0);//게임 종료
		}
	}

	//게임 실행
	
	while (sel == 1) {
		system("cls");
		stack = game.setBlock(stack);//다음 블록 선택
		stack = game.drawBlock();//블록의 위치를 테이블위에 정함
		game.moveSide();//블록을 양옆으로 
		game.changeRotation();//블록의 방향을 바꿈
		game.drawTable();//블록을 테이블에 
		Sleep(50);//대기
	}
	return 0;
}

헤더파일

//game.h

#pragma once
#include<vector>
using namespace std;

class Game
{
private:
	int x, y;
	int num;
	int rotation;
	int shape[4][4][4];
	int Selected_block;
	int stack;
	int stop;
	int blockList[7];
	int blockList2[7];
	int rand_seed;
	int drop;
	int nextblock[3];
	int dropspeed;
	int removeblock;
	int removecombo;
	int score;
	int backtoback;
	int stackblock;
	int rotationenable;
	vector<vector<int>> table;
public:
	Game();
	void orderBlock();
	int setBlock(int stacks);
	void selectBlock();
	void drawTable();
	int drawBlock();
	void moveSide();
	void moveDrop();
	void changeRotation();
	void drawNextBlock();
};

//screen.h

#pragma once

class Screen {
private:
	int sel, enter;
public:
	Screen();
	int MainMenu();
	void SelectMenu();
	void how();
};

//system.h

#pragma once
#include <iostream>
#include <vector>
#include <conio.h>
#include <windows.h>
#include <thread>
#include<ctime>
#include <cstdlib>
void CursorView(char show); // 커서 설정
void gotoxy(int x, int y); // 커서 위치 설정

클래스 / 함수 코드

//game.cpp

#include "game.h"
#include "system.h"
using namespace std;
#define TABLE_X 12
#define TABLE_Y 20

/*
* 테트리스 블록 선언
*/
const int Block_I[4][4][4] = { // I블록
        {
                        {0, 0, 0, 0},
                        {2, 2, 2, 2},
                        {0, 0, 0, 0},
                        {0, 0, 0, 0}
        },
        {
                        {0, 0, 2, 0},
                        {0, 0, 2, 0}, 
                        {0, 0, 2, 0},
                        {0, 0, 2, 0}
        },
        {
                        {0, 0, 0, 0},
                        {0, 0, 0, 0},
                        {2, 2, 2, 2},
                        {0, 0, 0, 0}
        },
        {
                        {0, 2, 0, 0},
                        {0, 2, 0, 0},
                        {0, 2, 0, 0},
                        {0, 2, 0, 0}
        },
};

const int Block_L[4][4][4] = { //L블록
    {
                    {0, 2, 0, 0},
                    {0, 2, 0, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 2},
                    {0, 2, 0, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 0, 2, 0},
                    {0, 0, 2, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 0, 2, 0},
                    {2, 2, 2, 0},
                    {0, 0, 0, 0}
    },
};
const int Block_J[4][4][4] = { //J블록
    {
                    {0, 0, 2, 0},
                    {0, 0, 2, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 0, 0},
                    {0, 2, 2, 2},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 2, 0, 0},
                    {0, 2, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {2, 2, 2, 0},
                    {0, 0, 2, 0},
                    {0, 0, 0, 0}
    },
};
const int Block_Z[4][4][4] = { //Z블록
    {
                    {0, 0, 0, 0},
                    {0, 2, 0, 0},
                    {0, 2, 2, 0},
                    {0, 0, 2, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {2, 2, 0, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 2, 0},
                    {0, 0, 2, 2},
                    {0, 0, 0, 2},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 0, 0, 0},
                    {0, 0, 2, 2},
                    {0, 2, 2, 0}
    },
};
const int Block_S[4][4][4] = {//S블록
    {
                    {0, 0, 0, 0},
                    {0, 0, 2, 0},
                    {0, 2, 2, 0},
                    {0, 2, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {2, 2, 0, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 2},
                    {0, 0, 2, 2},
                    {0, 0, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 0, 2, 2}
    },
};
const int Block_O[4][4][4] = {//O블록
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 0},
                    {0, 2, 2, 0},
                    {0, 0, 0, 0}
    },
};
const int Block_T[4][4][4] = {//T블록
    {
                    {0, 0, 0, 0},
                    {0, 2, 2, 2},
                    {0, 0, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 2, 0},
                    {0, 2, 2, 0},
                    {0, 0, 2, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 2, 0},
                    {0, 2, 2, 2},
                    {0, 0, 0, 0},
                    {0, 0, 0, 0}
    },
    {
                    {0, 0, 2, 0},
                    {0, 0, 2, 2},
                    {0, 0, 2, 0},
                    {0, 0, 0, 0}
    },
};

//게임배경 설정
Game::Game() {
    int buffer;
    int randset;

	for (int i = 0; i < TABLE_Y; i++) {
		vector<int> temp;
		for (int j = 0; j < TABLE_X; j++) {
			temp.push_back(0);
		}
		table.push_back(temp);
	}
	for (int i = 0; i < TABLE_X; i++) {
		table[0][i] = 1;
		table[TABLE_Y - 1][i] = 1;
	}
	for (int i = 0; i < TABLE_Y-1; i++) {
		table[i][0] = 1;
		table[i][TABLE_X-1] = 1;
	}

    rand_seed = (unsigned int)time(NULL);
    num = 0;
    srand(rand_seed);
    drop = 1;
    score = 0;
    backtoback = 0;

    for (int i = 0; i < 7; i++) {
        blockList2[i] = i + 1;
    }
    for (int i = 0; i < 7; i++) {
        randset = rand() % (7 - i);
        buffer = blockList2[randset];
        blockList2[randset] = blockList2[6 - i];
        blockList2[6 - i] = buffer;
    }
    drawNextBlock();
}

//게임화면 출력 및 업데이트
void Game::drawTable() {
    gotoxy(15, 4);
    removecombo = 0;
	for (int i = 0; i < TABLE_Y; i++) {
        removeblock = 0;
		for (int j = 0; j < TABLE_X; j++) {
			if (table[i][j] == 1)cout << "▦";
			else if (table[i][j] == 2) { // 블록을 실시간으로 이동시키는기능
				cout << "■";
                if (stack > 5) {
                    table[i][j] = 3;
                    removeblock += 1;
                }
				else table[i][j] = 0;
			}
			else if (table[i][j] == 3) { // 블록 쌓이는기능
				cout << "■";
                removeblock += 1;
			}
			else cout << "  ";
		}
        gotoxy(15, 4 + 1 + i);
        if (removeblock == 10) {
            for (int l = 1; l < TABLE_X - 1; l++) {
                table[i][l] = table[i - 1][l];
                for (int m = i; m > 1; m--) {
                    if (table[m - 1][l] != 1 && table[m - 2][l] != 1) {
                        table[m - 1][l] = table[m - 2][l];
                        table[m-2][l] = 0;
                    }
                }
            }
            removecombo += 1;
        }
	}

    if (removecombo == 1) {
        score += 100;
        backtoback = 0;
        
        stackblock = 1;
    }
    else if (removecombo == 2) {
        score += 250;
        backtoback = 0;
        stackblock = 2;
    }
    else if (removecombo == 3) {
        score += 500;
        backtoback = 0;
        stackblock = 3;
        
    }
    else if (removecombo == 4) {
        if (backtoback == 1) {
            score += 1200;
            stackblock = 5;
            
        }
        else {
            score += 1000;
            stackblock = 4;
            
        }
        backtoback = 1;
    }

    if(stackblock == 1) cout << "single" << endl;
    else if (stackblock == 2) cout << "double" << endl;
    else if (stackblock == 3) cout << "triple" << endl;
    else if (stackblock == 4) cout << "tetris " << endl;
    else if (stackblock == 5) cout << "back to back tetris " << endl;

    gotoxy(15, 3);
    cout << "Score - " << score << " , back to back : " << backtoback;
}

//다음 블록을 화면에 그림
void Game::drawNextBlock() {
    for (int k = 0; k < 3; k++) {
        if (num + k+1 == 7) nextblock[k] = blockList2[0];
        else if (num + k+1 == 8) nextblock[k] = blockList2[1];
        else if (num + k+1 == 9) nextblock[k] = blockList2[2];
        else nextblock[k] = blockList[num + k + 1];
        if (nextblock[k] == 1) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_I[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
        else if (nextblock[k] == 2) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_J[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
        else if (nextblock[k] == 3) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_L[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
        else if (nextblock[k] == 4) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_Z[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
        else if (nextblock[k] == 5) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_S[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
        else if (nextblock[k] == 6) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_T[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
        else if (nextblock[k] == 7) {
            for (int i = 0; i < 4; i++) {
                gotoxy(40, 5 + i+(5*k));
                for (int j = 0; j < 4; j++) {
                    if (Block_O[0][i][j] == 2)cout << "■";
                    else cout << "  ";
                }
            }
        }
    }
}

//출력될 블록 세팅
int Game::setBlock(int stacks) {
    stack = stacks; 
if (stack > 5) {
    x = 4;
    y = 1;
    rotation = 0;
    stop = 0;
    stack = 0;
    if (num == 7) num = 0;
    if (num == 0) orderBlock();
    num++;
    selectBlock();
}
drawNextBlock();
return stack;
}

//다음에 나올 블럭을 설정함
void Game::selectBlock() {
    if (blockList[num] == 1) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_I[i][j][k];
                }
            }
        }
    }
    else if (blockList[num] == 2) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_J[i][j][k];
                }
            }
        }
    }
    else if (blockList[num] == 3) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_L[i][j][k];
                }
            }
        }
    }
    else if (blockList[num] == 4) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_Z[i][j][k];
                }
            }
        }
    }
    else if (blockList[num] == 5) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_S[i][j][k];
                }
            }
        }
    }
    else if (blockList[num] == 6) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_T[i][j][k];
                }
            }
        }
    }
    else if (blockList[num] == 7) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    shape[i][j][k] = Block_O[i][j][k];
                }
            }
        }
    }
}

//블록을 화면상 출력하기위해 세팅
int Game::drawBlock() {
    char c;
    int error = 1;
    if (drop > 5) {
        moveDrop();
        drop = 0;
    }

    if (stop != 1 && GetKeyState(VK_RIGHT) & 0x8000) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (shape[rotation][i][j] == 2 && table[y + i][x + j + 1] != 3) {
                    stop = 1;
                }
                else if (shape[rotation][i][j] == 2 && table[y + i][x + j + 1] != 1) {
                    stop = 1;
                }
                else if(shape[rotation][i][j] == 2 && table[y + i][x + j + 1] != 0){
                    stop = 0;
                }
            }
        }
        if(stop = 1)x++;
    }

    if (stop !=2 && GetKeyState(VK_LEFT) & 0x8000) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (shape[rotation][i][j] == 2 && table[y + i][x + j - 1] != 3) {
                    stop = 1;
                }
                else if (shape[rotation][i][j] == 2 && table[y + i][x + j - 1] != 1) {
                    stop = 1;
                }
                else if (shape[rotation][i][j] == 2 && table[y + i][x + j - 1] != 0) {
                    stop = 0;
                }
            }
        }
        if (stop = 1)
        x--;
    }

    //키를 입력받아서 블록을 돌림
    

    if (GetKeyState('z') & 0x8000 || 0x8000 && GetKeyState('Z') & 0x8000)rotation++;
    else if (GetKeyState('x') & 0x8000 || 0x8000 && GetKeyState('X') & 0x8000)rotation--;
    

    if (rotation > 3) rotation = 0;
    else if (rotation < 0)rotation = 3;

    //블록을 돌렸을때 오류해결
    while (error != 0) {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (shape[rotation][i][j] == 2 && table[y + i][x + j] == 1) {
                    if (x > 5) {
                        x--;
                    }
                    else {
                        x++;
                    }
                    if (y > 18) {
                        y--;
                    }
                    error++;
                }
                if (shape[rotation][i][j] == 2 && table[y + i][x + j] == 3) {
                     
                }
            }
        }
        error--;
    }

    stop = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if(shape[rotation][i][j] == 2){
                table[y+i][x+j] = 2;
                if (table[y + i + 1][x + j] == 1 || table[y + i + 1][x + j] == 3) {
                    stack += 1;
                    drop = 0;
                }
                if (table[y + i][x + j + 1] == 1 || table[y + i][x + j + 1] == 3) {//오른쪽이 벽이거나 블록이면 옆으로 이동하지않음
                    stop = 1;
                }
                else if (table[y + i][x + j - 1] == 1 || table[y + i][x + j - 1] == 3) {//왼쪽이 벽이거나 블록이면 옆으로 이동하지않음
                    stop =2;
                }
            }
        }
    }

    //아래키를 누르면 블록이 빠르게 떨어짐
    if (GetAsyncKeyState(VK_DOWN) & 0x8000) {
        drop += 5;
    }
    else drop++;
    return stack;
}

//블록을 한칸 아래로 내림
void Game::moveDrop() { 
    y += 1;
}

//블록을 양옆으로 이동시킴
void Game::moveSide() {
}

//블록의 방향을 바꿈
void Game::changeRotation() {
    
}

//다음 7개의 블록의 순서를 결정함
void Game::orderBlock() {
    int buffer;
    int randset;
    rand_seed++;
    srand(rand_seed);
    for (int i = 0; i < 7; i++) {
        blockList[i] = blockList2[i];
    }
    for (int i = 0; i < 7; i++) {
        blockList2[i] = i + 1;
    }
    for (int i = 0; i < 7; i++) {
        randset = rand() % (7 - i);
        buffer = blockList2[randset];
        blockList2[randset] = blockList2[6 - i];
        blockList2[6 - i] = buffer;
    }
}

//mainscreen.cpp

#include "screen.h"
#include "system.h"
using namespace std;
Screen::Screen() {
    sel = 1;
    enter = 0;
}
//메인화면 출력
int Screen::MainMenu() {
    cout << "\n\n\n\n";
    cout << "\t\t" << "□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□\n";
    cout << "\t\t" << "□■■■■□□■□■□□□□■■■■■■■■□□□■■■■■■□□■□□□□□□□□■□□□□□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□■□□□□□□□□□□□□□□□■□□■□□□□□□□□■□□□□□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□■□□□□□□□□□□□□□□□■□□■□□□□□□□□■□□□□□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□■■■■■■■■□□□□□□□□■□□■□□□□□□□■□■□□□□\n";
    cout << "\t\t" << "□■■■□■■■□■□□□□■□□□□□□□□□□■■■■■■□□■□□□□□□■□□□■□□□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□■□□□□□□□□□□■□□□□□□□■□□□□■■□□□□□■■□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□■■■■■■■■□□□■□□□□□□□■□□□□□□□□□□□□□□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□□□□□□□□□□□□■□□□□□□□■□□□□□□□□□□□□□□\n";
    cout << "\t\t" << "□■□□□□□■□■□□□□□□□□□□□□□□□■□□□□□□□■□□□□□□□□□□□□□□\n";
    cout << "\t\t" << "□■■■■■□■□■□□□■■■■■■■■■■□□■■■■■■■□■□□□■■■■■■■■■■□\n";
    cout << "\t\t" << "□□□□□□□■□■□□□□□□□□□□□□□□□□□□□□□□□■□□□□□□□□□□□□□□\n";
    cout << "\t\t" << "□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□\n";
    if (sel == 1) {//게임시작 선택
        cout << "\n\n\t\t\t\t\t\t\t" << "> 게임시작\n";
        cout << "\n\n\t\t\t\t\t\t\t" << "게임방법\n";
        cout << "\n\n\t\t\t\t\t\t\t" << "게임종료\n";
    }
    else if (sel == 2) {//게임방법 선택
        cout << "\n\n\t\t\t\t\t\t\t" << "게임시작\n";
        cout << "\n\n\t\t\t\t\t\t\t" << "> 게임방법\n";
        cout << "\n\n\t\t\t\t\t\t\t" << "게임종료\n";
    }
    else if (sel == 3) {//게임종료선택
        cout << "\n\n\t\t\t\t\t\t\t" << "게임시작\n";
        cout << "\n\n\t\t\t\t\t\t\t" << "게임방법\n";
        cout << "\n\n\t\t\t\t\t\t\t" << "> 게임종료\n";
    }

    if (enter == 1) {//선택한 메뉴를 실행
        system("cls");
        return sel;
    }
    else {
        SelectMenu();//위아래로 움직이며 메뉴를 선택
        system("cls");
        return 0;
    } 
}

//조작법 및 플레이방법
void Screen::how() {
    cout << "\n\n\n\n";
    cout << "\t\t\t" << "조작법" << endl;
    cout << "\n\n\t\t\t" << "←→ 좌우로 움직이기" << endl;
    cout << "\n\t\t\t" << "↓ 빠르게 떨어뜨리기" << endl;
    cout << "\n\t\t\t" << "z 오른쪽으로 회전" << endl;
    cout << "\n\t\t\t" << "x 왼쪽으로 회전" << endl;
    cout << "\n\t\t\t" << "spacebar 바로 떨어뜨리기" << endl;
    cout << "\n\t\t\t" << "shift 홀드" << endl;
    cout << "\n\n\n\t\t\t" << "How to play" << endl;
    cout << "\n\n\t\t\t" << "1. 떨어지는 블록을 쌓습니다." << endl;
    cout << "\n\t\t\t" << "2. 줄을 빈틈없이 쌓으면 줄이 사라지며 점수를 얻을 수 있습니다." << endl;
    cout << "\n\t\t\t" << "3. 여러줄을 동시에 없애면 추가 점수를 얻을 수 있습니다." << endl;
    cout << "\n\t\t\t" << "4. 블록이 천장에 닿이면 게임오버입니다." << endl;
    system("pause>null");
    system("cls");
    enter = 0;
    sel = 1;
}

//키보드를 이용해 메뉴를 선택
void Screen::SelectMenu() {
    char c;
    c = _getch();
    if (c == 80) {
        if (sel < 3)sel += 1;
    }
    else if (c == 72) {
        if (sel > 1)sel -= 1;
    }
    if (c == 13) {
        enter = 1;
    }
}

//system.cpp

#include "system.h"
using namespace std;
//커서 설정
void CursorView(char show) {
    HANDLE hConsole;
    CONSOLE_CURSOR_INFO ConsoleCursor;

    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

    ConsoleCursor.bVisible = show;
    ConsoleCursor.dwSize = 1;

    SetConsoleCursorInfo(hConsole, &ConsoleCursor);
}

//커서 위치 지정
void gotoxy(int x, int y) {
    COORD pos = { x,y };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
profile
다양한 분야 해보는중

0개의 댓글