home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / BATTLE.ZIP / INSTALL.ZIP / BATTLE.C next >
C/C++ Source or Header  |  1996-06-23  |  96KB  |  2,530 lines

  1.  
  2. // I N C L U D E S ///////////////////////////////////////////////////////////
  3.  
  4. #include <io.h>
  5. #include <conio.h>
  6. #include <graph.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10. #include <bios.h>
  11. #include <fcntl.h>
  12. #include <memory.h>
  13. #include <malloc.h>
  14. #include <math.h>
  15. #include <string.h>
  16. #include <ctype.h>
  17.  
  18. #include "sound.h"
  19. #include "graphics.h"
  20. #include "input.h"
  21.  
  22. #define NUM_SOUND_FX 1     // the number of sound fx loaded in
  23. #define MENU_VOC 1
  24. #define MAX_SHIPS 4
  25.  
  26.  
  27. #define TRUE 1
  28. #define FALSE !TRUE
  29.  
  30. // state of the game itself
  31.  
  32. #define GAME_SETUP                  0   // the game is in the setup mode
  33. #define GAME_LINKING                1   // the communications link is being established
  34. #define GAME_RUNNING                2   // the game is running
  35. #define GAME_PAUSED                 3   // the game is paused (not implemented)
  36. #define GAME_OVER                   4   // what do you think
  37.  
  38. // general object states
  39.  
  40. #define DEAD                        0   // these are general states for any
  41. #define ALIVE                       1   // object
  42. #define DYING                       2
  43.  
  44. // defines for setup selections
  45.  
  46. #define SETUP_PLAY_SOLO             0
  47. #define SETUP_MAKE_CONNECTION       1
  48. #define SETUP_WAIT_FOR_CONNECTION   2
  49. #define SETUP_SELECT_SHIP           3
  50. #define SETUP_SET_COMM_PORT         4
  51. #define SETUP_BRIEFING              5
  52. #define SETUP_EXIT                  6
  53.  
  54. #define NUM_SETUP                   7   // number of setup choices
  55.  
  56. #define USER_QUITTED
  57. #define USER_LOST
  58. #define USER_WON
  59.  
  60. #define EASY_AS_SNOT   1
  61. #define A_GOOD_BELCH   2
  62. #define PUKE_GRAVY     3
  63. #define TOUGH_AS_SHIT  4
  64. #define A_FARTS_CHANCE 5
  65.  
  66. ////////// F U N C T I O N S /////////////////////////////////////////////////
  67.  
  68. void SetupShips(int connected);
  69. int PlayGame(int connected);
  70. int computersTurn();
  71. int intro(void);
  72. void selectDifficulty(void);
  73. void makeHarder (int * xptr, int * yptr);
  74.  
  75. //// G L O B A L S  ////////////////////////////////////////////////////////////
  76.  
  77.  
  78. void (_interrupt _far *Old_Key_Isr)(); // holds old keyboard interrupt handler
  79.  
  80. int direction[4] = {0, 0, 0, 0}; // 0 up, 1 down, 2 left, 3 right
  81.  
  82. sprite shipPlacer;
  83.  
  84. sprite userShip[4];
  85. sprite computerShip[4]; 
  86.  
  87. Sound digital_FX[8];
  88. music song;
  89.  
  90. int font_init = 0;
  91. int game_state = GAME_SETUP;  // the overall state of the game
  92. int PlayerWantsToQuit = FALSE;
  93. int counterH = 0, counterV = 0;
  94.  
  95. gridSquare bGrid[12][12]; // bad guy's grid system
  96. gridSquare gGrid[12][12]; // good guy's grid system
  97.  
  98. int gShipsGone = 0;
  99. int numComputerShots = 4;
  100. int bShipsGone = 0;
  101. int curDirection; //the current direction of attack
  102.  
  103. int difficulty;
  104.  
  105. sprite shotCovering;
  106. sprite missCovering;
  107.  
  108. int hitFlag = 0;
  109. int cheat = 0;
  110.  
  111. //////////////////////////////////////////////////////////////////////////////
  112.  
  113. // M A I N ///////////////////////////////////////////////////////////////////
  114.  
  115. //////////////////////////////////////////////////////////////////////////////
  116.  
  117. void main(void)
  118. {
  119.         int counter = 0, done = 0, i;
  120.         int redraw = 1;
  121.         int index;
  122.         RGB_color animate[256], temp;
  123.                 
  124.         //fade DOS prompt and other text stuff out
  125.         Screen_Transition(SCREEN_DARKNESS);
  126.  
  127.         // set video mode to 320x200 256 color mode
  128.         Set_Graphics_Mode(GRAPHICS_MODE13);
  129.  
  130.         Sound_Load("menu.voc",(sound_ptr)&digital_FX[0],1);
  131.         Sound_Load("thunder.voc",(sound_ptr)&digital_FX[1],1);
  132.         Sound_Load("shpmove.voc",(sound_ptr)&digital_FX[2],1);
  133.         Sound_Load("splash.voc",(sound_ptr)&digital_FX[4],1);
  134.         Sound_Load("shot.voc",(sound_ptr)&digital_FX[5],1);
  135.         Sound_Load("blowup.voc",(sound_ptr)&digital_FX[6],1);
  136.         Sound_Load("laugh.voc",(sound_ptr)&digital_FX[7],1);
  137.  
  138.         Music_Load("music.xmi", (music_ptr)&song);
  139.         Music_Play((music_ptr)&song,0);
  140.  
  141.         Font_Engine_1(0,0,0,0,NULL,NULL);
  142.  
  143.         PCX_Init((pcx_picture_ptr)&background);
  144.         PCX_Load("water.pcx", (pcx_picture_ptr)&background, 0);
  145.         Wait_For_Vertical_Retrace();
  146.         PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  147.  
  148.         // install new isr's
  149.         Keyboard_Install_Driver();
  150.  
  151.         for(index = 0; index < 256; index++)
  152.         {
  153.             Read_Color_Reg(index, (RGB_color_ptr)&animate[index]);
  154.         }
  155.  
  156.         while(!keys_active)
  157.         {
  158.             temp.red = animate[1].red;
  159.             temp.green = animate[1].green;
  160.             temp.blue = animate[1].blue;
  161.             for(index = 1; index < 256; index++)
  162.             {
  163.                 animate[index].red = animate[index + 1].red;
  164.                 animate[index].green = animate[index + 1].green;
  165.                 animate[index].blue = animate[index + 1].blue;
  166.             }
  167.             animate[255].red = temp.red;
  168.             animate[255].green = temp.green;
  169.             animate[255].blue = temp.blue;
  170.  
  171.             for(index = 1; index < 256; index++)
  172.             {
  173.                 Write_Color_Reg(index, (RGB_color_ptr)&animate[index]);
  174.             }
  175.         }
  176.  
  177.         PCX_Delete((pcx_picture_ptr)&background);
  178.         
  179.         intro();
  180.         Screen_Transition(SCREEN_DARKNESS);
  181.  
  182.         PCX_Init((pcx_picture_ptr)&background);
  183.         PCX_Load("menu.pcx", (pcx_picture_ptr)&background, 0);
  184.         PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  185.         PCX_Delete((pcx_picture_ptr)&background);
  186.  
  187.         PCX_Init((pcx_picture_ptr)&shell_back);
  188.         PCX_Load("torp.pcx", (pcx_picture_ptr)&shell_back, 0);
  189.  
  190.         Sprite_Init((sprite_ptr)&shell, 75, 40, 75, 40, 24, 24, 0, 0, 0, 0, 0);
  191.         PCX_Get_Sprite((pcx_picture_ptr)&shell_back, (sprite_ptr)&shell, 0, 0, 0);
  192.         PCX_Get_Sprite((pcx_picture_ptr)&shell_back, (sprite_ptr)&shell, 1, 1, 0);
  193.         PCX_Get_Sprite((pcx_picture_ptr)&shell_back, (sprite_ptr)&shell, 2, 2, 0);
  194.         PCX_Get_Sprite((pcx_picture_ptr)&shell_back, (sprite_ptr)&shell, 3, 3, 0);
  195.         PCX_Delete((pcx_picture_ptr)&shell_back);
  196.  
  197.         Sprite_Under((sprite_ptr)&shell, video_buffer);
  198.         Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  199.  
  200.         while(done != 1)
  201.         {
  202.             if (Music_Status()==2 || Music_Status()==0)
  203.             {
  204.                 Music_Stop();
  205.                 Music_Play((music_ptr)&song,0);
  206.             }
  207.  
  208.             if(keys_active > 0)
  209.             {
  210.                 // what is user doing
  211.                 if (keyboard_state[MAKE_UP])
  212.                 {
  213.                     shell.y-=16;
  214.  
  215.                     // test if we need to wrap around bottom
  216.  
  217.                     if (--counter < 0)
  218.                     {
  219.                         counter = 6;
  220.                         shell.y = 135;
  221.                     } // end if wrap around
  222.                     //keyboard_state[MAKE_UP] = 0;
  223.                     Sound_Stop();
  224.                     Sound_Play((sound_ptr)&digital_FX[0]);
  225.                     redraw = 1;
  226.                 } // end if up
  227.  
  228.                 if (keyboard_state[MAKE_DOWN])
  229.                 {
  230.                     shell.y+=16;
  231.  
  232.                     // test if we need to wrap around bottom
  233.  
  234.                     if (++counter > 6)
  235.                     {
  236.                         counter = 0;
  237.                         shell.y = 40;
  238.                     } // end if wrap around
  239.                     //keyboard_state[MAKE_DOWN] = 0;
  240.                     Sound_Stop();
  241.                     Sound_Play((sound_ptr)&digital_FX[0]);
  242.                     redraw = 1;
  243.                 } // end if down
  244.  
  245.                 if(keyboard_state[MAKE_HOME])
  246.                 {
  247.                     shell.y = 40;
  248.                     counter = 0;
  249.                     Sound_Stop();
  250.                     Sound_Play((sound_ptr)&digital_FX[0]);
  251.                     redraw = 1;
  252.                 }
  253.  
  254.                 if(keyboard_state[MAKE_END])
  255.                 {
  256.                     shell.y = 135;
  257.                     counter = 6;
  258.                     Sound_Stop();
  259.                     Sound_Play((sound_ptr)&digital_FX[0]);
  260.                     redraw = 1;
  261.                 }
  262.  
  263.                 if(keyboard_state[MAKE_ENTER])
  264.                 {
  265.                     switch(counter)
  266.                     {
  267.                             case 0:
  268. //                          Screen_Transition(SCREEN_DARKNESS);
  269. //                          Sprite_Delete(&shell);
  270.                             selectDifficulty();
  271.                             SetupShips(0);
  272.                             shell.x_old = shell.x = 75;
  273.                             shell.y_old = shell.y = 40;
  274.                             PlayGame(0);
  275.                             Screen_Transition(SCREEN_DARKNESS);
  276.                             PCX_Init((pcx_picture_ptr)&background);
  277.                             PCX_Load("menu.pcx", (pcx_picture_ptr)&background, 0);
  278.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  279.                             PCX_Delete((pcx_picture_ptr)&background);
  280.                             shell.y = 40;
  281.                             counter = 0;
  282.                             // scan the background at new postition
  283.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  284.                             //erase sprite at old position
  285.                             Sprite_Erase((sprite_ptr)&shell, video_buffer);
  286.                             // scan the background at new postition
  287.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  288.                             // draw sprite at new position
  289.                             Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  290.                             // update old position
  291.                             shell.y_old=shell.y;
  292.                             Music_Stop();
  293.                             Music_Unload((music_ptr)&song);
  294.                             Music_Load("menu.xmi", (music_ptr)&song);
  295.                             Music_Play((music_ptr)&song,0);
  296.                             break;
  297.                         case 1:
  298.                         case 2:
  299.                         case 3:
  300.                             Screen_Transition(SCREEN_DARKNESS);
  301.                             PCX_Init((pcx_picture_ptr)&background);
  302.                             PCX_Load("sorry.pcx", (pcx_picture_ptr)&background, 0);
  303.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  304. //                            PCX_Delete((pcx_picture_ptr)&background);
  305.                             keys_active = 0;
  306.                             while(!keys_active) //Wait for a key press to continue
  307.                             {
  308.                                 if (Music_Status()==2 || Music_Status()==0)
  309.                                 {
  310.                                     Music_Stop();
  311.                                     Music_Play((music_ptr)&song,0);
  312.                                 }
  313.                             }
  314.                             Screen_Transition(SCREEN_DARKNESS);
  315. //                            PCX_Init((pcx_picture_ptr)&background);
  316.                             PCX_Load("menu.pcx", (pcx_picture_ptr)&background, 0);
  317.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  318.                             PCX_Delete((pcx_picture_ptr)&background);
  319.                             shell.y = 40;
  320.                             counter = 0;
  321.                             // scan the background at new postition
  322.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  323.                             //erase sprite at old position
  324.                             Sprite_Erase((sprite_ptr)&shell, video_buffer);
  325.                             // scan the background at new postition
  326.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  327.                             // draw sprite at new position
  328.                             Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  329.                             // update old position
  330.                             shell.y_old=shell.y;
  331.                             break;
  332.                         case 4:
  333.                             Screen_Transition(SCREEN_DARKNESS);
  334.                             PCX_Init((pcx_picture_ptr)&background);
  335.                             PCX_Load("help.pcx", (pcx_picture_ptr)&background, 0);
  336.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  337. //                            PCX_Delete((pcx_picture_ptr)&background);
  338.                             keys_active = 0;
  339.                             while(!keys_active) //Wait for a key press to continue
  340.                             {
  341.                                 if (Music_Status()==2 || Music_Status()==0)
  342.                                 {
  343.                                     Music_Stop();
  344.                                     Music_Play((music_ptr)&song,0);
  345.                                 }
  346.                             }
  347.                             Screen_Transition(SCREEN_DARKNESS);
  348. //                            PCX_Init((pcx_picture_ptr)&background);
  349.                             PCX_Load("menu.pcx", (pcx_picture_ptr)&background, 0);
  350.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  351.                             PCX_Delete((pcx_picture_ptr)&background);
  352.                             shell.y = 40;
  353.                             counter = 0;
  354.                             // scan the background at new postition
  355.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  356.                             //erase sprite at old position
  357.                             Sprite_Erase((sprite_ptr)&shell, video_buffer);
  358.                             // scan the background at new postition
  359.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  360.                             // draw sprite at new position
  361.                             Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  362.                             // update old position
  363.                             shell.y_old=shell.y;
  364.                             break;
  365.                         case 5:
  366.                             done = 1;
  367.                             Screen_Transition(SCREEN_DARKNESS);
  368.                             PCX_Init((pcx_picture_ptr)&background);
  369.                             PCX_Load("rip.pcx", (pcx_picture_ptr)&background, 0);
  370.                             Wait_For_Vertical_Retrace();
  371.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  372.                             PCX_Delete((pcx_picture_ptr)&background);
  373.                             Music_Stop();
  374.                             Music_Play((music_ptr)&song,2);
  375.                             Keyboard_Remove_Driver();
  376.                             break;
  377.                         case 6:
  378.                             creadits();
  379.                             PCX_Init((pcx_picture_ptr)&background);
  380.                             PCX_Load("menu.pcx", (pcx_picture_ptr)&background, 0);
  381.                             PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  382.                             PCX_Delete((pcx_picture_ptr)&background);
  383.                             shell.y = 40;
  384.                             counter = 0;
  385.                             // scan the background at new postition
  386.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  387.                             //erase sprite at old position
  388.                             Sprite_Erase((sprite_ptr)&shell, video_buffer);
  389.                             // scan the background at new postition
  390.                             Sprite_Under((sprite_ptr)&shell, video_buffer);
  391.                             // draw sprite at new position
  392.                             Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  393.                             // update old position
  394.                             shell.y_old=shell.y;
  395.                             break;
  396.                     }
  397.                 }
  398.                 if (keyboard_state[MAKE_ESC]) //1 == ESC
  399.                 {
  400.                     done = 1;
  401.                     Screen_Transition(SCREEN_DARKNESS);
  402.                     PCX_Init((pcx_picture_ptr)&background);
  403.                     PCX_Load("rip.pcx", (pcx_picture_ptr)&background, 0);
  404.                     Wait_For_Vertical_Retrace();
  405.                     PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  406.                     PCX_Delete((pcx_picture_ptr)&background);
  407.                     Music_Stop();
  408.                     Music_Play((music_ptr)&song,2);
  409.                     Keyboard_Remove_Driver();
  410.                     break;
  411.                 }
  412.             }
  413.  
  414.             if (redraw)
  415.             {
  416.                 // erase sprite at old position
  417.                 Sprite_Erase((sprite_ptr)&shell, video_buffer);
  418.                 // scan the background at new postition
  419.                 Sprite_Under((sprite_ptr)&shell, video_buffer);
  420.                 // draw sprite at new position
  421.                 Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  422.                 // update old position
  423.                 shell.y_old = shell.y;
  424.                 Time_Delay(3);
  425.                 redraw = 0;
  426.             } // end if sprites needed to be redrawn
  427.         } //end while(done != 1)
  428.  
  429.  
  430.  
  431.         PCX_Delete((pcx_picture_ptr)&background);
  432.         PCX_Init((pcx_picture_ptr)&background);
  433.         PCX_Load("lightng.pcx", (pcx_picture_ptr)&background, 0);
  434.  
  435.         Sprite_Init((sprite_ptr)&shell, 75, 0, 75, 0, 53, 90, 0, 0, 0, 0, 0);
  436.         PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&shell, 0, 0, 0);
  437.         PCX_Delete((pcx_picture_ptr)&background);
  438.  
  439.         Sprite_Under((sprite_ptr)&shell, video_buffer);
  440.  
  441.         Time_Delay(5); //Wait a bit before blasting the lightning
  442.         
  443.         Sound_Stop();
  444.         Sound_Play((sound_ptr)&digital_FX[1]); //Make the thunder BOOM!
  445.         for(i = 0; i < 5; i++)
  446.         {
  447.             Sprite_Draw((sprite_ptr)&shell, video_buffer, 1); //Blast it!!
  448.             //Make the scenery light up
  449.             for(index = 0; index < 256; index++)
  450.             {
  451.                 Read_Color_Reg(index, (RGB_color_ptr)&animate[index]);
  452.             }
  453.  
  454.             for(index = 16; index < 256; index++)
  455.             {
  456.                 animate[index].red += 15;
  457.                 animate[index].green += 15;
  458.                 animate[index].blue += 15;
  459.             }
  460.                     
  461.             for(index = 16; index < 256; index++)
  462.             {
  463.                 Write_Color_Reg(index, (RGB_color_ptr)&animate[index]);
  464.             }
  465.  
  466.             Time_Delay(1); //Let it stay light for a bit
  467.         
  468.             //Darken things back up
  469.             Sprite_Erase((sprite_ptr)&shell, video_buffer); //Take away lightning bolt
  470.             for(index = 16; index < 256; index++)
  471.             {
  472.                 animate[index].red -= 15;
  473.                 animate[index].green -= 15;
  474.                 animate[index].blue -= 15;
  475.             }
  476.                     
  477.             for(index = 16; index < 256; index++)
  478.             {
  479.                 Write_Color_Reg(index, (RGB_color_ptr)&animate[index]);
  480.             }
  481.             Time_Delay(1);        
  482.         }
  483.  
  484.         Time_Delay(10); //Let 'm see that the lightning is done
  485.  
  486.         Screen_Transition(SCREEN_DARKNESS);
  487. //      Sprite_Delete(&shell);
  488.         PCX_Delete((pcx_picture_ptr)&background);
  489.         Music_Stop();
  490.         Music_Unload((music_ptr)&song);
  491.         Sound_Stop();
  492.         Sound_Unload((sound_ptr)&digital_FX);
  493.         Set_Graphics_Mode(TEXT_MODE);   
  494.  
  495.         _settextcolor( 15 );
  496.         _setbkcolor( 4 );
  497.         _outtext("+--| T H A N K S  F O R  P L A Y I N G  O U R  G A M E  |--+\n");
  498.         _outtext("|                                                          |\n");
  499.         _outtext("| Please, give this game to all your friends!              |\n");
  500.         _outtext("| Look for more of our games!!!                            |\n");
  501.         _outtext("|                                                          |\n");
  502.         _outtext("+----------------------------------------------------------+\n");
  503.  
  504.         _settextcolor( 7 );
  505.         _setbkcolor( _BLACK );
  506. } // end main
  507.  
  508. void SetupShips(int connected)
  509. {
  510.     // Declare variables ///////////////////////
  511.     int x, redraw = 0, OneATopOfAnother = 0, flag = 0;
  512.     int initLooper1, initLooper2;
  513.     int randVorH, randCounterH, randCounterV;
  514.     int cheatCounter = 0, index = 0;
  515.  
  516.     hitFlag = 0;
  517.     cheat = 0;
  518.  
  519.     srand((unsigned int) *clock);
  520.     curDirection = (rand() % 4);
  521.  
  522.     for(initLooper1 = 0; initLooper1 < 12; initLooper1++)
  523.     {
  524.         for(initLooper2 = 0; initLooper2 < 12; initLooper2++)
  525.         {
  526.             gGrid[initLooper1][initLooper2].coveredByShip = FALSE;
  527.             gGrid[initLooper1][initLooper2].coveredByWhat = NULL;
  528.             gGrid[initLooper1][initLooper2].beenShotAt    = FALSE;
  529.  
  530.             bGrid[initLooper1][initLooper2].coveredByShip = FALSE;
  531.             bGrid[initLooper1][initLooper2].coveredByWhat = NULL;
  532.             bGrid[initLooper1][initLooper2].beenShotAt    = FALSE;
  533.         }
  534.     }
  535.  
  536.     for(initLooper1 = 0; initLooper1 < 4; initLooper1++)
  537.     {
  538.         userShip[initLooper1].howManyTimesHit = 0;
  539.         computerShip[initLooper1].howManyTimesHit = 0;
  540.     }
  541.  
  542.     // Init and Load pictures ///////////////////////////
  543.     PCX_Init((pcx_picture_ptr)&background);
  544.     PCX_Load("grid.pcx", (pcx_picture_ptr)&background, 0);
  545.  
  546.     // DISPLAY PICTURES ////////////////////////////////
  547.     PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  548.     PCX_Delete((pcx_picture_ptr)&background);
  549.  
  550.     PCX_Init((pcx_picture_ptr)&ships_back);
  551.     PCX_Load("xhair.pcx", (pcx_picture_ptr)&ships_back, 0);
  552.     // INIT AND LOAD SPRITES ////////////////////////////
  553.  
  554.     Sprite_Init((sprite_ptr)&shipPlacer, 9, 11, 9, 11, 11, 11, 0, 0, 0, 0, 0);
  555.  
  556.     PCX_Get_Sprite((pcx_picture_ptr)&ships_back, (sprite_ptr)&shipPlacer, 0, 0, 0);
  557.  
  558.     PCX_Delete((pcx_picture_ptr)&ships_back);
  559.     // DISPLAY SPRITES /////////////////////////////////
  560.     Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  561.     Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  562.     // PRINT INSTRUCTIONS //////////////////////////////
  563.     Tech_Print(8, 180, "USE THE ARROW KEYS TO MOVE SHIP-PLACER. PRESS ENTER WHEN DONE.",video_buffer);
  564.     // TEST FOR CHEATS /////////////////////////////////
  565.     /*Not yet implimented*/
  566.     // LET USER SET UP SHIP LOCATIONS //////////////////
  567.     counterH = counterV = 0;
  568.     x = 0;
  569.     PlayerWantsToQuit = FALSE;   
  570.     while(x < 4 && PlayerWantsToQuit == FALSE) 
  571.     {
  572.         if(OneATopOfAnother == 1 && flag == 1)
  573.         {
  574.             Tech_Print(80, 180, "HEY, SMARTY, IF YOU", video_buffer);
  575.             Time_Delay(10);
  576.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  577.             Tech_Print(80, 180, "TRY TO PUT ONE SHIP ON", video_buffer);
  578.             Time_Delay(10);
  579.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  580.             Tech_Print(80, 180, "TOP OF ANOTHER AGAIN,", video_buffer);
  581.             Time_Delay(10);                                
  582.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  583.             Tech_Print(80, 180, "I WILL WUP YA!!!!", video_buffer);
  584.             Time_Delay(10);
  585.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  586.             flag = 0;
  587.         }
  588.  
  589.         if(OneATopOfAnother == 2 && flag == 1)
  590.         {
  591.             Tech_Print(80, 180, "I WARNED YOU...", video_buffer);
  592.             Time_Delay(20);
  593.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  594.             Tech_Print(10, 180, "SAY GOOD BYE!", video_buffer);
  595.             Time_Delay(20);
  596.             Screen_Transition(SCREEN_SWIPE_Y);
  597.             flag = 0;
  598.             PlayerWantsToQuit = TRUE; // Ha, ha, ha, ha! 8-)
  599.         }
  600.         
  601.         // IMPLEMENTATION OF THE "SAMMY" CHEAT CODE
  602.  
  603.         if(keyboard_state[MAKE_S] && cheatCounter == 0 && cheat != 1)
  604.         {
  605.             cheatCounter = 1;
  606.             keyboard_state[MAKE_S] = 0;
  607.         }
  608.  
  609.         if(keyboard_state[MAKE_A] && cheatCounter == 1 && cheat != 1)
  610.         {
  611.             cheatCounter++;
  612.             keyboard_state[MAKE_A] = 0;
  613.         }
  614.  
  615.         if(keys_active == 1 && keyboard_state[MAKE_A] == 0 && cheatCounter != 1)
  616.             cheatCounter = 0;
  617.  
  618.         if(keyboard_state[MAKE_M] && cheatCounter == 2 && cheat != 1)
  619.         {
  620.             cheatCounter++;
  621.             keyboard_state[MAKE_M] = 0;
  622.         }
  623.  
  624.  
  625.         if(keys_active == 1 && keyboard_state[MAKE_M] == 0 && cheatCounter != 2)
  626.             cheatCounter = 0;
  627.  
  628.         if(keyboard_state[MAKE_M] && cheatCounter == 3 && cheat != 1)
  629.         {
  630.             Time_Delay(4);
  631.             cheatCounter++;
  632.             keyboard_state[MAKE_M] = 0;
  633.         }
  634.  
  635.         if(keys_active == 1 && keyboard_state[MAKE_M] == 0 && cheatCounter != 3)
  636.             cheatCounter = 0;
  637.  
  638.         if(keyboard_state[MAKE_Y] && cheatCounter == 4 && cheat != 1)
  639.         {
  640.             Time_Delay(4);
  641.             cheatCounter++;
  642.             keyboard_state[MAKE_Y] = 0;
  643.         }
  644.  
  645.         if(keys_active == 1 && keyboard_state[MAKE_Y] == 0 && cheatCounter != 4)
  646.             cheatCounter = 0;
  647.  
  648.         if(cheatCounter == 5 && cheat != 1)
  649.         {
  650.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  651.             Tech_Print(80, 180, "SAMMY IS AWESOME!!", video_buffer);
  652.             Time_Delay(25);
  653.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  654.             Tech_Print(80, 180, "YOU GET AN EXTA SHOT PER TURN!", video_buffer);
  655.             Time_Delay(25);
  656.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  657.             cheat = 1;
  658.         }
  659.  
  660.         if(keyboard_state[MAKE_ESC])
  661.         {
  662.             PlayerWantsToQuit = TRUE;
  663.             continue;
  664.         }
  665.  
  666.         if (keyboard_state[MAKE_RIGHT])
  667.         {
  668.             if(++counterH > 11)
  669.             {
  670.                 counterH = 0;
  671.                 shipPlacer.x = 9;
  672.             }
  673.  
  674.             else
  675.             {
  676.                 shipPlacer.x += 12;
  677.             }
  678.             Sound_Stop();
  679.             Sound_Play((sound_ptr)&digital_FX[2]);
  680.             redraw = 1;
  681.         }
  682.  
  683.         if (keyboard_state[MAKE_LEFT])
  684.         {
  685.             if(--counterH < 0)
  686.             {
  687.                 counterH = 11;
  688.                 shipPlacer.x = 141;
  689.             }
  690.  
  691.             else
  692.             {
  693.                 shipPlacer.x -= 12;
  694.             }
  695.             Sound_Stop();
  696.             Sound_Play((sound_ptr)&digital_FX[2]);
  697.             redraw = 1;
  698.         }
  699.  
  700.         if (keyboard_state[MAKE_UP])
  701.         {
  702.             if(--counterV < 0)
  703.             {
  704.                 counterV = 11;
  705.                 shipPlacer.y = 143;
  706.             }
  707.  
  708.             else
  709.             {
  710.                 shipPlacer.y -= 12;
  711.             }
  712.             Sound_Stop();
  713.             Sound_Play((sound_ptr)&digital_FX[2]);
  714.             redraw = 1;
  715.         }
  716.  
  717.         if (keyboard_state[MAKE_DOWN])
  718.         {
  719.             if(++counterV > 11)
  720.             {
  721.                 counterV = 0;
  722.                 shipPlacer.y = 11;
  723.             }
  724.  
  725.             else
  726.             {
  727.                 shipPlacer.y += 12;
  728.             }
  729.             Sound_Stop();
  730.             Sound_Play((sound_ptr)&digital_FX[2]);
  731.             redraw = 1;
  732.         }
  733.  
  734.         if (redraw == 1)
  735.         {
  736.             // erase sprite at old position
  737.             Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  738.             // scan the background at new postition
  739.             Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  740.             // draw the sprite at the new position
  741.             Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  742.             // update old position
  743.             shipPlacer.y_old = shipPlacer.y;
  744.             shipPlacer.x_old = shipPlacer.x;
  745.  
  746.             Time_Delay(3);
  747.             redraw = 0;
  748.         } // end if sprites needed to be redrawn
  749.  
  750.         if(keyboard_state[MAKE_ENTER])
  751.         {
  752.             userShip[x].coveredSquare1.x = counterH;
  753.             userShip[x].coveredSquare1.y = counterV;
  754.  
  755.             userShip[x].x = ((counterH * 12) + 4);
  756.             userShip[x].y = ((counterV * 12) + 11);
  757.  
  758.             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  759.             Tech_Print(80, 180, "HORIZONTAL OR VERTICAL (H/V)?",video_buffer);
  760.  
  761.             keyboard_state[MAKE_ENTER] = 0;
  762.  
  763.             while(!keyboard_state[MAKE_H] && !keyboard_state[MAKE_V] && !keyboard_state[MAKE_ESC]) //Wait for a key press to continue
  764.             {
  765.             }
  766.  
  767.             if(keyboard_state[MAKE_ESC])
  768.             {
  769.                 _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  770.                 Tech_Print(80, 180, "SHIP PLACEMENT ABORTED.",video_buffer);                    
  771.                 Time_Delay(10);
  772.                 _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  773.                 keyboard_state[MAKE_ESC] = 0;
  774.                 continue;
  775.             }
  776.  
  777.             if(keyboard_state[MAKE_H])
  778.             {
  779.                 if(counterH > 9)
  780.                 {
  781.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  782.  
  783.                     if(counterV < 10)
  784.                     {
  785.                         Tech_Print(80, 180, "CAN'T MAKE THIS SHIP HORIZONTAL",video_buffer);                    
  786.                         Time_Delay(10);
  787.                         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  788.                         Tech_Print(80, 180, "SO MAKING IT VERTICAL.", video_buffer);
  789.                         Time_Delay(10);
  790.                         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  791.  
  792.                         userShip[x].coveredSquare2.x = userShip[x].coveredSquare1.x;
  793.                         userShip[x].coveredSquare3.x = userShip[x].coveredSquare1.x;
  794.                         userShip[x].coveredSquare2.y = userShip[x].coveredSquare1.y + 1;
  795.                         userShip[x].coveredSquare3.y = userShip[x].coveredSquare2.y + 1;
  796.  
  797.                         if(x > 0)
  798.                         {
  799.                             if(gGrid[ userShip[x].coveredSquare1.x ][ userShip[x].coveredSquare1.y ].coveredByShip == TRUE ||
  800.                             gGrid[ userShip[x].coveredSquare2.x ][ userShip[x].coveredSquare2.y ].coveredByShip == TRUE ||
  801.                             gGrid[ userShip[x].coveredSquare3.x ][ userShip[x].coveredSquare3.y ].coveredByShip == TRUE)
  802.                             {
  803.                                 OneATopOfAnother++;
  804.                                 flag = 1;
  805.                                 continue;
  806.                             }
  807.                         }
  808.  
  809.                         gGrid[counterH][counterV].coveredByWhat = &userShip[x].coveredSquare1.hit;
  810.                         gGrid[counterH][counterV].coveredByShip = TRUE;
  811.                         gGrid[counterH][counterV + 1].coveredByShip = TRUE;
  812.                         gGrid[counterH][counterV + 1].coveredByWhat = &userShip[x].coveredSquare2.hit;
  813.                         gGrid[counterH][counterV + 2].coveredByShip = TRUE;
  814.                         gGrid[counterH][counterV + 2].coveredByWhat = &userShip[x].coveredSquare3.hit;
  815.  
  816.                         PCX_Init((pcx_picture_ptr)&background);
  817.                         PCX_Load("vShip.pcx", (pcx_picture_ptr)&background, 0);
  818.                         Sprite_Init((sprite_ptr)&userShip[x], userShip[x].x, userShip[x].y, userShip[x].x, userShip[x].y, 23, 35, 0, 0, 0, counterH, counterV);
  819.                         PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&userShip[x], 0, 0, 0);
  820.                         PCX_Delete((pcx_picture_ptr)&background);
  821.                         Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  822.                         Sprite_Under((sprite_ptr)&userShip[x], video_buffer);
  823.                         Sprite_Draw((sprite_ptr)&userShip[x], video_buffer, 1);
  824.                         Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  825.                         Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  826.                         userShip[x].howManyTimesHit = 0;
  827.                         x++;
  828.                         Sound_Stop();
  829.                         Sound_Play((sound_ptr)&digital_FX[4]);
  830.                     }
  831.  
  832.                     else
  833.                     {
  834.                         Tech_Print(80, 180, "YOU CAN'T PUT YOUR SHIP THERE!",video_buffer);                    
  835.                         Time_Delay(10);
  836.                         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  837.                     }
  838.                 }
  839.  
  840.                 else
  841.                 {
  842.  
  843.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  844.                     Tech_Print(95, 180, "OK, SIR!", video_buffer);
  845.                     Time_Delay(10);
  846.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  847.  
  848.                     userShip[x].coveredSquare2.y = userShip[x].coveredSquare1.y;
  849.                     userShip[x].coveredSquare3.y = userShip[x].coveredSquare1.y;
  850.                     userShip[x].coveredSquare2.x = userShip[x].coveredSquare1.x + 1;
  851.                     userShip[x].coveredSquare3.x = userShip[x].coveredSquare2.x + 1;
  852.  
  853.                     if(x > 0)
  854.                     {
  855.                         if(gGrid[ userShip[x].coveredSquare1.x ][ userShip[x].coveredSquare1.y ].coveredByShip == TRUE ||
  856.                         gGrid[ userShip[x].coveredSquare2.x ][ userShip[x].coveredSquare2.y ].coveredByShip == TRUE ||
  857.                         gGrid[ userShip[x].coveredSquare3.x ][ userShip[x].coveredSquare3.y ].coveredByShip == TRUE)
  858.                         {
  859.                             OneATopOfAnother++;
  860.                             flag = 1;
  861.                             continue;
  862.                         }
  863.                     }
  864.  
  865.                     gGrid[counterH][counterV].coveredByWhat = &userShip[x].coveredSquare1.hit;
  866.                     gGrid[counterH][counterV].coveredByShip = TRUE;
  867.                     gGrid[counterH + 1][counterV].coveredByShip = TRUE;
  868.                     gGrid[counterH + 1][counterV].coveredByWhat = &userShip[x].coveredSquare2.hit;
  869.                     gGrid[counterH + 2][counterV].coveredByShip = TRUE;
  870.                     gGrid[counterH + 2][counterV].coveredByWhat = &userShip[x].coveredSquare3.hit;
  871.  
  872.                     userShip[x].x += 5;
  873.                     userShip[x].y -= 5;
  874.  
  875.                     PCX_Init((pcx_picture_ptr)&background);
  876.                     PCX_Load("hShip.pcx", (pcx_picture_ptr)&background, 0);
  877.                     Sprite_Init((sprite_ptr)&userShip[x], userShip[x].x, userShip[x].y, userShip[x].x, userShip[x].y, 35, 23, 0, 0, 0, counterH, counterV);
  878.                     PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&userShip[x], 0, 0, 0);
  879.                     PCX_Delete((pcx_picture_ptr)&background);
  880.                     Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  881.                     Sprite_Under((sprite_ptr)&userShip[x], video_buffer);
  882.                     Sprite_Draw((sprite_ptr)&userShip[x], video_buffer, 1);
  883.                     Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  884.                     Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  885.                     userShip[x].howManyTimesHit = 0;
  886.                     x++;
  887.                     Sound_Stop();
  888.                     Sound_Play((sound_ptr)&digital_FX[4]);
  889.                 }
  890.             }
  891.  
  892.             if(keyboard_state[MAKE_V])
  893.             {
  894.                 if(counterV > 9)
  895.                 {
  896.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  897.  
  898.                     if(counterH < 10)
  899.                     {
  900.                         Tech_Print(80, 180, "CAN'T MAKE THIS SHIP VERTICAL",video_buffer);                    
  901.                         Time_Delay(10);
  902.                         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  903.                         Tech_Print(80, 180, "SO MAKING IT HORIZONTAL.", video_buffer);
  904.                         Time_Delay(10);
  905.                         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  906.  
  907.                         userShip[x].coveredSquare2.y = userShip[x].coveredSquare1.y;
  908.                         userShip[x].coveredSquare3.y = userShip[x].coveredSquare1.y;
  909.                         userShip[x].coveredSquare2.x = userShip[x].coveredSquare1.x + 1;
  910.                         userShip[x].coveredSquare3.x = userShip[x].coveredSquare2.x + 1;
  911.  
  912.                         if(x > 0)
  913.                         {
  914.                             if(gGrid[ userShip[x].coveredSquare1.x ][ userShip[x].coveredSquare1.y ].coveredByShip == TRUE ||
  915.                             gGrid[ userShip[x].coveredSquare2.x ][ userShip[x].coveredSquare2.y ].coveredByShip == TRUE ||
  916.                             gGrid[ userShip[x].coveredSquare3.x ][ userShip[x].coveredSquare3.y ].coveredByShip == TRUE)
  917.                             {
  918.                                 OneATopOfAnother++;
  919.                                 flag = 1;
  920.                                 continue;
  921.                             }
  922.                         }
  923.  
  924.                         gGrid[counterH][counterV].coveredByWhat = &userShip[x].coveredSquare1.hit;
  925.                         gGrid[counterH][counterV].coveredByShip = TRUE;
  926.                         gGrid[counterH + 1][counterV].coveredByShip = TRUE;
  927.                         gGrid[counterH + 1][counterV].coveredByWhat = &userShip[x].coveredSquare2.hit;
  928.                         gGrid[counterH + 2][counterV].coveredByShip = TRUE;
  929.                         gGrid[counterH + 2][counterV].coveredByWhat = &userShip[x].coveredSquare3.hit;
  930.  
  931.                         userShip[x].x += 5;
  932.                         userShip[x].y -= 5;
  933.  
  934.                         PCX_Init((pcx_picture_ptr)&background);
  935.                         PCX_Load("hShip.pcx", (pcx_picture_ptr)&background, 0);
  936.                         Sprite_Init((sprite_ptr)&userShip[x], userShip[x].x, userShip[x].y, userShip[x].x, userShip[x].y, 35, 23, 0, 0, 0, counterH, counterV);
  937.                         PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&userShip[x], 0, 0, 0);
  938.                         PCX_Delete((pcx_picture_ptr)&background);
  939.                         Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  940.                         Sprite_Under((sprite_ptr)&userShip[x], video_buffer);
  941.                         Sprite_Draw((sprite_ptr)&userShip[x], video_buffer, 1);
  942.                         Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  943.                         Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  944.                         userShip[x].howManyTimesHit = 0;
  945.                         x++;
  946.                         Sound_Stop();
  947.                         Sound_Play((sound_ptr)&digital_FX[4]);
  948.                     }
  949.  
  950.                     else
  951.                     {
  952.                         Tech_Print(80, 180, "YOU CAN'T PUT YOUR SHIP THERE!",video_buffer);                    
  953.                         Time_Delay(10);
  954.                         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  955.                     }
  956.                 }
  957.  
  958.                 else
  959.                 {
  960.  
  961.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  962.                     Tech_Print(95, 180, "OK, SIR!", video_buffer);
  963.                     Time_Delay(10);
  964.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  965.  
  966.                     userShip[x].coveredSquare2.x = userShip[x].coveredSquare1.x;
  967.                     userShip[x].coveredSquare3.x = userShip[x].coveredSquare1.x;
  968.                     userShip[x].coveredSquare2.y = userShip[x].coveredSquare1.y + 1;
  969.                     userShip[x].coveredSquare3.y = userShip[x].coveredSquare2.y + 1;
  970.  
  971.                     if(x > 0)
  972.                     {
  973.                         if(gGrid[ userShip[x].coveredSquare1.x ][ userShip[x].coveredSquare1.y ].coveredByShip == TRUE ||
  974.                         gGrid[ userShip[x].coveredSquare2.x ][ userShip[x].coveredSquare2.y ].coveredByShip == TRUE ||
  975.                         gGrid[ userShip[x].coveredSquare3.x ][ userShip[x].coveredSquare3.y ].coveredByShip == TRUE)
  976.                         {
  977.                             OneATopOfAnother++;
  978.                             flag = 1;
  979.                             continue;
  980.                         }
  981.                     }
  982.  
  983.                     gGrid[counterH][counterV].coveredByWhat = &userShip[x].coveredSquare1.hit;
  984.                     gGrid[counterH][counterV].coveredByShip = TRUE;
  985.                     gGrid[counterH][counterV + 1].coveredByShip = TRUE;
  986.                     gGrid[counterH][counterV + 1].coveredByWhat = &userShip[x].coveredSquare2.hit;
  987.                     gGrid[counterH][counterV + 2].coveredByShip = TRUE;
  988.                     gGrid[counterH][counterV + 2].coveredByWhat = &userShip[x].coveredSquare3.hit;
  989.  
  990.                     PCX_Init((pcx_picture_ptr)&background);
  991.                     PCX_Load("vShip.pcx", (pcx_picture_ptr)&background, 0);
  992.                     Sprite_Init((sprite_ptr)&userShip[x], userShip[x].x, userShip[x].y, userShip[x].x, userShip[x].y, 23, 35, 0, 0, 0, counterH, counterV);
  993.                     PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&userShip[x], 0, 0, 0);
  994.                     PCX_Delete((pcx_picture_ptr)&background);
  995.                     Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  996.                     Sprite_Under((sprite_ptr)&userShip[x], video_buffer);
  997.                     Sprite_Draw((sprite_ptr)&userShip[x], video_buffer, 1);
  998.                     Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  999.                     Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1000.                     userShip[x].howManyTimesHit = 0;
  1001.                     x++;
  1002.                     Sound_Stop();
  1003.                     Sound_Play((sound_ptr)&digital_FX[4]);
  1004.                 }
  1005.             }
  1006.         }
  1007.     } // end local player setup
  1008.  
  1009.     if(PlayerWantsToQuit == FALSE)
  1010.     {
  1011.         Time_Delay(10);
  1012.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1013.         Tech_Print(95, 180, "NOW IT IS TIME FOR ME TO SET", video_buffer);
  1014.         Time_Delay(20);
  1015.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);        
  1016.         Tech_Print(95, 180, "UP AND KICK YOUR BUTT IN THIS GAME!!", video_buffer);
  1017.         Time_Delay(20);
  1018.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1019.     }
  1020.  
  1021.     x = 0;
  1022.     while(x < 4 && PlayerWantsToQuit == FALSE)
  1023.     {
  1024.         srand((unsigned int) *clock);
  1025.         randVorH     = (int)(rand() %  2);
  1026.         randCounterV = (int)(rand() % 12);
  1027.         randCounterH = (int)(rand() % 12);
  1028.  
  1029.         computerShip[x].coveredSquare1.x = randCounterH;
  1030.         computerShip[x].coveredSquare1.y = randCounterV;
  1031.  
  1032.         computerShip[x].x = ((randCounterH * 12) + 4);
  1033.         computerShip[x].y = ((randCounterV * 12) + 11);
  1034.  
  1035.         if(randVorH == 1) // the computer selected a horizantal ship
  1036.         {
  1037.             computerShip[x].coveredSquare3.y = computerShip[x].coveredSquare2.y =
  1038.                 computerShip[x].coveredSquare1.y;
  1039.             computerShip[x].coveredSquare2.x = computerShip[x].coveredSquare1.x + 1;
  1040.             computerShip[x].coveredSquare3.x = computerShip[x].coveredSquare2.x + 1;
  1041.  
  1042.             if(randCounterH > 9)
  1043.                 continue;
  1044.  
  1045.             if(bGrid[ computerShip[x].coveredSquare1.x ][ computerShip[x].coveredSquare1.y ].coveredByShip == TRUE ||
  1046.             bGrid[ computerShip[x].coveredSquare2.x ][ computerShip[x].coveredSquare2.y ].coveredByShip == TRUE ||
  1047.             bGrid[ computerShip[x].coveredSquare3.x ][ computerShip[x].coveredSquare3.y ].coveredByShip == TRUE)
  1048.             {
  1049.                 continue;
  1050.             }
  1051.  
  1052.             bGrid[randCounterH][randCounterV].coveredByWhat = &computerShip[x].coveredSquare1.hit;
  1053.             bGrid[randCounterH][randCounterV].coveredByShip = TRUE;
  1054.             bGrid[randCounterH + 1][randCounterV].coveredByShip = TRUE;
  1055.             bGrid[randCounterH + 1][randCounterV].coveredByWhat = &computerShip[x].coveredSquare2.hit;
  1056.             bGrid[randCounterH + 2][randCounterV].coveredByShip = TRUE;
  1057.             bGrid[randCounterH + 2][randCounterV].coveredByWhat = &computerShip[x].coveredSquare3.hit;
  1058.  
  1059.             computerShip[x].x += 5;
  1060.             computerShip[x].y -= 5;
  1061.             x++;
  1062.         }            
  1063.  
  1064.         if(randVorH == 0) // the computer selected a vertical ship
  1065.         {
  1066.             if(randCounterV > 9)
  1067.                 continue;
  1068.  
  1069.             computerShip[x].coveredSquare3.x = computerShip[x].coveredSquare2.x =
  1070.                 computerShip[x].coveredSquare1.x;
  1071.             computerShip[x].coveredSquare2.y = computerShip[x].coveredSquare1.y + 1;
  1072.             computerShip[x].coveredSquare3.y = computerShip[x].coveredSquare2.y + 1;
  1073.  
  1074.             if(bGrid[ computerShip[x].coveredSquare1.x ][ computerShip[x].coveredSquare1.y ].coveredByShip == TRUE ||
  1075.             bGrid[ computerShip[x].coveredSquare2.x ][ computerShip[x].coveredSquare2.y ].coveredByShip == TRUE ||
  1076.             bGrid[ computerShip[x].coveredSquare3.x ][ computerShip[x].coveredSquare3.y ].coveredByShip == TRUE)
  1077.             {
  1078.                 continue;
  1079.             }
  1080.  
  1081.             bGrid[randCounterH][randCounterV].coveredByWhat = &computerShip[x].coveredSquare1.hit;
  1082.             bGrid[randCounterH][randCounterV].coveredByShip = TRUE;
  1083.             bGrid[randCounterH][randCounterV + 1].coveredByShip = TRUE;
  1084.             bGrid[randCounterH][randCounterV + 1].coveredByWhat = &computerShip[x].coveredSquare2.hit;
  1085.             bGrid[randCounterH][randCounterV + 2].coveredByShip = TRUE;
  1086.             bGrid[randCounterH][randCounterV + 2].coveredByWhat = &computerShip[x].coveredSquare3.hit;            
  1087.             x++;
  1088.         }                        
  1089.     }// end the while loop for the computer's setup    
  1090.  
  1091.     if(PlayerWantsToQuit == FALSE)
  1092.     {
  1093.         Time_Delay(10);
  1094.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1095.         Tech_Print(95, 180, "OK. NOW I HAVE SET UP AND", video_buffer);
  1096.         Time_Delay(20);
  1097.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);        
  1098.         Tech_Print(35, 180, "I AM FLIPPING A COIN TO SEE WHO GOES FIRST.", video_buffer);
  1099.         Time_Delay(40);
  1100.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1101.     }
  1102.  
  1103.     if(PlayerWantsToQuit == TRUE)
  1104.     {
  1105.         for(index = 0; index < x; index++)
  1106.             Sprite_Delete((sprite_ptr)&userShip[index]);
  1107.  
  1108.         Sprite_Delete((sprite_ptr)&shipPlacer);
  1109.     }
  1110.  
  1111.     Sound_Stop();
  1112. }
  1113.  
  1114. int PlayGame(int connected)
  1115. {
  1116.     int xMovePlacer = 166, yMovePlacer = 11, theyAreInPosition = FALSE, numUserShots = 4;
  1117.     int redraw = 0, randMove;
  1118.     int index = 0, randPhraze = 0, gameEndStatus;
  1119.     music endSong;
  1120.     char madPhraze[4][38] = {
  1121.         "HOW DARE YOU?!? I LOVED THAT SHIP!   ",
  1122.         "ACK! TWAS MY FAVORITE ONE YOU SANK!  ",
  1123.         "I CANNOT BELIEVE YOU DID THAT TO ME!!",
  1124.         "YOU WILL PAY FOR THAT!!!             "
  1125.     };
  1126.  
  1127.     gShipsGone = bShipsGone = 0;
  1128.     if(PlayerWantsToQuit != FALSE)
  1129.         return 0;
  1130.  
  1131.     PCX_Init((pcx_picture_ptr)&ships_back);
  1132.     PCX_Load("xhair.pcx", (pcx_picture_ptr)&ships_back, 0);
  1133.     PCX_Get_Sprite((pcx_picture_ptr)&ships_back, (sprite_ptr)&shipPlacer, 0, 1, 0);
  1134. //    PCX_Delete((pcx_picture_ptr)&ships_back);
  1135.     Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1136.     Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1137.     Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1138.  
  1139. //    PCX_Init((pcx_picture_ptr)&ships_back);
  1140.     PCX_Load("xhair.pcx", (pcx_picture_ptr)&ships_back, 0);
  1141.     Sprite_Init((sprite_ptr)&shotCovering, 9, 11, 9, 11, 11, 11, 0, 0, 0, 0, 0);
  1142.     PCX_Get_Sprite((pcx_picture_ptr)&ships_back, (sprite_ptr)&shotCovering, 0, 3, 0);
  1143. //    PCX_Delete((pcx_picture_ptr)&ships_back);    
  1144.  //   Sprite_Delete((sprite_ptr)&shotCovering);
  1145.  
  1146. //    PCX_Init((pcx_picture_ptr)&ships_back);
  1147.     PCX_Load("xhair.pcx", (pcx_picture_ptr)&ships_back, 0);
  1148.     Sprite_Init((sprite_ptr)&missCovering, 9, 11, 9, 11, 11, 11, 0, 0, 0, 0, 0);
  1149.     PCX_Get_Sprite((pcx_picture_ptr)&ships_back, (sprite_ptr)&missCovering, 0, 2, 0);
  1150.     PCX_Delete((pcx_picture_ptr)&ships_back);    
  1151.  //   Sprite_Delete((sprite_ptr)&missCovering);
  1152.  
  1153.     srand((unsigned int) *clock);
  1154.     randMove = (rand()% 2);
  1155.  
  1156.     if(randMove == 0)
  1157.     {
  1158.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1159.         Tech_Print(95, 180, "YOU GET FIRST MOVE.", video_buffer);
  1160.         Music_Stop();
  1161.         Music_Unload((music_ptr)&song);
  1162.         Music_Load("mars.xmi", (music_ptr)&song);
  1163.         Music_Play((music_ptr)&song,0);
  1164.         Time_Delay(25);
  1165.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1166.     }
  1167.  
  1168.     if(randMove == 1)
  1169.     {
  1170.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1171.         Tech_Print(95, 180, "I GET FIRST MOVE!", video_buffer);
  1172.         Time_Delay(25);
  1173.         _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1174.         Music_Stop();
  1175.         computersTurn();
  1176.         if(cheat == 1)
  1177.             numUserShots = ((4 - gShipsGone) + 1);
  1178.         if(cheat == 0)
  1179.             numUserShots = 4 - gShipsGone;
  1180.  
  1181. }
  1182.  
  1183.     while(theyAreInPosition == FALSE)
  1184.     {
  1185.         if(shipPlacer.x < xMovePlacer)
  1186.         {
  1187.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1188.                 shipPlacer.x++;
  1189.  
  1190.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1191.                 shipPlacer.x++;
  1192.  
  1193.             else
  1194.                 shipPlacer.x+=3;
  1195.         }
  1196.  
  1197.         if(shipPlacer.x > xMovePlacer)
  1198.         {
  1199.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1200.                 shipPlacer.x--;
  1201.  
  1202.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1203.                 shipPlacer.x--;
  1204.  
  1205.             else
  1206.                 shipPlacer.x--;
  1207.         }
  1208.  
  1209.         if(shipPlacer.y < yMovePlacer)
  1210.         {
  1211.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1212.                 shipPlacer.y++;
  1213.  
  1214.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1215.                 shipPlacer.y++;
  1216.  
  1217.             else
  1218.                 shipPlacer.y+=3;
  1219.         }
  1220.  
  1221.         if(shipPlacer.y > yMovePlacer)
  1222.         {
  1223.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1224.                 shipPlacer.y--;
  1225.  
  1226.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1227.                 shipPlacer.y--;
  1228.  
  1229.             else
  1230.                 shipPlacer.y--;
  1231.         }
  1232.  
  1233.         if(shipPlacer.x == xMovePlacer && shipPlacer.y == yMovePlacer)
  1234.             theyAreInPosition = TRUE;
  1235.  
  1236.         Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1237.         Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1238.         Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);        
  1239.         // update old position
  1240.         shipPlacer.y_old = shipPlacer.y;
  1241.         shipPlacer.x_old = shipPlacer.x;
  1242.         Time_Delay(1);
  1243.     }
  1244.  
  1245.     while(!keys_active) //Wait for a key press to continue
  1246.     {
  1247.         if (Music_Status()==2 || Music_Status()==0)
  1248.         {
  1249.             Music_Stop();
  1250.             Music_Play((music_ptr)&song,0);
  1251.         }
  1252.     }
  1253.  
  1254.     Music_Stop();
  1255.  
  1256.     counterH = counterV = 0;
  1257.  
  1258.     while((bShipsGone < 4 && gShipsGone < 4) && PlayerWantsToQuit == FALSE) 
  1259.     {
  1260.         if(keyboard_state[MAKE_ESC])
  1261.         {
  1262.             PlayerWantsToQuit = TRUE;
  1263.             continue;
  1264.         }
  1265.  
  1266.         if (keyboard_state[MAKE_RIGHT])
  1267.         {
  1268.             if(++counterH > 11)
  1269.             {
  1270.                 counterH = 0;
  1271.                 shipPlacer.x = 166;
  1272.             }
  1273.  
  1274.             else
  1275.             {
  1276.                 shipPlacer.x += 12;
  1277.             }
  1278.             Sound_Stop();
  1279.             Sound_Play((sound_ptr)&digital_FX[2]);
  1280.             redraw = 1;
  1281.         }
  1282.  
  1283.         if (keyboard_state[MAKE_LEFT])
  1284.         {
  1285.             if(--counterH < 0)
  1286.             {
  1287.                 counterH = 11;
  1288.                 shipPlacer.x = 298;
  1289.             }
  1290.  
  1291.             else
  1292.             {
  1293.                 shipPlacer.x -= 12;
  1294.             }
  1295.             Sound_Stop();
  1296.             Sound_Play((sound_ptr)&digital_FX[2]);
  1297.             redraw = 1;
  1298.         }
  1299.  
  1300.         if (keyboard_state[MAKE_UP])
  1301.         {
  1302.             if(--counterV < 0)
  1303.             {
  1304.                 counterV = 11;
  1305.                 shipPlacer.y = 143;
  1306.             }
  1307.  
  1308.             else
  1309.             {
  1310.                 shipPlacer.y -= 12;
  1311.             }
  1312.             Sound_Stop();
  1313.             Sound_Play((sound_ptr)&digital_FX[2]);
  1314.             redraw = 1;
  1315.         }
  1316.  
  1317.         if (keyboard_state[MAKE_DOWN])
  1318.         {
  1319.             if(++counterV > 11)
  1320.             {
  1321.                 counterV = 0;
  1322.                 shipPlacer.y = 11;
  1323.             }
  1324.  
  1325.             else
  1326.             {
  1327.                 shipPlacer.y += 12;
  1328.             }
  1329.             Sound_Stop();
  1330.             Sound_Play((sound_ptr)&digital_FX[2]);
  1331.             redraw = 1;
  1332.         }
  1333.  
  1334.         if(keyboard_state[MAKE_ENTER])
  1335.         {
  1336.             keyboard_state[MAKE_ENTER] = 0;
  1337.             
  1338.             if(bGrid[counterH][counterV].coveredByShip == FALSE) // user shot and missed
  1339.             {
  1340.                 if(bGrid[counterH][counterV].beenShotAt == FALSE)
  1341.                 {
  1342.                     bGrid[counterH][counterV].beenShotAt = TRUE;
  1343.                     missCovering.x = missCovering.x_old = ((counterH * 12) + 166);
  1344.                     missCovering.y = missCovering.y_old = ((counterV * 12) +  11);
  1345.                     Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1346.                     Sprite_Draw((sprite_ptr)&missCovering, video_buffer, 1);        
  1347.                     Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1348.                     Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1349.                     Sound_Stop();
  1350.                     Sound_Play((sound_ptr)&digital_FX[5]);
  1351.  
  1352.                     numUserShots--;
  1353.  
  1354.                     if(numUserShots == 0)
  1355.                     {
  1356.                         computersTurn();
  1357.                         if(cheat == 1)
  1358.                             numUserShots = ((4 - gShipsGone) + 1);
  1359.                         if(cheat == 0)
  1360.                         numUserShots = 4 - gShipsGone;
  1361.                     }
  1362.                     
  1363.                     continue;
  1364.                 }
  1365.  
  1366.                 else
  1367.                 {
  1368.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1369.                     Tech_Print(75, 180, "YOU ALREADY SHOT AND MISSED THERE, DAMNIT!", video_buffer);
  1370.                     Time_Delay(20);
  1371.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1372.                     continue;
  1373.                 }               
  1374.             }
  1375.  
  1376.             if(bGrid[counterH][counterV].coveredByShip == TRUE) // user shot and hit!
  1377.             {
  1378.                 if(bGrid[counterH][counterV].beenShotAt == FALSE)
  1379.                 {                
  1380.                     bGrid[counterH][counterV].beenShotAt = TRUE;
  1381.                     shotCovering.x = shotCovering.x_old = ((counterH * 12) + 166);
  1382.                     shotCovering.y = shotCovering.y_old = ((counterV * 12) +  11);
  1383.                     *bGrid[counterH][counterV].coveredByWhat = TRUE; //notify the ship that covered
  1384.                                                                      //this position that it was
  1385.                                                                      //hit!!
  1386.                     Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1387.                     Sound_Stop();
  1388.                     Sound_Play((sound_ptr)&digital_FX[5]);
  1389.  
  1390.                     Time_Delay(50);
  1391.                     Sound_Stop();
  1392.                     Sprite_Draw((sprite_ptr)&shotCovering, video_buffer, 1);        
  1393.                     Sound_Play((sound_ptr)&digital_FX[6]);
  1394.                     Time_Delay(30);
  1395.                     Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1396.                     Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1397.  
  1398.                     numUserShots--;
  1399.  
  1400.                     for(index = 0; index < 4; index++) //loop through all the computer's ships
  1401.                     {
  1402.                         if(computerShip[index].coveredSquare1.x == counterH &&
  1403.                            computerShip[index].coveredSquare1.y == counterV ||
  1404.                            computerShip[index].coveredSquare2.x == counterH &&
  1405.                            computerShip[index].coveredSquare2.y == counterV ||
  1406.                            computerShip[index].coveredSquare3.x == counterH &&
  1407.                            computerShip[index].coveredSquare3.y == counterV)
  1408.                         {
  1409.                             computerShip[index].howManyTimesHit++;
  1410.  
  1411.                             if(computerShip[index].howManyTimesHit == 3)
  1412.                             {
  1413.                                 srand((unsigned int) *clock);
  1414.                                 randPhraze = (int)(rand() % 4);
  1415.  
  1416.                                 _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1417.                                 Tech_Print(75, 180, &madPhraze[randPhraze], video_buffer);
  1418.                                 Time_Delay(20);
  1419.                                 _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1420.  
  1421.                                 bShipsGone++;
  1422.                                 break;
  1423.                             }
  1424.                         }
  1425.                     }
  1426.  
  1427.                     if(numUserShots == 0)
  1428.                     {
  1429.                         computersTurn();
  1430.                         if(cheat == 1)
  1431.                             numUserShots = ((4 - gShipsGone) + 1);
  1432.                         if(cheat == 0)
  1433.                         numUserShots = 4 - gShipsGone;
  1434.                     }
  1435.                     continue;
  1436.                 }
  1437.  
  1438.                 else
  1439.                 {
  1440.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1441.                     Tech_Print(95, 180, "YOU ALREADY SHOT THERE, DAMNIT!", video_buffer);
  1442.                     Time_Delay(20);
  1443.                     _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1444.                     continue;
  1445.                 }
  1446.             }
  1447.         }
  1448.         if (redraw == 1)
  1449.         {
  1450.             // erase sprite at old position
  1451.             Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1452.             // scan the background at new postition
  1453.             Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1454.             // draw the sprite at the new position
  1455.             Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1456.             // update old position
  1457.             shipPlacer.y_old = shipPlacer.y;
  1458.             shipPlacer.x_old = shipPlacer.x;
  1459.  
  1460.             Time_Delay(3);
  1461.             redraw = 0;
  1462.         } // end if sprites needed to be redrawn
  1463.     } // end game loop
  1464.  
  1465.     if(bShipsGone == 4)
  1466.     {
  1467.         Screen_Transition(SCREEN_DARKNESS);
  1468.         Music_Stop();
  1469.         Music_Load("endhapy.xmi", (music_ptr)&endSong);
  1470.         Music_Play((music_ptr)&endSong,0);
  1471.         PCX_Init((pcx_picture_ptr)&background);
  1472.         PCX_Load("lose.pcx", (pcx_picture_ptr)&background, 0); //as in the computer lost
  1473.         PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  1474.         PCX_Delete((pcx_picture_ptr)&background);
  1475.         keys_active = 0;
  1476.         while(!keys_active) //Wait for a key press to continue
  1477.         {
  1478.         }
  1479.         Music_Stop();
  1480.         Music_Unload(&endSong);
  1481.         Screen_Transition(SCREEN_DARKNESS);
  1482.     }
  1483.  
  1484.     if(gShipsGone == 4)
  1485.     {
  1486.         Screen_Transition(SCREEN_DARKNESS);
  1487.         Music_Stop();
  1488.         Music_Load("farmer.xmi", (music_ptr)&endSong);
  1489.         Music_Play((music_ptr)&endSong,0);
  1490.         PCX_Init((pcx_picture_ptr)&background);
  1491.         PCX_Load("roundup.pcx", (pcx_picture_ptr)&background, 0);
  1492.         PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  1493.         PCX_Delete((pcx_picture_ptr)&background);
  1494.         keys_active = 0;
  1495.         while(!keys_active) //Wait for a key press to continue
  1496.         {
  1497.         }
  1498.         Music_Stop();
  1499.         Music_Unload(&endSong);
  1500.         Screen_Transition(SCREEN_DARKNESS);
  1501.     }
  1502.                 
  1503.     Sprite_Delete((sprite_ptr)&shotCovering);
  1504.     return 1;
  1505. }
  1506.  
  1507. int computersTurn() // 8-)
  1508. {
  1509.     int theyAreInPosition = FALSE;
  1510.     int xMovePlacer = 9;
  1511.     int yMovePlacer = 11;
  1512.     int computerIsDone = FALSE, nextStopX, nextStopY;
  1513.     static int guessX, guessY;
  1514.     int index = 0, hangCounter = 0, tempDir = 0, tempGuessX, tempGuessY;
  1515.  
  1516.     counterH = counterV = 0;
  1517.     numComputerShots = 4 - bShipsGone;
  1518.  
  1519.     if(bShipsGone >= 4)
  1520.         return 0;
  1521.  
  1522.     while(theyAreInPosition == FALSE)
  1523.     {
  1524.         if(shipPlacer.x < xMovePlacer)
  1525.         {
  1526.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1527.                 shipPlacer.x++;
  1528.  
  1529.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1530.                 shipPlacer.x++;
  1531.  
  1532.             else
  1533.                 shipPlacer.x++;
  1534.         }
  1535.  
  1536.         if(shipPlacer.x > xMovePlacer)
  1537.         {
  1538.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1539.                 shipPlacer.x-=3;
  1540.  
  1541.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1542.                 shipPlacer.x-=3;
  1543.  
  1544.             else
  1545.                 shipPlacer.x-=3;
  1546.         }
  1547.  
  1548.         if(shipPlacer.y < yMovePlacer)
  1549.         {
  1550.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1551.                 shipPlacer.y++;
  1552.  
  1553.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1554.                 shipPlacer.y++;
  1555.  
  1556.             else
  1557.                 shipPlacer.y++;
  1558.         }
  1559.  
  1560.         if(shipPlacer.y > yMovePlacer)
  1561.         {
  1562.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1563.                 shipPlacer.y-=3;
  1564.  
  1565.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1566.                 shipPlacer.y-=3;
  1567.  
  1568.             else
  1569.                 shipPlacer.y-=3;
  1570.         }
  1571.  
  1572.         if(shipPlacer.x == xMovePlacer && shipPlacer.y == yMovePlacer)
  1573.             theyAreInPosition = TRUE;
  1574.  
  1575.         Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1576.         Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1577.         Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);        
  1578.         // update old position
  1579.         shipPlacer.y_old = shipPlacer.y;
  1580.         shipPlacer.x_old = shipPlacer.x;
  1581.         Time_Delay(1);
  1582.     }
  1583.  
  1584.     while(computerIsDone == FALSE)
  1585.     {
  1586.         srand((unsigned int) *clock);
  1587.  
  1588.         nextStopX = (rand() % 12);
  1589.         nextStopY = (rand() % 12);
  1590.  
  1591.         if(hitFlag == 0)
  1592.         {
  1593.               makeHarder(&guessX, &guessY);
  1594. //            guessX = (rand() % 12);        
  1595. //            guessY = (rand() % 12);
  1596.         }
  1597.  
  1598.         if(gGrid[guessX][guessY].beenShotAt == TRUE && hitFlag == 0)
  1599.             continue;
  1600.  
  1601.  
  1602.         if(hitFlag == 1)
  1603.         {
  1604.             tempGuessX = guessX; //holds old if need it
  1605.             tempGuessY = guessY;
  1606.  
  1607.             if(curDirection == 0) // up
  1608.             {
  1609.                 tempGuessY = guessY;
  1610.                 guessY--;
  1611.                 direction[curDirection]++;
  1612.             }
  1613.  
  1614.             if(curDirection == 1) // down
  1615.             {
  1616.                 tempGuessY = guessY;
  1617.                 guessY++;
  1618.                 direction[curDirection]++;
  1619.             }
  1620.  
  1621.             if(curDirection == 2) //left
  1622.             {
  1623.                 tempGuessX = guessX;
  1624.                 guessX--;
  1625.                 direction[curDirection]++;
  1626.             }
  1627.  
  1628.             if(curDirection == 3) // right
  1629.             {
  1630.                 tempGuessX = guessX;
  1631.                 guessX++;
  1632.                 direction[curDirection]++;
  1633.             }
  1634.             
  1635.             if(direction[0] > 0 && (guessY < 0 || gGrid[guessX][guessY + 1].coveredByShip == FALSE || gGrid[guessX][guessY].beenShotAt == TRUE)) //wants to go up; but can't
  1636.             {
  1637.                 guessY += direction[curDirection];
  1638.                 direction[0] = 0;
  1639.                 while(curDirection == 0) //keep a-try'n
  1640.                 {
  1641.                     curDirection = (rand()% 4);
  1642.                 }
  1643.                 continue;
  1644.             }
  1645.  
  1646.             if(direction[1] > 0 && (guessY > 11 || gGrid[guessX][guessY - 1].coveredByShip == FALSE || gGrid[guessX][guessY].beenShotAt == TRUE)) //wants to go down; but can't
  1647.             {
  1648.                 guessY -= direction[curDirection];
  1649.                 direction[1] = 0;
  1650.                 while(curDirection == 1) //keep a-try'n
  1651.                 {
  1652.                     curDirection = (rand()% 4);
  1653.                 }
  1654.                 continue;
  1655.             }
  1656.  
  1657.             if(direction[2] > 0 && (guessX < 0 || gGrid[guessX + 1][guessY].coveredByShip == FALSE || gGrid[guessX][guessY].beenShotAt == TRUE)) //wants to go left; but can't
  1658.             {
  1659.                 guessX += direction[curDirection];
  1660.                 direction[2] = 0;
  1661.                 while(curDirection == 2) //keep a-try'n
  1662.                 {
  1663.                     curDirection = (rand()% 4);
  1664.                 }
  1665.                 continue;
  1666.             }
  1667.  
  1668.             if(direction[3] > 0 && (guessX > 11 || gGrid[guessX - 1][guessY].coveredByShip == FALSE || gGrid[guessX][guessY].beenShotAt == TRUE)) //wants to go right; but can't
  1669.             {
  1670.                 guessX -= direction[curDirection];
  1671.                 direction[3] = 0;
  1672.                 while(curDirection == 3) //keep a-try'n
  1673.                 {
  1674.                     curDirection = (rand()% 4);
  1675.                 }
  1676.                 continue;
  1677.             }
  1678.  
  1679.         }
  1680.  
  1681.         if(gGrid[guessX][guessY].beenShotAt == TRUE && hitFlag == 1)
  1682.         {
  1683.             direction[curDirection] = 0;
  1684.             guessX = tempGuessX;
  1685.             guessY = tempGuessY;
  1686.             tempDir = curDirection;
  1687.             while(curDirection == tempDir) //keep a-try'n
  1688.             {
  1689.                 curDirection = (rand()% 4);
  1690.             }
  1691.             continue;
  1692.         }
  1693.  
  1694.         theyAreInPosition = FALSE;
  1695.         while(theyAreInPosition == FALSE && hitFlag != 1)
  1696.         {
  1697.             if(counterH < nextStopX)
  1698.                 counterH++;
  1699.  
  1700.             if(counterH > nextStopX)
  1701.                 counterH--;
  1702.  
  1703.             if(counterV < nextStopY)
  1704.                 counterV++;
  1705.  
  1706.             if(counterV > nextStopY)
  1707.                 counterV--;
  1708.  
  1709.             shipPlacer.x = ((counterH * 12) + 9 );
  1710.             shipPlacer.y = ((counterV * 12) + 11);
  1711.  
  1712.             Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1713.             Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1714.             Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1715.  
  1716.             shipPlacer.x_old = shipPlacer.x;
  1717.             shipPlacer.y_old = shipPlacer.y;
  1718.  
  1719.             if(counterH == nextStopX && counterV == nextStopY)
  1720.                 theyAreInPosition = TRUE;
  1721.  
  1722.             Sound_Stop();
  1723.             Sound_Play((sound_ptr)&digital_FX[2]);
  1724.             Time_Delay((rand() % 5 + 7));
  1725.         }
  1726.  
  1727.         theyAreInPosition = FALSE;
  1728.         while(theyAreInPosition == FALSE)
  1729.         {
  1730.             if(counterH < guessX)
  1731.                 counterH++;
  1732.  
  1733.             if(counterH > guessX)
  1734.                 counterH--;
  1735.  
  1736.             if(counterV < guessY)
  1737.                 counterV++;
  1738.  
  1739.             if(counterV > guessY)
  1740.                 counterV--;
  1741.  
  1742.             shipPlacer.x = ((counterH * 12) + 9 );
  1743.             shipPlacer.y = ((counterV * 12) + 11);
  1744.  
  1745.             Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1746.             Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1747.             Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1748.  
  1749.             shipPlacer.x_old = shipPlacer.x;
  1750.             shipPlacer.y_old = shipPlacer.y;
  1751.  
  1752.             if(counterH == guessX && counterV == guessY)
  1753.                 theyAreInPosition = TRUE;
  1754.  
  1755.             Sound_Stop();
  1756.             Sound_Play((sound_ptr)&digital_FX[2]);
  1757.             Time_Delay((rand() % 5 + 7));
  1758.         }        
  1759.  
  1760.         //S H O O T !
  1761.         if(gGrid[counterH][counterV].coveredByShip == FALSE) // computer shot and missed
  1762.         {
  1763.             if(gGrid[counterH][counterV].beenShotAt == FALSE)
  1764.             {
  1765.                 gGrid[counterH][counterV].beenShotAt = TRUE;
  1766.                 missCovering.x = missCovering.x_old = ((counterH * 12) + 9);
  1767.                 missCovering.y = missCovering.y_old = ((counterV * 12) +  11);
  1768.                 Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1769.                 Sprite_Draw((sprite_ptr)&missCovering, video_buffer, 1);        
  1770.                 Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1771.                 Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1772.                 Sound_Stop();
  1773.                 Sound_Play((sound_ptr)&digital_FX[5]);
  1774.                 Time_Delay(10);
  1775.  
  1776.                 numComputerShots--;
  1777.  
  1778.                 if(numComputerShots == 0)
  1779.                 {
  1780.                     computerIsDone = TRUE;
  1781.                 }
  1782.                                                         
  1783.                 continue;
  1784.             } 
  1785.         }
  1786.  
  1787.         if(gGrid[counterH][counterV].coveredByShip == TRUE) // computer shot and hit!
  1788.         {
  1789.             if(gGrid[counterH][counterV].beenShotAt == FALSE)
  1790.             {                
  1791.                 gGrid[counterH][counterV].beenShotAt = TRUE;
  1792.                 shotCovering.x = shotCovering.x_old = ((counterH * 12) + 9);
  1793.                 shotCovering.y = shotCovering.y_old = ((counterV * 12) +  11);
  1794.                 *gGrid[counterH][counterV].coveredByWhat = TRUE; //notify the ship that covered
  1795.                                                                  //this position that it was
  1796.                                                                  //hit!!
  1797.                 Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1798.                 Sound_Stop();
  1799.                 Sound_Play((sound_ptr)&digital_FX[5]);
  1800.  
  1801.                 Time_Delay(50);
  1802.                 Sound_Stop();
  1803.                 Sprite_Draw((sprite_ptr)&shotCovering, video_buffer, 1);        
  1804.                 Sound_Play((sound_ptr)&digital_FX[6]);
  1805.                 Time_Delay(30);
  1806.                 Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1807.                 Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);
  1808.                 if (hitFlag == 0)
  1809.                     curDirection = rand() %4; //random direction for the first go
  1810.                 hitFlag = 1;
  1811.                 numComputerShots--;
  1812.  
  1813.                 for(index = 0; index < 4; index++) //loop through all the user's ships
  1814.                 {
  1815.                     if((userShip[index].coveredSquare1.x == counterH &&
  1816.                        userShip[index].coveredSquare1.y == counterV) ||
  1817.                        (userShip[index].coveredSquare2.x == counterH &&
  1818.                        userShip[index].coveredSquare2.y == counterV) ||
  1819.                        (userShip[index].coveredSquare3.x == counterH &&
  1820.                        userShip[index].coveredSquare3.y == counterV))
  1821.                     {
  1822.                         userShip[index].howManyTimesHit++;
  1823.  
  1824.                         if(userShip[index].howManyTimesHit == 3)
  1825.                         {
  1826.                             /*srand((unsigned int) *clock);
  1827.                             randPhraze = (int)(rand() % 4);*/
  1828.  
  1829.                             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1830.                             Tech_Print(75, 180, "HA HA! GOTCHA!", video_buffer);
  1831.                             Time_Delay(20);
  1832.                             _fmemset((char far *)(video_buffer + 57600), 0, 3200);
  1833.  
  1834.                             for(index = 0; index < 4; index++)
  1835.                                 direction[index] = 0;
  1836.  
  1837.                             Sound_Stop();
  1838.                             Sound_Play((sound_ptr)&digital_FX[7]);
  1839.                             Time_Delay(120);                            
  1840.                             hitFlag = 0;
  1841.                             gShipsGone++;
  1842.                             break;
  1843.                         }
  1844.                     }
  1845.                 }
  1846.  
  1847.                 if(gShipsGone == 4)
  1848.                     return 0;
  1849.  
  1850.                 if(numComputerShots <= 0)
  1851.                 {
  1852.                     computerIsDone = TRUE;
  1853.                 }
  1854.                 continue;
  1855.             }
  1856.         }
  1857.         Time_Delay(18);
  1858.     } // end while coputerIsDone == FALSE
  1859.  
  1860.     xMovePlacer = 166;
  1861.     yMovePlacer = 11;
  1862.     
  1863.     theyAreInPosition = FALSE;
  1864.     while(theyAreInPosition == FALSE)
  1865.     {
  1866.         if(shipPlacer.x < xMovePlacer)
  1867.         {
  1868.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1869.                 shipPlacer.x+=3;
  1870.  
  1871.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1872.                 shipPlacer.x+=3;
  1873.  
  1874.             else
  1875.                 shipPlacer.x+=3;
  1876.         }
  1877.  
  1878.         if(shipPlacer.x > xMovePlacer)
  1879.         {
  1880.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1881.                 shipPlacer.x--;
  1882.  
  1883.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1884.                 shipPlacer.x--;
  1885.  
  1886.             else
  1887.                 shipPlacer.x--;
  1888.         }
  1889.  
  1890.         if(shipPlacer.y < yMovePlacer)
  1891.         {
  1892.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1893.                 shipPlacer.y+=3;
  1894.  
  1895.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1896.                 shipPlacer.y+=3;
  1897.  
  1898.             else
  1899.                 shipPlacer.y+=3;
  1900.         }
  1901.  
  1902.         if(shipPlacer.y > yMovePlacer)
  1903.         {
  1904.             if((xMovePlacer - shipPlacer.x) > (yMovePlacer - shipPlacer.y))
  1905.                 shipPlacer.y-=3;
  1906.  
  1907.             else if((xMovePlacer - shipPlacer.x) == (yMovePlacer - shipPlacer.y))
  1908.                 shipPlacer.y-=3;
  1909.  
  1910.             else
  1911.                 shipPlacer.y-=3;
  1912.         }
  1913.  
  1914.         if(shipPlacer.x == xMovePlacer && shipPlacer.y == yMovePlacer)
  1915.             theyAreInPosition = TRUE;
  1916.  
  1917.         Sprite_Erase((sprite_ptr)&shipPlacer, video_buffer);
  1918.         Sprite_Under((sprite_ptr)&shipPlacer, video_buffer);
  1919.         Sprite_Draw((sprite_ptr)&shipPlacer, video_buffer, 1);        
  1920.         // update old position
  1921.         shipPlacer.y_old = shipPlacer.y;
  1922.         shipPlacer.x_old = shipPlacer.x;
  1923.         Time_Delay(1);
  1924.     }
  1925.  
  1926.     counterH = 0;
  1927.     counterV = 0;
  1928. }
  1929.  
  1930. void creadits(void)
  1931. {
  1932.     sprite bouncer;
  1933.     pcx_picture cool_back;
  1934.     int xVelo, yVelo;
  1935.     Sound boing;
  1936.  
  1937.     Sound_Load("boing.voc",(sound_ptr)&boing,1);
  1938.  
  1939.     srand((unsigned int) *clock);
  1940.  
  1941.     xVelo = ((rand()%3) + 1);
  1942.     yVelo = ((rand()%3) + 1);
  1943.  
  1944.     Screen_Transition(SCREEN_DARKNESS);
  1945.     PCX_Init((pcx_picture_ptr)&cool_back);
  1946.     PCX_Load("credits.pcx", (pcx_picture_ptr)&cool_back, 0);
  1947.     PCX_Show_Buffer((pcx_picture_ptr)&cool_back, 1);
  1948.     
  1949. //    PCX_Init((pcx_picture_ptr)&cool_back);
  1950.     PCX_Load("vShip.pcx", (pcx_picture_ptr)&cool_back, 0);
  1951.     Sprite_Init((sprite_ptr)&bouncer, 160, 100, 160, 100, 23, 35, 0, 0, 0, 0, 0);
  1952.  
  1953.     PCX_Get_Sprite((pcx_picture_ptr)&cool_back, (sprite_ptr)&bouncer, 0, 0, 0);
  1954.  
  1955.     Tech_Print(10, 40,  "TOM NELSON",video_buffer);
  1956.     Tech_Print(20, 50,  "DEBUGGING DUDE",video_buffer);
  1957.     Tech_Print(10, 60,  "JOE NELSON",video_buffer);
  1958.     Tech_Print(20, 70,  "SUPER CODER!",video_buffer);
  1959.     Tech_Print(10, 80,  "NATE SOBERG",video_buffer);
  1960.     Tech_Print(20, 90,  "SOUND DISTRIBUTER",video_buffer);
  1961.     Tech_Print(10, 100, "CORDELL WESSELINK",video_buffer);
  1962.     Tech_Print(20, 110, "TESTING GUY",video_buffer);
  1963.     Tech_Print(10, 120, "BRIAN HOSCHEIT",video_buffer);
  1964.     Tech_Print(20, 130, "AWESOME ARTIST!",video_buffer);
  1965.     Tech_Print(10, 140, "MATIAS RUDOLPH",video_buffer);
  1966.     Tech_Print(20, 150, "GOOD INTENTION GUY :-)",video_buffer);
  1967.     Tech_Print(10, 160, "STACY KINGSTON",video_buffer);
  1968.     Tech_Print(20, 170, "CHEAT-CODE INSPIRATION! XOXOXOXOXO!!!",video_buffer);
  1969.  
  1970.     Sprite_Under((sprite_ptr)&bouncer, video_buffer);
  1971.     Sprite_Draw((sprite_ptr)&bouncer, video_buffer, 1);
  1972.  
  1973.     keys_active = 0;
  1974.     while(!keys_active) //Wait for a key press to continue
  1975.     {
  1976.         if (Music_Status()==2 || Music_Status()==0) //keep the music go'n
  1977.         {
  1978.             Music_Stop();
  1979.             Music_Play((music_ptr)&song, 0);
  1980.         }
  1981.  
  1982.         if(bouncer.x < 4  )
  1983.         {
  1984.             Sound_Stop();
  1985.             Sound_Play((sound_ptr)&boing);
  1986.             xVelo = -xVelo;
  1987.         }
  1988.         
  1989.         if(bouncer.x > 294)
  1990.         {
  1991.             Sound_Stop();
  1992.             Sound_Play((sound_ptr)&boing);
  1993.             xVelo = -xVelo;
  1994.         }
  1995.         
  1996.         if(bouncer.y < 4  )
  1997.         {
  1998.             Sound_Stop();
  1999.             Sound_Play((sound_ptr)&boing);
  2000.             yVelo = -yVelo;
  2001.         }
  2002.         
  2003.         if(bouncer.y > 152)
  2004.         {
  2005.             Sound_Stop();
  2006.             Sound_Play((sound_ptr)&boing);
  2007.             yVelo = -yVelo;
  2008.         }
  2009.  
  2010.         bouncer.x += xVelo;
  2011.         bouncer.y += yVelo;
  2012.  
  2013.         Sprite_Erase((sprite_ptr)&bouncer, video_buffer);
  2014.         Sprite_Under((sprite_ptr)&bouncer, video_buffer);
  2015.         Sprite_Draw((sprite_ptr)&bouncer, video_buffer, 1);
  2016.         bouncer.x_old = bouncer.x;
  2017.         bouncer.y_old = bouncer.y;
  2018.         Wait_For_Vertical_Retrace();
  2019.     }
  2020.  
  2021.     Sound_Unload((sound_ptr)&boing);
  2022.     Sprite_Delete(&bouncer);
  2023.     PCX_Delete(&cool_back);
  2024.     Screen_Transition(SCREEN_DARKNESS);
  2025. }
  2026.  
  2027. int intro(void)
  2028. {
  2029.     sprite ship, theShell;
  2030.     music theMusic;
  2031.     Sound boom;
  2032.     int notDone = FALSE, index = 0;
  2033.  
  2034.     Music_Stop();
  2035.     Music_Load("sweet.xmi", (music_ptr)&theMusic);
  2036.     Music_Play((music_ptr)&song,0);
  2037.     Screen_Transition(SCREEN_DARKNESS);
  2038.     PCX_Init((pcx_picture_ptr)&background);
  2039.     PCX_Load("scene.pcx", (pcx_picture_ptr)&background, 0);
  2040.     PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  2041.  
  2042.     PCX_Load("bShip1.pcx", (pcx_picture_ptr)&background, 0);
  2043.     Sprite_Init((sprite_ptr)&ship, 80, 130, 80, 130, 200, 78, 0, 0, 0, 0, 0);
  2044.     PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&ship, 0, 0, 0);
  2045.  
  2046.     Sprite_Under((sprite_ptr)&ship, video_buffer);
  2047.     Sprite_Draw((sprite_ptr)&ship, video_buffer, 1);
  2048.  
  2049.     PCX_Load("sTorp.pcx", (pcx_picture_ptr)&background, 0);
  2050.     Sprite_Init((sprite_ptr)&theShell, 0, 0, 0, 0, 24, 24, 0, 0, 0, 0, 0);
  2051.     PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&theShell, 0, 0, 0);
  2052.  
  2053.     for(index = 0; index < 100; index++)
  2054.     {
  2055.         if(keyboard_state[MAKE_ESC])
  2056.         {
  2057.             Sprite_Delete(&theShell);
  2058.             Sprite_Delete(&ship);
  2059.             Sound_Stop();
  2060.             Sound_Unload((sound_ptr)&boom);
  2061.             Music_Load("menu.xmi", (music_ptr)&song);
  2062.             Music_Play((music_ptr)&song,0);
  2063.             return 0;
  2064.         }
  2065.         Time_Delay(1);
  2066.     }
  2067.  
  2068.     Sound_Load("shot.voc",(sound_ptr)&boom,1);
  2069.     Sound_Play((sound_ptr)&boom);
  2070.  
  2071.     for(index = 0; index < 25; index++)
  2072.     {
  2073.         if(keyboard_state[MAKE_ESC])
  2074.         {
  2075.             Sprite_Delete(&theShell);
  2076.             Sprite_Delete(&ship);
  2077.             Sound_Stop();
  2078.             Sound_Unload((sound_ptr)&boom);
  2079.             Music_Load("menu.xmi", (music_ptr)&song);
  2080.             Music_Play((music_ptr)&song,0);
  2081.             return 0;
  2082.         }
  2083.         Time_Delay(1);
  2084.     }
  2085.  
  2086.  
  2087.     Sprite_Under((sprite_ptr)&theShell, video_buffer);
  2088.     Sprite_Draw((sprite_ptr)&theShell, video_buffer, 1);
  2089.  
  2090.     while(notDone == FALSE && !keyboard_state[MAKE_ESC])
  2091.     {
  2092.         if(theShell.x >= 100 && theShell.y >= 121)
  2093.             notDone = TRUE;
  2094.  
  2095.         theShell.x += 5;
  2096.         theShell.y += 5;
  2097.         // erase sprite at old position
  2098.         Sprite_Erase((sprite_ptr)&theShell, video_buffer);
  2099.         // scan the background at new postition
  2100.         Sprite_Under((sprite_ptr)&theShell, video_buffer);
  2101.         // draw sprite at new position
  2102.         Sprite_Draw((sprite_ptr)&theShell, video_buffer, 1);
  2103.         // update old position
  2104.         theShell.x_old = theShell.x;
  2105.         theShell.y_old = theShell.y;
  2106.         Time_Delay(1);
  2107.     }
  2108.  
  2109.     notDone = FALSE;
  2110.     if(keyboard_state[MAKE_ESC])
  2111.     {
  2112.         Sprite_Delete(&theShell);
  2113.         Sprite_Delete(&ship);
  2114.         Sound_Stop();
  2115.         Sound_Unload((sound_ptr)&boom);
  2116.         Music_Load("menu.xmi", (music_ptr)&song);
  2117.         Music_Play((music_ptr)&song,0);
  2118.         return 0;
  2119.     }
  2120.  
  2121.     // erase sprite at old position
  2122.     Sprite_Erase((sprite_ptr)&theShell, video_buffer);
  2123.     Sprite_Erase((sprite_ptr)&ship, video_buffer);
  2124.  
  2125.     PCX_Load("expShip.pcx", (pcx_picture_ptr)&background, 0);
  2126.     PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&ship, 0, 0, 0);
  2127.  
  2128.     // scan the background at new postition
  2129.     Sprite_Under((sprite_ptr)&ship, video_buffer);
  2130.     // draw sprite at new position
  2131.     Sprite_Draw((sprite_ptr)&ship, video_buffer, 1);
  2132.  
  2133.     Sound_Stop();
  2134.     Sound_Unload((sound_ptr)&boom);
  2135.     Sound_Load("blowup.voc",(sound_ptr)&boom,1);
  2136.     Sound_Play((sound_ptr)&boom);
  2137.     Music_Stop();
  2138.     Music_Unload((music_ptr)&song);
  2139.     Music_Load("menu.xmi", (music_ptr)&song);
  2140.     Music_Play((music_ptr)&song,0);
  2141.  
  2142.     for(index = 0; index < 50; index++)
  2143.     {
  2144.         if(keyboard_state[MAKE_ESC])
  2145.         {
  2146.             Sprite_Delete(&theShell);
  2147.             Sprite_Delete(&ship);
  2148.             Sound_Stop();
  2149.             Sound_Unload((sound_ptr)&boom);
  2150.             Music_Load("menu.xmi", (music_ptr)&song);
  2151.             Music_Play((music_ptr)&song,0);
  2152.             return 0;
  2153.         }
  2154.         Time_Delay(1);
  2155.     }
  2156.  
  2157.     PCX_Load("sign.pcx", (pcx_picture_ptr)&background, 0);
  2158.     Sprite_Init((sprite_ptr)&theShell, 80, 0, 80, 0, 182, 82, 0, 0, 0, 0, 0);
  2159.     PCX_Get_Sprite((pcx_picture_ptr)&background, (sprite_ptr)&theShell, 0, 0, 0);
  2160.     Sound_Stop();
  2161.     Sound_Unload((sound_ptr)&boom);
  2162.     Sound_Load("shot.voc",(sound_ptr)&boom,1);
  2163.     Sound_Play((sound_ptr)&boom);
  2164.     for(index = 0; index < 35; index++)
  2165.     {
  2166.         if(keyboard_state[MAKE_ESC])
  2167.         {
  2168.             Sprite_Delete(&theShell);
  2169.             Sprite_Delete(&ship);
  2170.             Sound_Stop();
  2171.             Sound_Unload((sound_ptr)&boom);
  2172.             Music_Load("menu.xmi", (music_ptr)&song);
  2173.             Music_Play((music_ptr)&song,0);
  2174.             return 0;
  2175.         }
  2176.         Time_Delay(1);
  2177.     }
  2178.  
  2179.  
  2180.     // scan the background at new position
  2181.     Sprite_Under((sprite_ptr)&theShell, video_buffer);
  2182.     // draw sprite at new position
  2183.     Sprite_Draw((sprite_ptr)&theShell, video_buffer, 1);    
  2184.  
  2185.     while(theShell.y < 70 && !keyboard_state[MAKE_ESC])
  2186.     {
  2187.         theShell.y += 5;
  2188.         // erase sprite at old position
  2189.         Sprite_Erase((sprite_ptr)&theShell, video_buffer);
  2190.         // scan the background at new postition
  2191.         Sprite_Under((sprite_ptr)&theShell, video_buffer);
  2192.         // draw sprite at new position
  2193.         Wait_For_Vertical_Retrace();
  2194.         Sprite_Draw((sprite_ptr)&theShell, video_buffer, 1);
  2195. //        Time_Delay(1);
  2196.         // update old position
  2197.         theShell.y_old = theShell.y;
  2198.         theShell.x_old = theShell.x;
  2199.     }
  2200.  
  2201.     for(index = 0; index < 50; index++)
  2202.     {
  2203.         if(keyboard_state[MAKE_ESC])
  2204.         {
  2205.             Sprite_Delete(&theShell);
  2206.             Sprite_Delete(&ship);
  2207.             Sound_Stop();
  2208.             Sound_Unload((sound_ptr)&boom);
  2209.             Music_Load("menu.xmi", (music_ptr)&song);
  2210.             Music_Play((music_ptr)&song,0);
  2211.             return 0;
  2212.         }
  2213.         Time_Delay(1);
  2214.     }
  2215.  
  2216.     Sprite_Delete(&theShell);
  2217.     Sprite_Delete(&ship);
  2218.     Sound_Stop();
  2219.     Sound_Unload((sound_ptr)&boom);
  2220.     return 0;
  2221. }
  2222.  
  2223. void selectDifficulty(void)
  2224. {
  2225.     int counter = 0, done = FALSE, redraw = 0, index = 0, pal_reg = 0;
  2226.     RGB_color color;
  2227.  
  2228.     Screen_Transition(SCREEN_DARKNESS);
  2229.     PCX_Init((pcx_picture_ptr)&background);    
  2230.     PCX_Load("hardLev.pcx", (pcx_picture_ptr)&background, 0);
  2231.     PCX_Show_Buffer((pcx_picture_ptr)&background, 1);
  2232.     PCX_Delete((pcx_picture_ptr)&background);    
  2233.  
  2234.     shell.x_old = shell.x = 41;
  2235.     shell.y_old = shell.y = 18;
  2236.     Sprite_Under((sprite_ptr)&shell, video_buffer);
  2237.     Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  2238.  
  2239.         while(done != 1)
  2240.         {
  2241.             if (Music_Status()==2 || Music_Status()==0)
  2242.             {
  2243.                 Music_Stop();
  2244.                 Music_Play((music_ptr)&song,0);
  2245.             }
  2246.  
  2247.             if(keys_active > 0)
  2248.             {
  2249.                 // what is user doing
  2250.                 if (keyboard_state[MAKE_UP])
  2251.                 {
  2252.                     shell.y-=36;
  2253.  
  2254.                     // test if we need to wrap around bottom
  2255.  
  2256.                     if (--counter < 0)
  2257.                     {
  2258.                         counter = 4;
  2259.                         shell.y = 162;
  2260.                     } // end if wrap around
  2261.                     //keyboard_state[MAKE_UP] = 0;
  2262.                     Sound_Stop();
  2263.                     Sound_Play((sound_ptr)&digital_FX[0]);
  2264.                     redraw = 1;
  2265.                 } // end if up
  2266.  
  2267.                 if (keyboard_state[MAKE_DOWN])
  2268.                 {
  2269.                     shell.y+=36;
  2270.  
  2271.                     // test if we need to wrap around bottom
  2272.  
  2273.                     if (++counter > 4)
  2274.                     {
  2275.                         counter = 0;
  2276.                         shell.y = 18;
  2277.                     } // end if wrap around
  2278.                     //keyboard_state[MAKE_DOWN] = 0;
  2279.                     Sound_Stop();
  2280.                     Sound_Play((sound_ptr)&digital_FX[0]);
  2281.                     redraw = 1;
  2282.                 } // end if down
  2283.  
  2284.                 if(keyboard_state[MAKE_HOME])
  2285.                 {
  2286.                     shell.y = 18;
  2287.                     counter = 0;
  2288.                     Sound_Stop();
  2289.                     Sound_Play((sound_ptr)&digital_FX[0]);
  2290.                     redraw = 1;
  2291.                 }
  2292.  
  2293.                 if(keyboard_state[MAKE_END])
  2294.                 {
  2295.                     shell.y = 162;
  2296.                     counter = 4;
  2297.                     Sound_Stop();
  2298.                     Sound_Play((sound_ptr)&digital_FX[0]);
  2299.                     redraw = 1;
  2300.                 }
  2301.  
  2302.                 if(keyboard_state[MAKE_ENTER])
  2303.                 {
  2304.                     switch(counter)
  2305.                     {
  2306.                         case 0:
  2307.                             Screen_Transition(SCREEN_WHITENESS);
  2308.                             Screen_Transition(SCREEN_DARKNESS);
  2309.                             difficulty = EASY_AS_SNOT;
  2310.                             done = TRUE;
  2311.                             break;
  2312.                         case 1:
  2313.                             for (index=0; index<20; index++)
  2314.                             {
  2315.                                 // loop thru all palette registers
  2316.  
  2317.                                 for (pal_reg=0; pal_reg<256; pal_reg++)
  2318.                                 {
  2319.                                     Read_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2320.                                     // get the color to fade
  2321.                                     color.blue+=4;
  2322.  
  2323.                                     if (color.blue > 63)
  2324.                                         color.blue = 63;
  2325.  
  2326.                                     // set the color to a brightend intensity
  2327.  
  2328.                                     Write_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2329.                                 } // end for pal_reg
  2330.  
  2331.                                 // wait a bit
  2332.  
  2333.                                 Time_Delay(1);
  2334.  
  2335.                             } // end for index
  2336.                             difficulty = A_GOOD_BELCH;
  2337.                             Screen_Transition(SCREEN_DARKNESS);
  2338.                             done = TRUE;
  2339.                             break;
  2340.                         case 2:
  2341.                             for (index=0; index<20; index++)
  2342.                             {
  2343.                                 // loop thru all palette registers
  2344.  
  2345.                                 for (pal_reg=0; pal_reg<256; pal_reg++)
  2346.                                 {
  2347.                                     Read_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2348.                                     // get the color to fade
  2349.                                     color.green+=4;
  2350.  
  2351.                                     if (color.green > 63)
  2352.                                         color.green = 63;
  2353.  
  2354.                                     // set the color to a brightend intensity
  2355.  
  2356.                                     Write_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2357.                                 } // end for pal_reg
  2358.  
  2359.                                 // wait a bit
  2360.  
  2361.                                 Time_Delay(1);
  2362.  
  2363.                             } // end for index
  2364.                             difficulty = PUKE_GRAVY;
  2365.                             Screen_Transition(SCREEN_DARKNESS);
  2366.                             done = TRUE;
  2367.                             break;
  2368.                         case 3:
  2369.                             for (index=0; index<20; index++)
  2370.                             {
  2371.                                 // loop thru all palette registers
  2372.  
  2373.                                 for (pal_reg=0; pal_reg<256; pal_reg++)
  2374.                                 {
  2375.                                     Read_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2376.                                     // get the color to fade
  2377.                                     color.green+=4;
  2378.                                     color.red+=4;
  2379.  
  2380.                                     if (color.green > 63)
  2381.                                         color.green = 63;
  2382.  
  2383.                                     if (color.red > 63)
  2384.                                         color.red = 63;
  2385.  
  2386.                                     // set the color to a brightend intensity
  2387.  
  2388.                                     Write_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2389.                                 } // end for pal_reg
  2390.  
  2391.                                 // wait a bit
  2392.  
  2393.                                 Time_Delay(1);
  2394.  
  2395.                             } // end for index
  2396.                             difficulty = TOUGH_AS_SHIT;
  2397.                             Screen_Transition(SCREEN_DARKNESS);
  2398.                             done = TRUE;
  2399.                             break;
  2400.                         case 4:
  2401.                             for (index=0; index<20; index++)
  2402.                             {
  2403.                                 // loop thru all palette registers
  2404.  
  2405.                                 for (pal_reg=0; pal_reg<256; pal_reg++)
  2406.                                 {
  2407.                                     Read_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2408.                                     // get the color to fade
  2409.                                     color.red+=4;
  2410.  
  2411.                                     if (color.red > 63)
  2412.                                         color.red = 63;
  2413.  
  2414.                                     // set the color to a brightend intensity
  2415.  
  2416.                                     Write_Color_Reg(pal_reg,(RGB_color_ptr)&color);
  2417.                                 } // end for pal_reg
  2418.  
  2419.                                 // wait a bit
  2420.  
  2421.                                 Time_Delay(1);
  2422.  
  2423.                             } // end for index
  2424.                             difficulty = A_FARTS_CHANCE;
  2425.                             Screen_Transition(SCREEN_DARKNESS);
  2426.                             done = TRUE;
  2427.                             break;
  2428.                     }
  2429.                 }
  2430.             }
  2431.  
  2432.             if (redraw)
  2433.             {
  2434.                 // erase sprite at old position
  2435.                 Sprite_Erase((sprite_ptr)&shell, video_buffer);
  2436.                 // scan the background at new postition
  2437.                 Sprite_Under((sprite_ptr)&shell, video_buffer);
  2438.                 // draw sprite at new position
  2439.                 Sprite_Draw((sprite_ptr)&shell, video_buffer, 1);
  2440.                 // update old position
  2441.                 shell.y_old = shell.y;
  2442.                 Time_Delay(3);
  2443.                 redraw = 0;
  2444.             } // end if sprites needed to be redrawn
  2445.         } //end while(done != 1)
  2446. }
  2447.  
  2448. void makeHarder (int * xptr, int * yptr)
  2449. {
  2450.  
  2451.     int bogusShip, bogusGuess, done = FALSE;
  2452.     int randEdge;
  2453.     
  2454.     switch(difficulty)
  2455.         {
  2456.         case 1:
  2457.             *xptr = rand() % 12;
  2458.             *yptr = rand() % 12;
  2459.             break;
  2460.  
  2461.         case 2:
  2462.             while(done == FALSE)
  2463.             {
  2464.                 *xptr = rand() % 12;
  2465.                 *yptr = rand() % 12;
  2466.  
  2467.                 if((*xptr == 0 || *xptr == 12) || (*yptr == 0 || *yptr == 12))
  2468.                 {
  2469.                     if((randEdge = rand() % 4) == 1)
  2470.                     {
  2471.                         done = TRUE;
  2472.                         continue;
  2473.                     }
  2474.                 }
  2475.                 done = TRUE;
  2476.             }
  2477.             break;
  2478.  
  2479.         case 3:
  2480.             bogusGuess = rand() % 14;
  2481.             if (bogusGuess == 0)
  2482.                 {
  2483.                 do
  2484.                  {
  2485.                     bogusShip = rand() % 4;
  2486.                     }
  2487.                 while (gGrid[userShip[bogusShip].x]
  2488.                         [userShip[bogusShip].y].beenShotAt == TRUE);
  2489.                 *xptr = userShip[bogusShip].coveredSquare1.x;
  2490.                 *yptr = userShip[bogusShip].coveredSquare1.y;
  2491.                 }                    
  2492.             else
  2493.                 { 
  2494.                 *xptr = rand() % 12;
  2495.                 *yptr = rand() % 12;
  2496.                 }
  2497.             break;
  2498.  
  2499.         case 4:
  2500.             bogusGuess = rand() % 8;
  2501.             if (bogusGuess == 0)
  2502.                 {
  2503.                 do
  2504.                     {
  2505.                     bogusShip = rand() % 4;
  2506.                     }
  2507.                 while (gGrid[userShip[bogusShip].x]
  2508.                         [userShip[bogusShip].y].beenShotAt == TRUE);
  2509.                 *xptr = userShip[bogusShip].coveredSquare1.x;
  2510.                 *yptr = userShip[bogusShip].coveredSquare1.y;
  2511.                 }                    
  2512.             else
  2513.                 { 
  2514.                 *xptr = rand() % 12;
  2515.                 *yptr = rand() % 12;
  2516.                 }
  2517.             break;
  2518.  
  2519.         case 5:
  2520.             do
  2521.                 {
  2522.                 bogusShip = rand() % 4;
  2523.                 }
  2524.             while (gGrid[userShip[bogusShip].x]
  2525.                         [userShip[bogusShip].y].beenShotAt == TRUE);
  2526.             *xptr = userShip[bogusShip].coveredSquare1.x;
  2527.             *yptr = userShip[bogusShip].coveredSquare1.y;
  2528.         }
  2529. }
  2530.