Author: Anonymous Language: text
Description: No description Timestamp: 2008-11-20 10:22:30 -0400
View raw paste Reply
  1. #include<iostream.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5. char Board[10][10]=
  6.         {
  7.                 '+','+','+','+','+','+','+','+','+',' ',
  8.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  9.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  10.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  11.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  12.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  13.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  14.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  15.                 '+',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  16.                 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' '
  17.         };
  18.  
  19. class Starlight
  20. {
  21. private:
  22.         int numstars;
  23. public:
  24.         Starlight();
  25.         void Intro();
  26.         void Placestars();
  27.         void Countem();
  28.         void Showboard();
  29.         void Clearboard();
  30. };
  31.  
  32.  
  33. Starlight::Starlight()
  34. {
  35.         numstars=0;
  36. }
  37.  
  38.  
  39. void Starlight::Intro()
  40. {
  41.         cout<<" ________________________________________________________ "<<endl;
  42.         cout<<"| Welcome to Starlight                                   |"<<endl;
  43.         cout<<"|--------------------------------------------------------|"<<endl;
  44.         cout<<"|                                                        |"<<endl;
  45.         cout<<"|                                                        |"<<endl;
  46.         cout<<"|                                                        |"<<endl;
  47.         cout<<"|                                                        |"<<endl;
  48.         cout<<"|                                                        |"<<endl;
  49.         cout<<"|                                                        |"<<endl;
  50.         cout<<"|                                                        |"<<endl;
  51.         cout<<"| Good luck                                              |"<<endl;
  52.         cout<<"|________________________________________________________|"<<endl;
  53.         cout<<endl;
  54.         system("pause");
  55.         system("cls");
  56.  
  57. }
  58.  
  59. void Starlight::Placestars()
  60. {
  61.         for (int a=1;a<9;a++)
  62.         {
  63.                 for (int b=1;b<9;b++)
  64.                 {
  65.                         int temp=rand()%8;
  66.  
  67.                         if (temp<2)
  68.                                 Board[a][b]=48;
  69.                         else
  70.                         {
  71.                                 int temp=rand()%9+48;
  72.                                 Board[a][b]=temp;
  73.                         }
  74.  
  75.                 }
  76.                 cout<<endl;
  77.         }
  78. }
  79.  
  80. void Starlight::Countem()
  81. {
  82.         for (int a=1;a<9;a++)
  83.         {
  84.                 for (int b=1;b<9;b++)
  85.                 {
  86.                         int temp=0;
  87.  
  88.                         if(a==1 && b==1)
  89.                                 temp=(Board[a][b]+Board[a][b+1]+Board[a+1][b])-(48*3);
  90.                         else if(a==1 && b==8)
  91.                                 temp=(Board[a][b]+Board[a][b-1]+Board[a+1][b])-(48*3);
  92.                         else if(a==8 && b==1)
  93.                                 temp=(Board[a][b]+Board[a-1][b]+Board[a][b+1])-(48*3);
  94.                         else if(a==8 && b==8)
  95.                                 temp=(Board[a][b]+Board[a][b-1]+Board[a-1][b])-(48*3);
  96.  
  97.                         else if(a==1 && b!=1 && b!=8)
  98.                                 temp=(Board[a][b]+Board[a][b-1]+Board[a][b+1]+Board[a+1][b])-(48*4);
  99.                         else if(a==8 && b!=8 && b!=1)
  100.                                 temp=(Board[a][b]+Board[a][b-1]+Board[a][b+1]+Board[a-1][b])-(48*4);
  101.                         else if(a!=8 && a!=1 && b==1)
  102.                                 temp=(Board[a-1][b]+Board[a+1][b]+Board[a][b+1]+Board[a][b])-(48*4);
  103.                         else if(a!=8 && a!=1 && b==8)
  104.                                 temp=(Board[a-1][b]+Board[a+1][b]+Board[a][b-1]+Board[a][b])-(48*4);
  105.  
  106.                         else
  107.                                 temp=(Board[a][b]+Board[a-1][b]+Board[a+1][b]+Board[a][b+1]+Board[a][b-1])-(48*5);
  108.  
  109.                                
  110.                         if(temp/5>4)
  111.                         {
  112.                                 Board[a][b]='*';
  113.                                 numstars++;
  114.                         }
  115.        
  116.                 }
  117.         }
  118.         cout<<numstars<<" stars found"<<endl;
  119. }
  120.  
  121. void Starlight::Showboard()
  122. {
  123.         for (int a=0;a<10;a++)
  124.         {
  125.                 for (int b=0;b<10;b++)
  126.                 {
  127.                         cout<<Board[a][b]<<" ";
  128.                 }
  129.                 cout<<endl;
  130.         }
  131.  
  132. }
  133.  
  134. void Starlight::Clearboard()
  135. {
  136.         for (int a=0;a<10;a++)
  137.         {
  138.                 for (int b=0;b<10;b++)
  139.                 {
  140.                         if (Board[a][b]!='*' && Board[a][b]!='+')
  141.                         {
  142.                                 Board[a][b]=' ';
  143.                         }
  144.                 }
  145.         }
  146.  
  147. }
  148.  
  149. int main()
  150. {
  151. srand(time(0));
  152.  
  153. Starlight thissearch;
  154.  
  155. thissearch.Intro();
  156. thissearch.Placestars();
  157. system("cls");
  158. thissearch.Showboard();
  159. thissearch.Countem();
  160. cout<<endl;
  161. thissearch.Clearboard();
  162. thissearch.Showboard();
  163.  
  164.  
  165.         return 0;
  166. }
View raw paste Reply