⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 marquee.c

📁 C.Game.Programming.For.Dummies.原码
💻 C
字号:
/* Scrolling marquee program */
/* Uses cls() from Lesson 5-6 */
/* Uses locate() from Lesson 5-6 */
/* Uses input() from Lesson 9-3 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <alloc.h>

#define CR 0x0d     //carriage return
#define ESC 0x1b    //Escape key
#define TAB 0x09
#define LF 0x0a     //Line feed
#define BACKSPACE 0x08
#define NULL 0      //Empty character
#define TRUE 1
#define FALSE 0
#define LENGTH 80   //size of the string
#define COLS 80     //screen width
#define VIDEO 0x10  //Video interrupt
#define ROWS 25		//Screen rows
#define DELAY 250   //millisecond delay
#define MROW 24

void input(char *string, int length);
void cls(void);
void locate(int row,int col);

void main()
{
    char buffer[81];    //space character padding
    char text[LENGTH];  //input string
    char *marquee;      //the marquee
    char *sto;
    int m_size;
    long x;

/* Initialize the buffer full of spaces */

    for(x=0;x<80;x++)
        buffer[x] = ' ';    //spaces

    buffer[80] = '\0';      //NULL at the end

/* Get input */

    cls();
    puts("Enter a phrase to be scrolled 'cross the screen.");
    input(text,LENGTH);

/* Allocate the marquee */

    m_size = 80 + 80 + strlen(text) + 1;
    if((marquee = (char *)malloc(m_size)) == NULL)
    {
        puts("Out of memory");
        exit(1);
    }

/* Create the marquee */

    strcpy(marquee,buffer);
    strcat(marquee,text);
    strcat(marquee,buffer);

/* display the marquee and scroll */

    sto = marquee;

    for(;;)
    {
        marquee = sto;

        while(*(marquee+80))
        {
            locate(0,MROW);
            for(x=0;x<79;x++)
                putchar(*(marquee+x));
            if(kbhit())
            {
                getch();    //read key
                exit(0);    //exit on key
            }
            delay(DELAY);   //pause 1 sec.
            marquee++;
        }

    }
}

void input(char *string, int length)
{
    int done = FALSE;
    int index = 0;
    char ch;

    string[0] = NULL;   // init the buffer

    do
    {
        ch = getch();

/* Check to see if the buffer is full */

        if (index == length)
        {
            switch(ch)
            {
                case CR:
                    break;
                default:
                    ch = NULL;
                    break;
            }
        }

/* process the keyboard input */

        switch(ch)
        {
            case CR:        //Enter key
                putchar(ch);
                putchar(LF);
                string[index] = NULL;
                done = TRUE;
                break;
            case BACKSPACE:
                if(index==0)
                {
                    break;
                }
                else
                {
                    putchar(ch);
                    putchar(' ');
                    putchar(ch);
                    index--;
                    break;
                }
            case NULL:
                break;
            default:        //display & sto
                putchar(ch);
                string[index] = ch;
                index++;
                break;
        }
    }
    while(!done);
}

void cls(void)
{
	union REGS regs;

	regs.h.ah=0x06;		//call function 6, scroll window
	regs.h.al=0x00;		//clear screen
	regs.h.bh=0x07;		//make screen "blank" color
	regs.h.ch=0x00;		//Upper left row
	regs.h.cl=0x00;		//Upper left column
	regs.h.dh=ROWS-1;	//Lower right row
	regs.h.dl=COLS-1;	//Lower right column
	int86(VIDEO,&regs,&regs);

	locate(0,0);		//"Home" the cursor
}

/*
 row ranges from 0 to 79
 col from 0 to 24
*/

void locate(int row,int col)
{
	union REGS regs;

	regs.h.ah=0x02;		//video function 2, move cursor
	regs.h.bh=0x00;		//video screen (always 0)
	regs.h.dh=col;		//cursor's column position
	regs.h.dl=row;		//cursor's row position
	int86(VIDEO,&regs,&regs);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -