We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I am looking for someone who can help me with a problem. Its a beginner problem, but I am learning.
I want to make a menuscreen before the game will start. So first you need to put your name on it and then you ll begin. but my problem is, that I can't select on a textbox for putting a name.
// huidige naam die je typt String naamSpeler1=""; String naamSpeler2=""; String savedPlayer1; String savedPlayer2;
void setup() { size(444, 444); background(51); }
void draw () { background(111);
// Tekst boven fill(0, 255, 163); // groen text("SPELER 1", 20, 60); text("SPELER 2", 20, 80);
// naam op vulhokje noFill(); stroke(255); rect (10, 115, 170, 20); rect (10, 200, 170, 20); // text fill(255); // white text(naamSpeler1, 20, 129); text(naamSpeler2, 20, 216);
//start knop noFill(); rect(305,300,60,20); textSize(15); text("START",310,315);
} void keyPressed () {
if (key == ENTER) {//heeft gekozen voor naam if (!naamSpeler1.equals("")|| !naamSpeler2.equals("")) { savedPlayer1 = naamSpeler1; naamSpeler1 = ""; println (savedPlayer1); savedPlayer2 = naamSpeler2; naamSpeler2 = ""; println (savedPlayer2); } } //else { // record the keys (in the current word) naamSpeler1 = naamSpeler1 + (key+""); naamSpeler2 = naamSpeler2 + (key+"");
} //else } // func //
its in dutch but you ll understand what I mean, if you run it.
Answers
Please read how to format code for this forum below: :-@
http://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
Quickest dirty solution is to use JOptionPane and its showInputDialog():
http://docs.Oracle.com/javase/8/docs/api/javax/swing/JOptionPane.html
If you intend to deploy it via "JS Mode" PJS you're gonna need a small utility library I wrote:
http://forum.Processing.org/two/discussion/12532/windowjs-cross-mode-alert-confirm-prompt-other-js-api-for-java
Then call window.prompt() to get the same effect as showInputDialog() but compatible w/ JS. *-:)
Additionally I recommend using states.
The idea here is that you have a var state that tells you if your program is in mode nameEnter or in mode Game
So in draw() you either paint the stuff for name entering OR the stuff for the actual game
Yes! actually its a begin of a game.
So you first need to enter your name twice, because its a multiplayer game. But I want to press on the textbox and press my name on and then I will enter my name in the second box.
I really don't understand much of this program. But i tried everything what i could.
Would you give me an example or anything.
Thank you!
I am on a journey but can have a look later
[EDITED]
I posted now a bit...
I hope this is not too long for you to grasp.
It just shows the usage of states and how to get two player names
anyway, it is all code from this forum, not by me really.
I hope this is not too long for you to grasp.
It just shows the usage of states and how to get two player names
anyway it is all code from this forum.
OK, you need to learn how to format code here on the forum
you could go back and edit your post to format the code better
you need to learn how to give your posts better headlines. Don't use capitals and don't say you need help, just describe your issue and post code.
a memory game
to do a memoy game is a little harder.
Are you familiar with object oriented programming? There is a tutorial for that. It's called Objects.
Thus each card would have a x,y position and an image and an ID that it shairs with its partner.
You would have an array of those objects.
I am on a longer journey now, so I can't help you with that