This site requires JavaScript, please enable it in your browser!
Greenfoot back
Ram1254
Ram1254 wrote ...

2017/4/3

Help Me

Ram1254 Ram1254

2017/4/3

#
Well im really really new to green foot and I want to make a Quiz type game But I have absolutely no clue how I gave it a try but that not getting me any where so can You guys help me Im not trying to make anything anything to complicated just a simple quiz question game that has
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
 
/**
 * Write a description of class MyWorld here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class MyWorld extends World
{
    ArrayList questions = new ArrayList<Question>();
    int currentQuestion = 0;
    int score = 0;
    /**
     * Constructor for objects of class MyWorld.
     *
     */
    public MyWorld()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
         
        //Define Questions
        String[] awnsers = {"15%","20%","30%","40%"};
        questions.add(new Question("How many percent of the worlds population live in Asia?",
                                   awnsers,
                                   3));
        showQuestion(currentQuestion);
        showScore();
         
        checkClick();
    }
    public void checkClick(){
        MouseInfo mouse = Greenfoot.getMouseInfo();
        if(mouse==null)return;
        int x = mouse.getX();
        int y = mouse.getY();
    }
    public void showScore(){
         this.showText("Score: "+score, 50, 375);
    }
    public void showQuestion(int index){
        Question q = (Question) questions.get(index);
        this.showText(q.question, 300, 50);
         
        this.showText(q.awnsers[0], 300, 100);
        this.showText(q.awnsers[1], 300, 150);
        this.showText(q.awnsers[2], 300, 200);
        this.showText(q.awnsers[3], 300, 250);
    }
}
right and wrong answers and can Go from question to question after you answer . This is what i had so far:
ALPH3A ALPH3A

2017/4/3

#
hello
Ram1254 Ram1254

2017/4/3

#
Help me
Nosson1459 Nosson1459

2017/4/3

#
What did you try to do and what happened as opposed to what was supposed to.
Ram1254 Ram1254

2017/4/3

#
Well the code Up there literally just brings the text on the screen up and that is about all
Ram1254 Ram1254

2017/4/3

#
I need the code to add score for correct answers and Minus score for incorrect answers
Super_Hippo Super_Hippo

2017/4/3

#
If you use 'showText', then you can't check for mouse clicks on them. Well, you can get the mouse coordinates and compare them with the position of where you added the text, but this is quite complicated.
danpost danpost

2017/4/3

#
The constructor block, lines 19 through 33, is only executed once and is used to set up the world. Since asking questions will probably be done while the scenario is running, the constructor, then, would not be the place to initiate a question. Also, the answers are lost once the world is done being constructed because you declare the String array within the constructor block. I do not believe that a List object is the best choice for the questions, either. A standard array would seem more appropriate as the length (depending on the number of questions you include within the code) is fixed and the data would be easier to code (and visibly so). Alright, so now you would have a field array of questions with their optional answers along with the score value and current question number; you would have a constructor with only a 'super' statement in it (unless you want to do something with the background image there); and you are missing one thing -- an 'act' method that "runs" the world. It would control the asking of the questions and game over checking. Currently, I would say that lines 29 through 32 would go in the act method, however, each of these lines has a specific problem. The 'showQuestion' lines needs to be done only under specific conditions -- initially and when prior question is completed. The 'showScore' method only needs to be done initially and when the score changes. The 'checkClick' method will only need done between the time a question is given to the time a valid click is performed. The implementation of the method if quite useless, however; and the name of the method does not fit what the method is trying to do. Currently, the method gets any new location of the mouse and that is it. It does not save the information or use it in any way. The 'x' and 'y' variables are declared inside the method and their values are lost the moment the method is done executing each act cycle. No clicks are even mentioned inside the method, so the name is inappropriate. I will presume that the reason for the location of the mouse is to determine where a click does occur (when it occurs) so that it can be checked for validity (that is was done on one of the answer options of the question) and, in turn, determine if was clicked on the correct answer or not.
You need to login to post a reply.