/* * @(#)Practicum2.java 1.0 03/02/06 * * You can modify the template of this file in the * directory ..\JCreator\Templates\Template_2\Project_Name.java * * You can also create your own project template by making a new * folder in the directory ..\JCreator\Template\. Use the other * templates as examples. * */ import java.awt.*; import java.applet.*; import java.awt.event.*; public class Practicum2 extends Applet implements MouseListener, ActionListener { final int steend=40; final int vakjeb=50; final int ox=10,oy=90; int vakkenx,vakkeny,speler; int [][] plaats; boolean show,stop; String stat; Button nieuw, help; public int ConvInt(String a, int normal) { int b=0; try { b=Integer.parseInt(a); } catch(Exception e) { b=normal; } finally { return b; } } public void init() { int loop,lop,mx,my; vakkeny=ConvInt(this.getParameter("vakkeny"),6); vakkenx=ConvInt(this.getParameter("vakkenx"),6); this.addMouseListener(this); nieuw = new Button("Nieuw"); help = new Button("Help"); this.add(nieuw); this.add(help); nieuw.addActionListener(this); help.addActionListener(this); plaats = new int[vakkenx][vakkeny]; reset(); } //klik op knop: public void actionPerformed(ActionEvent e) { //knop is help if(e.getSource()==help&&!stop) { //laten zien wat methode help legale zetten vindt //of als help al aan stond, help weer uitzetten show=!show; this.repaint(); } //knop is nieuw if(e.getSource()==nieuw) { //resetten reset(); } } //methode voor herstellen beginsituatie public void reset() { int x,y; for(x=0;x=0 && y>=0 && y0) { //dan kleur bepalen if (val==1) { gr.setColor(Color.blue); } if (val==2) { gr.setColor(Color.red); } //en tekenen gr.fillOval(ox+vakjeb*x+(vakjeb-steend)/2,oy+vakjeb*y+(vakjeb-steend)/2,steend,steend); } } } } //rondjesmethode tbv help-functie public void tekenrondje(Graphics gr,int x,int y) { gr.drawOval(ox+vakjeb*x+(vakjeb-steend/2)/2,oy+vakjeb*y+(vakjeb-steend/2)/2,steend/2,steend/2); } public void paint(Graphics g) { stat=""; //als er geen zetten gedaan kunnen worden if(!help(g)&&!stop) { //dan wissel van speler speler=nietspeler(); //maar als deze ook geen zetten kan if(!help(g)&&!stop) { //dan is het einde spel stop=true; if(hoeveel(1)>hoeveel(2)) { //dan heeft blauw gewonnen stat="Blauw heeft gewonnen!"; } else { if(hoeveel(2)>hoeveel(1)) { //dan heeft rood gewonnen stat="Rood heeft gewonnen!"; } else { stat="Remise!"; } } } } //teken veld enzo tekenveld(g); tekenstukken(g); } public void mousePressed(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} }