public void Update(String event) { if (event.equals("time")) { MODEL.time = "<html>Elapsed Time: <font color =\"GREEN\">" + MODEL.watch.getElapsedTimeSecs() + "</font> Seconds</html>"; timeLab.setText(MODEL.time); } else if (event.equals("invalid")) { MODEL.answerInvalid(); msg.setText(MODEL.msg); } else if (event.equals("correct")) { MODEL.answerCorrect(); score.setText(MODEL.str); msg.setText(MODEL.msg); problem.setText(MODEL.prb); entry.setText(""); entry.requestFocus(); } else if (event.equals("wrong")) { MODEL.answerWrong(); msg.setText(MODEL.msg); } else if (event.equals("replay")) { MODEL.gameReplay(); problem.setText(MODEL.prb); score.setText(MODEL.str); msg.setText(MODEL.msg); timeLab.setText(MODEL.time); } else System.out.println("Invalid Update Command"); }
public void ajouterAllActionListener(ActionListener actionListener) { for (int i = 0; i < model.getTableauBijou().length; i++) { for (int j = 0; j < model.getTableauBijou()[i].length; j++) { tableauBijouButton[i][j].addActionListener(actionListener); } } }
@Override public Model clone() { Model model = new Model(); for (Mesh mesh : meshes) model.meshes.add(mesh.clone()); model.render_normals = render_normals; model.render_wireframe = render_wireframe; return model; }
public void coloreUnCoupPossible() { if (model.getCoupsPossibles().size() == 0) { partieEstPerdu(" coup possible a jouer"); } Coup coupPossible = model.getUnCoupPossible(); tableauBijouButton[coupPossible.getCoord1().getX()][coupPossible.getCoord1().getY()] .setBackground(Color.BLACK); }
/** * Is called from the model when data is changed, updates members and view of this class. Checks * if the game is over. * * @param e ChangeEvent object */ public void stateChanged(ChangeEvent e) { // update the view: accessors and repaint data = model.getData(); repaint(); if (model.isFinish() && !gameOver) { gameOver = true; JFrame frame = new JFrame("Declare Winner"); if (model.declareWinner() == 1) JOptionPane.showMessageDialog(frame, "A is the winner!!!"); else if (model.declareWinner() == 2) JOptionPane.showMessageDialog(frame, "B is the winner!!!"); else JOptionPane.showMessageDialog(frame, "It is a tie!!!"); } }
public int compteScore(ArrayList<ArrayList<Coord>> lignesCombo) { int score = 0; for (int i = 0; i < lignesCombo.size(); i++) { if (lignesCombo.get(i).size() == 3) { score += 100 * model.getLevel(); } else if (lignesCombo.get(i).size() == 4) { score += 300 * model.getLevel(); } else if (lignesCombo.get(i).size() >= 5) { score += 1000 * model.getLevel(); } } return score; }
public void actualiserTableau() { for (int i = 0; i < tableauBijouButton.length; i++) { for (int j = 0; j < tableauBijouButton[i].length; j++) { tableauBijouButton[i][j].setType(model.getTableauBijou()[i][j]); tableauBijouButton[i][j].setIcon( model.getTextures()[tableauBijouButton[i][j].getTypeBijou().getIndex()]); if (tableauBijouButton[i][j].getBackground() == Color.BLACK) { tableauBijouButton[i][j].setBackground(Color.WHITE); } } // coloreCoupPossible(); } }
public ArrayList<ArrayList<Coord>> coloreLigneCombo() { ArrayList<ArrayList<Coord>> lignesCombo; lignesCombo = model.getLignesCombo(); if (lignesCombo.size() != 0) { /* for (int i = 0; i < lignesCombo.size(); i++) { for (int j = 0; j < lignesCombo.get(i).size(); j++) { //tableauBijouButton[lignesCombo.get(i).get(j).getX()][lignesCombo.get(i).get(j).getY()].setBackground(Color.CYAN); tableauBijouButton[lignesCombo.get(i).get(j).getX()][lignesCombo.get(i).get(j).getY()].repaint(); } }*/ /* long time1 = java.lang.System.currentTimeMillis(); long time2; do { time2 = java.lang.System.currentTimeMillis(); }while(time1 > time2 + 1000);*/ for (int i = 0; i < lignesCombo.size(); i++) { for (int j = 0; j < lignesCombo.get(i).size(); j++) { tableauBijouButton[lignesCombo.get(i).get(j).getX()][lignesCombo.get(i).get(j).getY()] .setBackground(Color.WHITE); } } actualiserTableau(); } return lignesCombo; }
/** * Constructor that takes model as a parameter * * @param model */ public BoardFrame(Model model) { this.model = model; data = model.getData(); gameOver = false; initScreen(); setLayout(new BorderLayout()); setLocation(300, 200); // undoBtn is a controller that resets the turn and last state of board undoBtn = new JButton("Undo : " + this.model.getUndoCounter()); undoBtn.setPreferredSize(new Dimension(80, 50)); undoBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (BoardFrame.this.model.getUndoCounter() != 0) { BoardFrame.this.model.undo(); undoBtn.setText("Undo : " + BoardFrame.this.model.getUndoCounter()); } else ; } }); JPanel undoPanel = new JPanel(); undoPanel.add(undoBtn); // end of undoBtn code add(boardPanel, BorderLayout.CENTER); add(undoPanel, BorderLayout.SOUTH); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setResizable(false); setVisible(true); }
public void actualiserTries() { int nbTries = model.getTries(); if (nbTries <= 0) { partieEstPerdu(" trie (essai)"); } tries.setText(String.valueOf(nbTries)); }
/** If a button is pressed... */ @Override public void actionPerformed(ActionEvent event) { // TODO Auto-generated method stub for (int i = 0; i < 11; i++) { if (event.getSource() == numButtons[i]) { model.numberPress("" + i); } } for (int i = 0; i < functions.length; i++) { if (event.getSource() == funcButtons[i]) { model.functionPress(i); } } display.setText(model.getDisplay()); // Update the display }
public boolean gestionHighScore() { String chemin = "HighScore.txt"; Vector<Integer> highScores = getHighScore(chemin); if (highScores.size() != 0 && model.getScore() > highScores.get(highScores.size() - 1) || highScores.size() < 5) { triTableau(highScores, model.getScore()); ecrireFichier(chemin, highScores); return true; } return false; }
public void initAttribut(Model model) { this.model = model; tableauBijouButton = new Bijou[model.getTableauBijou().length][model.getTableauBijou()[0].length]; for (int i = 0; i < model.getTableauBijou().length; i++) { for (int j = 0; j < model.getTableauBijou()[i].length; j++) { tableauBijouButton[i][j] = new Bijou(model.getTableauBijou()[i][j], new Coord(i, j)); tableauBijouButton[i][j].setIcon( model.getTextures()[model.getTableauBijou()[i][j].getIndex()]); tableauBijouButton[i][j].setBackground(Color.white); } } menuOption = new JMenu("Options"); menuScore = new JMenuItem("Meilleurs Scores"); menuNouvellePartie = new JMenuItem("Nouvelle Partie"); hint = new JButton("hint"); pause = new JButton("pause"); progressBar = new TheProgressBar(this); contentPane = new JPanel(); }
public void coloreCoupPossible() { ArrayList<Coup> coupsPossibles = model.getCoupsPossibles(); for (int i = 0; i < coupsPossibles.size(); i++) { tableauBijouButton[coupsPossibles.get(i).getCoord1().getX()][ coupsPossibles.get(i).getCoord1().getY()] .setBackground(Color.BLACK); } }
public void update() { strokes = this.model.getStrokes(); if (model.getScaledCanvas()) { this.setPreferredSize(null); } else { this.setPreferredSize(new Dimension((int) screenWidth, (int) screenHeight)); } this.revalidate(); this.repaint(); }
public void drawMap() { contentPane.removeAll(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); JPanel ligneIndication = new JPanel(); ligneIndication.setLayout(new GridLayout(1, 3)); JPanel caseLevel = new JPanel(); JLabel texteLevel = new JLabel("Level : "); caseLevel.add(texteLevel); level = new JLabel(String.valueOf(model.getLevel())); caseLevel.add(level); ligneIndication.add(caseLevel); JPanel caseTries = new JPanel(); JLabel texteTries = new JLabel("Tries : "); caseTries.add(texteTries); tries = new JLabel(String.valueOf(model.getTries())); caseTries.add(tries); ligneIndication.add(caseTries); JPanel caseScore = new JPanel(); JLabel texteScore = new JLabel("Score : "); caseScore.add(texteScore); score = new JLabel(String.valueOf(model.getScore())); caseScore.add(score); ligneIndication.add(caseScore); contentPane.add(ligneIndication); JPanel sousContentPane = new JPanel(); sousContentPane.setLayout(new GridLayout(8, 8)); for (int i = 0; i < tableauBijouButton.length; i++) { for (int j = 0; j < tableauBijouButton.length; j++) { sousContentPane.add(tableauBijouButton[i][j]); tableauBijouButton[i][j].setPreferredSize(new Dimension(60, 60)); } } contentPane.add(sousContentPane); contentPane.add(progressBar.getProgressBar()); // coloreCoupPossible(); setContentPane(contentPane); }
public void update(Observable o, Object arg) { String gameStatus = model.getStatus(); if (gameStatus.equals("finished")) { statusbar.setText("Game over. You won."); } else if (gameStatus.equals("paused")) { statusbar.setText("Paused"); } else if (gameStatus.equals("game over")) { statusbar.setText("Game over. You lost."); } else { statusbar.setText( "Your score: " + new Integer(model.getScore()).toString() + ", level " + new Integer(model.getLevel()).toString()); board.repaint(); } }
/** * Uses an item on a game object. * * @param item the item to use * @param target the game object to be used on by the item * @return <tt>true</tt> if the "Use" action had been used on both the inventory item and the game * object; otherwise <tt>false</tt> */ public static boolean useItem(Item item, GameObject target) { if (item != null && target != null) { for (int i = 0, r = Random.nextInt(5, 8); i < r; i++) { if (!isItemSelected()) { if (item.interact("Use")) { for (int j = 0; j < 10 && !isItemSelected(); j++) { Task.sleep(100, 200); } } else { return false; } } // just make sure in case something bad happened if (isItemSelected()) { final String itemName = item.getName(); final ObjectDefinition targetDef = target.getDef(); final Model targetModel = target.getModel(); if (targetDef != null && itemName != null && targetModel != null) { final String targetName = targetDef.getName(); Mouse.move(targetModel.getNextPoint()); final String action = "Use " + itemName.replace("<col=ff9040>", "") + " -> " + targetName.replace("<col=ff9040>", ""); for (int j = 0, s = Random.nextInt(5, 8); j < s; j++) { if (Menu.contains(action) && Menu.click(action)) { return true; } else { Mouse.move(targetModel.getNextPoint()); } } } // kay, since that failed, let's try just use if (target.interact("Use")) { return true; } } } } return false; }
/** Initial Option Panes that lets user select style and number of stones */ public void initScreen() { Object[] options = {"Style A", "Style B"}; int input = JOptionPane.showOptionDialog( null, "Choose a Board Style:", "Board Styles", JOptionPane.DEFAULT_OPTION, JOptionPane.DEFAULT_OPTION, null, options, options[0]); if (input == 0) { boardPanel = boardContextDoWork(new StrategyGreen()); } else if (input == 1) { boardPanel = boardContextDoWork(new StrategyBrown()); // change later } else { System.exit(0); } Object[] optionStones = {"3", "4"}; int inputStones = JOptionPane.showOptionDialog( null, "Choose Number of Stones:", "Initial Stones", JOptionPane.DEFAULT_OPTION, JOptionPane.DEFAULT_OPTION, null, optionStones, optionStones[0]); if (inputStones == 0) { model.refreshBoard(3); } else if (inputStones == 1) { model.refreshBoard(4); } else { System.exit(0); } }
public void partieEstPerdu(String origineFin) { boolean newRecord = gestionHighScore(); StringBuilder message = new StringBuilder(); message.append("Desole, vous n'avez plus de "); message.append(origineFin); if (newRecord) { message.append(", mais vous avez fait un nouveau meilleur score : " + model.getScore()); } JOptionPane optionPane = new JOptionPane(); JDialog dialog = new JDialog(); JOptionPane.showMessageDialog( optionPane, message, "Game Over", JOptionPane.INFORMATION_MESSAGE); model.genererTableau(); model.reinitialiser(); progressBar = new TheProgressBar(this); drawMap(); setVisible(true); model.setEstEnJeu(false); }
public void actualiserCase(Coord coord) { tableauBijouButton[coord.getX()][coord.getY()].setIcon( model.getTextures()[model.getTableauBijou()[coord.getX()][coord.getY()].getIndex()]); }
public void actualiserScore() { score.setText(String.valueOf(model.getScore())); }
public View(Model model) { this.model = model; model.makeMeObserver(this); frame = new JFrame(); statusbar = new JLabel(" 0"); board = new Board(); frame.add(board); JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("Settings"); file.setMnemonic(KeyEvent.VK_F); JMenuItem eMenuItem = new JMenuItem("New game"); eMenuItem.setToolTipText("Start a new game"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = -1; setChanged(); notifyObservers(); menuEvent = 0; } }); file.add(eMenuItem); eMenuItem = new JMenuItem("Pause"); eMenuItem.setMnemonic(KeyEvent.VK_P); eMenuItem.setToolTipText("Set pause"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 1; setChanged(); notifyObservers(); menuEvent = 0; } }); file.add(eMenuItem); JMenu imp = new JMenu("Set level"); imp.setMnemonic(KeyEvent.VK_M); JMenuItem lvl1 = new JMenuItem("level 1"); lvl1.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 2; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl2 = new JMenuItem("level 2"); lvl2.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 3; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl3 = new JMenuItem("level 3"); lvl3.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 4; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl4 = new JMenuItem("level 4"); lvl4.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 5; setChanged(); notifyObservers(); menuEvent = 0; } }); JMenuItem lvl5 = new JMenuItem("level 5"); lvl5.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { menuEvent = 6; setChanged(); notifyObservers(); menuEvent = 0; } }); imp.add(lvl1); imp.add(lvl2); imp.add(lvl3); imp.add(lvl4); imp.add(lvl5); file.add(imp); eMenuItem = new JMenuItem("Table of recorgs"); eMenuItem.setToolTipText("Show table of records"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { recordDialog ad; try { ad = new recordDialog(); ad.setVisible(true); } catch (IOException e) { e.printStackTrace(); } } }); file.add(eMenuItem); eMenuItem = new JMenuItem("Exit"); eMenuItem.setMnemonic(KeyEvent.VK_C); eMenuItem.setToolTipText("Exit application"); eMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); file.add(eMenuItem); menubar.add(file); frame.setJMenuBar(menubar); statusbar.setPreferredSize(new Dimension(-1, 22)); statusbar.setBorder(LineBorder.createGrayLineBorder()); frame.add(statusbar, BorderLayout.SOUTH); frame.setSize(200, 400); frame.setTitle("Tetris"); frame.setLocationRelativeTo(null); }
public void actionPerformed(ActionEvent e) { if (!model.getEstEnJeu()) { vue.getProgressBar().start(); model.setEstEnJeu(true); } System.out.println( e.getSource().toString() + model.getBijou(((Bijou) e.getSource()).getPosition())); if (e.getSource().getClass() == bouton1.getClass()) { if (bouton1selectionne && estProche((Bijou) e.getSource())) { bouton2.setBackground(Color.WHITE); bouton2 = (Bijou) e.getSource(); bouton2.setBackground(Color.DARK_GRAY); // model.permut(bouton1.getPosition(), bouton2.getPosition()); // vue.actualiserCase(bouton1.getPosition()); // vue.actualiserCase(bouton2.getPosition()); model.actualiserCoupPossible(); vue.actualiserTableau(); if (model.estUnCoupValide(new Coup(bouton1.getPosition(), bouton2.getPosition()))) { controlMenu.setHintPressed(false); /* try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); }*/ model.permut(bouton1.getPosition(), bouton2.getPosition()); vue.actualiserCase(bouton1.getPosition()); vue.actualiserCase(bouton2.getPosition()); bouton1selectionne = false; bouton1.setBackground(Color.WHITE); bouton2.setBackground(Color.WHITE); // model.actualiserCoupPossible(); // vue.coloreCoupPossible(); System.out.println("coup valide"); /* try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); }*/ int score = 0; int newScore = 0; int progres = 0; ArrayList<ArrayList<Coord>> lignesCombo; do { lignesCombo = vue.coloreLigneCombo(); newScore = compteScore(lignesCombo); score += newScore; progres += compteProgres(lignesCombo); } while (newScore != 0); model.addScore(score); vue.actualiserProgres(progres); vue.actualiserScore(); /* try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); }*/ model.actualiserCoupPossible(); vue.actualiserTableau(); if (vue.getProgressBar().getValue() >= 100) { model.genererTableau(); model.upLevel(); vue.actualiserTableau(); vue.drawMap(); vue.setVisible(true); vue.getProgressBar().setValue(50); } } else { model.enleveUnTrie(); vue.actualiserTries(); } } else { bouton1.setBackground(Color.WHITE); bouton2.setBackground(Color.WHITE); bouton1 = (Bijou) e.getSource(); bouton1.setBackground(Color.DARK_GRAY); bouton1selectionne = true; } } }
GamePanel() { MODEL = new Model(); // Set JLabel messages from MODEL & center align problem = new JLabel(MODEL.prb); score = new JLabel(MODEL.str); msg = new JLabel(MODEL.msg); timeLab = new JLabel(MODEL.time); problem.setHorizontalAlignment(JLabel.CENTER); score.setHorizontalAlignment(JLabel.CENTER); msg.setHorizontalAlignment(JLabel.CENTER); timeLab.setHorizontalAlignment(JLabel.CENTER); // create area where user types in answer answerPrompt = new JLabel("Answer: "); answerPrompt.setHorizontalAlignment(JLabel.RIGHT); entry = new JTextField("Type..."); entry.setSelectionStart(0); entry.setSelectionEnd(7); entry.setHorizontalAlignment(JTextField.CENTER); clear = new JButton("Clear"); // answer area contained in an HBox JPanel HBox = new JPanel(); HBox.setLayout(new GridLayout(1, 3)); HBox.add(answerPrompt); HBox.add(entry); HBox.add(clear); HBox.setDoubleBuffered(true); // Timer MODEL.timer = new Timer( 1000, new ActionListener() { public void actionPerformed(ActionEvent e) { Update("time"); } }); // Entire Game Area in VBox (messages & answer area) JPanel VBox = new JPanel(); VBox.setLayout(new GridLayout(5, 1)); VBox.setDoubleBuffered(true); VBox.add(problem); VBox.add(HBox); VBox.add(score); VBox.add(msg); VBox.add(timeLab); // Create KeyPad JPanel ButtonPanel = new JPanel(); ButtonPanel.setLayout(new GridLayout(4, 3)); ButtonPanel.setDoubleBuffered(true); buttons = new JButton[10]; for (int i = 1; i < buttons.length; i++) { buttons[i] = new JButton(Integer.toString(i)); ButtonPanel.add(buttons[i]); } JLabel filler = new JLabel(" "); ButtonPanel.add(filler); buttons[0] = new JButton("0"); ButtonPanel.add(buttons[0]); // put everything together add(VBox); add(ButtonPanel); } // end of GamePanel() constructor
void sumar() { jTextField3.setText( "" + m_modelo.getSuma( Integer.parseInt(jTextField1.getText()), Integer.parseInt(jTextField2.getText()))); }
@SuppressWarnings("unchecked") @Override public void actionPerformed(ActionEvent e) { Object Event = e.getSource(); if (Event == Searched) { // Code for Searching the Stock , i.e SELECT STATEMENT Model St_search = new Model( username, password); // calls model passing in username and password for database // needs work ResultSet cursor = St_search.DisplayStock(); System.out.println("displaying set of stock"); Vector<String> t = new Vector<String>(); try { while (cursor.next()) { String name, director; int id = cursor.getInt("stockId"); name = cursor.getString("dvdTitle"); int year = cursor.getInt("dvdYear"); director = cursor.getString("dvdDirector"); int quant = cursor.getInt("dvdQuant"); int rentfee = cursor.getInt("dvdRentFee"); System.out.println( "Id : " + id + " Name: " + name + " year:" + year + " director:" + director + " quantity:" + quant + " rentfee:" + rentfee); System.out.println("testing add to vector t"); t.add( "Id: " + id + " Name: " + name + " year: " + year + " director: " + director + " quantity: " + quant + " rentfee: " + rentfee); System.out.println("testing after adding to vector t"); } System.out.println("testing display"); Films.setListData(t); System.out.println("testing after display"); System.out.println("closing stock cursor"); cursor.close(); System.out.println("successfully closed"); } catch (SQLException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } St_search.closeResultSet(); St_search.closeStm(); // closes the statement St_search.closeDB(); // closes the database when finished } if (Event == cancel) { this.setVisible(false); } if (Event == Display_instock) { // Code for Searching the Stock , i.e SELECT STATEMENT Model St_search = new Model( username, password); // calls model passing in username and password for database // needs work ResultSet cursor = St_search.DisplayinStock(); System.out.println("displaying set of stock"); Vector<String> t = new Vector<String>(); try { while (cursor.next()) { String name, director; int id = cursor.getInt("stockId"); name = cursor.getString("dvdTitle"); int year = cursor.getInt("dvdYear"); director = cursor.getString("dvdDirector"); int quant = cursor.getInt("dvdQuant"); int rentfee = cursor.getInt("dvdRentFee"); String state = cursor.getString("dvdState"); System.out.println( "Id : " + id + " Name: " + name + " year:" + year + " director:" + director + " quantity:" + quant + " rentfee:" + rentfee + " State :" + state); System.out.println("testing add to vector t"); t.add( "Id: " + id + " Name: " + name + " year: " + year + " director: " + director + " quantity: " + quant + " rentfee: " + rentfee + " State :" + state); System.out.println("testing after adding to vector t"); } System.out.println("testing display"); Films.setListData(t); System.out.println("testing after display"); System.out.println("closing stock cursor"); cursor.close(); System.out.println("successfully closed"); } catch (SQLException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } St_search.closeResultSet(); St_search.closeStm(); // closes the statement St_search.closeDB(); // closes the database when finished } if (Event == goBack) { this.setVisible(false); } if (Event == confirm) { int No_days = Integer.parseInt(Days.getText()); System.out.println("" + No_days); System.out.println("" + Films.getSelectedValue()); System.out.println("id :" + Films.getSelectedValue().toString().charAt(4)); String ch = "" + Films.getSelectedValue().toString().charAt(4); int stockId = Integer.parseInt(ch); System.out.println("Stock id:" + stockId); Model ren = new Model(username, password); System.out.println("Stock id:" + stockId); System.out.println("Attempting rent in newrent"); ren.RentNew(No_days, stockId, custId); System.out.println("Rent successful"); } }
// IView interface public void updateView() { updateHelper(); if (model.getCounterValue() > 0) this.add(new JLabel(model.getTarget())); }