/*
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
*/
/*
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<math.h>
#include<time.h>
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main()
{
char input,p, words[5][10] = {"hello", "pineapple", "mango", "banana", "melon"};
char answer[10] = {0};
srand(time(NULL));
int randomNumber;
int c=0,k,i;
srand(time(NULL));
gotoxy(55,1);
printf("=======");
gotoxy(55,2);
printf("HANGMAN");
gotoxy(55,3);
printf("=======");
gotoxy(50,10);
printf("PRESS 'E' to START");
for(;;)
{
if(kbhit())
{
input = getch();
if(input=='E'||input=='e')
{
system("cls");
gotoxy(55,13);
printf("START!");
Sleep(1000);
system("cls");
break;
}
}
}
gotoxy(50,13);
printf("알파벳을 입력해주세요");
randomNumber = rand()%strlen(words);
for(;;)
{
system("cls");
for(i=0; i<strlen(words[randomNumber]); i++)
{
gotoxy(50,1);
printf("틀린 횟수:%d",c);
gotoxy(50+i,14);
if(answer[i]==0)
{
printf("_");
}
else
{
printf("%c", words[randomNumber][i]);
}
}
gotoxy(50, 15);
scanf(" %c", &p);
for(i=0; i<strlen(words[randomNumber]); i++)
{
if(p==words[randomNumber][i])
{
answer[i] = 1;
}
else
{
c++;
gotoxy(50,1);
printf("기회:%d",c);
}
if(c==20)
{
break;
system("cls");
gotoxy(50,13);
printf("Game over");
}
}
}
return 0;
}
*/
/*
#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<math.h>
#include<time.h>
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
int main()
{
char input;
int c=0;
gotoxy(50,13);
printf("A____A");
gotoxy(50,14);
printf("(^ㅅ^)");
gotoxy(50,15);
printf("------");
for(;;)
{
if(kbhit())
{
input=getch();
if(input=='w'||input=='W');
{
c++;
gotoxy(50,1);
printf("%d",c);
}
}
}
}
*/
/*
#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int map[100][100] = {0};
int resourceTable[15] = {0};
int x=9, y=20;
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void initMap()
{
for(int i=0; i<100; i++)
{
for(int j=0; j<100; j++)
{
if(i>=10)
{
map[i][j] = 9;
}
else
{
map[i][j] = 0;
}
gotoxy(j, i);
switch(map[i][j])
{
case 0:
printf(".");
break;
case 9:
printf("M");
break;
}
}
}
}
char drawBefore(int x, int y)
{
switch(map[x][y])
{
case 0:
return '.';
case 9:
return 'M';
}
}
char drawAfter(int x, int y)
{
}
// nothing:0, dirt:1, silver:2, gold:3,dia:4
int randomResource()
{
int r = rand()%100000000; // 1어ㅗㄱ
if(r < 50000000)
{
return 0;
}
else if(r < 75000000)
{
return 1;
}
else if(r < 90000000)
{
return 2;
}
else if(r < 99000000)
{
return 3;
}
else
{
return 4;
}
}
void resourceViewer()
{
char name[15][10] = {"dirt", "silver", "gold", "dia"};
gotoxy(103, 2);
gotoxy(103, x-6);
printf(" ");
for(int i=0; i<15; i++)
{
gotoxy(103, x+i-5);
printf("%6s: %05d", name[i], resourceTable[i]);
}
}
int main()
{
char input;
srand(time(NULL));
initMap();
resourceViewer();
gotoxy(y, x);
printf("@");
gotoxy(0,0);
printf(".");
while(1)
{
if(kbhit())
{
input = getch();
switch(input)
{
case LEFT:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
y--;
gotoxy(y, x);
printf("@");
break;
case RIGHT:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
y++;
gotoxy(y, x);
printf("@");
break;
case UP:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
x--;
gotoxy(y, x);
printf("@");
break;
case DOWN:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
x++;
gotoxy(y, x);
printf("@");
break;
case 's':
case 'S':
if(map[x+1][y]==9)
{
resourceTable[randomResource()] += (rand()%3+1);
resourceViewer();
map[x+1][y]=0;
gotoxy(y+1,x);
printf(".");
}
case 'd':
case 'D':
if(map[x+1][y]==9)
{
resourceTable[randomResource()] += (rand()%3+1);
resourceViewer();
map[x][y+1]=0;
gotoxy(y,x+1);
printf(".");
}
case 'a':
case 'A':
if(map[x+1][y]==9)
{
resourceTable[randomResource()] += (rand()%3+1);
resourceViewer();
map[x+1][y]=0;
gotoxy(y+1,x+1zzz);
printf(".");
}
case 'w':
case 'W':
if(map[x+1][y]==9)
{
resourceTable[randomResource()] += (rand()%3+1);
resourceViewer();
map[x][y+1]=0;
gotoxy(y,x+1);
printf(".");
}
}
}
}
}
*/
#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#define LEFT 75
#define RIGHT 77
#define UP 72
#define DOWN 80
int map[100][100] = {0};
int resourceTable[15] = {0};
void gotoxy(int x,int y)
{
COORD pos= {x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void initMap()
{
for(int i=0; i<100; i++)
{
for(int j=0; j<100; j++)
{
if(i>=10)
{
map[i][j] = 9;
}
else
{
map[i][j] = 0;
}
gotoxy(j, i);
switch(map[i][j])
{
case 0:
printf(".");
break;
case 9:
printf("M");
break;
}
}
}
}
char drawBefore(int x, int y)
{
switch(map[x][y])
{
case 0:
return '.';
case 9:
return 'M';
}
}
char drawAfter(int x, int y)
{
}
// nothing:0, dirt:1, silver:2, gold:3,dia:4
int randomResource()
{
int r = rand()%100000000; // 1어ㅗㄱ
if(r < 50000000)
{
return 0;
}
else if(r < 75000000)
{
return 1;
}
else if(r < 90000000)
{
return 2;
}
else if(r < 99000000)
{
return 3;
}
else
{
return 4;
}
}
void resourceViewer()
{
char name[15][10] = {"","dirt", "silver", "gold", "dia"};
gotoxy(103, 2);
for(int i=1; i<15; i++)
{
gotoxy(103, 2+i);
printf("%6s: %05d", name[i], resourceTable[i]);
}
}
int main()
{
char input;
int x=9, y=20;
srand(time(NULL));
initMap();
resourceViewer();
gotoxy(y, x);
printf("@");
gotoxy(0,0);
printf(".");
while(1)
{
if(kbhit())
{
input = getch();
switch(input)
{
case LEFT:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
y--;
gotoxy(y, x);
printf("@");
break;
case RIGHT:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
y++;
gotoxy(y, x);
printf("@");
break;
case UP:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
x--;
gotoxy(y, x);
printf("@");
break;
case DOWN:
if(map[x+1][y]==9)
{
continue;
}
gotoxy(y, x);
printf("%c", drawBefore(x, y));
x++;
gotoxy(y, x);
printf("@");
break;
case 's':
case 'S':
if(map[x+1][y]==9)
{
resourceTable[randomResource()] += (rand()%3+1);
resourceViewer();
map[x+1][y]=0;
gotoxy(y,x+1);
printf(".");
}
case 'w':
case 'W':
if(map[x+1][y]==9)
{
resourceTable[randomResource()] += (rand()%3+1);
resourceViewer();
map[x-1][y]=0;
gotoxy(y,x-1);
printf(".");
}
}
}
}
}