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

📄 gunner.c

📁 《C语言程序设计教程、实验与练习》 源文件下载
💻 C
字号:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <time.h>
#include <dos.h>
#include <string.h>
#include "funkey.h"
#define WIDE 48

char pos[3][3]={
' ',' ',' ',
' ',' ',' ',
' ',' ',' '
};
char mark[3][3];
int place_x,place_y;
int gun_x,gun_y;

void flash(int x,int y,int wide)
{
 

 }

void drawbullet(int x,int y)
{
 setfillstyle(SOLID_FILL,YELLOW);
 setcolor(DARKGRAY);
 bar(x,y+12,x+12,y+36);
 setfillstyle(SOLID_FILL,LIGHTGRAY);
 sector(x+6,y+12,0,180,6,12);
 setcolor(YELLOW);
 line(x,y+12,x+12,y+12);
  }
void drawplate(int x,int y,int wide)
{
 setfillstyle(SOLID_FILL,RED);
 setcolor(YELLOW);
 fillellipse(x+wide/2,y+wide/2+wide/4,wide/5,wide/5);
 fillellipse(x+wide/2,y+wide/2-wide/4,wide/5,wide/5);
 setfillstyle(SOLID_FILL,LIGHTRED);
 fillellipse(x+wide/2,y+wide/2,wide/2,wide/4);
 line(x,y+wide/2,x+wide-1,y+wide/2);
 }
void drawpost(int x,int y,int wide)
{
 setwritemode(XOR_PUT);
 setcolor(WHITE);
 rectangle(x+wide/4,y+wide/4,x+wide*3/4,y+wide*3/4);
 line(x,y+wide/2,x+wide,y+wide/2);
 line(x+wide/2,y,x+wide/2,y+wide);
 setwritemode(COPY_PUT);
  }
void bkground(int x,int y,int w,int h)
{
  setcolor(GREEN);
  setfillstyle(SOLID_FILL,GREEN);
  bar(x,y,x+w,y+h);
  setcolor(YELLOW);
  line(x,y,x+w,y+h);
  line(x,y+h,x+w,y);
  setcolor(DARKGRAY);
  setfillstyle(SOLID_FILL,BLUE);
  place_x=x+w/2-3*WIDE/2;
  place_y=y+h/2-3*WIDE/2;
  bar(x+w/2-3*WIDE/2,y+h/2-3*WIDE/2,x+w/2+3*WIDE/2,y+h/2+3*WIDE/2);
  setcolor(RED);
  outtextxy(x+w/2-8*strlen("@@@ GUNER WORLD ! @@@")/2,y+10,"@@@ GUNER WORLD ! @@@");
  setcolor(YELLOW);
  outtextxy(x+w-100,y+h/4,"bullets:");
  outtextxy(x+10,y+h/4,"targets:");
}//bkground
void positeplate(int num)
{
  int i;
  int h,l;
  for(i=0;i<num;)
    {
     h=random(3);
     l=random(3);
     if(pos[h][l]!='*')
      {
       pos[h][l]='*';
       i++;
	}
    }
  }
void drawshottingplace(int x,int y,int m)
{
  int i,j;
  if(m==0)
   for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    {
      setfillstyle(SOLID_FILL,BLUE);
      setcolor(BLUE);
      bar(x+j*WIDE,y+i*WIDE,x+j*WIDE+WIDE,y+i*WIDE+WIDE);
      if(pos[i][j]=='*')
	drawplate(x+j*WIDE+WIDE/2-12,y+i*WIDE+WIDE/2-12,24);
      }//for
  else
   {
    for(i=0;i<3;i++)
      for(j=0;j<3;j++)
	if(mark[i][j]==1)
	  {
	    setfillstyle(SOLID_FILL,BLUE);
	    setcolor(BLUE);
	    bar(x+j*WIDE,y+i*WIDE,x+j*WIDE+WIDE,y+i*WIDE+WIDE);
	    if(pos[i][j]=='*')
		drawplate(x+j*WIDE+WIDE/2-12,y+i*WIDE+WIDE/2-12,24);
	    }
     }//else
  }

void moveplate()
{


  }

void main(void)
{
   /* request auto detection */
  int gdriver = DETECT, gmode;
  int bullet_num=7;
  int plate_num=3;
  int target_num=0;
  int i,j;
  int count,key;

  randomize();
  initgraph(&gdriver, &gmode, "f:\\blc\\bgi");


  bkground(40,40,WIDE*8,WIDE*8);
  positeplate(plate_num);
  drawshottingplace(place_x,place_y,0);
  gun_x=place_x+WIDE;
  gun_y=place_y+WIDE;
  drawpost(gun_x,gun_y,WIDE);
  for(i=0;i<bullet_num;i++)
    drawbullet(40+WIDE*8-100+i%6*14,40+WIDE*8/4+20+i/6*40);
  count=0;
  while(1)
  {
   delay(10);
   count++;
   if(kbhit())
   {
    key=bioskey(0);
    if((key&0x00ff)==0)
     { //add your codes down here to move the post



      // add your codes up here to move the pos
      }
     else
      {
       key&=0x00ff;
       if(key==' ')
	{
	 //add your codes down here to fire




	 //add your codes up here to fire
	  }
	else if(key==27)
	{
	  closegraph();
	  return;
	   }
	}
     }
   if(count>=80)
   {
    count=0;
    // add your codes down here to move plates



    //add your codes up here to move plates
     }
    }
 }//main

⌨️ 快捷键说明

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