Exemplo n.º 1
0
	//[14] 게임 시작
	void StartGame(void)
	{
		int n;
		int kb;
		int c = 2;

		srand((unsigned)time(0)); // rand() 함수로 랜덤값을 주기 위해서 초기값 부여

		/*게임 시작~끝*/
		while (1)
		{
			//블록 생성 위치 좌표(13, 2)에서 시작 
			SetCursorPosition(13, 2);

			n = rand() % 7;        // 0~27까지의 인덱스 생성 : 블록 종류 결정
			n = n * 4;            // 각 블록의 첫번째 블록(0, 4, 8, 12, 16, 20, 24)을 기준으로 출력, 방향키로 변환할 수 있도록 

			if (level == 10) // 레벨이 10에 도달하면 게임 승리 
			{
				SetCursorPosition(40, 15);
				printf("게임 클리어");
				getchar();
				exit(1);
			}

			if (CanPositionedAt(n, 0, 0) == false)
				break; //게임 끝                

			/*블록 한개 위~밑 이동*/
			while (1)
			{
				int ww = 0;
				int k = 0;

				/*블록 아래로 이동*/
				while (!_kbhit())
				{
					//블록 쇼
					WriteBlock(n);
					//딜레이 타임
					Sleep(DELAY + speed);
					//아래이동시 1이 있는지 확인
					if (CanPositionedAt(n, 0, 1) == false)
					{
						ww = 1;
						BoardInit(n, 0, 0);//보드 열돌 배열 1추가
						RemoveLine();
						break;
					}
					ClearBlock(n, 0, 1);  //board배열 +1행 
				}
				/*CanPositionedAt함수에서 배열값 1발견시 중지*/
				if (ww == 1)
					break;

				kb = _getch();

				/*방향키*/
				switch (kb)
				{
				case LEFT:
					ClearBlock(n, -2, 0);
					WriteBlock(n);
					break;
				case RIGHT:
					ClearBlock(n, 2, 0);
					WriteBlock(n);
					break;
				case UP:
					// 첫수를구한다.
					k = n / 4;
					k *= 4;

					// 다음수가 끝수이하인가 
					if ((n + 1) <= (k + 3))
					{
						k = n + 1;
					}

					if (CanPositionedAt(k, 0, 0) == true)
					{
						ClearBlock(n, 0, 0);
						n = k;
						WriteBlock(n);
						break;
					}
					break;
				case DOWN:
					ClearBlock(n, 0, 2);
					break;
				case SPACE:    // 아래로 뚝 떨어지는 로직
					while (1)
					{
						ClearBlock(n, 0, 1);
						if (CanPositionedAt(n, 0, 1) == false)
						{
							WriteBlock(n);
							BoardInit(n, 0, 0);
							break;
						}
					}
				default: break;
				} // end switch
			} // end while(블록)        
		} // end while(게임)
	}
Exemplo n.º 2
0
int CsObjectInt::CsComprLZC (SAP_INT    sumlen,
                SAP_BYTE * inbuf,
                SAP_INT    inlen,
                SAP_BYTE * outbuf,
                SAP_INT    outlen,
                SAP_INT    option,
                SAP_INT *  bytes_read,
                SAP_INT *  bytes_written)
/*--------------------------------------------------------------------*/
/* LZC method to compress a file                                      */
/*                                                                    */
/* Adaptive Dictionary Compression                                    */
/*   Lempel-Zip-Thomas                                                */
/*                                                                    */
/*                                                                    */
/* Input:                                                             */
/* -----                                                              */
/*        sumlen            length of data stream to compress         */
/*        inbuf             Pointer to input memory                   */
/*        inlen             Length of input memory                    */
/*        outbuf            Pointer to output area                    */
/*        outlen            Length of output area                     */
/*        option            Compress option:                          */
/*                             CS_INIT_COMPRESS      initial          */
/*                             CS_NORMAL_COMPRESS                     */
/* Output:                                                            */
/* ------                                                             */
/*        bytes_read        Bytes read from input buffer              */
/*        bytes_compressed  Bytes compressed to output buffer         */
/*                                                                    */
/* Internal Functions:                                                */
/* ------------------                                                 */
/*       InitComp              Initialize Compression                 */
/*       PUTCODE               Write Code to output buffer            */
/*                                                                    */
/* Return Code:                                                       */
/* -----------                                                        */
/*        CS_END_OF_STREAM     End of input reached                   */
/*        CS_END_INBUFFER      End of input reached                   */
/*        CS_END_OUTBUFFER     End of output reached                  */
/*                                                                    */
/*        CS_E_IN_BUFFER_LEN   Input buffer length to short           */
/*        CS_E_OUT_BUFFER_LEN  Output Buffer length to short          */
/*        CS_E_INVALID_SUMLEN  sumlen <= 0                            */
/*        CS_E_INVALID_ADDR    Invalid addr for input or output buffer*/
/*        CS_E_FATAL           internal (should never happen)         */
/*                                                                    */
/*--------------------------------------------------------------------*/
{
  register SAP_INT fcode;
  register CODE_INT i = 0;
  register BYTE_TYP *inptr = inbuf;
  register int c;
  register CODE_INT disp;

  int rc;

  *bytes_read    = 0;
  *bytes_written = 0;

  /* Check input parameters ..........................................*/

  if (inlen < 0) return CS_E_IN_BUFFER_LEN;     /* return ............*/

  if (outlen < 0) return CS_E_OUT_BUFFER_LEN;   /* return ............*/

  if (inbuf == (BYTE_TYP *) 0 || outbuf == (BYTE_TYP *) 0)
    return CS_E_INVALID_ADDR;                   /* return ............*/

  if (inbuf == outbuf) return CS_E_IN_EQU_OUT;  /* return ............*/

  csc.outptr = outbuf;

  if (option & CS_INIT_COMPRESS)      /* only initial ................*/
  {
    if (sumlen <= 0) return CS_E_INVALID_SUMLEN;  /* return ..........*/

    rc = InitComp (outbuf, outlen, sumlen);
    if (rc) return rc;            /* return with Error ...............*/

    csc.cs_offset    = 0;
    csc.csc_offset   = 0;
    csc.in_count_sum = 0;
    csc.put_n_bytes  = 0;
    csc.bytes_out    = 0;
    csc.sflush       = 0;
    csc.org_len   = sumlen;           /* save sum length .................*/
    csc.outptr    = outbuf + CS_HEAD_SIZE; /* 4 byte length, 4 byte header*/

    csc.hshift = 0;
    for (fcode = (SAP_INT) csc.hsize;  fcode < 65536; fcode += fcode)
      (csc.hshift)++;
    csc.hshift = 8 - csc.hshift;          /* set hash code range bound .......*/

    csc.ent = (CODE_INT) -1;
    if (inlen == 0)               /* only header .....................*/
    {
      *bytes_written = CS_HEAD_SIZE;
      csc.bytes_out     += *bytes_written;
      return CS_END_INBUFFER;
    }
  }

  if (csc.ent == (CODE_INT) -1)       /* get first byte ..................*/
    csc.ent = *inptr++;

  csc.end_inbuf  = inbuf  + inlen;    /* end of input buffer .............*/
  csc.end_outbuf = outbuf + outlen;   /* end of output buffer ............*/

  if (csc.sflush == 1)   /* end of outbuf in last run, must output CLEAR .*/
  {
    if ((rc = PutCode ((CODE_INT) CLEAR)) < 0)
      goto ende;

    if (csc.put_n_bytes)              /* no more space in outbuf .........*/
    {
      rc = CS_END_OUTBUFFER;
      goto ende;
    }
    csc.sflush = 0;
  }

  while (inptr < csc.end_inbuf)          /* until end of input ...........*/
  {
    c = *inptr++;                    /* next char ....................*/
                                     /* hash function ................*/
    fcode = (SAP_INT) (((SAP_INT) c << csc.maxbits) + csc.ent);
    i = (((CODE_INT)c << csc.hshift) ^ csc.ent);    /* xor hashing ...........*/

    if (i < 0) return CS_E_FATAL;    /* should never happen ..........*/

    if (HTABOF (i) == fcode)         /* found in htab ................*/
    {
      csc.ent = CODETABOF (i);
      continue;
    }
    else
    if ((SAP_INT)HTABOF (i) < 0)       /* empty slot ....................*/
      goto nomatch;

    disp = csc.hsize - i;               /* secondary hash (G. Knott) .....*/
    if (i == 0) disp = 1;

probe:
    if ((i -= disp) < 0)
      i += csc.hsize;

    if (HTABOF (i) == fcode)        /* found in htab .................*/
    {
      csc.ent = CODETABOF (i);
      continue;                     /* get next char .................*/
    }

    if ( (SAP_INT)HTABOF (i) > 0 )
      goto probe;                   /* test again ....................*/

nomatch:                            /* new entry .....................*/
    PUTCODE ((CODE_INT) csc.ent)

    csc.ent = c;
    if (csc.free_ent < csc.maxmaxcode)      /* enough space in table ? .......*/
    {
      CODETABOF (i) = (csc.free_ent)++;   /* code -> hashtable .............*/
      HTABOF (i) = fcode;
    }
    else                            /* test clear code table .........*/
    if (((SAP_INT)(inptr - inbuf) + csc.in_count_sum >=
                                     csc.checkpoint) && csc.block_compress)
    {
      rc = ClearBlock (csc.in_count_sum + (SAP_INT)(inptr - inbuf),
                       csc.bytes_out + (SAP_INT) (csc.outptr - outbuf));
      if (rc)
      {
        if (csc.put_n_bytes)            /* no more space in outbuf .......*/
        {
          csc.sflush = 1;
          rc = CS_END_OUTBUFFER;
          goto ende;
        }
        if ((rc = PutCode ((CODE_INT) CLEAR)) < 0)
          goto ende;
      }
    }

    if (csc.put_n_bytes)                /* not enough space in outbuffer .*/
    {
      rc = CS_END_OUTBUFFER;
      goto ende;
    }
  }  /* end while ....................................................*/

  rc = CS_END_INBUFFER;
                                                 /* end of stream ....*/
  if (csc.in_count_sum + (SAP_INT)(inptr - inbuf) >= csc.org_len)
  {
    if (csc.sflush < 3)
    {
      if ((rc = PutCode ((CODE_INT) csc.ent)) < 0)
        goto ende;
      if (csc.put_n_bytes)            /* not enough space in outbuffer ...*/
      {
        csc.sflush = 3;
        rc = CS_END_OUTBUFFER;
        goto ende;
      }
    }

    if (csc.sflush != 4)
    {
      if ((rc = PutCode ((CODE_INT) -1)) < 0)
        goto ende;

      if (csc.put_n_bytes)            /* not enough space in outbuffer ...*/
      {
        csc.sflush = 4;
        rc = CS_END_OUTBUFFER;
        goto ende;
      }
    }
    else
      if ((rc = PutCode ((CODE_INT) -1)) < 0)
        goto ende;

    rc = CS_END_OF_STREAM;       /* end of data reached ..............*/
  }

ende:                            /* set output parameters and save    */
  *bytes_written = (SAP_INT) (csc.outptr - outbuf);
  *bytes_read    = (SAP_INT) (inptr  - inbuf);
  csc.in_count_sum  += *bytes_read;     /* the sum of input length .......*/
  csc.bytes_out     += *bytes_written;  /* the sum of output length ......*/

  return rc;
}
Exemplo n.º 3
0
static void blockIntra( mpeg_decode* dec, int pos )
{
	int j;
	idct_block_t *block;
	const uint16_t *table = vld_mpeg1;
	int qscale;

	dec->Codec.IDCT.Ptr->Process(dec->Codec.IDCT.Ptr,POSX(pos),POSY(pos));

	block = dec->blockptr;
	qscale = dec->qscale;

	for (j=0;j<6;++j)
	{
		int bitpos;
		int len;

		ClearBlock(block);	
		loadbits(dec);

		{
			int dct_dc_size, dct_dc_diff;

			dct_dc_diff = 0;
			dct_dc_size = j<4 ? getDCsizeLum(dec) : getDCsizeChr(dec); //max11bit

			if (dct_dc_size)
				dct_dc_diff = getDCdiff(dct_dc_size,dec);

			dct_dc_size = j<4 ? 0 : j-4+1;
			DEBUG_MSG2(DEBUG_VCODEC2,T("dc=%d diff=%d"), dec->last_dc[dct_dc_size]+dct_dc_diff, dct_dc_diff );
			dct_dc_diff += dec->last_dc[dct_dc_size];
			dec->last_dc[dct_dc_size] = dct_dc_diff;

			*block = (idct_block_t)(dct_dc_diff << 3);
			len = 1;
		}

		bitpos = dec->bitpos;
		
		for (;;) // event vld
		{
			int code,level;

			loadbits_pos(dec,bitpos);
			code = showbits_pos(dec,bitpos,16);	

			vld_code;
			level = code & 63;
			if (level < 62) 
			{
				level *= qscale;
				code >>= 6;
				code &= 63;
				len += code; // run
				if (len >= 64)
					break;

				code = dec->zigzag[len];
				level *= dec->IntraMatrix[len];
				level >>= 3;
				level = (level-1)|1;

				if (getbits1_pos(dec,bitpos)) 
					level = -level;

				block[code] = (idct_block_t)level;
				++len;
			} 
			else 
			{
				if (level==63)
					break;

				// this value is escaped
				loadbits_pos(dec,bitpos);

				len += showbits_pos(dec,bitpos,6); flushbits_pos(dec,bitpos,6);
				if (len >= 64)
					break;

				code = showbits_pos(dec,bitpos,8); flushbits_pos(dec,bitpos,8);
				level = (code << 24) >> 24; //sign extend the lower 8 bits
				code = dec->zigzag[len];

				if (level == -128)
				{
					level = showbits_pos(dec,bitpos,8)-256; flushbits_pos(dec,bitpos,8);
				}
				else 
				if (level == 0)
				{
					level = showbits_pos(dec,bitpos,8); flushbits_pos(dec,bitpos,8);
				}

				if (level<0)
				{
					level= -level;
					level *= qscale * dec->IntraMatrix[len];
					level >>= 3;
					level= (level-1)|1;
					level= -level;

					block[code] = (idct_block_t)level;
					++len;
				}
				else
				{