⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questioncanvas.java

📁 用J2ME写的一个益智类手机游戏。玩家回答问题
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package mindsurf;

import java.util.*;
import javax.microedition.lcdui.*;
import com.nokia.mid.ui.FullCanvas;

public class QuestionCanvas extends FullCanvas {
  Display display;
  private Image ques[]=new Image[6];
  //flag=1为答题界面,flag=2为考试界面
  private int flag=0;
  private int score=0;
  private int life=0;
  private int time=0;
  private int correct=0;
  private int tishu=0;
  private int num=0;
  private int option=0;
  private int n=0;
  private int j=0;
  private int ren=0;
  private int renx=0;
  private int reny=0;
  private int qie=0;
  private int reward=0;
  private int scoindex=0;
  private int s=0;
  private int dindex=-1;
  private int scorere=0;
  private int piyue=0;
  private int clean[]=new int[6];
  private boolean qnext=false;
  private boolean over=false;
  private boolean dong=false;
  private boolean timeflag=true;
  private boolean d=true;
  private boolean e=false;
  private boolean next=false;
  private String[][] question;
  private String scorestr;
  private String lifestr;
  private String correctstr;
  private String tishustr;
  private String rewardstr;
  private Timer timer;

  /** Constructor */
  public QuestionCanvas(Display display) {
    this.display=display;
    try {
      ques[0] = Image.createImage("/res/wenda.png");
      ques[1]=Image.createImage("/res/ketang.png");
      ques[2]=Image.createImage("/res/life.png");
      ques[3]=Image.createImage("/res/student.png");
      ques[4]=Image.createImage("/res/right_wrong.png");
      ques[5]=Image.createImage("/res/gaizhang.png");
    }catch(Exception e){}
    if(PlayCanvas.para==21||PlayCanvas.para==22||PlayCanvas.para==23){
      flag=2;
      renx=10;
      reny=66;
     }else {
      flag = 1;
      renx=94;
      reny=76;
     }
     //将生命值和总分附给life、score
     life=IqMIDlet.life;
     lifestr=String.valueOf(life);
     score=IqMIDlet.score;
     scorestr=String.valueOf(score);
     if(flag==1)
       qie=1;

     //选择的题型
     switch (PlayCanvas.para) {
      case 1:
        question = SmallTrue_falseInterface.smalltrue_false;
        IqMIDlet.len = SmallTrue_falseInterface.len;
        break;
      case 2:
        question = SmallmathInterface.smallmath;
        IqMIDlet.len=SmallmathInterface.len;
        break;
      case 3:
        question = SmallmusicInterface.smallmusic;
        IqMIDlet.len=SmallmusicInterface.len;
        break;
      case 4:
        question = SmallsocietyInterface.smallsociety;
        IqMIDlet.len=SmallsocietyInterface.len;
        break;
      case 5:
        question = SmallchineseInterface.smallchinese;
        IqMIDlet.len=SmallchineseInterface.len;
        break;
      case 6:
        question = SmallrelaxInterface.smallrelax;
        IqMIDlet.len=SmallrelaxInterface.len;
        break;
      case 7 :
         question = True_falseInterface.true_false;
         IqMIDlet.len=True_falseInterface.len;
         break;
      case 8:
        question = MathInterface.math;
        IqMIDlet.len=MathInterface.len;
        break;
      case 9:
        question = MusicInterface.music;
        IqMIDlet.len=MusicInterface.len;
        break;
      case 10:
        question = SocietyInterface.society;
        IqMIDlet.len=SocietyInterface.len;
        break;
      case 11:
        question = ChineseInterface.chinese;
        IqMIDlet.len=ChineseInterface.len;
        break;
      case 12:
        question = RelaxInterface.relax;
        IqMIDlet.len=RelaxInterface.len;
        break;
      case 13:
        question = ScienceInterface.science;
        IqMIDlet.len=ScienceInterface.len;
        break;
      case 14 :
       question = BigTrue_falseInterface.bigtrue_false;
       IqMIDlet.len=BigTrue_falseInterface.len;
       break;
      case 15 :
       question = BigMathInterface.bigmath;
       IqMIDlet.len=BigMathInterface.len;
       break;
      case 16:
       question = BigMusicInterface.bigmusic;
       IqMIDlet.len=BigMusicInterface.len;
       break;
      case 17:
       question = BigSocietyInterface.bigsociety;
       IqMIDlet.len=BigSocietyInterface.len;
       break;
      case 18:
       question = BigRelaxInterface.bigrelax;
       IqMIDlet.len=BigRelaxInterface.len;
       break;
     case 19:
       question = BigScienceInterface.bigscience;
       IqMIDlet.len=BigScienceInterface.len;
       break;
     case 21:
      question = SmallexamInterface.smallexam;
      IqMIDlet.len=SmallexamInterface.len;
      tishu=3;
      break;
    case 22:
      question = ExamInterface.exam;
      IqMIDlet.len=ExamInterface.len;
      tishu=4;
      break;
    case 23:
      question = GraduateInterface.graduate;
      IqMIDlet.len=GraduateInterface.len;
      tishu=5;
      break;
    }

    correctstr=String.valueOf(correct);
    tishustr=String.valueOf(tishu);
    j=index();
    //确定需要正确答对的题数correct
   if(PlayCanvas.para==21){
       num=2;
     }else if(PlayCanvas.para==22){
       num=3;
     }else if(PlayCanvas.para==23){
       num=4;
     }else{
       num=2;
     }
     //需知道是双选还是3选,option=4为双选,option=5为3选
    if(PlayCanvas.para==1||PlayCanvas.para==2||PlayCanvas.para==3||PlayCanvas.para==4||PlayCanvas.para==5||PlayCanvas.para==6||PlayCanvas.para==7||PlayCanvas.para==14){
      option=4;
    }else{
      option=5;
    }

    timer = new Timer();
    timer.schedule(new timeTask(),0,1000);
    timer.schedule(new scoreTask(),0,50);

  }

  protected void paint(Graphics g) {
    //设字体
    Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    g.setFont(f);

    //画答题界面
    if(flag==1){
      switch(PlayCanvas.color){
        case 1:
          g.setColor(0x3333FF);
          break;
        case 2:
          g.setColor(0xCC0000);
          break;
        case 3:
          g.setColor(0x669900);
          break;
      }
      g.fillRect(0,0,128,128);
      g.drawImage(ques[0], 3, 2, Graphics.LEFT | Graphics.TOP);

    if(qie==1){
      if (num > -1) {
    //题目
        g.setColor(255, 255, 255);
        switch (question[j][1].length() / 10) {
          case 0:
            g.drawString(question[j][1].substring(0, question[j][1].length()),
                         10, 10, Graphics.LEFT | Graphics.TOP);
            n = 1;
            break;
          case 1:
            g.drawString(question[j][1].substring(0, 9), 10, 10,
                         Graphics.LEFT | Graphics.TOP);
            g.drawString(question[j][1].substring(9, question[j][1].length()),
                         10, 25, Graphics.LEFT | Graphics.TOP);
            n = 2;
            break;
          case 2:
            g.drawString(question[j][1].substring(0, 9), 10, 10,
                         Graphics.LEFT | Graphics.TOP);
            g.drawString(question[j][1].substring(9, 18), 10, 25,
                         Graphics.LEFT | Graphics.TOP);
            g.drawString(question[j][1].substring(18, question[j][1].length()),
                         10, 40, Graphics.LEFT | Graphics.TOP);
            n = 3;
            break;
        }
        for (int i = 2; i < option; i++) {
          g.drawString(question[j][i], 15, 10 + (n + i - 2) * 15,
                       Graphics.LEFT | Graphics.TOP);
        }
      }
    }
 }

    //画考试界面
    if(flag==2){
      g.setColor(255, 255, 255);
      g.drawImage(ques[1],0,0,Graphics.TOP | Graphics.LEFT);
      g.drawString("-",60,4,Graphics.TOP | Graphics.LEFT);

      if(qie==0||qie==1||qie==2||qie==3||qie==4||qie==5||qie==6||qie==7){
        g.drawString(correctstr,50,4,Graphics.TOP | Graphics.LEFT);
        g.drawString(tishustr,70,4,Graphics.TOP | Graphics.LEFT);
      }

      if(qie==0){
        if (PlayCanvas.para == 21) {
        g.drawString("升学考试",35,25,Graphics.TOP | Graphics.LEFT);
        g.drawString("3题答对2题合格", 22, 50, Graphics.TOP | Graphics.LEFT);
        }
      if (PlayCanvas.para == 22) {
        g.drawString("升学考试",35,25,Graphics.TOP | Graphics.LEFT);
        g.drawString("4题答对3题合格", 22, 50, Graphics.TOP | Graphics.LEFT);
        }
      if (PlayCanvas.para == 23) {
        g.drawString("毕业考试",35,25,Graphics.TOP | Graphics.LEFT);
        g.drawString("5题答对4题合格", 22, 50, Graphics.TOP | Graphics.LEFT);
        }
     }

     if(qie==1){
       if (tishu > -1) {
        //题目
         switch (question[j][1].length() / 11) {
          case 0:
            g.drawString(question[j][1].substring(0, question[j][1].length()),
                         4, 17, Graphics.LEFT | Graphics.TOP);
            break;
          case 1:
            g.drawString(question[j][1].substring(0, 10), 4, 17,
                         Graphics.LEFT | Graphics.TOP);
            g.drawString(question[j][1].substring(10, question[j][1].length()),
                         4, 30, Graphics.LEFT | Graphics.TOP);
            break;
         }
        for (int i = 2; i < option; i++) {
          g.drawString(question[j][i], 25, 50 + (i - 2) * 15,
                       Graphics.LEFT | Graphics.TOP);
          }
        }
     }

     if(qie==3||qie==4){
       g.setColor(255,0,0);
       g.fillArc(40,50,45,45,0,360);
       g.setColor(0x003399);
       g.fillArc(45,55,35,35,0,360);
       g.setColor(255,0,0);
       //合格
       if(qie==3){
         g.drawString("合格",50,65,Graphics.LEFT | Graphics.TOP);
       }
       //不合格
       if(qie==4){
         g.drawString("不合格",45,65,Graphics.LEFT | Graphics.TOP);
       }
     }

     if(qie==5){
       g.drawString("奖励5000分", 35, 22, Graphics.LEFT | Graphics.TOP);
     }

     if(qie==5||qie==7){
        if(PlayCanvas.para==21){
          g.drawString("升入中学", 40, 60, Graphics.LEFT | Graphics.TOP);
        }else
        if(PlayCanvas.para==22){
          g.drawString("升入大学", 40, 60, Graphics.LEFT | Graphics.TOP);
        }else
        if(PlayCanvas.para==23){
          g.drawString("恭喜毕业", 40, 60, Graphics.LEFT | Graphics.TOP);
        }
     }
     //加分动画
     if(qie==7){
       score=scorere+scoindex*100;
       scorestr=String.valueOf(score);
       g.drawString(scorestr, 91, 115, Graphics.LEFT | Graphics.TOP);
       reward=5000-scoindex*100;
       rewardstr=String.valueOf(reward);
       g.drawString(rewardstr, 40, 22, Graphics.LEFT | Graphics.TOP);
     }

      if(qie==6){
        if(PlayCanvas.para==21){
          g.drawString("九年义务教育", 30, 22, Graphics.LEFT | Graphics.TOP);
          g.drawString("升入中学", 40, 60, Graphics.LEFT | Graphics.TOP);
        }else
        if(PlayCanvas.para==22||PlayCanvas.para==23){
          g.drawString("退学", 50, 60, Graphics.LEFT | Graphics.TOP);
        }
      }
   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -