1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include <conio2.h>
#include <stdio.h>
#include <time.h>
#include <dos.h>
#include <windows.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
bool gameover=false;
int shipx=10,shipy=10,wepx=0,wepy=0,i=0,enemyx=0,enemyy=0,score=0;
void ship (int shipx,int shipy)
{
textcolor (YELLOW);
gotoxy (shipx,shipy);
printf ("Y");
}
int shipm ()
{
if ( GetAsyncKeyState( 'W' ) & 0x8000 )
{
shipy=(shipy-1);
}
if ( GetAsyncKeyState( 'S' ) & 0x8000 )
{
shipy=(shipy+1);
}
if ( GetAsyncKeyState( 'A' ) & 0x8000 )
{
shipx=(shipx-1);
}
if ( GetAsyncKeyState( 'D' ) & 0x8000 )
{
shipx=(shipx+1);
}
}
void wep ()
{
wepx=i;
gotoxy (wepx,wepy);
textcolor(WHITE);
printf ("-");
delay (50);
}
void enemy ()
{
gotoxy (enemyx,enemyy);
textcolor (RED);
printf ("N");
}
void clearship ()
{
gotoxy (shipx,shipy);
printf (" ");
}
void clearwep()
{
gotoxy (wepx,wepy);
printf (" ");
}
void clearenemy()
{
gotoxy (enemyx,enemyy);
printf (" ");
}
int main ()
{
enemyx = rand () % 10 + 20;
enemyy = rand () % 20;
enemy();
do
{
shipm ();
ship (shipx,shipy);
delay(100);
if(GetAsyncKeyState( 'M' ) & 0x8000 )
{
wepx=shipx+i;
wepy=shipy;
for (i=wepx;i<30;i++)
{
wep ();
shipm ();
ship (shipx,shipy);
delay(100);
clearship();
//cleararma();
}
if (i<29)
i=0;
}
if ((enemyx == wepx) && (enemyy == wepy))
{
clearenemy();
enemy();
score++;
}
gotoxy (1,1);
textcolor (WHITE);
printf ("Score: %d ",score);
clearship();
}
while (gameover==false);
}
|