Hallo allen,
ik ben nogal een leek op het gebied van programmeren e.d. en zit dus nu ook compleet vast.
Het idee is dat ik een sketch maak waar er telkens een vraag wordt gesteld waarop mensen 'Yes' of 'No' kunnen antwoorden. De code hieronder heb ik ergens van het internet vandaan geplukt en ik probeer 'm dus te veranderen naar hetgeen dat ik wil. Het probleem is dat ik na elk antwoord een nieuwe vraag wil waarop mensen dan vervolgens weer Yes of No op antwoorden. Ik krijg dit echter niet voor elkaar. Ik kom niet verder dan de eerste vraag. Waar gaat 't fout?
Uiteindelijk moet er dus na # vragen een scherm komen eindscherm komen met iets van 'Thanks for you participation'. En zou 't ook mogelijk zijn om alle vragen van 1 persoon op te slaan in een txt file? Daarna moet de vragenlijst uit zichzelf weer herstarten.
Ik zit hier echt al veel te lang op te piekeren ;(]
Alvast bedankt
ik ben nogal een leek op het gebied van programmeren e.d. en zit dus nu ook compleet vast.
Het idee is dat ik een sketch maak waar er telkens een vraag wordt gesteld waarop mensen 'Yes' of 'No' kunnen antwoorden. De code hieronder heb ik ergens van het internet vandaan geplukt en ik probeer 'm dus te veranderen naar hetgeen dat ik wil. Het probleem is dat ik na elk antwoord een nieuwe vraag wil waarop mensen dan vervolgens weer Yes of No op antwoorden. Ik krijg dit echter niet voor elkaar. Ik kom niet verder dan de eerste vraag. Waar gaat 't fout?
code:
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
| int gameState=0; int currentQuestion = 0; int START_SCREEN = 0; int GAME_QUESTION = 1; int CORRECT_ANSWER = 2; int WRONG_ANSWER = 3; int WIN_SCREEN = 4; Question[] questions = new Question[4]; void setup() { size(800, 600); textSize(30); String[] answers0 = { "Yes", "No" }; questions [0] = new Question("Have you ever stolen something?", 'y', answers0); String[] answers1= { "Yes", "No" }; questions [1] = new Question("Have you ever used Processing?", 'y', answers1); String[] answers2 = { "Yes", "No" }; questions [2]= new Question ("Do you have a teddybear?", 'y', answers2); String[] answers3 = { "Yes", "No" }; questions [3] = new Question("Have you ever eaten a banana", 'y', answers3); } void draw () { background (#FFFFFF); if (gameState == START_SCREEN) { drawSplashScreen(); text ("Please answer the following questions.", width/2, height/2); } else if (gameState == GAME_QUESTION) { questions[currentQuestion].display(); } else if (gameState == CORRECT_ANSWER) { drawCorrectScreen(); } else if (gameState == WRONG_ANSWER) { drawWrongAnswerScreen(); } else if (gameState == WIN_SCREEN) { drawWinScreen(); } } void keyPressed() { if (gameState == START_SCREEN) { gameState = 1; } else if (gameState == WRONG_ANSWER) { if (key == ' ') { gameState = GAME_QUESTION; } } if (key =='n') { gameState = WRONG_ANSWER; } else if (gameState == WRONG_ANSWER) { currentQuestion = 0; gameState = GAME_QUESTION; } else if (gameState == WRONG_ANSWER) { currentQuestion = 1; gameState = GAME_QUESTION; } else if (gameState == WRONG_ANSWER) { currentQuestion = 2; gameState = GAME_QUESTION; } else if (gameState == WRONG_ANSWER) { currentQuestion = 3; gameState = GAME_QUESTION; } if (key =='y') { gameState = CORRECT_ANSWER; } else if (gameState == CORRECT_ANSWER) { currentQuestion = 0; gameState = GAME_QUESTION; } else if (gameState == CORRECT_ANSWER) { currentQuestion = 1; gameState = GAME_QUESTION; } else if (gameState == CORRECT_ANSWER) { currentQuestion = 2; gameState = GAME_QUESTION; } else if (gameState == CORRECT_ANSWER) { currentQuestion = 3; gameState = GAME_QUESTION; } } void drawSplashScreen () { textAlign (CENTER); fill (#000000); text ("Please answer the following questions.", width/2, height/2); } void drawCorrectScreen() { textAlign(CENTER); fill(0); text("You answered yes.", width/2, height/2); } void drawWrongAnswerScreen() { textAlign(CENTER); fill(0); text("You answered no.", width/2, height/2); } void drawWinScreen() { textAlign(CENTER); fill(0); text("Thank you for your participation.", width/2, height/2); } class Question { String question; char correctAnswer; String[] answers; Question(String nquestion, char ncorrectAnswer, String[] nanswers) { question = nquestion; correctAnswer = ncorrectAnswer; answers = nanswers; } void display() { textAlign(CENTER); noFill(); // Question text(question, 400, 100); // Answer 0 text(answers[0], 200, 300); // Answer 1 text(answers[1], 600, 300); } boolean isCorrectAnswer(char answer) { if ( answer == correctAnswer )return true; else return false; } } |
Uiteindelijk moet er dus na # vragen een scherm komen eindscherm komen met iets van 'Thanks for you participation'. En zou 't ook mogelijk zijn om alle vragen van 1 persoon op te slaan in een txt file? Daarna moet de vragenlijst uit zichzelf weer herstarten.
Ik zit hier echt al veel te lang op te piekeren ;(]
Alvast bedankt