'Code > c/c++' 카테고리의 다른 글
[C++]Double Linked List 기본기능만 (0) | 2011.12.23 |
---|---|
[C++]Game of Snake. (0) | 2011.09.03 |
[C++]poker (0) | 2011.09.03 |
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
[C++ Code]Swap (0) | 2011.07.28 |
[C++]Double Linked List 기본기능만 (0) | 2011.12.23 |
---|---|
[C++]Game of Snake. (0) | 2011.09.03 |
[C++]poker (0) | 2011.09.03 |
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
[C++ Code]Swap (0) | 2011.07.28 |
[C++]연산자오버로딩 (0) | 2012.02.11 |
---|---|
[C++]Game of Snake. (0) | 2011.09.03 |
[C++]poker (0) | 2011.09.03 |
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
[C++ Code]Swap (0) | 2011.07.28 |
//2011.06.28
//daun
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <time.h>
#define ON 1
#define OFF 0
using namespace std;
//전체 크기 80*25
//0번은 배경 1번은 뱀의몸통 2번은 먹이
//3이 되면 count가 1이 증가하고 ... 이런식으로해야겟군.. 아아아아아아아아 복잡하다 일단은 해봅시다
void headWay(int, int *, int *);
struct room{
int time;
int type;
};
int main()
{
srand(time(NULL));
int count=1 ; //먹이를 먹은 횟수이자 뱀의 몸통길이를 나타냄
room arr[70][23]={0,0};
int headx=0, heady=0;
int type=117;
int foodx =0, foody = 0;
int level;
int leveltime = 0;
cout << "1~10 Level중 몇 Level을 할거인지 입력해주세요 ." << endl;
cout << "1 : 가장 쉬운 난이도 , 10 : 가장 어려운 난이도 " << endl;
cin >> level;
leveltime = 25*(11-level);
headx = rand()%70;
heady = rand()%23;
foodx = rand()%70;
foody = rand()%23;
arr[foodx][foody].type = 3;
while(1)
{
Sleep(leveltime);
system("cls");
if(_kbhit())
{
type = _getch();
headWay(type, &headx, &heady);
} //방향키를 누른경우
else
{
headWay(type, &headx, &heady);
} //방향키를 누르지 않은 경우
arr[headx][heady].type += 1;
arr[headx][heady].time = count;
//먹이는 숫자 3임
cout << "위 : U, 아래 : J, 왼쪽 : H, 오른쪽 : K <난이도" << level << ">"<<endl;
for(int b = 0 ; b <23; b++)
{
for(int a=0; a<70; a++)
{
if(arr[a][b].type == 0)
cout << " "; //그냥배경
if(arr[a][b].type == 1)
{
cout << "o";
arr[a][b].time --;
if(arr[a][b].time == 0)
arr[a][b].type = 0;
} //그냥 뱀몸통
if(arr[a][b].type == 2)
{
system("cls");
cout << "Your Score is " << count -1 << endl;
cout << "END GAME " <<endl;
Sleep(10000);
return 0;
} //뱀이 자신의 몸에 닿아 게임이 끝난 경우
if(arr[a][b].type == 3)
{
cout <<"X";
} //그냥 먹이가 놓여진경우
if(arr[a][b].type == 4)
{
arr[a][b].type = 1;
count++;
foodx = rand()%20;
foody = rand()%20;
arr[foodx][foody].type = 3;
} //뱀이 먹이를 먹은경우
}
cout << endl;
}
}
return 0;
}
void headWay(int type, int *x, int *y)
{
switch(type)
{
case 117:
if(*y == 0)
*y = 22;
else
*y = *y - 1;
break;//위로
case 106:
if(*y == 22)
*y = 0;
else
*y = *y + 1;
break; // 아래로
case 104:
if(*x == 0)
*x = 69;
else
*x = *x - 1;
break; //왼쪽으로
case 107:
if(*x == 69)
*x = 0;
else
*x = *x + 1;
break; //오른쪽으로
}
} //방향키를 눌럿을때 뱀이 움직이는 방향 조절하는 함수
[C++]연산자오버로딩 (0) | 2012.02.11 |
---|---|
[C++]Double Linked List 기본기능만 (0) | 2011.12.23 |
[C++]poker (0) | 2011.09.03 |
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
[C++ Code]Swap (0) | 2011.07.28 |
/*
2011.05.19-20.
The Game Of Poker For Socket
Daun...
*/
/*
-카드 -
1~13 : 하트
14~26 : 다이아
27~39 : 스페이드
40~52 : 크로바
-무늬-
1:하트
2:다이아
3:스페이드
4:크로바
-숫자-
1~10 : 1~10
11 : J
12 : Q
13 : K
*/
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));
int myRandCard[5]={0}, num[13]={0}, shape[4]={0};
cout << " J : 11, Q : 12 , K : 13"<<endl;
cout << "shape[0] : ♥ shape[1] : ◆ shape[2] : ♠ shape[3] : ♣"<<"\n\n";
while(1)
{
for (int i = 0 ; i < 5 ; i++)
myRandCard[i]=rand()%52+1;
int count=0;
for(int i = 0 ; i < 5 ; i++)
for(int a = i+1 ; a < 5 ; a++)
if(myRandCard[a]==myRandCard[i])
count++;
if(count ==0)
break;
} //랜덤으로 카드를 뽑음!
for (int i = 0 ; i < 5 ; i++)
{
if( myRandCard[i]/13 == 0)
{
shape[0]++;
num[myRandCard[i]%13]++;
cout << "뽑은 카드는 ♥" << myRandCard[i]%13 +1<<"입니다"<<endl;
}
else if(myRandCard[i]/13 == 1)
{
shape[1]++;
num[myRandCard[i]%13]++;
cout << "뽑은 카드는 ◆"<<myRandCard[i]%13 +1 << "입니다."<<endl;
}
else if(myRandCard[i]/13 == 2)
{
shape[2]++;
num[myRandCard[i]%13]++;
cout << "뽑은 카드는 ♠"<<myRandCard[i]%13 +1 << "입니다."<<endl;
}
else
{
shape[3]++;
num[myRandCard[i]%13]++;
cout <<"뽑은 카드는 ♣"<<myRandCard[i]%13 +1 << "입니다."<<endl;
}
} //카드의 무늬 판별!+카드보여주기->저거 뽑은카드 숫자보여주는거 따로 함수써서 하고싶당! 13같은거는 K로 나타나도록!
// for(int i = 0 ; i < 4 ; i++)
// cout << "shape[" << i << "] : " << shape[i] << "\t";
//
// cout << endl;
//
// for(int i = 0 ; i < 13 ; i++)
// cout << "num[" << i+1 << "] : " << num[i] << "\t"; //카드 숫자새는거 제대로 된거인지 확인용이엿음!!
int two=0, three=0, four=0;
for(int i = 0 ; i < 13 ; i++)
{
if(num[i]==2)
two++;
else if(num[i]==3)
three++;
else if(num[i]==4)
four++;
}
int flush = 0;
for(int i = 0 ; i < 4 ; i++)
if(shape[i]==5)
flush++;
cout << endl;
if(four ==1)
cout << "포카드 (Four Card)"<<endl;
else if(three == 1 && two == 1)
cout << "풀하우스 (Full house)"<<endl;
else if(flush == 1 )
cout << "플러쉬 (Flush)"<<endl;
else if(three ==1)
cout << "트리플(Triple)"<<endl;
else if(two == 2)
cout << "투페어(Two Pair)"<<endl;
else if(two == 1)
cout << "원페어(One Pair)"<<endl;
else
{
int sum = 0;
if(num[0]==1)
{
for(int i = 0 ; i < 5 ; i++)
if(num[i]==1)
sum++;
if(sum == 5)
cout << "백스트레이트(Back Straight)"<<endl;
}
sum = 0 ;
if(num[0]==1)
{
for(int i = 9 ; i < 13 ; i++)
if(num[i]==1)
sum++;
if(sum==4)
cout << "마운틴 (Mountain)"<<endl;
}
else
{
for (int i = 1 ; i < 9 ; i ++)
{
sum = 0 ;
for(int a = i ; a < i + 5 ; a++)
if(num[a]==1)
sum++;
if(sum == 5)
cout << "스트레이트 (Straight)" <<endl;
}
}
}
return 0;
}
[C++]Double Linked List 기본기능만 (0) | 2011.12.23 |
---|---|
[C++]Game of Snake. (0) | 2011.09.03 |
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
[C++ Code]Swap (0) | 2011.07.28 |
[C++ Code]주소값출력하기 (0) | 2011.07.28 |
//2011 08 28
//유클리드 알고리즘 구현하기
//Daun..
//I_co@IGRUS
#include <iostream>
using namespace std;
void swap(int,int);
int GCD(int,int);
int main()
{
int num1=0, num2 = 0;
cout << "두개의 숫자를 입력해 주세요\n";
cin >> num1>>num2;
cout << GCD(num1,num2);
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int GCD(int num1, int num2)
{
if(num1<num2)
swap(num1,num2);
if(num2)
{
GCD(num2, num1-num2);
}
else
{
return num1;
}
}
[C++]Game of Snake. (0) | 2011.09.03 |
---|---|
[C++]poker (0) | 2011.09.03 |
[C++ Code]Swap (0) | 2011.07.28 |
[C++ Code]주소값출력하기 (0) | 2011.07.28 |
[C++ Code]재귀함수 (0) | 2011.07.28 |
//2011 04
//Daun..
//포인터를 가장 많이 사용하게되는, 이제는 거의 외워써 쓰는 Swap함수!
#include <iostream>
using namespace std;
void swap (int *pa, int *pb)
{
int temp;
temp=*pa;
*pa=*pb;
*pb=temp;
}
int main ()
{
int num1=10, num2=20;
cout << num1 << " " << num2 << endl;
swap (&num1, &num2);
cout << num1 << " " << num2;
return 0;
}
[C++]poker (0) | 2011.09.03 |
---|---|
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
[C++ Code]주소값출력하기 (0) | 2011.07.28 |
[C++ Code]재귀함수 (0) | 2011.07.28 |
[C++ Code]야구게임 (0) | 2011.07.28 |
//2011 03
//Daun..
//주소값 출력하기.. 포인터의 개념이 어려울때 시도해보던 코드!
//포인터는 처음에 어렵지만 차근차근 간단하게 도전해보면서 하다보면 어느순간 익숙해질꺼!!
#include <iostream>
using namespace std;
int main()
{
int a = 123;
int * ptra = &a;
cout << "int a &a의 값 출력" << &a << "\n";
cout << "int a *ptra의 값 출력 " << *ptra << "\n";
cout << "int a ptra의 값 출력" << ptra << "\n";
cout << "int a sizeof(ptra)값 출력 " << sizeof(ptra) << "\n";
char i = 'S';
char * ptri = &i;
cout <<"char i &i의 값 출력" <<(int*)&i << "\n";
cout <<"char i * ptri의 값 출력 " << * ptri << "\n";
cout <<"char i ptri의 값 출력" << ptri << "\n";
cout <<"char i sizeof(ptri)값 출력 " << sizeof(ptri) << "\n";
int arr[4];
cout << "arr[0]의 주소값 출력" << &arr[0] << "\n";
cout << "arr[1]의 주소값 출력" << &arr[1] << "\n";
cout << "arr[2]의 주소값 출력" << &arr[2] << "\n";
cout << "arr[3]의 주소값 출력" << &arr[3] << "\n";
char m[3]="ap";
char n[3]={'a','p','\0'};
char * ptrm0 = &m[0];
char * ptrm1 = &m[1];
cout << "m0자리 주소 출력 : "<<ptrm0 <<"\n"<< "m1자리 주소 출력 : " << ptrm1 << "\n";
return 0;
}
[Code] 유클리드 알고리즘(Euclid Algorism) (0) | 2011.08.29 |
---|---|
[C++ Code]Swap (0) | 2011.07.28 |
[C++ Code]재귀함수 (0) | 2011.07.28 |
[C++ Code]야구게임 (0) | 2011.07.28 |
[C++ Code]스위치연습 (0) | 2011.07.28 |
//Daun..
//2011 03
//재귀함수의 정석... 난 왜 아직도 재귀함수를 어려워할까나..
#include <iostream>
using namespace std;
int sum(int n){
if(n==1){
return 1;
}
else {
return n+sum(n-1);
}
}
int main ()
{
int i; // 시그마 숫자
cout << "숫자를 입력해 주세요.";
cin >> i;
cout << sum (i);
return 0;
}
[C++ Code]Swap (0) | 2011.07.28 |
---|---|
[C++ Code]주소값출력하기 (0) | 2011.07.28 |
[C++ Code]야구게임 (0) | 2011.07.28 |
[C++ Code]스위치연습 (0) | 2011.07.28 |
[C++ Code]소수출력하기 (0) | 2011.07.28 |
//Daun..
//2011 03
/*4자리숫자로 야구게임
아직은 문자를 입력하면 애러뜸!*/
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main()
{
cout <<"\n\n신나는 야구게임!\n\n"; //처음 게임의 제목 입력
cout <<"규칙 : 각자리 숫자는 1-9까지 입니다.\n.총4자리 숫자입니다.\n또한, 각자리수는 전부 달라야합니다.\n\n\n\n"; //규칙설명문구 생성
srand(time(0)); //값 랜덤 생성
int number[4]; //number=컴퓨터가 준 값
int put[4]; //put=입력하는 값의 각 자리수
int putin; //putin=처음입력값
int s,ball; //s=strike갯수,ball=ball갯수,z=버릴꺼(내컴이 똥컴이라해논거)
int b[4]; //ball갯수 더할때 사용할꺼->근데 4로 쓰는게 맞나?
while(1){
for(int t=0;t<=3;t++){
number[t]=rand()%9 +1;
}
if(number[0]!=number[1]&&number[0]!=number[2]&&number[0]!=number[3]&&number[1]!=number[2]&&number[1]!=number[3]&&number[2]!=number[3]){
break;
}
} /*while문-1값을 대입함으로써 항상 돌아가도록 만들엇고,
number은 각각의 자리의 숫자를 컴퓨터가 만들어 준것이다.
단, 각 자리숫자는 모두 달라야 하기 때문에
if절을 이용해서 각자리 숫자가 전부 다른경우 for문을 끝내라는 조건을
달아주었다.*/
cout << number[0]<<number[1]<<number[2]<<number[3] <<endl;//정답 테스트를위해 적어줌->본래에는 지워야함.!!!!!!!!!!!!!!!!!!
cout << "숫자를 입력해 주세요.\n";//숫자를 입력하라는 문구 출력
while(1){
cin >> putin; //숫자를 입력.
put[0]=putin/1000; //1000자리숫자를 put[0]에 입력
put[1]=(putin%1000)/100; //100자리숫자를 put[1]에 입력
put[2]=putin%100/10; //10자리숫자를 put[2]에입력
put[3]=putin%10; //1자리숫자를 put[3]에입력
if(putin>=1000 && putin<10000 && put[0]!=put[1] && put[0]!=put[2]&& put[0]!=put[3] && put[1]!=put[2] && put[1]!=put[3] && put[2]!=put[3]){
// if문을 이용하여 양의 4자리인경우에만 계산을 하라고 함, 각자리수가 다 다른숫자만입력하게 만듬
if(put[0]==number[0]&&put[1]==number[1]&&put[2]==number[2]&&put[3]==number[3]){
cout << "정답입니다!!>_<\n\n 게임이 끝났습니다.\n";
break;
} /*만약 정답을 맞췃을경우에 게임이 끝낫다는 문구와함께
while문을 빠져나오라는 명령을 내립니다*/
else{
b[0]=0;
b[1]=0;
b[2]=0;
b[3]=0;
s=0; /*이것이 처음에는 중요하지 않아 보이나
한번 else과정을 거치고 났을때 남아잇던 값들을 초기화 시키는 역활을 합니다.*/
for(int q=0; q<4;q++){
if(number[q]==put[q]){
s++;
} //for문을 이용하여 strike의 갯수를 파악합니다.
}
if(number[0]==put[1] || number[0]==put[2] ||number[0]==put[3]){
b[0]++;
} //대입한 수의 첫번째 자리 숫자가 ball이 성립하는지 검토합니다.
if(number[1]==put[0] || number[1]==put[2] || number[1]==put[3]){
b[1]++;
} //대입한 수의 두번째 자리 숫자가 ball이 성립하는지 검토합니다.
if(number[2]==put[0] || number[2]==put[1] || number[2]==put[3]){
b[2]++;
} //대입한 수의 세번째 자리 숫자가 ball이 성립하는지 검토합니다.
if(number[3]==put[0] || number[3]==put[1] || number[3]==put[2]){
b[3]++;
} //대입한 수의 세번째 자리 숫자가 ball이 성립하는지 검토합니다.
ball=b[0]+b[1]+b[2]+b[3];//각각 구해논 ball의 갯수를 합합니다.
cout << s << "스트라이크" << ball << "볼" << "입니다.\n\n"<<"***다시입력하세요.\n";//최종적인 문구 출력
} /*else 문의 끝. 정답을 맞추지 못하엿을경우에
계산해야 할것들이 들어있습니다.*/
} /*while문의 끝. 1을 대입함으로써 항상 돌아가도록 만들었으며
이때의 while의 역활은 숫자를 계속해서 대입하라는 문구가 뜨는 역활입니다.
또한 대입시 strike와 ball을 표시해주는것도 있습니다.*/
else {
cout << "4자리 각자리수가 다 다른 정수만 가능합니다.\n 숫자를 다시 입력해 주세요,\n";
} //4자리 정수가 아닌경우에 출력할 값
}
return 0;
}
/*
4자리 숫자로 하는 야구게임
너무 어려워서 처음에는 3자리숫자로 먼저 시작햇다...
그러고나서 바꾸니 금세 하더라;....
처음으로 만든 거대한 코드라서 ㅇ만들고나니 완전 두근두근 신남신남이엿지요
*/
[C++ Code]주소값출력하기 (0) | 2011.07.28 |
---|---|
[C++ Code]재귀함수 (0) | 2011.07.28 |
[C++ Code]스위치연습 (0) | 2011.07.28 |
[C++ Code]소수출력하기 (0) | 2011.07.28 |
[C++ Code]포인터없이 최대값출력하기 (0) | 2011.07.28 |
//Daun,,
//2011 03
//스위치를 처음 배우고나서...
#include <iostream>
using namespace std;
int main(){
char grade;
cin >> grade;
switch(grade){
case 'A':
cout <<"A맞앗지롱!\n";
break;
case 'B':
cout << "B맞았음!\n";
break;
default:
cout << "A랑B가 둘다 아님!\n";
}
return 0;
}
[C++ Code]재귀함수 (0) | 2011.07.28 |
---|---|
[C++ Code]야구게임 (0) | 2011.07.28 |
[C++ Code]소수출력하기 (0) | 2011.07.28 |
[C++ Code]포인터없이 최대값출력하기 (0) | 2011.07.28 |
[C++ Code]피보나치수열 (0) | 2011.07.28 |