본문 바로가기
C/☞

[00]-A. 캐릭터 이동

by TR. 2020. 7. 24.
# include <Windows.h>
# include <stdio.h>
# include <time.h>

void main(){
	// # 숫자이동
	// int game[7] = {0, 0, 0, 3, 0, 0, 0};
	srand(time(0));

	// int Monster = 3;
	// 1. 왼쪽으로 이동
	// 2. 오른쪽으로 이동
	// . 예외처리 : 유효하지 않은 경우 경고메세지 출력, 무브하지 않음
	
	// . 캐릭터는 기호로 출력 : 
	// 조건문을 사용해서, 
	// 1) 0일때는 로드표기 / 
	// 2) 몬스터값과 일치하면 캐릭터용 기호 표시
	// 0 0 0 3 0 0 0
	// _ _ _ ★ _ _ _
		
	int game[7] = {0};
	int Monster = 3;

	int idx = rand() % 7;
	while(1){
		game[idx] = Monster;		// 몬스터 변수의 사용
		// print
		for(int i=0; i<7; i++){
			if(game[i] == Monster){
				printf("_●_");
			} else{
				printf("___");
			}
		}
		printf("\n");

		int sel;
		printf("\n1)왼쪽 \n2)오른쪽\n");
		scanf("%d", &sel);

		// move
		if(sel == 1){
			if(idx == 0){
				printf("더 이상 움직일 수 없습니다.\n");
			} else{
				game[idx] = 0; // point
				idx -= 1;
			}
		}
		else if(sel == 2){
			if(idx == 6){
				printf("더 이상 움직일 수 없습니다.\n");
			} else{
				game[idx] = 0; // point
				idx += 1;
			}
		}
		else{
			printf("잘 못 입력했습니다.");
		}
		printf("\n");

	}




	system("pause");
}

'C > ' 카테고리의 다른 글

[52] 문자열 함수  (0) 2020.07.27
[51] 문자열 기본  (0) 2020.07.27
[00] 캐릭터 이동  (0) 2020.07.24
[50]-A. 기억력 게임  (0) 2020.07.23
[50] 기억력 게임  (0) 2020.07.23

댓글