Jump to content


Raka9393

Member Since 09 Nov 2011
Offline Last Active Nov 10 2011 03:15 PM

Posts I've Made

In Topic: Hangman Game - Example or Tutorial NEEDED

10 November 2011 - 09:22 AM

Welcome to the forum, I'll give you a little start with some of the basics!

If you have a hard time following the example:
Read up on "for loops" and "arrays".


CREATE EVENT:

//set up rules
tries = 0
max_tries = 10
right_guesses = 0

//set up a word
word_string = get_string('Enter a word','')
word_length = string_length(word_string)
for(i = 0; i < word_length; i += 1) {
word[0, i] = 0
word[1, i] = string_char_at(word_string, i + 1)
}

SOME KEY PRESS EVENT (space or enter or anything...)
//check a letter
check_letter = string_char_at(get_string('Enter a letter, only the first letter will count!',''), 1)
tries += 1
for(i = 0; i < word_length; i += 1) {
if word[1, i] = check_letter {
if word[0, i] = 0 {
right_guesses += 1
}
word[0, i] = 1
}

//check if you won, if so, show a message and restart the game
if right_guesses = word_length {
show_message('You won!')
game_restart()
exit
}

//check if you used all your tries, if so, show a message and restart the game
if tries > max_tries {
show_message('Game over, you lost!')
game_restart()
}

DRAW EVENT:
//draw your tries
draw_text(10, 10, 'Tries: ' + string(tries) + '/' + string(max_tries))

//draw the letters if the have been guessed at, else draw a star "*"
for(i = 0; i < word_length) {
if word[0, i] = 1 draw_text(10 + i * 10, 30, word[1, i])
else draw_text(10 + i * 10, 30, '*'}

So this is basically just the game, now you can modefiy it with your own rules, graphics, random words and what not :)


Thanks a lot, sire. I appreciate it. Off I go to make my Hangman!! :D