import java.awt.*; import java.awt.event.*; /*CIS144java-Fall2000*/ import java.applet.*; /*Abbas Moghtanai */ import java.util.*;import java.util.Vector; /*Dan Carte */ import java.io.*; /**************************************************************************$*/ /**************************************************************************$*/ /* */ public class MM extends Applet implements ActionListener { String msg =" There are two versions of this game. In the easy version'\n'"; String msg1="the color will apeare when a match is found.'\n'"; String msg2=" In the hard version you will just be given information '\n'"; String msg3="as to the collor and possition. If the color is in the set'\n'"; String msg4="but does not match the collor dirrectly above it in the '\n'"; String msg5="matrix you will get a number followed by a for the number'\n'"; String msg6="corres[onding matches. If the possition matches you will get'\n'"; String msg7="a number followed by a

. No 's will be recorded for '\n'"; String msg8="number. You get 7 chances for the easy version and 10 for'\n'"; String msg9="the hard version. Good Luck!!"; String str = ""; int iColor,ic=0,ir=0,pos=0,correct=0; int wide=30,high=18,colom=0,row=0; boolean repeat=false,show=false,match=false; /*Putting the buttons in */ Button bList[]=new Button[13]; /*array means we can use a*/ TextField title; /*loop to add the buttons.*/ TextArea helpMe; Checkbox beginner,advanced; /*Have to use a group to make*/ CheckboxGroup cbg; /*the CheckBoxes exclusive. */ Vector c =new Vector(10); /*This Vector stores the colors*/ Vector sc =new Vector(50); /*This stores the user selected colors*/ Vector mycolor=new Vector(5); /*This stores the 5 random colors.*/ public void init() { /*Set the default Colors*/ setBackground(Color.lightGray); setForeground(Color.black); setLayout(null); /*Kill LayoutManager! */ /**************************************************************************$*/ /* Add colors to the vector. */ /**************************************************************************$*/ c.addElement(new Color(230,0,0)); /*red */ c.addElement(new Color(255,180,200)); /*pink */ c.addElement(new Color(255,170,0)); /*orange*/ c.addElement(new Color(235,235,0)); /*yellow*/ c.addElement(new Color(0,245,0)); /*lGreen*/ c.addElement(new Color(0,135,0)); /*dGreen*/ c.addElement(new Color(0,0,222)); /*lBlue */ c.addElement(new Color(0,0,131)); /*dBlue */ c.addElement(new Color(191,0,131)); /*violet*/ c.addElement(new Color(131,0,131)); /*purple*/ /**************************************************************************$*/ /* Initialize all the buttons and textfields. */ /**************************************************************************$*/ Button red =new Button(""); Button pink =new Button(""); Button orange =new Button(""); Button yellow =new Button(""); Button lGreen =new Button(""); Button dGreen =new Button(""); Button lBlue =new Button(""); Button dBlue =new Button(""); Button violet =new Button(""); Button purple =new Button(""); Button help =new Button("Help!"); Button start =new Button("Start"); Button stop =new Button("Stop"); title =new TextField(2); helpMe =new TextArea(); cbg = new CheckboxGroup(); beginner =new Checkbox("Beginner",cbg,true); advanced =new Checkbox("Advanced",cbg,false); /**************************************************************************$*/ /* Store references to buttons. */ /**************************************************************************$*/ setBackground(Color.gray); /*Red group*/ bList[0] = (Button) add(red); bList[1] = (Button) add(pink); bList[2] = (Button) add(orange); bList[3] = (Button) add(yellow); bList[4] = (Button) add(lGreen); bList[5] = (Button) add(dGreen); bList[6] = (Button) add(lBlue); bList[7] = (Button) add(dBlue); bList[8] = (Button) add(violet); bList[9] = (Button) add(purple); bList[10] = (Button) add(help); bList[11] = (Button) add(start); bList[12] = (Button) add(stop); add(helpMe); add(title); add(beginner); /*CheckBox for beginner*/ add(advanced); /*CheckBox for advanced*/ /**************************************************************************$*/ /* Place the Buttons, and Textfields. */ /**************************************************************************$*/ bList[0].setBounds(340,30,60,20); /*Red Group*/ bList[1].setBounds(440,30,60,20); bList[2].setBounds(540,30,60,20); bList[3].setBounds(340,60,60,20); bList[4].setBounds(440,60,60,20); bList[5].setBounds(540,60,60,20); /*Green Group*/ bList[6].setBounds(340,90,60,20); bList[7].setBounds(440,90,60,20); bList[8].setBounds(540,90,60,20); bList[9].setBounds(540,120,60,20); bList[10].setBounds(340,415,50,20); /*Blue Group*/ bList[11].setBounds(440,415,50,20); bList[12].setBounds(540,415,50,20); title.setText("Master Mind"); /*Have to set the text*/ title.setBounds(0,0,620,20); beginner.setBounds(420,390,15,15); advanced.setBounds(520,390,15,15); for (int i=0; i<13; i++) /*Add buttons. */ { if(i<10) bList[i].setBackground((Color)c.elementAt(i));/*Put colors in */ bList[i].addActionListener(this); /*the buttons. */ } } public void start() /*Reset the screen.*/ { match=false; int choose,pos=0,correct=0; repeat=true; show=false; for (int i=0;i<5;i++) /*Seed the array with 5*/ { /*random collors. */ choose= (int) (Math.random() *10); mycolor.insertElementAt((Color)(c.elementAt(choose)),i); /*lGreen*/ } for(int u=1;u<5;u++) /*Make the unique.*/ { for(int k=0;k