설인컴퓨터

블로그 이미지

jhSnowman

[관악구 설인컴퓨터] /C++/프로그램 소스/제목:스네이크 게임/VER:0.a.1

Program Language/C, C++ 2021. 7. 28. 13:04

안녕하세요! 오늘은 프로그램언어를 통해 간단한 게임을 만들어보았는데요 (버그가 있을 수 있어요)

제가 아직 못 찾은 버그가 있을지 모르겠네요.

찾아주셔서 알려주시면 감사하겠습니다.

만든 프로그램과 소스를 공유하겠습니다.

jhSnakeGames.exe
0.13MB

소스


#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

#define start 3
#define Width 60
#define Height 30

typedef struct modaa
{
	int x;
	int y;
}
moda;

void modf(moda *plays, moda *modb, int a);
void play(moda * plays, moda *modb);
void xyz(int x, int y);
void bba(int a);
void end(int a);
void gstart();
void panel();
void hlpe();



int crash(moda *plays, int a);
int agth = start;
int direction = 2;
int speed = 200;
int i;

    

int main(void)
{   
	xyz(20,12);
	printf("아무키나 누르면 시작합니다..");
	getch();
	system("cls");
	
	xyz(20,14);
	printf("세상에서 가장 큰 뱀을 만들자!");
	getch();
	
	system("cls");
	gstart();
	system("modae con cols=90 lines=40");	
	xyz(20,13);
}

void gstart()
{
	
	
	moda *plays = (moda *)malloc(sizeof(moda) * start);
	moda modb;
	
	srand(time(NULL));
	play(plays, &modb);
	while(1)
	{
		char key;
		key = getch();
		switch(key)
		{
		case 72:
		if (direction != 1)	direction = 0;
		break;
		case 80:
		if (direction != 0) direction = 1;
		break;
		case 75:
		if (direction != 3) direction = 2;
		break;
		case 77:
		if (direction != 2) direction = 3;
		break;
		}
		while(!kbhit())
		{
			if (!(plays[agth-1].x == plays[agth-2].x && plays[agth-1].y == plays[agth-2].y))
			{
				xyz( plays[agth-1].x, plays[agth-1].y);		printf("  ");
			}
			for (i = agth - 1 ; i > 0 ; i--)	
			{	
			plays[i] = plays[i-1];	
			}
			switch(direction)																
			{
			case 0:
			plays[0].y -= 1;
			break;
			case 1:
			plays[0].y += 1;
			break;
			case 2:
			plays[0].x -= 2;
			break;
			case 3:
			plays[0].x += 2;
			break;
			}
			xyz(plays[0].x,plays[0].y);
			printf("◇");

			if( modb.x == plays[0].x && modb.y == plays[0].y)
			{
				agth++;
				plays = (moda *) realloc(plays,sizeof(moda) * agth);
				plays[agth-1] = plays[agth-2];
				modf(plays,&modb,agth);
				bba(agth);
				if(agth %5 == 0)
					speed -= 20;
			}
			Sleep(speed);
			if(crash(plays,agth))
				goto END;
		}
	}
END:
	end(agth);
	free(plays);
}

void play(moda * plays, moda *modb)
{
	panel();
	for(i = 0; i < start; i++)
	{
		plays[i].x = 20+2*i;
		plays[i].y = 8;
		xyz(plays[i].x,plays[i].y);
		printf("◆"); 
	}
	modf(plays,modb,start);
	bba(start);
	hlpe();
}

void xyz(int x, int y)
{
	COORD Pos = {x,y};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Pos);
}

void modf(moda *plays, moda *modb, int a)
{
	srand(time(NULL));
	do{
		modb->x = rand()%28 * 2+2;
		modb->y = rand()%28+1;
		for (i = 0 ; i < a ; i++)
		{
			if(modb->x == plays[i].x && modb->y == plays[i].y)	
			{
			break;	
			}
			if(i == a-1)
			{
				xyz(modb->x, modb->y);
				printf("☆");
				return;
			} 
		}
	}while(1);
}

void panel()
{
	for (i = 0 ; i < Width/2 ; i++) 
	{ 
	printf("□");
	}
	for (i = 0 ; i < Height ; i++) 
	{ 
	xyz(0,i); 
	printf("□");
    }
	for (i = 0 ; i < Height ; i++) 
	{ 
	xyz(Width,i); 
	printf("□"); 
	}
	xyz(0,Height-1);
	for (i = 0 ; i < Width/2 ; i++) 
	{ 
	printf("□");
	}
}

int crash(moda *plays, int a)	
{
	if(plays[0].x < 2 || plays[0].x > 58 || plays[0].y < 1 || plays[0].y > 28) 
	{
	 return 1; 
	 }
	for (i = 1 ; i < a ; i++)
	{
		if (plays[0].x == plays[i].x && plays[0].y == plays	[i].y)
			return 1;	
	}
	return 0;	
}

void bba(int a)
{
	xyz(61,1);
	printf("현재 크기:%dM",a);
}
void hlpe()
{
	xyz(61,10);
	printf("추억의 뱀꼬리 게임");
	xyz(61,15);
	printf("자제작");
	xyz(61,18);
	printf("jhSnowman");
	xyz(61,22);
	printf("ver:0.a.1");
	xyz(61,26);
	printf("버그제보");
	xyz(61,28);
	printf("i177@hanmail.net");
}

void end(int a)
{
	system("cls");
	xyz(20,13);
	printf("최종 크기 점수: %dM",a);
	xyz(20,14);
	system("pause");

구동이미지


과연 몇 점까지 클리어할 수 있을지 궁금하네요 추후 코볼로도 게임을 만들 예정입니다!


 

다음 이 소스는 아래의 스펙과 설정으로 구동이 되었습니다.

구동 디바이스:데스크톱
운영체제:Windows 10 Pro (1903)
S/W 정보:Dev-Cpp 5.11
S/W 언어:C++

 

Posted by jhSnowman
블로그 이미지

by jhSnowman

공지사항

    최근...

  • 포스트
  • 댓글
  • 트랙백
  • 더 보기

태그

  • 신림동
  • 조립PC
  • 기초
  • 카카오톡 봇
  • 비트코인
  • 난곡동
  • 매직키보드
  • 신림동컴퓨터
  • 인텔
  • 소스
  • 보드
  • 관악구 컴퓨터
  • 애플
  • 핫소스
  • 관악구설인컴퓨터
  • 데이터복구
  • 설인컴퓨터
  • 가상화
  • 프로그래밍 소스
  • 갈릴레오
  • 이더리움
  • 프로그램소스
  • 게이밍pc
  • 가상화폐
  • 관악구 설인컴퓨터
  • 워크스테이션
  • 관악구컴퓨터
  • 프로그래밍
  • 애플매직키보드
  • 회로도

글 보관함

«   2025/06   »
일 월 화 수 목 금 토
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

링크

카테고리

  • 분류 전체보기 (36)
    • 고객 주문 PC 조립과정 (3)
    • 언박싱, 사용기 (13)
    • Program Language (11)
      • Java Script (4)
      • C# (1)
      • C, C++ (1)
      • Python (1)
      • Cobol (1)
      • R (1)
      • PHP (1)
    • Software (2)
    • 회로도, 도면, 모델링 (5)
    • 가상화폐 채굴 정보 (1)

카운터

Total
Today
Yesterday
방명록 : 관리자 : 글쓰기
jhSnowman's Blog is powered by daumkakao
favicon

설인컴퓨터

  • 태그
  • 링크 추가
  • 방명록

관리자 메뉴

  • 관리자 모드
  • 글쓰기
  • 분류 전체보기 (36)
    • 고객 주문 PC 조립과정 (3)
    • 언박싱, 사용기 (13)
    • Program Language (11)
      • Java Script (4)
      • C# (1)
      • C, C++ (1)
      • Python (1)
      • Cobol (1)
      • R (1)
      • PHP (1)
    • Software (2)
    • 회로도, 도면, 모델링 (5)
    • 가상화폐 채굴 정보 (1)

카테고리

PC화면 보기 티스토리 Daum
여기에 페이지 제목

Hello World!

이 테마의 원본 제작자

Skin info material T Mark3 by 뭐하라 여기에 페이지 제목

Error World!

Error!