![]() These cookies ensure basic functionalities and security features of the website, anonymously. this method will play the sound whose name is stored at index num of the sounds array.Ĭlip = Applet.newAudioClip(new (currentDir.Necessary cookies are absolutely essential for the website to function properly. this method can be invoked from the event dispatching thread (or elsewhere) Private static java.io.File currentDir = new java.io.File(System.getProperty("user.dir")) SetText("You managed " + howMan圜orrect + " correctly!") Ĭase 2: setText("Oh dear, not very good :-(") break Ĭase 5: setText("Okay for a beginner") break Ĭase 11: setText("Very good! :-)") break Ĭase 14: setText("Excellent! -)") break SetText("‘Whoops, got one wrong there!’") Public void showEndMessages(int howMan圜orrect) ![]() ![]() ** Creates a new instance of MessagePanel */ Public void actionPerformed(ActionEvent e) Private class MenuSelection implements ActionListener MessagePanel.showEndMessages(buttonPanel.getPlayerSequence().size()-1) tText("Well done! Now get ready for the next turn!") tText("Here comes the sequence of " + (buttonPanel.getPlayerSequence().size() + 1)) tText("Welcome to SIMON - let's start!") aySound(0) // initial gong to get started Restart.addActionListener(new MenuSelection()) Speed.addActionListener(new MenuSelection()) TODO: add listeners for the menu options Speed = new JMenuItem("Speed up the game") MessagePanel = new MessagePanel() // message area SetDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) īuttonPanel = new ButtonPanel() // button area ** Creates a new instance of GameFrame */ Private ButtonPanel buttonPanel // for buttons Private MessagePanel messagePanel //for writing messages underneath the buttons ResetPlayer() // so start storing from first player click SleepTime = (int) (sleepTime * 0.95) // get progressively faster Int i = firstChar + (int) (4 * Math.random()) choose the next button for Simon's sequence ("current sequence is " + simonSequence) Private void setButtonsEnabled(boolean v) ![]() SimonSequence.clear() // redundant on first use Private ImageIcon createImageIcon(String path) returns an ImageIcon or null if the path was invalid Public void actionPerformed(ActionEvent b) Public class ButtonWatcher implements ActionListener is this how to create and add a ButtonWatcher for each of the buttonsī.addActionListener(new ButtonWatcher()) SetLayout(new GridLayout(2,2)) // two rows two columns for the buttonsī.setActionCommand("" + label) // for use in ButtonWatcher Pressed = createImageIcon("smile.gif") // icon to show button being pressed ** Creates a new instance of ButtonPanel */ Private static final Character lastChar = 'D' Private static final Character firstChar = 'A' Private boolean playerCorrect // player correct so far Private ArrayList playerSequence // sequence pressed by player Private ArrayList simonSequence // Simon's sequence of numbered buttons This all works ok but there is a problem with the output sequence during the game, it tell us how large the computers sequence is and what characters it holds but for the players sequence it says 0 for the size and for the characters im at a loss to what ive done wrong as the game works apart from that part. The problem is the game is a simon game so I the computer picks a letter randomly and the player has to copy it, if the player picks the wrong letter in the sequence the game informs the user that they have lost and tells them how many right in the sequence they got. Hi, Im slightly stuck with a java project ive been asked to do.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |