Click here to Skip to main content
12,507,596 members (81,263 online)

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy except programming questions.

Technical discussions are encouraged, but click here to ask your programming question.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
GeneralRe: Chinese hackers! Pin
Chris Losinger10-Jan-13 11:52
memberChris Losinger10-Jan-13 11:52 
GeneralRe: Chinese hackers! Pin
AspDotNetDev10-Jan-13 11:58
protectorAspDotNetDev10-Jan-13 11:58 
GeneralRe: Chinese hackers! Pin
Roger Wright10-Jan-13 18:01
memberRoger Wright10-Jan-13 18:01 
GeneralRe: Chinese hackers! Pin
Roger Wright10-Jan-13 17:59
memberRoger Wright10-Jan-13 17:59 
GeneralRe: Chinese hackers! Pin
Mark_Wallace10-Jan-13 20:31
memberMark_Wallace10-Jan-13 20:31 
GeneralRe: Chinese hackers! Pin
Mark_Wallace10-Jan-13 20:50
memberMark_Wallace10-Jan-13 20:50 
GeneralRe: Chinese hackers! Pin
Marco Bertschi11-Jan-13 1:17
memberMarco Bertschi11-Jan-13 1:17 
GeneralThe first descent code I wrote in my life Pin
Vasily Tserekh10-Jan-13 6:57
memberVasily Tserekh10-Jan-13 6:57 
This is the first descent code I wrote when I began to make programs, it was in C++
Is about an algorithm to arrangle ships in a classic battleship game, first funcion is to check if a ship can be placed at x;y second is for placing the ship and 3th was for placing all the ships. I was so amazed that the code worked that I felt a joy I only felt few times since then.
How about you


//------Check if in square X;Y a ship can be placed------------------

/* x,y: Board coordinates
   Size: Ship size
   Pos: posicion (1 horizontal vertical)
   board: board number
*/
bool TGame::Free(int x,int y,int size,int pos,int board )
{
int ship[7];
int side1[7];
int side2[7];
 bool answer=true;
 if(aBoard[board]->GetInfo(x,y)!=0)
   {
    return answer=false;
   }
 if (pos==1)
  {
   for(int i=0;i<size+2;i++)
    {ship[i]=aBoard[board]->GetInfo(x-1+i,y);
     side1[i]=aBoard[board]->GetInfo(x-1+i,y-1);
     side2[i]=aBoard[board]->GetInfo(x-1+i,y+1);
    }
   }
 
 else
  { for(int i=0;i<size+2;i++)
    {ship[i]=aBoard[board]->GetInfo(x,y-1+i);
     side1[i]=aBoard[board]->GetInfo(x-1,y-1+i);
     side2[i]=aBoard[board]->GetInfo(x+1,y-1+i);
    }
  }
 if (x==0 && pos==1)
  {ship[0]=0;
   side1[0]=0;
   side2[0]=0;
 
  }
   for (int i=0;i<size+2;i++)
    {if (ship[i]!= 0)answer=false;
     if (side1[i]!= 0)answer=false;
     if (side2[i]!= 0)answer=false;
    }
 return answer;
 }
//------Place a ship in the board-------------------------------------

/* Size: Ship size
   board: Board
   Ship: Place of the ship in the ship array
   Type: ship type
*/
 void TGame:: RandomShip(int size,int type,int board,int ship)
{
    int pos=random(2);
    randomize();
    int x,y;
    bool answer=false; ;
    if (pos==1)
      {
      while (answer==false)
        {
          x=random(11)-size;
          while(x<0)
           {x=random(11)-size;
           }
          y=random(15);
          answer=Free(x,y,size,pos,board);
        }
         for(int i=0;i<size;i++)
        {aBoard[board]->SetInfo(x+i,y,type);
        }
       }
     else
       {
       while (answer==false)
         {
          x=random(10);
          y=random(16)-size;
          while(y<0)
           {y=random(16)-size;
           }
          answer=Free(x,y,size,pos,board);
         }
       for(int i=0;i<size;i++)
          {aBoard[board]->SetInfo(x,y+i,type);
          }
       }
if(board==0)
{
int ax=Transform(x);
int ay=Transform(y);
aPosXY[ship].x=ax;
aPosXY[ship].y=ay;
aPosXY[ship].pos=pos;
}
 
}
//----Posiciona todos los barcos en el tablero------------------------------

 void TGame::RandomAllocation(int board)
 {
   RandomShip(5,6,board,0);
   RandomShip(4,5,board,1);
   RandomShip(3,4,board,2);
   RandomShip(3,3,board,3);
   RandomShip(2,2,board,4);
   RandomShip(2,1,board,5);
 }
//---------------------------------------------------------------------------

GeneralRe: The first descent code I wrote in my life Pin
Richard Deeming10-Jan-13 7:11
memberRichard Deeming10-Jan-13 7:11 
GeneralRe: The first descent code I wrote in my life Pin
mla15410-Jan-13 7:24
membermla15410-Jan-13 7:24 
GeneralRe: The first descent code I wrote in my life Pin
Member 460889812-Jan-13 22:52
memberMember 460889812-Jan-13 22:52 
GeneralRe: The first descent code I wrote in my life Pin
Roger Wright10-Jan-13 7:12
memberRoger Wright10-Jan-13 7:12 
GeneralRe: The first descent code I wrote in my life Pin
Gary Wheeler10-Jan-13 8:11
memberGary Wheeler10-Jan-13 8:11 
GeneralRe: The first descent code I wrote in my life Pin
Roger Wright10-Jan-13 8:26
memberRoger Wright10-Jan-13 8:26 
GeneralRe: The first descent code I wrote in my life Pin
Gary Wheeler10-Jan-13 8:35
memberGary Wheeler10-Jan-13 8:35 
GeneralRe: The first descent code I wrote in my life Pin
Roger Wright10-Jan-13 9:49
memberRoger Wright10-Jan-13 9:49 
GeneralRe: The first descent code I wrote in my life Pin
Gary Wheeler10-Jan-13 10:16
memberGary Wheeler10-Jan-13 10:16 
GeneralRe: The first descent code I wrote in my life Pin
Roger Wright10-Jan-13 10:35
memberRoger Wright10-Jan-13 10:35 
GeneralRe: The first descent code I wrote in my life Pin
Mathlab10-Jan-13 7:15
memberMathlab10-Jan-13 7:15 
GeneralRe: The first descent code I wrote in my life Pin
Ravi Bhavnani10-Jan-13 7:16
memberRavi Bhavnani10-Jan-13 7:16 
GeneralRe: The first descent code I wrote in my life Pin
MehGerbil10-Jan-13 7:24
memberMehGerbil10-Jan-13 7:24 
GeneralRe: The first descent code I wrote in my life Pin
Chris Maunder10-Jan-13 9:44
adminChris Maunder10-Jan-13 9:44 
GeneralRe: The first descent code I wrote in my life Pin
_Maxxx_10-Jan-13 10:09
member_Maxxx_10-Jan-13 10:09 
GeneralRe: The first descent code I wrote in my life Pin
Vasily Tserekh10-Jan-13 10:13
memberVasily Tserekh10-Jan-13 10:13 
GeneralRe: The first descent code I wrote in my life Pin
PIEBALDconsult10-Jan-13 7:56
memberPIEBALDconsult10-Jan-13 7:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.160927.1 | Last Updated 28 Sep 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid