Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

i would like to code a single player game where at each turn a player has to write a letter on a grid. In response the computer would write a letter and so on. As soon as a word is created as a result of writing a letter, the player gets as many points as the no of letters in the word. how would i code it.

share|improve this question

closed as not a real question by Tetrad Dec 26 '12 at 4:03

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
You should start coding by your self and then ask for a particular problem if it occurs. But basically you need to generate a random letter, get human input, check the string toward a dictionary and then start over. –  danijar Dec 25 '12 at 22:03
    

1 Answer 1

up vote 0 down vote accepted

That’s a pretty easy almost-infinite loop. The main loop is something very common in game programming.

In Pseudo code:

playerTurn = 1 // playerTurn = 1 means its players turn, = 0 means computers turn

somebodyWon = False

while somebodyWon = False:
    if playerTurn:
        askPlayerForInput()
    else:
        writeInputFromComputerArtificialIntelligence()
    somebodyWon = checkIfSomebodyHasWonByUsingADictionary()

As you see, you need several components here:

  • Main class where you handle this loop
  • Some input for the player to input a letter (e.g. scanf() in C or StreamReader in Java)
  • Some easy artificial intelligence for the computer (he could search for words in his dictionary and add one letter for some real word he sees in the dictionary). Ideally, the computer should only know a subset of all real words. This could depend on the difficulty of your game (e.g. on very easy it knows 10% of all words, on very hard it knows 90% of all words)
  • A check for the input word against a list of winner words: Just take the word player + computer have already created and search in a dictionary (list of all real words) for it. If it is there, somebody has won.
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.