<<

%%Hangman words = {'electricity', 'donkey', 'hardware', 'xerox', 'transistor', 'computer', 'desktop'...

'engineering', 'hangman', 'circuit', 'imagination', 'robot', 'memory', 'power', 'recursion'...

'submarine', 'chess', 'resistance', 'matrix', 'function', 'laser', 'mechanism', 'telephone'...

'bodyguard', 'titanic', 'global', 'ozone', 'bridge', 'technology', '', 'universe'...

'pyramid', 'sphere', 'member', 'warning', 'yourself', 'screen', 'language', 'elevator'...

'system', 'internet', 'parameter', 'traffic', 'network', 'filter', 'nucleus', 'result'...

'automatic', 'microphone', 'cassette', 'operation', 'country', 'beautiful', 'mission'...

'picture', 'teacher', '', 'undertaker', 'alarm', 'process', 'keyboard', 'poetry'...

'electron', 'certificate', 'grandfather', 'landmark', 'relativity', 'eraser', 'amplifier'...

'design', 'football', 'human', 'musician', 'egyptian', 'elephant', 'queen', 'reception'...

'message', 'wallpaper', 'nationality', 'answer', 'wrong', 'statement', 'forest', 'dolphin'...

'puzzle', 'voltage', 'current', 'mathematics', 'wisdom', 'dream', 'supermarket', 'notebook'...

'database', 'collection', 'barrier', 'project', 'sunlight', 'figure', 'graph', 'orange'...

'battle', 'hundred', 'signal', 'thousand', 'transformation', 'daughter', 'flower', 'knife'...

'communication', 'microwave', 'electronic', 'peace', 'wireless', 'delete', 'window'...

'brain', 'control', 'prophet', 'freedom', 'harbour', 'confidence', 'positive', 'husband'...

'harvest', 'hunger', 'woman', 'children', 'stranger', 'garden', 'pleasure', 'laughter'...

'between', 'recognition', 'tomorrow', 'autumn', 'monkey', 'spring', 'winter', 'misfortune'...

'classification', 'typewriter', 'success', 'difference', 'acoustics', 'astronomy', 'train'...

'agreement', 'sorrow', 'christmas', 'silver', 'birthday', 'championship', 'friendship'...

'comfortable', 'diffusion', 'murder', 'policeman', 'science', 'desert', 'basketball'...

'blood', 'funeral', 'silence', 'garment', 'merchant', 'spirit', 'punishment', 'stone'...

'measurement', 'ocean', 'digital', 'illusion', 'tyrant', 'castle', 'passion', 'physician'...

'magician', 'remedy', 'knowledge', 'threshold', 'number', '', 'expectation', 'fluid'...

'absence', 'mystery', 'morning', 'device', 'thoughts', 'spirit', 'future', 'impossible'...

1

'mountain', 'treasure', 'machine', 'whispering', 'eternity', 'reflection', 'occupation'...

'achievement', 'lightning', 'secret', 'environment', 'shepherd', 'confusion', 'expansion'...

'grave', 'promise', 'honour', 'reward', 'temple', 'distance', 'eagle', 'saturn', 'grass'...

'finger', 'belief', 'crystal', 'fashion', 'direction', 'captain', 'moment', 'improvement'...

'permission', 'logic', 'analysis', 'password', 'english', 'equalizer', 'simulation'...

'emotion', 'battle', 'expression', 'scissors', 'trousers', 'glasses', 'department', 'creation'...

'dictionary', 'chemistry', 'induction', 'detail', 'widow', 'wealth', 'health', 'faculty'...

'disaster', 'volcano', 'poverty', 'limitation', 'perfect', 'intelligence', 'infinite'...

'failure', 'ignorance', 'destination', 'source', 'resort', 'satisfaction', 'example', 'night'...

'frequency', 'selection', 'substitution', 'kingdom', 'pattern', 'management', 'experience'...

'situation', 'multiply', 'treatment', 'dollar', 'intuition', 'chapter', '', 'miracle'...

'desire', 'command', 'action', 'consciousness', 'enemy', 'security', 'object', 'realization'...

'happen', 'happiness', 'worry', 'method', 'tolerance', 'error', 'hesitation', 'register'...

'record', 'tongue', 'supply', 'vibration', 'stress', 'despair', 'restaurant', 'month', 'never'...

'television', 'video', 'audio', 'layer', 'mixture', 'doorbell', 'cousin', 'beard', 'corner'...

'finance', 'production', 'invisible', 'excitement', 'afternoon', 'office', 'alphabet', 'certain'...

'illustration', 'valley', 'apartment', 'necessary', 'shortage', 'almost', 'furniture'...

'blanket', 'suggestion', 'overflow', 'demonstration', 'challenge', 'compact', 'kitchen'...

'tower', 'question', 'problem', 'pressure', 'beast', 'encouragement', 'afraid', 'giant'...

'cavity', 'appearance', 'wonderful', 'matter', 'dimension', 'business', 'doubt', 'minute'...

'conversation', 'reaction', 'psychology', 'superstition', 'smash', 'horseshoe', 'change'...

'surprise', 'nothing', 'ladder', 'opposite', 'reality', 'genius', 'string', 'disease'...

'destruction', 'expensive', 'painting', 'chicken', 'wishing', 'profession', 'engagement'...

'hatred', 'possession', 'criticism', 'zebra', 'harmony', 'personality', 'overcome', 'defeat'...

'addition', 'subtraction', 'cipher', 'encryption', 'compression', 'extension', 'towards'...

'blessing', 'meeting', 'difficulty', 'weapon', 'against', 'external', 'internal', 'absolute'...

'legend', 'servant', 'secondary', 'license', 'directory', 'statistics', 'generator', 'motor'...

2

'attraction', 'sensitivity', 'magnification', 'someone', 'symptom', 'recipe', 'muscle'...

'service', 'family', 'island', 'planet', 'butterfly', 'diving', 'strength', 'missile', 'stream'...

'extreme', 'opportunity', 'illumination', 'cable', 'conflict', 'interference', 'anxiety'...

'receiver', 'transmitter', 'channel', 'company', 'grocery', 'devil', '', 'angle', 'ellipse'...

'exactly', 'document', 'tutorial', 'sound', 'voice', 'abbreviation', 'abdomen', 'abort'...

'abrupt', 'absolute', 'absorption', 'abstract', 'academy', 'acceleration', 'accessory'...

'accident', 'account', 'acidification', 'actress', 'adaptation', 'addiction', 'address'...

'adjustment', 'admiration', 'adoption', 'advanced', 'adventure', 'advertisement', 'aeroplane'...

'agenda', 'airport', 'algorithm', 'allocation', 'aluminium', 'ambiguity', 'ambition', 'ammeter'...

'amphibian', 'anaesthesia', 'analogy', 'anchor', 'animation', 'anode', 'cathode', 'antibiotic'...

'apparent', 'appendix', 'approval', 'approximation', 'arbitrary', 'architecture', 'argument'...

'arithmetic', 'arrangement', 'article', 'ascending', 'ashamed', 'asleep', 'assassination'...

'assembly', 'astonishment', 'atmosphere', 'awful', 'bachelor', 'backbone', 'background'...

'bacteria', 'balance', 'balloon', 'banana', 'barbecue', 'baseball', 'beaker', 'bedroom'...

'beggar', 'behaviour', 'benefit', 'bidirectional', 'biology', 'blackboard', 'blackmail'...

'bladder', 'bleeding', 'blender', 'bonus', 'bottle', 'bracket', 'branch', 'brilliant', 'brown'...

'bubble', 'bucket', 'budget', 'bullet', 'burglar', 'butcher', 'bypass', 'cafeteria', 'calendar'...

'calculator', 'calibration', 'campaign', 'cancellation', 'candidate', 'candle', 'capacitor'...

'carpenter', 'carriage', 'cartoon', 'cascade', 'casual', 'catalyst', 'category', 'celebration'...

'cement', 'ceremony', 'chairman', 'checkout', 'chimney', 'chocolate', 'cigarette', 'church'...

'circumference', 'civilization', 'classroom', 'clearance', 'client', 'coconut', 'coffee'...

'coincidence', 'colleague', 'comfortable', 'competition', 'kangaroo', 'kidnap', 'junction'...

'journal', 'jockey', 'iteration', 'isometric', 'isolation', 'invitation', 'intersection'...

'institution', 'injection', 'humanity', 'housekeeper', 'history', 'heaven', 'guitar', 'guilt'...

'greenhouse', 'glory', 'foundation', 'formula', 'fluctuation', 'fiction', 'extraordinary'...

'emission', 'elasticity', 'earthquake', 'dynamic', 'doctorate', 'divorce', 'derivation'... 'nightmare', 'virtue', 'description'}; %%Picking word

3 word_index = randi(length(words), 1,1); %%Turns into the guessing word guessingWord = words{word_index}; %%Creates a array of numbers word = cell(1,length(guessingWord)); %%Fills in letters for i=1:length(guessingWord) word{i}= '_'; end incorrect = 0; correct = 0; wrongcounter = 0; %%Loop of game playing while(true) %%Displays the underscores for i=1:length(guessingWord) fprintf('%s ',word{i}); end fprintf('\n'); %%Input from player, only takes one letter guess = input('Please guess a letter : ','s');

%%Loop that fills in letters and finds if you got the letter correct or %%wrong for i=1:length(guessingWord) if(guessingWord(i) == guess) word{i} = guessingWord(i); correct = correct + 1; end if(guessingWord(i) ~= guess) wrongcounter = wrongcounter + 1; end if (wrongcounter == length(guessingWord)) incorrect = incorrect + 1; fprintf('incorrect: %1.0f out of 7\n',incorrect) end end wrongcounter = 0;

%%If statements for drawing hanged person if (incorrect == 1) fprintf(' ______') fprintf('\n| | ') fprintf('\n| O ') fprintf('\n| ') fprintf('\n| ') fprintf('\n| ') fprintf('\n| ') fprintf('\n|__ \n') elseif (incorrect == 2) fprintf(' ______') fprintf('\n| | ')

4 fprintf('\n| O ') fprintf('\n| | ') fprintf('\n| ') fprintf('\n| ') fprintf('\n| ') fprintf('\n|__ \n') elseif (incorrect == 3) fprintf(' ______') fprintf('\n| | ') fprintf('\n| O ') fprintf('\n| /| ') fprintf('\n| ') fprintf('\n| ') fprintf('\n| ') fprintf('\n|__ \n') elseif (incorrect == 4) fprintf(' ______') fprintf('\n| | ') fprintf('\n| O ') fprintf('\n| /|\\ ') fprintf('\n| ') fprintf('\n| ') fprintf('\n| ') fprintf('\n|__ \n') elseif (incorrect == 5) fprintf(' ______') fprintf('\n| | ') fprintf('\n| O ') fprintf('\n| /|\\ ') fprintf('\n| | ') fprintf('\n| ') fprintf('\n| ') fprintf('\n|__ \n') elseif (incorrect == 6) fprintf(' ______') fprintf('\n| | ') fprintf('\n| O ') fprintf('\n| /|\\ ') fprintf('\n| | ') fprintf('\n| / ') fprintf('\n| ') fprintf('\n|__ \n') elseif (incorrect == 7) fprintf(' ______') fprintf('\n| | ') fprintf('\n| O ') fprintf('\n| /|\\ ') fprintf('\n| | ') fprintf('\n| / \\ ') fprintf('\n| ') fprintf('\n|__ \n') end

5 if (correct == length(guessingWord) || incorrect == 7 ) break end end for i=1:length(guessingWord) fprintf('%s ',word{i}); end

%%Winning screen if (correct == length(guessingWord)) fprintf('\nCongratulations, you win!\n'); fprintf('\nThe word was %s \n', guessingWord ) elseif (incorrect == 7) fprintf('\nBetter luck next time!\n'); fprintf('\nThe word was %s \n', guessingWord ) end

%%END!

______

Error using input Cannot call INPUT from EVALC.

Error in DaHangerBro (line 103) guess = input('Please guess a letter : ','s');

Published with MATLAB® R2020b

6