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

📄 main.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 3 页
字号:
	    fscanf(fp,"%d %d", &games, &kills);	    fclose(fp);	    if (games == 0)		ave = 0;	    else		ave = (float)kills/(float)games;	    if (ave > 99)		ave = 99.0;	    }	}    }saveave()    /*     * Save average number of kills per game in user's home directory.     * We keep a .starship there with 2 integer numbers in it:     * 1. the number of games played, 2. the total number of kills.     *     * Increment games here, add present kills to total and rewrite     *   .starship file.     */    {    int fd;    FILE *fp;    ruid = getuid();    if (setreuid (ruid,ruid) < 0)	{	perror("set effective to real");	exit(-1);	}    /*     * open/create to create it if it doesn't exist.     */    if (mustcreate)	{	if ((fd = open(scorepath, O_CREAT | O_RDWR, 0644)) == NULL)	    {	    printf("open on %s failed.\n", scorepath);	    perror("starship");	    }	close (fd);	chmod (scorepath, 0644);	}    /*     * open to write score file     */    if ((fp = fopen(scorepath, "w")) == NULL)	{	printf("open on %s failed.\n", scorepath);	perror("starship");	}    else	{	games++;	fprintf(fp,"%d %d", games, kills);	fclose(fp);	}    }instructs()    {    /* Prints out instructions for the users.  */	char in_str[5];		/* user input */	char ch;		/* user input */	char name[NAMESIZE +1];/* ship name */	char index_ch;		/* loop index */	boolean already_used;	/* set true if letter already in use */	char ypasswd[10];	/* pass word user enters */	char passwd[10];	/* true pass word */	int i;			/* loop index */    for (i = 0; i < PASSWDLEN; i ++)	passwd [i] = ' ';    passwd [0] = (char)78;    passwd [1] = (char)69;    passwd [2] = (char)86;    passwd [3] = (char)69;    passwd [4] = (char)82;    passwd [5] = '\0';    clear_screen();    refresh_scr();    printf ("\n                              Welcome to STAR-SHIP\n\n");    printf ("                                 by Al Delorey\n\n\n");    printf (" These are the voyages of the independent star ships.\n\n");    printf (" Whose lifetime mission: To explore strange new galaxies,\n");    printf ("                         To seek out and destroy other star ships,\n");    printf ("                         To boldly go where no other star ship dares!\n\n");    printf (" Do you want instructions? ");    gets (in_str);    ch = in_str[0];    upchar(&ch);    if (ch != 'N')         {		/* print instructions */	clear_screen();	refresh_scr();	printf (" STAR-SHIP is an interactive game that you can play against ");	printf ("other players,\n");	printf (" Or you can play against a drone ship that the game controls.\n\n");	printf (" The Galaxy is a matrix of 10x10 quadrants.  Each quadrant ");	printf ("has 10x10 sectors.\n");	printf (" A sector is one character position.\n");	printf (" Quadrant & sector displays are given as <row>-<col>\n");	printf ("         Where the upper left corner is      0-0\n");	printf ("           and the lower right corner is     9-9\n\n");	printf (" On the game screen, the numbers around the short ");	printf ("range scan show the\n");	printf (" directional bearings.  The reverse video section shows ");	printf ("command usage.\n\n");	printf (" STAR *     BASE +     TORPEDO .     SHIP <capital letter>");	printf ("     ION CLOUD -\n\n");	printf (" Passing through a star costs %d energy units.\n", STAR_COST);	printf (" Being hit by Photon Torpedo costs %d energy units.\n", TORP_COST);	printf (" Torpedos travel 10 sectors (one quadrant) maximum.\n");	printf (" Damaged devices show an asterisk and the time remaining to complete repairs\n");	printf ("    until they will be operational again.\n");	printf (" Phasers reach %d sectors maximum, and their effect decreases with distance.\n", PHSRANGE);	printf (" Using your phasers consumes your energy.\n\n");	printf (" Do you want to continue with instructions? ");	gets (in_str);	ch = in_str[0];	upchar (&ch);	if (ch != 'N')	    {	    clear_screen ();	    refresh_scr ();	    printf (" To dock at a base you must be at one of the 4 `docking bays' (+ points)\n");	    printf ("         and use the D command.\n");	    printf ("     This restores all energy and devices, and also drops your shields.\n");	    printf ("     NOTE: You cannot use your weapons when docked - but others can attack you.\n");	    printf ("           You must move away from the base to use your weapons.\n\n");	    printf (" You can only raise your shields to 1/2 of your present energy level.\n");	    printf (" Accelerating or decelerating costs energy.\n");	    printf (" At a constant speed, if your warp engines are operating, ");	    printf ("energy regenerates.\n\n");	    printf (" To invoke a drone opponent radio the R or the K and ");	    printf ("specify the difficulty\n");	    printf ("   level by sending a one digit message of 1 to 4 ");	    printf ("(4 is hardest).  eg:  RK1.\n\n");	    printf (" A few usefull commands to help you get started:\n");	    printf (" Typing a single digit will change your bearing.\n");	    printf (" Typing `i' will get you moving. `i0' will stop you.\n");	    printf (" The `w' command will move you faster; try it after you get some experience.\n");	    printf (" Typing `s15' will put 15k units of strength in your shields.\n");	    printf (" The Quit, Radio & Shields commands MUST END WITH A <CR>\n\n");	    printf (" To supress the bell, invoke Star-Ship with the -b option.\n");	    }	}; /* print instructions */    do	{	printf ("\n Enter the name of your ship (upto 10 chars) ");	gets (name);	name[NAMESIZE] = '\0';	upcase (name);	already_used = false;	if (!strcmp(name, "ENTERPRISE"))	    {	    printf (" PASSWORD ");	    /* turn off echo and scan password */#	    ifndef DEBUG	    noecho();#	    endif	    gets (ypasswd);	    /* turn echo back on */#	    ifndef DEBUG	    echo();#	    endif	    if (strcmp(ypasswd, passwd) || (ships['E'-A].ship_ch == 'E'))	        {	 	printf (" Sorry but that ship is in use already\n");		already_used = true;		};	     };	}    while (already_used);    if (!strcmp(name, "ENTERPRISE"))         ch = 'E';    else do	    {	    printf (" Enter a letter to represent the %s ", name);	    gets (in_str);	    ch = in_str[0];	    upchar(&ch);	    already_used = false;	    if (ch == 'E')	         {		 already_used = true;		 printf ("\n That letter is in use, choose another\n");		 }	    else if (ch < 'A' || ch > 'Z')		      {		      already_used = true;  /* to stay in repeat loop */		      printf ("\n You must use a LETTER\n");		      }	    else for (index_ch = 'A'; index_ch < 'Z'; index_ch ++)		    if (ships [index_ch-A].ship_ch == ch)		         {			 already_used = true;			 printf ("\n That letter is in use, choose another\n");			 };	    }	while (already_used);    init_a_ship (ch, name);    local_ship = ch;    clear_screen();    refresh_scr();    }; /* instructs */upcase (name)    char *name;    /* convert string in name to upper case.     */    {    int i;    for (i=0; name[i] != '\0'; i++)	{	if (name[i] >= 'a' && name[i] <= 'z')	    name[i] = name[i] - 32;	};    };upchar (ch)    char *ch;    /* convert char to upper case.     */    {    if (*ch >= 'a' && *ch <= 'z')	*ch = *ch - 32;    };draw_sr()    {    register int i,j;    /* Draw srscan area */    move_to(SRSCANR-1, SRSCANC-1);    string_out ("7---------------9");    for (i = SRSCANR; i <= LSRSCANR; i ++)	{	j = i;	if (i == SRSCANR + SRSCANROWS / 2)	    {	    move_to(j,SRSCANC-2);	    string_out ("4|               |6");	    }	else	    {	    move_to(j,SRSCANC-1);	    string_out ("|               |");	    }	};    move_to((SRSCANR + SRSCANROWS), (SRSCANC -1));    string_out ("1---------------3");    }draw_lr()    {    /* draw LR SCAN */    register int i,j;    move_to (LRSCANR - 3, LRSCANC);    string_out ("Long Range Scan");    move_to(LRSCANR - 1, LRSCANC - 2);    string_out ("+-----|-----|-----+");    j = LRSCANR;    for (i = 0; i < LRSCANSECTS; i ++)	{	if (i == 1)	    {	    move_to(j, LRSCANC - 3);	    string_out (" | 000 | 000 | 000 | ");	    }	else	    {	    move_to(j, LRSCANC - 2);	    string_out ("| 000 | 000 | 000 |");	    }	move_to(j+1, LRSCANC - 2);	string_out ("+-----|-----|-----+");	j = j + 2;	};    move_to(LRSCANR + 5, LRSCANC - 2);    string_out ("+-----|-----|-----+");    move_to(LRLABELR, LRLABELC);    string_out ("SHIPS|BASES|STARS");    }draw_dir()    /* directional display */    {    register int i;    move_to(DIRDISPR - 2, MAPDISPC - 1);    string_out ("   Bearings");    move_to(DIRDISPR - 1, MAPDISPC);    string_out ("            ");    move_to(DIRDISPR, MAPDISPC);    string_out ("   7 8 9    ");    move_to(DIRDISPR + 1, MAPDISPC);    string_out ("    \\|/     ");    move_to(DIRDISPR + 2, MAPDISPC);    string_out ("   4-|-6    ");    move_to(DIRDISPR + 3, MAPDISPC);    string_out ("    /|\\     ");    move_to(DIRDISPR + 4, MAPDISPC);    string_out ("   1 2 3    ");    for (i = DIRDISPR + 5; i <= DIRDISPR + 10; i++)	{	move_to(i, MAPDISPC);	string_out ("            ");	}    }draw_map()    /* directional display */    {    register int i,j;    char tmp_str[10];	/* temp output string */    move_to(MAPDISPR - 1, MAPDISPC + 2);    string_out ("   Map   ");    move_to(MAPDISPR, MAPDISPC);    string_out (" 0123456789");    j = 0;    for (i = MAPDISPR + 1; i <= MAPDISPR + 10; i++)	{	move_to(i, MAPDISPC);	sprintf (tmp_str, "%d%s", j, "       ");	string_out (tmp_str);	j++;	}    move_to(MAPDISPR + 11, MAPDISPC);    string_out (" 0123456789");    }draw_screen()    {    /* This procedure draws the initial image on the screen.    */        char tmp_str[10];	/* temp output string */    clear_screen();    refresh_scr();    draw_sr();    draw_lr();    draw_dir();    /* label display fields */    move_to(ENERGYR, ENERGYC - 10);    string_out ("ENERGY:");    move_to(ENERGYR, ENERGYC);    sprintf (tmp_str, "%5d", ENERGY_MAX);    string_out (tmp_str);    move_to(SHIELDSR, SHIELDSC - 10);    string_out ("SHIELDS:      0");    move_to(TORPR, TORPC - 11);    string_out ("TORPEDOS:");    move_to(TORPR, TORPC);    sprintf (tmp_str, "%4d", TORP_MAX);    string_out (tmp_str);    move_to(PHASERR, PHASERC - 11);    string_out ("PHASERS:    opr");    move_to(WARPDRIVER,WARPDRIVEC-11);    string_out ("WARP DRV:   opr");    move_to(QUADR, QUADC - 12);    string_out ("QUADRANT:   0-0");    move_to(SECTORR, SECTORC - 12);    string_out ("SECTOR:     0-0");    move_to(WARPSETR, WARPSETC - 12);    string_out ("WARP SET:   0.0");    move_to(WARPSPEEDR, WARPSPEEDC-12);    string_out ("WARP SPEED: 0.0");    move_to(BEARINGR, BEARINGC - 12);    string_out ("BEARING:    6");    move_to(IMPULSER, IMPULSEC - 15);    string_out ("IMPULSE ENG:    opr");    move_to(LIFESUPR, LIFESUPC - 14);    string_out ("LIFE SUPPORT: green");    move_to(SRCONDR, SRCONDC - 15);    string_out ("S.R. SCAN:      opr");    move_to(LRCONDR, LRCONDC - 15);    string_out ("L.R. SCAN:      opr");    move_to(RADIOR, RADIOC - 15);    string_out ("RADIO:          opr");    move_to(SENSORR, SENSORC - 13);    string_out ("SENSORS:      opr");    move_to(CLOAKINGR, CLOAKINGC - 13);    string_out ("CLOAKING:     opr");

⌨️ 快捷键说明

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