Difference between revisions of "Assessment 2008 Hard"
(→Monopoly) |
|||
(32 intermediate revisions by the same user not shown) | |||
Line 26: | Line 26: | ||
</shell> | </shell> | ||
==Fanorona== | ==Fanorona== | ||
− | <question className='Raster' imgOut='flag.png' copyFile='fanorona.png' width=' | + | <question className='Raster' imgOut='flag.png' copyFile='fanorona.png' width='184' height='104'> |
[[Image:fanorona.png|frame|Fanorona]] | [[Image:fanorona.png|frame|Fanorona]] | ||
− | *The separation is | + | *The separation is 20 |
− | *The disks have radius | + | *The disks have radius 6 |
− | *The background is | + | *The background is 184x104 |
+ | *The blue is 64,64,255 | ||
<prog> | <prog> | ||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
} | } | ||
</prog> | </prog> | ||
− | <answer> | + | <answer><![CDATA[ |
+ | //This answer is way too complicated :( mant students came up with | ||
+ | //better solutions. | ||
+ | static int s=20; | ||
+ | static int off=12; | ||
+ | static int r = 6; | ||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
− | + | g.setColor(new Color(64,64,255)); | |
− | + | g.fillRect(off,off,8*s,4*s); | |
− | + | g.setColor(Color.black); | |
− | + | g.translate(off,off); | |
− | g. | + | for (int i=-4;i<8;i++) |
− | } | + | g.drawLine(Math.max(0,i*s),Math.max(0,-i*s), |
+ | Math.min(i*s+4*s,8*s),Math.min(4*s,(8-i)*s)); | ||
+ | for (int i=0;i<12;i++) | ||
+ | g.drawLine(Math.min(i*s,8*s), | ||
+ | Math.max(0,(i-8)*s), | ||
+ | //Math.max(i*s,0),0,//Math.max(0,i*s), | ||
+ | Math.max(i*s-4*s,0),Math.min(i*s,4*s)); | ||
+ | g.setColor(Color.white); | ||
+ | g.setColor(Color.black); | ||
+ | for (int i=0;i<9;i++){ | ||
+ | g.drawLine(i*s,0,i*s,4*s); | ||
+ | } | ||
+ | for (int i=0;i<5;i++){ | ||
+ | g.drawLine(0,i*s,8*s,i*s); | ||
+ | } | ||
+ | g.setRenderingHint( | ||
+ | RenderingHints.KEY_ANTIALIASING, | ||
+ | RenderingHints.VALUE_ANTIALIAS_ON); | ||
+ | for (int i=0;i<9;i++) | ||
+ | for (int j=0;j<5;j++){ | ||
+ | if (j<2||(j==2 && (i==0||i==2||i==5||i==7))){ | ||
+ | g.setColor(Color.black); | ||
+ | g.fillOval(-r+i*s,-r+j*s,2*r,2*r); | ||
+ | } | ||
+ | if (j>2||(j==2 && (i==1||i==3||i==6||i==8))) { | ||
+ | g.setColor(Color.white); | ||
+ | g.fillOval(-r+i*s,-r+j*s,2*r,2*r); | ||
+ | g.setColor(Color.black); | ||
+ | g.drawOval(-r+i*s,-r+j*s,2*r,2*r); | ||
+ | } | ||
+ | } | ||
} | } | ||
− | </answer> | + | ]]></answer> |
</question> | </question> | ||
− | |||
==Snakes and Ladders== | ==Snakes and Ladders== | ||
− | <question className='Raster' imgOut='flag.png' copyFile='snakes_and_ladders.png' width=' | + | <question className='Raster' imgOut='flag.png' copyFile='snakes_and_ladders.png' width='241' height='241'> |
[[Image:snakes_and_ladders.png|frame|Snakes and Ladders]] | [[Image:snakes_and_ladders.png|frame|Snakes and Ladders]] | ||
*The squares are 24 | *The squares are 24 | ||
− | *The background is | + | *The background is 241x241 |
<prog> | <prog> | ||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
} | } | ||
</prog> | </prog> | ||
− | <answer> | + | <answer><![CDATA[ |
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
− | + | int d=24; | |
− | + | g.setColor(Color.black); | |
− | + | for (int i=0;i<10;i++){ | |
− | + | for (int j=0;j<10;j++){ | |
− | + | g.drawRect(i*d,j*d,d,d); | |
− | + | int k = 1+10*(9-j)+((j%2==1)?i:(9-i)); | |
+ | g.drawString(""+k,i*d,j*d+d); | ||
+ | } | ||
+ | } | ||
} | } | ||
− | </answer> | + | ]]></answer> |
</question> | </question> | ||
− | |||
==Ludo== | ==Ludo== | ||
Line 74: | Line 111: | ||
[[Image:ludo.png|frame|Ludo]] | [[Image:ludo.png|frame|Ludo]] | ||
*The background is 256x256 | *The background is 256x256 | ||
+ | *The gray is 228, 228, 228 | ||
<prog> | <prog> | ||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
} | } | ||
</prog> | </prog> | ||
− | <answer> | + | <answer><![CDATA[ |
+ | static int d = 16; | ||
+ | static void quarter(Graphics2D g,Color c){ | ||
+ | //This list of coordinates is describe square with a | ||
+ | //square cut out of it. Start in the middle top, go | ||
+ | //around the outside of the outer square then round | ||
+ | //the inner square | ||
+ | int x[] = new int[] {1,0,0,2,2,1,0,1,2}; | ||
+ | int y[] = new int[] {0,0,2,2,0,0,1,2,1}; | ||
+ | Polygon p = new Polygon(); | ||
+ | for (int i=0;i<x.length;i++) | ||
+ | p.addPoint(3*d*x[i],3*d*y[i]); | ||
+ | g.setColor(c); | ||
+ | g.fillPolygon(p); | ||
+ | g.fillRect(d,6*d,d,2*d); | ||
+ | g.fillRect(2*d,7*d,4*d,d); | ||
+ | Polygon t =new Polygon(new int[]{6*d,6*d,15*d/2}, | ||
+ | new int[]{6*d,9*d,15*d/2},3); | ||
+ | g.fillPolygon(t); | ||
+ | g.setColor(Color.black); | ||
+ | g.drawPolygon(p); | ||
+ | g.drawPolygon(t); | ||
+ | for (int i=0;i<7;i++) | ||
+ | g.drawLine(i*d,6*d,i*d,9*d); | ||
+ | for (int i=0;i<4;i++) | ||
+ | g.drawLine(0,6*d+d*i,6*d,6*d+d*i); | ||
+ | } | ||
+ | |||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
− | + | g.translate(8,8); | |
− | + | g.setColor(new Color(228,228,228)); | |
− | + | g.fillRect(0,0,15*d,15*d); | |
− | + | for (Color c:new Color[]{Color.green,Color.yellow, | |
− | g. | + | Color.blue, Color.red}){ |
− | + | quarter(g,c); | |
+ | g.translate(0,15*d); | ||
+ | g.rotate(-Math.PI/2); | ||
+ | } | ||
} | } | ||
− | </answer> | + | ]]></answer> |
</question> | </question> | ||
− | |||
==Cards== | ==Cards== | ||
− | <question className='Raster' imgOut='flag.png' copyFile='cards.png' width=' | + | <question className='Raster' imgOut='flag.png' copyFile='cards.png clubs.png diamonds.png hearts.png spades.png' width='448' height='270'> |
+ | *The background is 448x270 | ||
+ | *The cards are 40 by 60 | ||
+ | *The radius of the rounded corners is 8 | ||
+ | *There is a gap of 4 between the cards | ||
+ | *Each suit image (e.g. clubs.png) is 16x16 | ||
+ | *The corner image is 13x20 from the centre of the card | ||
+ | *If you want to work outside progzoo you can get the images: http://progzoo.net/hearts.png http://progzoo.net/clubs.png http://progzoo.net/diamonds.png http://progzoo.net/spades.png | ||
[[Image:cards.png|frame|Deck of Cards]] | [[Image:cards.png|frame|Deck of Cards]] | ||
− | |||
<prog> | <prog> | ||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
+ | BufferedImage img= new BufferedImage(16,16, | ||
+ | BufferedImage.TYPE_INT_ARGB); | ||
+ | try{ | ||
+ | img = (BufferedImage)ImageIO.read(new File("diamonds.png")); | ||
+ | g.drawImage(img,10,10,null); | ||
+ | img = (BufferedImage)ImageIO.read(new File("clubs.png")); | ||
+ | g.drawImage(img,20,10,null); | ||
+ | img = (BufferedImage)ImageIO.read(new File("hearts.png")); | ||
+ | g.drawImage(img,14,20,null); | ||
+ | img = (BufferedImage)ImageIO.read(new File("spades.png")); | ||
+ | g.drawImage(img,24,20,null); | ||
+ | } catch (Exception ex) {} | ||
} | } | ||
</prog> | </prog> | ||
− | <answer> | + | <answer><![CDATA[ |
+ | static void doubleTB(Graphics2D g,int x,int y,BufferedImage img){ | ||
+ | g.translate(x,y); | ||
+ | g.drawImage(img,-8,-8,null); | ||
+ | g.translate(-x-x,-y-y); | ||
+ | g.rotate(Math.PI); | ||
+ | g.drawImage(img,-8,-8,null); | ||
+ | g.rotate(-Math.PI); | ||
+ | g.translate(x,y); | ||
+ | } | ||
+ | |||
+ | static void fillOff(Graphics2D g,int x,int y,BufferedImage img){ | ||
+ | g.translate(x,y); | ||
+ | g.drawImage(img,-8,-8,null); | ||
+ | g.translate(-x,-y); | ||
+ | } | ||
+ | |||
+ | static void pips(Graphics2D g,int x,int y,int n,BufferedImage img){ | ||
+ | int w=4; int h=6; | ||
+ | int tl = 20;int rl=13; | ||
+ | g.translate(x,y); | ||
+ | if (n==1||n==3||n==5||n==9) | ||
+ | g.drawImage(img,-8,-8,null); | ||
+ | if (n==2||n==3) | ||
+ | doubleTB(g,0,tl,img); | ||
+ | if (n>3){ | ||
+ | doubleTB(g,rl,tl,img); | ||
+ | doubleTB(g,-rl,tl,img); | ||
+ | } | ||
+ | if (n==6||n==7||n==8){ | ||
+ | fillOff(g,rl,0,img); | ||
+ | fillOff(g,-rl,0,img); | ||
+ | } | ||
+ | if (n==7) | ||
+ | fillOff(g,0,-tl/2,img); | ||
+ | if (n==8) | ||
+ | doubleTB(g,0,tl/2,img); | ||
+ | if (n==9||n==10){ | ||
+ | doubleTB(g,-rl,tl/3,img); | ||
+ | doubleTB(g,rl,tl/3,img); | ||
+ | } | ||
+ | if (n==10) doubleTB(g,0,2*tl/3,img); | ||
+ | g.translate(-x,-y); | ||
+ | } | ||
+ | |||
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
− | BufferedImage img= new BufferedImage( | + | int p = 4; |
+ | int r = 8; | ||
+ | int w = 40; | ||
+ | int h = 60; | ||
+ | g.setRenderingHint( | ||
+ | RenderingHints.KEY_ANTIALIASING, | ||
+ | RenderingHints.VALUE_ANTIALIAS_ON); | ||
+ | BufferedImage img = new BufferedImage(16,16, | ||
BufferedImage.TYPE_INT_ARGB); | BufferedImage.TYPE_INT_ARGB); | ||
− | try{ | + | String [] suits = "diamonds.png clubs.png hearts.png spades.png".split(" "); |
− | + | for (int j=0;j<4;j++){ | |
− | + | try { | |
− | + | img = (BufferedImage)ImageIO.read(new File(suits[j])); | |
+ | }catch (Exception e){} | ||
+ | for (int i=0;i<10;i++) | ||
+ | { | ||
+ | g.setColor(Color.white); | ||
+ | g.fillRoundRect((p+w)*i+p,(p+h)*j+p,w,h,r,r); | ||
+ | g.setColor(Color.black); | ||
+ | g.drawRoundRect((p+w)*i+p,(p+h)*j+p,w,h,r,r); | ||
+ | g.setColor((j%2==0)?Color.red:Color.black); | ||
+ | pips(g,(p+w)*i+p+w/2,(p+h)*j+p+h/2,i+1,img); | ||
+ | } | ||
+ | } | ||
} | } | ||
− | </answer> | + | ]]></answer> |
</question> | </question> | ||
==Monopoly== | ==Monopoly== | ||
− | <question className='Raster' imgOut='flag.png' copyFile='monopoly.png' width=' | + | <question className='Raster' imgOut='flag.png' copyFile='monopoly.png' width='1040' height='1040'> |
− | *The background is | + | This is a large image and takes too much memory on the the progzoo system. Please use Dr Java or similar. |
− | + | *The width of each property is 85 | |
+ | *The background is 1040x1040 | ||
+ | *You should use strings in the array | ||
<prog> | <prog> | ||
static String [] [] monopoly = | static String [] [] monopoly = | ||
Line 135: | Line 284: | ||
} | } | ||
</prog> | </prog> | ||
− | <answer> | + | <answer><![CDATA[ |
static void drawFlag(Graphics2D g){ | static void drawFlag(Graphics2D g){ | ||
− | + | FontMetrics fm = g.getFontMetrics(); | |
− | + | String [] [] monopoly = | |
− | + | new String [] [] { | |
− | + | new String [] {"Old Kent\nRoad#7e3517","Community\nChest","Whitechapel#7e3517", | |
− | + | "Income Tax","King's Cross\nStation","The Angel\nIslington#6699ff", | |
− | + | "Chance","Euston Road#6699ff","Pentonville\nRoad#6699ff"}, | |
+ | new String [] {"Pall Mall#cc44cc","Electric\nCompany","Whitehall#cc44cc", | ||
+ | "Northum'nd\nAvenue#cc44cc","Marlebone\nStation","Bow\nStreet#ff9900", | ||
+ | "Community\nChest","Marlborough\nStreet#ff9900","Vine\nStreet#ff9900"}, | ||
+ | new String [] {"Strand#ee0000","Chance","Fleet\nStreet#ee0000","Trafalgar\nSquare#ee0000", | ||
+ | "Fenchurch\nStreet\nStation","Leichester\nSquare#ffff00", | ||
+ | "Coventry\nStreet#ffff00","Water Works","Piccadilly#ffff00"}, | ||
+ | new String [] {"Regent\nStreet#008000","Oxford\nStreet#008000","Community\nChest", | ||
+ | "Bond\nStreet#008000","Liverpool\nStreet\nStation","Chance", | ||
+ | "Park\nLane#333366","Super Tax","Mayfair#333366"} | ||
+ | }; | ||
+ | int w = 85; | ||
+ | int h = (1000-w*9)/2; | ||
+ | g.setRenderingHint( | ||
+ | RenderingHints.KEY_ANTIALIASING, | ||
+ | RenderingHints.VALUE_ANTIALIAS_ON); | ||
+ | g.setColor(Color.black); | ||
+ | g.translate(h+8*w,h+9*w); | ||
+ | for (String [] row : monopoly){ | ||
+ | for (String property : row){ | ||
+ | String [] s = property.split("#"); | ||
+ | g.drawRect(0,0,w,h); | ||
+ | String [] lines = s[0].split("\n"); | ||
+ | g.translate(w/2,h/5); | ||
+ | for (String l : lines){ | ||
+ | g.translate(0,fm.getHeight()); | ||
+ | g.drawString(l,(0-fm.stringWidth(l))/2,0); | ||
+ | } | ||
+ | g.translate(0,-1*fm.getHeight()*lines.length); | ||
+ | g.translate(-w/2,-h/5); | ||
+ | if (s.length>1){ | ||
+ | g.setColor(new Color(Integer.parseInt(s[1],16))); | ||
+ | g.fillRect(0,0,w,h/5); | ||
+ | g.setColor(Color.black); | ||
+ | g.drawRect(0,0,w,h/5); | ||
+ | } | ||
+ | g.translate(-w,0); | ||
+ | } | ||
+ | g.translate(w,0); | ||
+ | g.rotate(Math.PI/2.0); | ||
+ | g.translate(-w,0); | ||
+ | } | ||
} | } | ||
− | </answer> | + | ]]></answer> |
+ | [[Image:monopoly.png]] | ||
</question> | </question> |
Latest revision as of 01:28, 10 November 2008
Fanorona
- The separation is 20
- The disks have radius 6
- The background is 184x104
- The blue is 64,64,255
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Snakes and Ladders
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Ludo
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]
Cards
- The background is 448x270
- The cards are 40 by 60
- The radius of the rounded corners is 8
- There is a gap of 4 between the cards
- Each suit image (e.g. clubs.png) is 16x16
- The corner image is 13x20 from the centre of the card
- If you want to work outside progzoo you can get the images: http://progzoo.net/hearts.png http://progzoo.net/clubs.png http://progzoo.net/diamonds.png http://progzoo.net/spades.png
[Font]
[Default]
[Show]
[Resize]
[History]
[Profile]