Sandrine_87
Messages postés5Date d'inscriptionjeudi 9 juin 2005StatutMembreDernière intervention17 juin 2005
-
9 juin 2005 à 01:21
Sandrine_87
Messages postés5Date d'inscriptionjeudi 9 juin 2005StatutMembreDernière intervention17 juin 2005
-
9 juin 2005 à 18:12
Bonjour tout le monde !
Bon je vais faire ca bref. Je fais presentement un stage d'ete a
l'universite de montreal et je dois apprendre le Java. Cela fais donc
un gros 5 jours que j'ai commence a apprendre ce langage. Je comprends
pas comment faire la question suivante (qui est encore a propos d'un
bonhomme pendu !!!) et j'aimerais savoir si une gentille ame
voudrait m'aider ^^. (dsl si c'est dur a lire sans accent :S)
You will have to implement or modify some functionalities to the
actual version (que je vais inclure a la question) we give you.
a) The first part of this assignments is to initialize the applet and
to show the GUI components (text boxes and buttons). Methods to do this
job were already ceated in the Hangman.java file, you just have to call
them in the appropriate way.
Voici ce que le prof nous a
donne. (Vous remarquez qu'il manque des donnees dans certaines
fonctions, comme Graphics car c'est dans les questions b,c et d, que je
vous demanderez surment apres ! )
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.Date;
import java.util.Random;
/*
This GUI component serve has a drawing canvas to delimit the drawing region.
*/
class HangmanCanvas extends Canvas
{
// ---------------------------
// --- Class member fields ---
// ---------------------------
// User good answer counter.
private int goodCounter = 0;
// User error counter.
private int badCounter = 0;
// Flag set to true when the word is found by the user.
private boolean won = false;
// Flag set to true when the game is over (won or lost).
private boolean exit = false;
// Drawing canvas fixed size.
private Dimension canvasSize = new Dimension (400, 400);
// ---------------------------
// -- Class member methods ---
// ---------------------------
// Simple field access methods
public boolean getWon () { return won; }
public boolean getExit () { return exit; }
public int getBadCounter () { return badCounter; }
public int getGoodCounter () { return goodCounter; }
/*
Increments the good answer counter and returns the new value.
*/
public int good ()
{
return ++goodCounter;
}
/*
Increments the error counter (up to 6) and returns the new value.
*/
public int wrong ()
{
if (++badCounter > 6)
badCounter = 6;
return badCounter;
}
public void victory ()
{
won = true;
}
/*
Canvas drawing method. This method will be called when the applet is redrawn.
(see the refresh() method in the Hangman class)
** TODO **
You must draw the hangman here, in 6 parts (head, body, arms and legs).
The parts drawn depend on how many errors the user has made. When the
game is terminated, you must also draw a message
*/
public void paint (Graphics page)
{
}
// These two methods fix the canvas size.
public Dimension getMinimumSize () { return canvasSize; }
public Dimension getPreferredSize () { return canvasSize; }
}
/*
This is the main Applet class that implements the hangman game.
*/
public class Hangman
extends Applet
implements ActionListener
{
private static final int nbwordsmax = 100;
private static final int maxlength = 20;
// GUI components.
private Button ok;
private TextField input;
private TextField[] letters;
private TextArea saidArea;
// Drawing canvas.
private HangmanCanvas canvas;
// The word to find.
private String wordToFind;
// Contains already said characters by the user.
private StringBuffer charSaid;
// Word list read from "wordlist.txt".
private String[] wordlist;
// Word read counter.
private int nbwords;
private Random generator;
/*
This method is called once when the applet is loaded.
Sandrine_87
Messages postés5Date d'inscriptionjeudi 9 juin 2005StatutMembreDernière intervention17 juin 2005 9 juin 2005 à 18:12
merci :) si je comprends bien, je dois faire un copier coller des
methodes ? Ou je suis carement dans le champs et c'est pas ca que tu
veux dire par appeler