티스토리 뷰

c언어

게임프로젝트_c코드

stopin 2017. 5. 22. 01:54
#include<stdio.h>
#include<Windows.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
int page;
int con;//창 크기_가로
int line;//창 크기_세로
int g_level;//현재레벨
int g_nextlevels;//다음레벨에 가기위한 점수
int g_score;//현재점수
int g_beforescore;
int g_combo = 0;//콤보 수
int g_speed = 150;//현재속도
int g_speed_r[7] = { 150,70,120, 50, 100, 90, 80 };//4, 5단계용 속도값
int g_rsp[3][5][5] = { { { 1, 95, 95, 95, 4 },//가위
{ 124, 64, 32, 64, 124 },
{ 124, 64, 32, 64, 124 },
{ 124, 32, 64, 32, 124 },
{ 2, 95, 95, 95, 3 } },
{ { 1, 95, 95, 95, 4 },//바위
{ 124, 32, 32, 32, 124 },
{ 124, 64, 64, 64, 124 },
{ 124, 64, 64, 64, 124 },
{ 2, 95, 95, 95, 3 } },
{ { 1, 95, 95, 95, 4 },//보
{ 124, 64, 64, 64, 124 },
{ 124, 64, 64, 64, 124 },
{ 124, 64, 64, 64, 124 },
{ 2, 95, 95, 95, 3 } } };//내려오는 손모양 //가위바위보 모양
int g_rspcon; //내려올 손모양 배열 1
int g_rspline; //내려올 손모양 배열 2
int g_nextblock[7];//다음블록과의 칸갯수차이
int g_life = 5;//생명
int gm_put;//사용자 입력값 저장
int g_y;//현재 y좌표
int gm_y;//입력했을 타이밍의 y좌표
int rspshape = -1;//블록모양결정변수
int main_i;
int lastscore=0;//지난게임점수
int rule();//게임방법함수
int startpage();//시작화면
int game();//게임실행
int score(g_level);//게임진행안내
int sideboard();//점수판
int makeblock();//블록그림
int drop();//떨어지는 함수
int rhythmbox(); //박자칸
int scankey();//입력받은 키 저장
int combo();//콤보, 오타시 점수 결정
int gameover();//게임종료창
int win();//게임승리창
int reset();//재시작시 게임정보 리셋
int levelup();//레벨 증가 조건, 게임진행안내창(score()) 호출
int levelscore();//레벨별 점수 증가, 속도 증가
int levelscore() {
if (g_level == 1 && gm_put - 1 == rspshape && gm_y >= 20) {//레벨 1_비겨야 점수증가
g_score += 10;
g_speed -= 5;
}
else if (g_level == 2 && gm_y > 20) { //레벨2_이겨야 점수증가
if (rspshape == 0 && gm_put == 2) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 1 && gm_put == 3) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 2 && gm_put == 1) {
g_score += 10;
g_speed -= 4;
}
}
else if (g_level == 3 && gm_y > 20) { //레벨3_져야 점수증가
if (rspshape == 0 && gm_put == 3) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 1 && gm_put == 1) {
g_score += 10;
g_speed -= 4;
}
else if (rspshape == 2 && gm_put == 2) {
g_score += 10;
g_speed -= 4;
}
}
else if (g_level == 4 && gm_y > 20) { //레벨4_이겨야 점수증가_속도
if (rspshape == 0 && gm_put == 2) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];//속도난수생성
}
else if (rspshape == 1 && gm_put == 3) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 2 && gm_put == 1) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
}
else if (g_level == 5 && gm_y > 20) { //레벨5_져야 점수증가_속도
if (rspshape == 0 && gm_put == 3) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 1 && gm_put == 1) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
else if (rspshape == 2 && gm_put == 2) {
g_score += 10;
g_speed = g_speed_r[rand() % 7];
}
}
}
int levelup() {
if (g_score >= 50 && g_score <= 60) {//1단계→2단계
g_level = 2;
score();
g_speed = 120;
}
else if (g_score >= 100 && g_score <= 110) {//2단계→3단계
g_level = 3;
score();
g_speed = 100;
}
else if (g_score >= 170 && g_score <= 180) {//3단계→5단계
g_level = 4;
score();
g_speed = 100;
}
else if (g_score >= 230 && g_score <= 240) {//4단계→5단계
g_level = 5;
score();
g_speed = 100;
}
}
int reset() {
g_level = 1;
g_score = 0;
g_combo = 0;
g_life = 5;
}
int gameover() {
int x = 7, y = 13;
system("cls");
gotoxy(x, y); printf(" ┌─────────┐");
gotoxy(x, y + 1); printf(" │ G A M E O V E R !│");
gotoxy(x, y + 2); printf(" └─────────┘");
gotoxy(x, y + 3); printf(" 재시작_a ");
gotoxy(x, y + 4); printf("종료하려면 d를 2번 누르세요");
gotoxy(x, y + 10);
reset();
return 0;
}
int win() {
int x = 7, y = 13;
system("cls");
gotoxy(x, y); printf(" ┌─────────┐");
gotoxy(x, y + 1); printf(" │ Y O U W I N ! │");
gotoxy(x, y + 2); printf(" └─────────┘");
gotoxy(x, y + 3); printf(" 재시작_a ");
gotoxy(x, y + 4); printf("종료하려면 d를 2번 누르세요");
reset();
return 0;
}
int combo() {
if (g_beforescore + 10 == g_score) {
++g_combo;
g_score = g_score + 2;
}
else if (g_beforescore == g_score && g_score == 0) {
g_combo = 0;
g_score = 0;
--g_life;
}
else if (g_beforescore == g_score) {
g_combo = 0;
g_speed += 10;
g_score = g_score - 10;
--g_life;
}
}
int scankey() {
gm_put = getch();
if (gm_put == 'a') {
gm_put = 1;
}
else if (gm_put == 's') {
gm_put = 2;
}
else if (gm_put == 'd') {
gm_put = 3;
}
gm_y = g_y;//입력받은 타이밍을 알기위해 변수에 현재 y좌표값 저장
}
int rhythmbox() {
for (int i = 0; i < 20; ++i) {
gotoxy(i, 21); printf("=");
gotoxy(i, 27); printf("=");
}
}
int startpage() {
system("cls");
printf("\n\n\n\n\n");
printf(" ▦▦▦ ▦ ▦ ▦ \n");
printf(" ▦ ▦ ▦ ▦ ▦ ▦▦▦ ▦ ▦▦ ▦▦\n");
printf(" ▦▦ ▦▦▦ ▦▦▦ ▦ ▦▦▦ ▦ ▦ ▦\n");
printf(" ▦ ▦ ▦ ▦ ▦ ▦▦ ▦ ▦ ▦ ▦ ▦\n");
printf(" ▦▦\n\n\n"); //rhythm출력
printf(" ▦▦ ▦▦ ▦▦▦▦▦\n");
printf(" ▦▦ ▦▦ ▦ | | ▦\n");
printf(" ▦▦ ▦▦ ▦▦▦▦▦ ▦ | | ▦\n");
printf(" ▦▦▦▦▦▦ ▦ ▦ ▦ ▦ | | ▦\n");
printf(" ▦ ▦ ▦▦▦ ▦ ▦ ▦ ▦\n");
printf(" ▦▦▦ ▦ ▦ ▦ ▦▦ ▦\n");
printf(" ▦ ▦ ▦▦▦▦▦▦ ▦ ▦\n");
printf(" ▦▦▦▦▦▦ ▦▦▦▦▦\n\n\n\n");//그림출력
printf(" 게임방법 : a 게임시작 : s\n");
reset();
char start = getch();
system("cls");
if (start == 'a') {
return 97;
}
}
int rule() {
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n");
printf(" ┌────────────────────────┐\n");
printf(" │ <게임방법> │\n");
printf(" │ │\n");
printf(" │ ≫조작법 : 가위 _ a │\n");
printf(" │ 바위 _ s │\n");
printf(" │ 보 _ d 로 조작합니다. │\n");
printf(" │ ≫내려오는 가위, 바위, 보를 밑에 칸에 내려오는 │\n");
printf(" │ 타이밍에 맞추어 알맞은 키를 누릅니다. │\n");
printf(" │ │\n");
printf(" │ 돌아가기 _ d 게임시작 _ s │\n");
printf(" └────────────────────────┘\n");
char d = getch();
if (d == 'd') {
return startpage();
}
}
int score() {
int x = 7, y = 12;
switch (g_level)
{
case 1: {
gotoxy(x, y); printf("┌──────────────┐");
gotoxy(x, y + 1); printf("│ ROUND1 │\n");
gotoxy(x, y + 2); printf("│ 비 겨 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);//2초간 화면유지
system("cls");
rhythmbox();
sideboard();
break;
}
case 2: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND2 │\n");
gotoxy(x, y + 2); printf("│ 이 겨 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}
case 3: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND3 │\n");
gotoxy(x, y + 2); printf("│ 져 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}case 4: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND4 │\n");
gotoxy(x, y + 2); printf("│ 이 겨 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}case 5: {
gotoxy(x, y); printf("┌──────────────┐\n");
gotoxy(x, y + 1); printf("│ ROUND5 │\n");
gotoxy(x, y + 2); printf("│ 져 라 │\n");
gotoxy(x, y + 3); printf("└──────────────┘\n");
Sleep(2000);
system("cls");
rhythmbox();
sideboard();
break;
}
}
}
int gotoxy(int x, int y) { //gotoxy함수
COORD pos = { 2 * x,y };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void CursorView(char show)//커서숨기기
{
HANDLE hConsole;
CONSOLE_CURSOR_INFO ConsoleCursor;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
ConsoleCursor.bVisible = show;
ConsoleCursor.dwSize = 1;
SetConsoleCursorInfo(hConsole, &ConsoleCursor);
}
int sideboard() {
int x = 9;
int y = 3;
con = 30;
line = 28;
system("cls");
gotoxy(con - x + 1, line - y - 4);
for (int i = 0; i < g_life; ++i) {
printf("♥ ");
}
gotoxy(con - x, line - y - 3); printf("┌───────┐");
gotoxy(con - x, line - y - 2); printf("│LEVEL : %6d│", g_level);
gotoxy(con - x, line - y - 1); printf("│SCORE : %6d│", g_score);
gotoxy(con - x, line - y); printf("│COMBO : %6d│", g_combo);
gotoxy(con - x, line - y + 1); printf("└───────┘");
gotoxy(con - x, line - y+2); printf("best score : %4d", lastscore);
}
int makeblock(g_rspcon, g_rspline) {
switch (g_rsp[rspshape][g_rspline][g_rspcon]) {
case 1:
printf("┌"); break;
case 2:
printf("└"); break;
case 3:
printf("┘"); break;
case 4:
printf("┐"); break;
case 95:
printf("─"); break;
case 124:
printf("│"); break;
case 32:
printf(" "); break;
case 64:
printf("▦"); break;
}
}
int drop()
{
int x = 15;
rspshape = rand() % 3;
gm_put = 0;
sideboard();
for (g_y = 0; g_y < 22; ++g_y) {//내려가는 모양
for (int i = -1; i < 5; ++i) {////
for (x = 8; x < 13; ++x) {////i와x에따라 모양 면 출력
gotoxy(x, g_y + i);
if (i == -1) {//첫줄은 공백출력
printf(" ");
}
else {
makeblock(x - 8, i);
}
}
}
rhythmbox();
if (kbhit()) scankey();//입력이 있을때만 키 인식
Sleep(g_speed);//저장되는 g_speed값만큼으로 내려오게함
}
levelscore();
combo();
g_beforescore = g_score;
}
int main() {
int startpage(void);
int rule(void);
reset();
CursorView(0);//커서숨기기
system("mode con cols=60 lines=28");//게임 화면 크기
srand((unsigned)time(NULL));//난수 매번 다르게 생성
page = startpage();
while (1) {//게임방법 외에 다른 입력값이 들어올 때 까지 반복
if (page == 97) {//startpage반환값이 97(a)면 게임방법화면함수
page = rule();//방법화면 반환값에 따라 다음 화면 결정
}
else if (page == 115) {
main_i = 0;
g_level = 1;
score();
while (main_i<100000) {
levelup();
drop();
sideboard();
if (g_speed <= 70) {//속도가 어느이상 빨라지지 않도록 조정
g_speed = 70;
}
if (g_score < 0 || g_life == 0) {//게임 종료
if (lastscore < g_score) {//최고기록 갱신 시 저장
lastscore = g_score;
}
reset();
gameover();
if (getch() == 'a') continue;
else if (getch() == 'd') return 0;
}
if (g_score > 800) {//게임 승리
lastscore = g_score;
reset();
win();
if (getch() == 'a') continue;
else if (getch() == 'd') return 0;
}
}
}
else {
break;
}
}
}
//정지인 바보 ㅋㅋㅋㅋㅋㅋ
//정지인 멍청이 ㅋㅋㅋㅋㅋㅋㅋ
//정지인 핵 바아아아아아아아아아아아아아보 ㅋ
//※지우지 말 것※
//광선검 꺼낼 땐 지인~
//내 핸드폰 진동 소리도 지인~
//즤즈ㅢ즤즤즤지인ㄴㄴㄴㄴㄴㄴㄴㄴ ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
//정지인 짱이닼ㅋㅋㅋㅋㅋㅋ
//힘...ㅋㅋㅋㅋ


'c언어' 카테고리의 다른 글

c언어 (배열, 함수, 구조체, 포인터 수업자료)  (0) 2018.05.16
게임프로젝트 보고서  (0) 2017.05.24
코드업 1505  (0) 2017.03.26
코드업 1561  (0) 2017.03.24
코드업 1358  (0) 2017.03.24
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함