Shorter code for this? :S - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Shorter code for this? :S (/showthread.php?tid=71627)
Shorter code for this? :S by albert on 02-11-2007 at 04:16 PM
I have a little problem with this code.
Basicly it's a array (I think that's how it's called in english, in french it's tableau, well it's some kind of table for programming that you can put date in..)
Anyhow, I'm doing this Othello game, and I'm quite sure there's an easier way to code this, but I can't seem to find a solution.
Here's the current code :
code: for ( compteurColonnes = 0 ; compteurColonnes < 10 ; compteurColonnes ++ )
for ( compteurRangees = 0 ; compteurRangees < 10 ; compteurRangees ++)
othellier[compteurColonnes][compteurRangees]= '~' ;
othellier[0][0]= ' ' ;
othellier[0][1]= 'A' ;
othellier[0][2]= 'B' ;
othellier[0][3]= 'C' ;
othellier[0][4]= 'D' ;
othellier[0][5]= 'E' ;
othellier[0][6]= 'F' ;
othellier[0][7]= 'G' ;
othellier[0][8]= 'H' ;
othellier[0][9]= ' ' ;
othellier[9][0]= ' ' ;
othellier[9][1]= 'A' ;
othellier[9][2]= 'B' ;
othellier[9][3]= 'C' ;
othellier[9][4]= 'D' ;
othellier[9][5]= 'E' ;
othellier[9][6]= 'F' ;
othellier[9][7]= 'G' ;
othellier[9][8]= 'H' ;
othellier[9][9]= ' ' ;
othellier[0][0]= ' ' ;
othellier[1][0]= '1' ;
othellier[2][0]= '2' ;
othellier[3][0]= '3' ;
othellier[4][0]= '4' ;
othellier[5][0]= '5' ;
othellier[6][0]= '6' ;
othellier[7][0]= '7' ;
othellier[8][0]= '8' ;
othellier[9][0]= ' ' ;
othellier[0][9]= ' ' ;
othellier[1][9]= '1' ;
othellier[2][9]= '2' ;
othellier[3][9]= '3' ;
othellier[4][9]= '4' ;
othellier[5][9]= '5' ;
othellier[6][9]= '6' ;
othellier[7][9]= '7' ;
othellier[8][9]= '8' ;
othellier[9][9]= ' ' ;
the code is in java, but i think anyone with a little programming skills can understand it
and i have tried making a few "for"s with the numbers.. but the problem is that the array in "char" since I have to represent black by * and white by -
so.. yeah,.. anyhelp would be appreciated.
RE: Shorter code for this? :S by Jesus on 02-11-2007 at 04:29 PM
well, IIRC, this code:
code: othellier[0][0]= ' ' ;
othellier[0][1]= 'A' ;
othellier[0][2]= 'B' ;
othellier[0][3]= 'C' ;
othellier[0][4]= 'D' ;
othellier[0][5]= 'E' ;
othellier[0][6]= 'F' ;
othellier[0][7]= 'G' ;
othellier[0][8]= 'H' ;
othellier[0][9]= ' ' ;
othellier[9][0]= ' ' ;
othellier[9][1]= 'A' ;
othellier[9][2]= 'B' ;
othellier[9][3]= 'C' ;
othellier[9][4]= 'D' ;
othellier[9][5]= 'E' ;
othellier[9][6]= 'F' ;
othellier[9][7]= 'G' ;
othellier[9][8]= 'H' ;
othellier[9][9]= ' ' ;
can be replaced with this
code: othellier[0]=new Array(' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', ' ');
othellier[9]=new Array(' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', ' ');
not too sure though...
does your own code work?
RE: Shorter code for this? :S by albert on 02-11-2007 at 04:34 PM
Jesus, thanks for the help but shawnz has given me a good idea
put the labels outside the array.
Should fix it.
RE: Shorter code for this? :S by vikke on 02-11-2007 at 05:56 PM
I don't know Java but you could do:
code: var Alph = " ABCDEFGH";
for(var i;i=0;i<Alph.length){
othellier[0][i] = Alph.charAt;
othellier[9][i] = Alph.charAt;
}
etc.
Edit: removed smileys from post which would appear in the code sample
RE: Shorter code for this? :S by RaceProUK on 02-11-2007 at 09:53 PM
code: String Alph = " ABCDEFGH";
for(int i; i = 0; i < Alph.length){
othellier[0][i] = Alph.charAt(i);
othellier[9][i] = Alph.charAt(i);
}
var doesn't exist in Java.
RE: Shorter code for this? :S by vikke on 02-12-2007 at 11:16 AM
I said I didn't know java .
RE: Shorter code for this? :S by RaceProUK on 02-13-2007 at 04:59 PM
I know, but hopefully you know a tiny bit of it now
|