Memory Drive

반응형
  1. <%
  2.   Option Explicit
  3.   ' ASP의 Rand를 이용한 3x3 Puzzle Game
  4. %>
  5. <style type="text/css">
  6. h2 {
  7.   font-family:  Arial;
  8.   font-size:    24px;
  9.   color:      #666;
  10.   padding:    4px;
  11.   background:  #CCCCFF;
  12.   border-bottom:  2px solid #ddd;
  13.   text-align:  center;
  14. }
  15. td {
  16.   font-family:  Impact;
  17.   font-size:    60px;
  18.   color:      white;
  19.   background:  #DDE8FF;
  20. }
  21. a:hover {
  22.   color: #FF0066;
  23.   text-decoration: none;
  24.   font-weight: bold
  25. }
  26. a:visited {
  27.   color: #000099;
  28.   text-decoration: none;
  29. }
  30. a:active {  
  31.   text-decoration: none;
  32. }
  33. a:link {
  34.   color: #000099;
  35.   text-decoration: none;
  36. }
  37. </style>
  38. <h2> 3x3 Puzzle Game by ASP</h2>
  39. <%
  40.   ' Random Seed값 초기화
  41.   Randomize
  42.     Dim board(8)  ' 배열을 선언한다.
  43.     Dim ThePick  ' 임의로 선택된 값의 색인 변수
  44.     Dim Temp    ' 값을 교환하기 위한 임시 변수
  45.     Dim i, j    ' 반복문의 카운터용
  46.   Dim ct
  47.   Dim cnt   ' 클릭한 인덱스값 받기
  48.   Dim getArr    ' 값을 저장해 Get으로 던지는 변수
  49.   Dim getArr2  ' 값을 저장한것을 받는 변수
  50.   Dim sum   ' 0-8 까지 합을 저장하기 위한 변수
  51.   Dim chaos  ' 무질서도 판단
  52.   Dim loopcnt  ' loop cnt
  53.   ' Request...
  54.   getArr  = Request.QueryString("getArr") ' get된 전체 값들
  55.   cnt  = Request.QueryString("ct")    ' get된 index값
  56. ' 처음 실행 할경우
  57. If cnt=0 Then
  58.   loopcnt = true
  59.   While loopcnt
  60.     ' 배열을 채운다.
  61.     For I = 0 To 8
  62.       board(I) = I
  63.     Next
  64.     ' 배열을 썩는다.
  65.     For I = 0 To 8
  66.       ThePick = Int(1 + Rnd * 8)  ' 랜덤으로 생성!
  67.       Temp = board(I)
  68.       board(I) = board(ThePick)
  69.       board(ThePick) = Temp
  70.     Next
  71.     ' 무질서도 체크
  72.     For i = 0 To 8
  73.       For j = i To 8
  74.         If board(i) > board(j) Then chaos=chaos+1 : End if
  75.       next
  76.     Next
  77.     '무질서 더한값이 짝수 이면 Loop 탈출
  78.     ' 무질서도가 홀수이면 게임 퍼즐을 풀수 없다.
  79.     If (chaos Mod 2) = 0 Then
  80.       loopcnt = false
  81.       Else
  82.       loopcnt = true
  83.     End if
  84.   wend
  85. ' 두번째 실행
  86. Else
  87.   ' getArr String -> 배열 로 변경
  88.     getArr2 = Split( getArr , "-" )
  89.   For i=0 To 8
  90.       board(i) = getArr2(i)
  91.   Next
  92.   ' 해당 Index으로 값을 이동
  93.   Select Case CInt(cnt) ' 위치값(Index)
  94.     Case 1
  95.       If board(1) = 0 Then  ' 1번이 비었다면
  96.       board(1) = board(0)
  97.             board(0) = 0
  98.          End If
  99.         If board(3) = 0 Then  ' 3번이 비었다면
  100.             board(3) = board(0)
  101.             board(0) = 0
  102.       End If
  103.     Case 2
  104.        If board(0) = 0 Then
  105.         board(0) = board(1)
  106.         board(1) = 0
  107.       End If
  108.       If board(2) = 0 Then
  109.         board(2) = board(1)
  110.         board(1) = 0
  111.       End If
  112.       If board(4) = 0 Then
  113.         board(4) = board(1)
  114.         board(1) = 0
  115.       End If     
  116.     Case 3
  117.       If board(1) = 0 Then
  118.         board(1) = board(2)
  119.         board(2) = 0
  120.       End If
  121.       If board(5) = 0 Then
  122.         board(5) = board(2)
  123.         board(2) = 0
  124.       End If
  125.     Case 4
  126.       If board(0) = 0 Then
  127.         board(0) = board(3)
  128.         board(3) = 0
  129.       End If
  130.       If board(4) = 0 Then
  131.         board(4) = board(3)
  132.         board(3) = 0
  133.       End If
  134.       If board(6) = 0 Then
  135.         board(6) = board(3)
  136.         board(3) = 0
  137.       End If
  138.     Case 5
  139.       If board(1) = 0 Then
  140.         board(1) = board(4)
  141.         board(4) = 0
  142.       End If
  143.       If board(3) = 0 Then
  144.         board(3) = board(4)
  145.         board(4) = 0
  146.       End If
  147.         If board(5) = 0 Then
  148.         board(5) = board(4)
  149.         board(4) = 0
  150.       End If
  151.       If board(7) = 0 Then
  152.         board(7) = board(4)
  153.         board(4) = 0
  154.       End If
  155.     Case 6
  156.       If board(8) = 0 Then
  157.       board(8) = board(5)
  158.       board(5) = 0
  159.       End If
  160.       If board(4) = 0 Then
  161.         board(4) = board(5)
  162.         board(5) = 0
  163.       End If
  164.       If board(2) = 0 Then
  165.         board(2) = board(5)
  166.         board(5) = 0
  167.       End If     
  168.     Case 7
  169.       If board(3) = 0 Then
  170.         board(3) = board(6)
  171.         board(6) = 0
  172.       End If
  173.       If board(7) = 0 Then
  174.         board(7) = board(6)
  175.         board(6) = 0
  176.       End If 
  177.     Case 8
  178.       If board(4) = 0 Then
  179.         board(4) = board(7)
  180.         board(7) = 0
  181.       End If
  182.       If board(6) = 0 Then
  183.         board(6) = board(7)
  184.         board(7) = 0
  185.       End If
  186.       If board(8) = 0 Then
  187.         board(8) = board(7)
  188.         board(7) = 0
  189.       End If
  190.     Case 9
  191.       If board(5) = 0 Then
  192.         board(5) = board(8)
  193.         board(8) = 0
  194.       End If
  195.       If board(7) = 0 Then
  196.         board(7) = board(8)
  197.         board(8) = 0
  198.       End If
  199.   End select
  200.   For i = 0 To 8
  201.     If board(i) = CStr(i+1) Then sum=sum+1 : End If
  202.     If sum=8 Then
  203.     response.write "<script language=javascript>alert('문제를 다 풀었습니다') </script>"
  204.     End if
  205.   Next
  206. End if
  207.   ' 넘기기 위한 묶음 변수 생성
  208.   getArr = ""
  209.   For i=0 To 8
  210.       getArr =  getArr &  board(i) & "-"
  211.   Next
  212.   '출력....
  213.   response.write "<table cellpadding=4 cellspacing=4 border=2 align=center>"
  214.   ct = 1
  215.   For i = 0 To 2
  216.     response.write "<tr align=center height=100>"
  217.     For j = 0 To 2
  218.       If board(ct-1) = 0 Then
  219.         response.write "<td width=100>&nbsp;</td>"
  220.       Else
  221.         response.write "<td width=100><a href=puzzle.asp?ct=" & ct & "&getArr=" & getArr & ">" &board(ct-1) &"</a></td>"
  222.       End if
  223.       ct = ct+1
  224.     next
  225.     response.write "</tr>"
  226.   Next
  227. %>
  228. </table>

Many Bugs!!!~
실행화면

실행화면


반응형

반응형
Console로 프로그래밍된 바둑 소스이다.

출처는 불분명... 어디더라??
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #define LEFT '4'
  6. #define RIGHT '6'
  7. #define UP  '8'
  8. #define DOWN '2'
  9. #define ENTER '5'
  10. #define CLEAR 0
  11. #define NONE 0
  12. #define MAPSIZE 19
  13. #define PLAYER1 1
  14. #define PLAYER2 2
  15. #define PLAY 1
  16. #define START 1
  17. #define END 0
  18. #define NO 0
  19. #define OK 1
  20. #define YES 1
  21. #define OKTOTALCOUNT 4
  22. #define FLAGTRUE 1
  23. #define FLAGFALSE 0
  24. void gotoxy(int x, int y);
  25. int xy[MAPSIZE][MAPSIZE];
  26. int map[MAPSIZE][MAPSIZE];
  27. int x, y, x2 = 2;
  28. int centerX=MAPSIZE/2, centerY=MAPSIZE/2;
  29. int displayX=0, displayLineY=21, displayY=22;
  30. char mapChar[]="┌┬┐├┼┤└┴┘";
  31. void clearValue() {
  32. int x,y;
  33. for(y=0;y<MAPSIZE;y++) {
  34. for(x=0;x<MAPSIZE;x++) {
  35.   map[y][x]=CLEAR;
  36. }
  37. }
  38. }
  39. int IsKill(int cnt) {
  40. return cnt==OKTOTALCOUNT;
  41. }
  42. int TestFlag(int x,int y) {
  43. if(x<0 x>=MAPSIZE y<0 y>=MAPSIZE) return FLAGTRUE;
  44. if(map[y][x]==OK) return FLAGTRUE;
  45. return FLAGFALSE;
  46. }
  47. int SefeDeleteTest(int x,int y,int OtherPlayer) {
  48. int result;
  49. int cnt;
  50. if(x<0 x>=MAPSIZE y<0 y>=MAPSIZE) return OK;
  51. if(xy[y][x]==OtherPlayer) return OK;
  52. if(xy[y][x]==NONE) return NO;
  53. cnt=0;
  54. result=NO;
  55. map[y][x]=OK;
  56. if(TestFlag(x,y-1)==FLAGFALSE) {
  57. if(SefeDeleteTest(x,y-1,OtherPlayer)) {
  58.   cnt=cnt + 1;
  59. }
  60. } else {
  61. cnt=cnt+1;
  62. }
  63. if(TestFlag(x-1,y)==FLAGFALSE) {
  64. if(SefeDeleteTest(x-1,y,OtherPlayer)) {
  65.   cnt=cnt + 1;
  66. }
  67. } else {
  68. cnt=cnt+1;
  69. }
  70. if(TestFlag(x+1,y)==FLAGFALSE) {
  71. if(SefeDeleteTest(x+1,y,OtherPlayer)) {
  72.   cnt=cnt + 1;
  73. }
  74. } else {
  75. cnt=cnt+1;
  76. }
  77. if(TestFlag(x,y+1)==FLAGFALSE) {
  78. if(SefeDeleteTest(x,y+1,OtherPlayer)) {
  79.   cnt=cnt + 1;
  80. }
  81. } else {
  82. cnt=cnt+1;
  83. }
  84. if(IsKill(cnt)){
  85. result=OK;
  86. }
  87. return result;
  88. }
  89. void DolDelete(int x,int y,int OtherPlayer) {
  90. if(x<0 x>=MAPSIZE y<0 y>=MAPSIZE) return;
  91. if(xy[y][x]==OtherPlayer) return;
  92. if(xy[y][x]==NONE) return;
  93. xy[y][x]=CLEAR;
  94. if(x+1<MAPSIZE) DolDelete(x+1,y,OtherPlayer);
  95. if(x-1>=0)      DolDelete(x-1,y,OtherPlayer);
  96. if(y+1<MAPSIZE) DolDelete(x,y+1,OtherPlayer);
  97. if(y-1>=0)      DolDelete(x,y-1,OtherPlayer);
  98. }
  99. void RalDeleteTest(int x,int y,int OtherPlayer) {
  100. clearValue();
  101. if(SefeDeleteTest(x+1,y,OtherPlayer)==YES)
  102. DolDelete(x+1,y,OtherPlayer);
  103. clearValue();
  104. if(SefeDeleteTest(x-1,y,OtherPlayer)==YES)
  105. DolDelete(x-1,y,OtherPlayer);
  106. clearValue();
  107. if(SefeDeleteTest(x,y+1,OtherPlayer)==YES)
  108. DolDelete(x,y+1,OtherPlayer);
  109. clearValue();
  110. if(SefeDeleteTest(x,y-1,OtherPlayer)==YES)
  111. DolDelete(x,y-1,OtherPlayer);
  112. }
  113. void input(int Player) {
  114. char c;
  115.   int LOOP=START;
  116. int OtherPlayer;
  117. if(Player == PLAYER1) {
  118. OtherPlayer = PLAYER2;
  119. } else {
  120. OtherPlayer = PLAYER1;
  121. }
  122.   while(LOOP!=END){
  123. c = getch();
  124. switch(c)
  125. {
  126. case RIGHT:
  127.   x=x+1;
  128.   if(x >= MAPSIZE) x=x-1;
  129.   gotoxy(x,y);
  130.   break;
  131. case LEFT:
  132.   x=x-1;
  133.   if(x < 0 ) x=x+1;
  134.   gotoxy(x,y);
  135.   break;
  136. case UP:
  137.   y=y-1;
  138.   if(y < 0 ) y=y+1;
  139.   gotoxy(x,y);
  140.   break;
  141. case DOWN: 
  142.   y=y+1;
  143.   if(y >= MAPSIZE ) y=y-1;
  144.   gotoxy(x,y);
  145.   break;
  146. case ENTER:
  147.   if(xy[y][x] != NONE ) break;
  148.   xy[y][x]=Player;
  149.   RalDeleteTest(x,y,Player);
  150.   clearValue();
  151.   if(SefeDeleteTest(x,y,OtherPlayer)==YES){
  152.    xy[y][x]=CLEAR;
  153.   } else {
  154.    LOOP = END;
  155.   }
  156. }
  157. }
  158. }
  159. void printScreen(){
  160. system("cls");
  161. int x,y,n;
  162. char c[3];
  163. for(y=0;y<MAPSIZE;y++) {
  164. for(x=0;x<MAPSIZE;x++) {
  165.            if(xy[y][x] == PLAYER1) {
  166.    printf("○");
  167.   } else if(xy[y][x] == PLAYER2 ) {
  168.    printf("●");
  169.   } else if(xy[y][x] == NONE ) {
  170.    n=(x+16)/17+(y+16)/17*3;
  171.    c[0]=mapChar[n*2];
  172.    c[1]=mapChar[n*2+1];
  173.    c[2]=0;
  174.    if((x-3)%6==0 && (y-3)%6==0) {
  175.     strcpy(c,"×");
  176.    }       
  177.    printf("%s",c);
  178.   }
  179. }
  180. printf("\n");
  181. }
  182. gotoxy(displayX,displayLineY);
  183. printf("UP:8  DOWN:2  LEFT:4  RIGHT:6  ENTER:5")
  184. }
  185. int gamePlayCheck(int Player)
  186. {
  187. //승패를 가른다.
  188. return 1;
  189. }
  190. void InitMapData() {
  191. int x,y;
  192. for(y=0;y<MAPSIZE;y++) {
  193. for(x=0;x<MAPSIZE;x++) {
  194.   xy[y][x]=CLEAR;
  195. }
  196. }
  197. }
  198. // 커서를 나타냅니다.
  199. void SetCursorShow(void)
  200. {
  201. HANDLE hConsole;
  202. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  203. CONSOLE_CURSOR_INFO ci;
  204. GetConsoleCursorInfo( hConsole, &ci );
  205. ci.dwSize=100;
  206. ci.bVisible = TRUE;
  207. SetConsoleCursorInfo( hConsole , &ci );
  208. }
  209. void main() {
  210. int Player=PLAYER1,GamePlayFlag=PLAY;
  211. InitMapData();
  212. SetCursorShow();
  213. clearValue();
  214. printScreen();
  215. x=centerX;
  216. y=centerY;
  217. while(GamePlayFlag!=END){
  218. gotoxy(displayX,displayY);
  219. printf("%d 님이 두실 차례입니다.",Player);
  220. gotoxy(x,y);
  221. input(Player);
  222. printScreen();
  223. if(Player==PLAYER1) {
  224.   Player=PLAYER2;
  225. } else {
  226.   Player=PLAYER1;
  227. }
  228. GamePlayFlag = gamePlayCheck(Player);
  229. }
  230. gotoxy(displayX,displayY);
  231.   printf("%d님의 승리",Player);
  232. }
  233. void gotoxy(int x , int y)
  234. {
  235. COORD Pos = { x*2 , y};
  236. SetConsoleCursorPosition(GetStdHandle( STD_OUTPUT_HANDLE), Pos);
  237. }
 
반응형

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

LinkedList 자료  (0) 2006.04.06
VC++ 단축키 모음  (2) 2006.03.19
Console Codepage 설정.  (0) 2006.02.15
[펌] Visual C++ Console - 사격게임  (0) 2006.02.15
Visual C++ Console 에서 TurboC clrscr 구현  (0) 2006.02.15

반응형
출처... 잊어먹었음.
  1. #include < stdio.h >
  2. #include < time.h >
  3. #include < conio.h >
  4. #include < stdlib.h >
  5. #include < windows.h >
  6. /*
  7. * < 사격게임 >
  8. *
  9. * 호환성
  10. * 이 프로그램은 Borland C++ 5.5 에서 컴파일하고 시험되었습니다.
  11. *
  12. * 게임설명
  13. * 사격장은 각각 하나씩의 화살을 포함하고 있는 아홉개의 레인으로 만들어져 있습니다.
  14. * 프로그램이 시작되면 레인의 오른쪽에 한개의 타겟(X)이 나타납니다.
  15. * 당신의 과제는 화살들 중의 하나로 타겟을 맞추는 것 입니다.
  16. * 화살을 쏘려면 레인 번호를 누르면 됩니다.
  17. * 25개의 타겟이 나타난 후에, 게임은 끝나고, 최종점수가 출력됩니다.
  18. *
  19. * 난이도 변경하기
  20. * 난이도를 변경하려면 ShootArrow(int)함수의 두번째 for루프를 변경해서 화살의 속도를 변경하면 됩니다.
  21. * 화살이 천천히 나갈수록 맞추기까지의 시간을 소비하므로 난이도는 높아집니다.
  22. * PlayGame(void)함수의 TIME_LIMIT값을 2초로 맞추어 놓았기 때문에
  23. * 화살이 발사되는데 2초가 걸린다면 게임이 안되죠. 역시 제한시간도 마음대로 수정하세요.
  24. */
  25. #define true 1
  26. #define false 0
  27. typedef int bool;
  28. void ShowScore(int);
  29. int PlayGame(void);
  30. void EraseTarget(int);
  31. void ShootArrow(int);
  32. int ShowTarget(void);
  33. void DrawScreen(void);
  34. void gotoxy(int x, int y);
  35. void clrscr(void);
  36. int main(void) {
  37.   int score;
  38.   srand((unsigned) time(NULL));
  39.   DrawScreen();
  40.   score = PlayGame();
  41.   ShowScore(score);
  42.   return 0;
  43. }
  44. void DrawScreen(void) {
  45.   int x;
  46.   clrscr();
  47.   gotoxy(20, 11);
  48.   printf("게임을 시작하려면 아무키나 누르세요.");
  49.   getch();
  50.   clrscr();
  51.   for (x = 1; x <= 10; x++) {    // 루프는 한번에 한 개의 헤인벽과 한개의 화살을 그린다.
  52.        gotoxy(1, x * 2 + 2);
  53.        printf("-----------------------------------");
  54.        if (x < 10) {
  55.            gotoxy(1, x * 2 + 3);
  56.            printf("%d%s", x, " >>-->");
  57.        }
  58.   }
  59. }
  60. void EraseTarget(int target_position) {
  61.   gotoxy(60, target_position * 2 + 3);
  62.   printf(" ");
  63. }
  64. int PlayGame(void) {
  65.   int score = 0;
  66.   int target_position;
  67.   long start_time;
  68.   bool shot_fired;
  69.   int num;       // 값으로 저장하는 숫자키
  70.   const int TIME_LIMIT = 2// 한 타겟당 제한시간 2초
  71.   int x;
  72.   for (x = 1; x <= 20; x++) {      // 이 루프는 25개의 타겟을 부여한다.
  73.        target_position = ShowTarget();
  74.        start_time = time(NULL);    // 여기에서 시작시간이 저장된다.
  75.        shot_fired = false;
  76.        
  77.        // 제한시간과 남은 화살개수를 알려줌
  78.        gotoxy(44, 2);
  79.        printf("%s%d%s", "남은 화살: ", 21 - x, " ");
  80.        gotoxy(10, 2);
  81.        printf("%s%d%s", "한 타겟 당 시간제한 ", TIME_LIMIT, "초");
  82.        
  83.        do {        // 선수가 사격을 할 때까지 키 입력을 기다린다.
  84.            num = getch() - '0';
  85.            if (num >= 1 && num <= 9) {
  86.                ShootArrow(num);
  87.                shot_fired = true;
  88.            }
  89.        } while (!shot_fired)
  90.        
  91.        // 시간 안에(2초) 타겟을 맞추었을 때 실행된다.
  92.        if ((time(NULL) < start_time + TIME_LIMIT) && num == target_position) {
  93.            putchar('\a');
  94.            ++score;
  95.        }
  96.        EraseTarget(target_position);
  97.   }
  98.   return score;
  99. }
  100. void ShootArrow(int a) {  // 파라미터 a는 발사한 화살의 번호
  101.   int x;
  102.   long delay;
  103.   for (x = 4; x <= 60; x++) {
  104.        gotoxy(x, a * 2 + 3);   // 루프의 매 회마다 화살을 1문자씩 오른쪽으로 움직인다.
  105.        printf(">>-->");
  106.        for (delay = 0; delay < 3999999; delay++) // 이 코드로 화살의 속도조절을 한다. 시스템의 성능에 따라 다르다.
  107.            continue;
  108.        gotoxy(x, a * 2 + 3);
  109.        printf("   ");
  110.   }
  111.   gotoxy(4, a * 2 + 3);
  112.   printf(">>-->");
  113. }
  114. void ShowScore(int score) {
  115.   gotoxy(60, 20);
  116.   printf("-----------------");
  117.   gotoxy(60, 21);
  118.   printf("%s%d", " Your score is ", score);
  119.   gotoxy(60, 22);
  120.   printf("-----------------");
  121. }
  122. int ShowTarget(void) {
  123.   int p = rand() % 9 + 1;      // 이 난수는 타겟이 나타날 레인번호이다. 1 ~ 9
  124.   gotoxy(60, p * 2 + 3);
  125.   printf("X");
  126.   return p;
  127. }
  128. void gotoxy(int x, int y)
  129. {
  130. COORD pos={x,y};
  131. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  132. }
  133. void clrscr(void)
  134. {
  135. COORD Cur= {0,0 };
  136. unsigned long dwLen;
  137. FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE) , ' ', 80*25, Cur, &dwLen);
  138. }
 
반응형

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

Console - 바둑소스  (0) 2006.02.22
Console Codepage 설정.  (0) 2006.02.15
Visual C++ Console 에서 TurboC clrscr 구현  (0) 2006.02.15
Visual C++ Console에서 TurboC gotoxy구현  (0) 2006.02.15
Compiler ...  (0) 2006.02.14