วันพุธที่ 15 ตุลาคม พ.ศ. 2557
Lab 4 - Draw Board Game (Mark Horse)
int MaxRow=8,MaxColumn=8;
int[][] HorseP1 = new int[MaxRow][MaxColumn];
int[][] HorseP2 = new int[MaxRow][MaxColumn];
void setup(){
size(400,400);
//MaxColumn = number of vertical line , MaxRow = number of horizontal line
color black=color(0),white=color(255),red=color(255,0,0),blue=color(5,255,255);
DrawBoard(MaxRow,MaxColumn,black,white);
ResetBoard(HorseP1,HorseP2);
DrawAllHorse(HorseP1,HorseP2,red,blue);
}
void DrawBoard(int R,int C,color Color1,color Color2){
color FillColor=Color1;
for(int r=0;r<R;r++){
for(int c=0;c<C;c++){
if((c%2)==(r%2)){
FillColor = Color1;
}
else{
FillColor = Color2;
}
fill(FillColor);
rect(c*(width/C),r*(height/R),width/C,height/R);
}
}
}
void ResetBoard(int[][] P1,int[][] P2){
//Reset All
for(int r=0;r<MaxRow;r++){
for(int c=0;c<MaxColumn;c++){
P1[r][c] = 0;
P2[r][c] = 0;
}
}
//Add P1
for(int r=0;r<=1;r++){
for(int c=0+r;c<P1[r].length;c=c+2){
P1[r][c] = 1;
}
}
//Add P2
for(int r=0;r<=1;r++){
for(int c=0+r;c<P2[r+MaxRow-2].length;c=c+2){
P2[r+MaxRow-2][c] = 1;
}
}
}
void DrawHorse(int x,int y,color c){
fill(c);
ellipse(x,y,(width/MaxColumn)-10,(height/MaxRow)-10);
}
void DrawAllHorse(int[][] P1,int[][] P2,color CP1,color CP2){
for(int r=0;r<MaxRow;r++){
for(int c=0;c<MaxColumn;c++){
if(P1[r][c]==1){
DrawHorse((c*(width/MaxColumn))+(width/(2*MaxColumn)),(r*(height/MaxRow))+(height/(2*MaxRow)),CP1);
}
if(P2[r][c]==1){
DrawHorse((c*(width/MaxColumn))+(width/(2*MaxColumn)),(r*(height/MaxRow))+(height/(2*MaxRow)),CP2);
}
}
}
}