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

2021/1/23

Spelletje programmeren hulp gezocht

Ilaria Ilaria

2021/1/23

#
Hallo Ik moet van school een spelletje programmeren met 2 andere personen. En het is de bedoeling dat wanneer het spel wordt opgestart dat er hindernissen op random plaatsen verschijnen. Naargelang het level (easy, medium of hard) zouden er dan meer of minder moeten verschijnen. De code die ik hiervoor heb uitgeschreven geeft alleen maar foutmeldingen die nergens op slaan. Ik vroeg me af of er iemand dit al heeft gedaan of hier goed mee overweg kan... De opgave moeten we programmeren in Java (Netbeans) mvg Ilaria
Ilaria Ilaria

2021/1/23

#
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
    public void setHindernissenRandom() {
        // voeg een 1e hindernis toe op random plaats
        Hindernis h = new Hindernis(x,y);
        hindernis.add(h);
        for (int i=0; i <= aantalHindernissen; i++){
         // voeg een hindernis toe op een random plaats
         double x = Math.random()*640;
         double y = Math.random()*480;
 
 
 
Dit is mijn code in de hoofdklasse
        }
         // zolang de plek al bezet is, zoek een nieuwe plek
        while (hindernis.contains(new Hindernis(x,y)) == true) {
            x = (int) (Math.random()*640);
            y = (int) (Math.random()*480);
        }
        hindernis.add(new Hindernis(x,y));
    }
     
    public void aantalHindernissen(Difficulty difficulty) {
        if (difficulty == Difficulty.EASY) {
            setAantalHindernissen(50);
        }
        else if (difficulty == Difficulty.MEDIUM) {
            setAantalHindernissen(30);
        }
        else if (difficulty == Difficulty.HARD){
            setAantalHindernissen(20);
        }
         
    }
Ilaria Ilaria

2021/1/23

#
(Problem in English) Hello For an assignment for school I have to program a game with 2 other people. The intention is that when the game starts, that obstacles appear in random places. Depending on the level (easy, medium or hard) more or less should appear. The code that I wrote for this only gives errors that make no sense. I was wondering if anyone has already done this or gets along well with this ... We have to program the assignment in Java (Netbeans) Kind regards Ilaria
danpost danpost

2021/1/23

#
Line 15 makes no sense. A newly created object cannot already be in an already existing list.
Ilaria Ilaria

2021/1/23

#
Oke, thanks. Do you have any more hints for us? We've already decided that we are not going to make levels anymore. We have the code to spawn one obstacle, but we need to spawn this around 30 times Kind regards Ilaria
danpost danpost

2021/1/23

#
Ilaria wrote...
Do you have any more hints for us?
No. You have only provided two independent methods; one is probably not current code and the other is probably obsolete (if not making levels anymore).
Ilaria Ilaria

2021/1/23

#
Oke, thank you. @Danpost
You need to login to post a reply.