/**#include<stdio.h>
int main()
{
int m,n,h=0,s=10000,c;
scanf("%d %d",&m,&n);
for(int f=m;f<=n;f++)
{
// f가 소수인지?
//f의 약수의 갯수(c)가 2개인지?
c=0;
for(int j=1;j<=f;j++)
{
if(f%j==0)
{
c++;
}
}
if(c==2) //f가 소수라면?
{
h+=f;
if(f<s)
{
s=f;
}
}
}
printf("%d\n%d",h,s);
return 0;
}**/
/**
#include<stdio.h>
#include<windows.h>
void gotoxy(int y, int x)
{
COORD Pos = {x - 1, y - 1};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
//콘솔 크기 지정
system( "mode con lines=20 cols=100" );
//글자 색상 지정 (0 ~15)
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 10 );
//글자 출력 위치 이동
gotoxy(20,10);
printf("hello 하진");
Sleep(1000); //1초 기다리기
//콘솔 모두 지우기
system( "cls" );
Sleep(500);
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 9 );
gotoxy(10,20);
printf("hello 하진");
return 0;
}**
int random;
srand(time(NULL)); // 난수 초기화
while(1){
for(int i=6;i<=15;i++)
{
gotoxy(rand()%100,rand()%100);
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), i );
printf("비호감+1\n");
Sleep(500);
system( "cls" );
Sleep(500);
}
}
#include<stdio.h>
#include<windows.h>
#include <stdlib.h> //srand, rand를 사용하기 위한 헤더파일
#include <time.h> // time을 사용하기 위한 헤더파일
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
void gotoxy(int x, int y)
{
COORD Pos = {x - 1, y - 1};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
int x=10, y=10;
char c;
for (;;) {
if (_kbhit()) { //키보드 입력 확인 (true / false)
c = _getch(); // 방향키 입력시 224 00이 들어오게 되기에 앞에 있는 값 224를 없앰
if (c == -32) { // -32로 입력되면
c = _getch(); // 새로 입력값을 판별하여 상하좌우 출력
system( "cls" );
switch (c) {
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
break;
}
}
}
gotoxy(x,y);
printf("■");
Sleep(50);
}
}
1. 키보드를 입력했을때, 콘솔 화면에 변화가 나타나게
2. 스페이스를 누르면, 현재 위치에서 오른쪽으로 선이 나타나게
#include<stdio.h>
#include<windows.h>
#include <stdlib.h> //srand, rand를 사용하기 위한 헤더파일
#include <time.h> // time을 사용하기 위한 헤더파일
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
void gotoxy(int x, int y)
{
COORD Pos = {x - 1, y - 1};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);
}
int main()
{
int x=10, y=10;
char c;
for (;;) {
if (_kbhit()) { //키보드 입력 확인 (true / false)
c = _getch();
if (c==' ')
{ for(int v=0;v<=4;v++)
{
printf("☞");
Sleep(100);
}
gotoxy(x,y); printf("■☞☞☞ "); Sleep(100);
gotoxy(x,y); printf("■☞☞ "); Sleep(100);
gotoxy(x,y); printf("■☞ "); Sleep(100);
gotoxy(x,y); printf("■ "); Sleep(100);
}// 방향키 입력시 224 00이 들어오게 되기에 앞에 있는 값 224를 없앰
if (c == -32) { // -32로 입력되면
c = _getch(); // 새로 입력값을 판별하여 상하좌우 출력
system( "cls" );
switch (c) {
case LEFT:
x--;
break;
case RIGHT:
x++;
break;
case UP:
y--;
break;
case DOWN:
y++;
break;
}
}
}
gotoxy(x,y);
printf("■");
Sleep(50);
}
}
homework
1. 키보드입력, 색상변경, Sleep, 전부지우기 를 포함한 프로그램 만들기
2. 위쪽방향키누르면 ▲로바뀌면서 위로 총쏘기
아래방향키 누르면 ▼로 바뀌면서 아래로 총쏘기
왼쪽오른쪽은 플레이어 움직이기
**/
/**=esc**/