Jump to content

  • Log In with Google      Sign In   
  • Create Account

dtkaos

Member Since 16 Feb 2012
Offline Last Active Jul 03 2013 11:21 PM

Posts I've Made

In Topic: GO home viking raiders "your drunk"

24 June 2013 - 05:33 PM

Doesn't beat my wonderful "String to Char" function I designed back in 2008. A masterpiece. With original comments!

 

function StrToChr(S: String): Char;  // Fonction pour transformer un String en Char
begin                                // Je n'en disposait pas de préfaite... si vous connaissez un
     if UpperCase(S) = 'A' then Result := 'A';    // moyen plus rapide, faites le moi savoir :)
     if UpperCase(S) = 'B' then Result := 'B';
     if UpperCase(S) = 'C' then Result := 'C';
     if UpperCase(S) = 'D' then Result := 'D';
     if UpperCase(S) = 'E' then Result := 'E';
     if UpperCase(S) = 'F' then Result := 'F';
     if UpperCase(S) = 'G' then Result := 'G';
     if UpperCase(S) = 'H' then Result := 'H';
     if UpperCase(S) = 'I' then Result := 'I';
     if UpperCase(S) = 'J' then Result := 'J';
     if UpperCase(S) = 'K' then Result := 'K';
     if UpperCase(S) = 'L' then Result := 'L';
     if UpperCase(S) = 'M' then Result := 'M';
     if UpperCase(S) = 'N' then Result := 'N';
     if UpperCase(S) = 'O' then Result := 'O';
     if UpperCase(S) = 'P' then Result := 'P';
     if UpperCase(S) = 'Q' then Result := 'Q';
     if UpperCase(S) = 'R' then Result := 'R';
     if UpperCase(S) = 'S' then Result := 'S';
     if UpperCase(S) = 'T' then Result := 'T';
     if UpperCase(S) = 'U' then Result := 'U';
     if UpperCase(S) = 'V' then Result := 'V';
     if UpperCase(S) = 'W' then Result := 'W';
     if UpperCase(S) = 'X' then Result := 'X';
     if UpperCase(S) = 'Y' then Result := 'Y';
     if UpperCase(S) = 'Z' then Result := 'Z';
end;

Actually I enumerated the alphabet at least three times in the code (hangman game, if you must know).

 

At least this is self-documenting, in a redundant kind of way ph34r.png

 

 

That's awesome! I use java and the first thing in my mind is a string to lowercase(or uppercase) then thake that string to to char array would solved have that problem.

 

My very first code was c# to back in 2004? I was like 14 and I only messed around with c# for 2 weeks but it was  a series of dialogbox not in a loop. I literally copy and pasted that many lines of code and I tought it was haularious to have people click the first one thinking it would go away.


In Topic: Separate two colliding rectangles

23 June 2013 - 08:05 PM

My first question is do you have any type of collision in place at the moment? If so, let take a look at the code; if not I would google some collision detection basics. Easiest way to make the objects repel is to multiply their velocity by -1 so it reverses the direction. 

 

I think some code example will help determine more of what is going on.


In Topic: GO home viking raiders "your drunk"

23 June 2013 - 07:28 PM

Tip for your code. Within the switch call methods/functions instead of having the code display there. It will clean it up nice!  If you notice you are repeating yourself... create a method becuase the further you get the more the code blurs together. If you need to change a value... you are going to have to change it 9 times ... I know you don't want to do that. :)

 

Also for the switch statments, use a variable name that has some meaning so when you go back to look at it  say something meaningful like

private static final int DOWN = 0;
private static final int UP = 1;

switch(DIRECTION){

   case DOWN: 
            moveDown();
            break;
    
    case UP:
           moveUp();
           break;

     default:
            System.out.println("Doing something in default, Always good pratice to have a default");
            break;
}

private void moveDown(){
         // move that code from the switch statement here 
}

private void moveUp(){
       //move that code from the switch statement here
}

However,

My first game code was pretty rubish. While yours is nice a neat I do belever everything I wrote was declared public and condensed to one file haha. Felt like a lot of code at the time but I believe it was only 50 -100 lines and I have work projects that spread thousands of line that are easier to read then it was. haha


PARTNERS