/******************************************************************************* Game - AN APPLET TO DISPLAY A CHOSEN NUMBER BETWEEN 1 AND 63 © 1998 George W. Jopling (V1.0) email: george.jopling@ukonline.co.uk Permission to use, copy, modify, and distribute this software and its documentation for non-commercial or commercial purposes and without fee is hereby granted. No responsibility is accepted for the use or suitablility of this software and you use it at your own risk 'Mind Reader' is an applet variation of a childrens novelty game. The player is requested to think of a number between 1 and 63. The player is then shown a set of six cards with different variations of numbers between 1 and 63. The player is asked to indicate yes or no if their chosen number is on the card. After the last card, the players's chosen number is revealed, as if by mind reading magic! Unzip game.ZIP and place the following in the same directory as your Web page... Game.class GAME_DIALOG.class DialogLayout.class Card0.Gif, Card1.Gif, Card2.Gif, Card3.Gif, Card4.Gif, Card5.Gif, Card6.Gif Add the following to your web page... A sample Web page and full source code are also included... game.htm Game.java GAME_DIALOG.java DialogLayout.java To use Mind Reader as a stand-alone application on your computer... 1. create a new directory e.g. Mindread 2. unzip all files into that directory 3. start your browser and open game.htm *******************************************************************************/ //****************************************************************************** // Game.java: Applet // //****************************************************************************** import java.applet.*; import java.awt.*; import GAME_DIALOG; //============================================================================== // Main Class for applet Game // //============================================================================== public class Game extends Applet { // Private Methods of the Class //-------------------------------------------------------------------------- private void NextGame() { m_CardNumber = 0; m_Answer = 0; m_Guess = 0; repaint(); } // Private data members //-------------------------------------------------------------------------- GAME_DIALOG GameControls; private Image m_ImageToDraw; private int m_CardNumber = 0; private int m_Answer = 0; private int m_Guess = 0; private Font m_f = new Font ("Arial",Font.BOLD,22); private String m_ImageArray [] = {"Card0.gif", "Card1.gif", "Card2.gif", "Card3.gif", "Card4.gif", "Card5.gif", "Card6.gif"}; private int m_Add [] = {1, 2, 4, 8, 16, 32}; private int m_ImgHeight = 0; // Game Class Constructor //-------------------------------------------------------------------------- public Game() { } // Applet info support //-------------------------------------------------------------------------- public String getAppletInfo() { return "Name: Game\r\n" + "Author: George W Jopling\r\n" + "Created with Microsoft Visual J++ Version 1.1"; } // Initialisation //-------------------------------------------------------------------------- public void init() { GameControls = new GAME_DIALOG(this); GameControls.CreateControls(); GameControls.IDC_YES; GameControls.IDC_NEXT; GameControls.IDC_NO; resize(302, 240); setBackground(Color.white); } // Destroy applet //-------------------------------------------------------------------------- public void destroy() { } // Game Paint Handler //-------------------------------------------------------------------------- public void paint(Graphics g) { g.drawString ("M I N D R E A D E R", 98, 15); m_ImageToDraw = getImage (getDocumentBase(), m_ImageArray [m_CardNumber] ); m_ImgHeight = m_ImageToDraw.getHeight(null); g.drawImage (m_ImageToDraw, 50, 20, this); if (m_ImgHeight < 0 ) { g.drawString ("Loading Image...", 110, 80); } if (m_CardNumber < 1 ) { g.drawString ("Think of a number between 1 and 63. After six cards, ", 20, 140); g.drawString ("Mind Reader will show the number you are thinking of.", 20, 155); } if (m_CardNumber == 6) { g.setFont (m_f); g.setColor (Color.red); g.drawString (String.valueOf(m_Answer), 140, 98); } else { g.drawString ("Is your number shown in the above card?", 55, 170); g.drawString ("Click on: YES or NO", 100, 185); } if (m_CardNumber == 6 && m_Answer == 0) { g.setFont (m_f); g.setColor (Color.red); g.drawString ("Gotcha!", 110, 116); } } // Action Event Handler //-------------------------------------------------------------------------- public boolean action(Event evt, Object whichAction) { if (evt.target instanceof Button) { if (GameControls.IDC_NEXT.getLabel() == (String)whichAction) { NextGame(); return true; } if (GameControls.IDC_YES.getLabel() == (String)whichAction) if (m_CardNumber == 6) { return true; } else { m_Answer = m_Answer + (m_Add[m_Guess]); } if (GameControls.IDC_NO.getLabel() == (String)whichAction) if (m_CardNumber == 6) { return true; } } m_CardNumber++; m_Guess++; repaint(); return true; } }