I am creating a MATLAB game for my school project. The goal of the game is to create a 'Treasure Hunt Game' that asks the user to input the number of players, the difficult (easy, medium, or hard), and asks the user(s) to pick spots on a matrix until the correct spot is chosen, therefore winning the game. If a player misses the spot, the command window doesn't show how far away the treasure is, but what direction it is in relation to the previously entered guess. At the start of the game, there is 1000 gold. Every time a player chooses a spot and misses, the game takes away 200 gold from the 'treasure' and the gold that is left is what you win when guessed correctly.
Here's the problem. I cannot figure out how to input the option for 2 players, 3 players, and 4 players. I have already created the code for single player with 3 difficulties, but I am totally clueless as to how to insert that option for the 2,3, and 4 players.
The code should ask for player 1 first, have them guess, then ask for player 2, have them guess, and so forth.
Here is my code so far. I know it can be shortened, but this is the way that best makes sense to me. If you have any suggestions as to how to implement this, that would be great!
Thank you!!!
%% Treasure Hunt Game
START=input('Would you like to play the Treasure Hunt Game? (1 for YES, 2 for NO)');
if START==1;
fprintf('\n')
fprintf('Welcome to Treasure Hunt!\n');
fprintf('\n')
PLAYERS=input('Enter number of players:');
fprintf('\n')
if PLAYERS==1 %%START OF EASY SETTING WITH ONE PLAYER
fprintf('What difficulty would you like to play on? (1 for Easy, 2 for Medium, or 3 for Hard)');
fprintf('\n')
MODE=input('Enter difficulty mode:');
if MODE==1
EZMAP=zeros(5,5);
mat=zeros(5,5);
fprintf('Treasure Map');
GROW=randi(5)
GCOLUMN=randi(5);
mat(GROW,GCOLUMN)=1;
disp(EZMAP)
GUESSROW=input('Guess the row:');
fprintf('\n');
GUESSCOLUMN=input('Guess the column:');
fprintf('\n');
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=0;
while GUESS~=1
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=gold+200;
points=0;
if GUESS==1
points=points+goldp;
fprintf('Congratulations! You have found the hidden treasure! You have earned %.f pieces of gold!\n',points);
break
elseif GUESS~=1
goldp=1000-gold;
fprintf('There are now %.f pieces of gold left. Hurry before it runs out!\n',goldp);
if GUESSROW>GROW
UP='North';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',UP,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',UP,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',UP);
end
elseif GUESSROW
DOWN='South';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',DOWN,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',DOWN,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',DOWN);
end
else
if GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',LEFT);
elseif GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',RIGHT);
end
end
GUESSROW=input('Guess the row');
GUESSCOLUMN=input('Guess the column');
end
if goldp==1200;
fprintf('Unfortunately you took too long to find the treasure. You lose:(');
break
end
end
end %%END OF EASY SETTING WITH ONE PLAYER
if MODE==2 %%START OF MEDIUM SETTING WITH ONE PLAYER
MMAP=zeros(10,10);
mat=zeros(10,10);
fprintf('Treasure Map');
GROW=randi(10)
GCOLUMN=randi(10);
mat(GROW,GCOLUMN)=1;
disp(EZMAP)
GUESSROW=input('Guess the row:');
fprintf('\n');
GUESSCOLUMN=input('Guess the column:');
fprintf('\n');
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=0;
while GUESS~=1
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=gold+200;
points=0;
if GUESS==1
points=points+goldp;
fprintf('Congratulations! You have found the hidden treasure! You have earned %.f pieces of gold!\n',points);
break
elseif GUESS~=1
goldp=1000-gold;
fprintf('There are now %.f pieces of gold left. Hurry before it runs out!\n',goldp);
if GUESSROW>GROW
UP='North';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',UP,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',UP,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',UP);
end
elseif GUESSROW
DOWN='South';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',DOWN,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',DOWN,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',DOWN);
end
else
if GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',LEFT);
elseif GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',RIGHT);
end
end
GUESSROW=input('Guess the row');
GUESSCOLUMN=input('Guess the column');
end
if goldp==1200;
fprintf('Unfortunately you took too long to find the treasure. You lose:(');
break
end
end
end %%END OF MEDIUM SETTING WITH ONE PLAYER
if MODE==3 %%START OF HARD SETTING WITH ONE PLAYER
HMAP=zeros(15,15);
mat=zeros(15,15);
fprintf('TREASURE MAP');
GROW=randi(15)
GCOLUMN=randi(15);
mat(GROW,GCOLUMN)=1;
disp(EZMAP)
GUESSROW=input('Guess the row:');
fprintf('\n');
GUESSCOLUMN=input('Guess the column:');
fprintf('\n');
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=0;
while GUESS~=1
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=gold+200;
points=0;
if GUESS==1
points=points+goldp;
fprintf('Congratulations! You have found the hidden treasure! You have earned %.f pieces of gold!\n',points);
break
elseif GUESS~=1
goldp=1000-gold;
fprintf('There are now %.f pieces of gold left. Hurry before it runs out!\n',goldp);
if GUESSROW>GROW
UP='North';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',UP,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',UP,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',UP);
end
elseif GUESSROW
DOWN='South';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',DOWN,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s from your previously guessed spot.\n',DOWN,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',DOWN);
end
else
if GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',LEFT);
elseif GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s from your previously guessed spot.\n',RIGHT);
end
end
GUESSROW=input('Guess the row');
GUESSCOLUMN=input('Guess the column');
end
if goldp==1200;
fprintf('Unfortunately you took too long to find the treasure. You lose:(');
break
end
end
end %%END OF HARD SETTING WITH ONE PLAYER
Matlab Code for multi-player:
clear
clc
%% Treasure Hunt Game
START=input('Would you like to play the Treasure Hunt Game? (1 for
YES, 2 for NO)');
if START==1;
fprintf('\n')
fprintf('Welcome to Treasure Hunt!\n');
fprintf('\n')
PLAYERS=input('Enter number of players:');
fprintf('\n')
for PLAYER=1:1:PLAYERS %%for multi-PLAYER
fprintf('\n-------------------------------------\n')
fprintf('Player - %d',PLAYER);
fprintf('\n-------------------------------------\n')
fprintf('What difficulty would you like to play on? (1 for Easy, 2
for Medium, or 3 for Hard)');
fprintf('\n')
MODE=input('Enter difficulty mode:');
if MODE==1
EZMAP=zeros(5,5);
mat=zeros(5,5);
fprintf('Treasure Map\n');
GROW=randi(5);
GCOLUMN=randi(5);
mat(GROW,GCOLUMN)=1;
disp(EZMAP)
GUESSROW=input('Guess the row:');
fprintf('\n');
GUESSCOLUMN=input('Guess the column:');
fprintf('\n');
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=0;
while GUESS~=1
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=gold+200;
points=0;
if GUESS==1
points=points+goldp;
fprintf('Congratulations! You have found the hidden treasure! You
have earned %.f pieces of gold!\n',points);
break
elseif GUESS~=1
goldp=1000-gold;
fprintf('There are now %.f pieces of gold left. Hurry before it
runs out!\n',goldp);
if GUESSROW>GROW
UP='North';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',UP,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',UP,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',UP);
end
elseif GUESSROW
DOWN='South';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',DOWN,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',DOWN,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',DOWN);
end
else
if GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',LEFT);
elseif GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',RIGHT);
end
end
GUESSROW=input('Guess the row');
GUESSCOLUMN=input('Guess the column');
end
if goldp==1200;
fprintf('Unfortunately you took too long to find the treasure. You
lose:(');
break
end
end
end %%END OF EASY SETTING WITH ONE PLAYER
if MODE==2 %%START OF MEDIUM SETTING WITH ONE PLAYER
MMAP=zeros(10,10);
mat=zeros(10,10);
fprintf('Treasure Map\n');
GROW=randi(10);
GCOLUMN=randi(10);
mat(GROW,GCOLUMN)=1;
disp(MMAP)
GUESSROW=input('Guess the row:');
fprintf('\n');
GUESSCOLUMN=input('Guess the column:');
fprintf('\n');
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=0;
while GUESS~=1
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=gold+200;
points=0;
if GUESS==1
points=points+goldp;
fprintf('Congratulations! You have found the hidden treasure! You
have earned %.f pieces of gold!\n',points);
break
elseif GUESS~=1
goldp=1000-gold;
fprintf('There are now %.f pieces of gold left. Hurry before it
runs out!\n',goldp);
if GUESSROW>GROW
UP='North';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',UP,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',UP,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',UP);
end
elseif GUESSROW
DOWN='South';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',DOWN,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',DOWN,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',DOWN);
end
else
if GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',LEFT);
elseif GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',RIGHT);
end
end
GUESSROW=input('Guess the row');
GUESSCOLUMN=input('Guess the column');
end
if goldp==1200;
fprintf('Unfortunately you took too long to find the treasure. You
lose:(');
break
end
end
end %%END OF MEDIUM SETTING WITH ONE PLAYER
if MODE==3 %%START OF HARD SETTING WITH ONE PLAYER
HMAP=zeros(15,15);
mat=zeros(15,15);
fprintf('TREASURE MAP');
GROW=randi(15);
GCOLUMN=randi(15);
mat(GROW,GCOLUMN)=1;
disp(HMAP)
GUESSROW=input('Guess the row:');
fprintf('\n');
GUESSCOLUMN=input('Guess the column:');
fprintf('\n');
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=0;
while GUESS~=1
GUESS=mat(GUESSROW,GUESSCOLUMN);
gold=gold+200;
points=0;
if GUESS==1
points=points+goldp;
fprintf('Congratulations! You have found the hidden treasure! You
have earned %.f pieces of gold!\n',points);
break
elseif GUESS~=1
goldp=1000-gold;
fprintf('There are now %.f pieces of gold left. Hurry before it
runs out!\n',goldp);
if GUESSROW>GROW
UP='North';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',UP,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',UP,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',UP);
end
elseif GUESSROW
DOWN='South';
if GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',DOWN,RIGHT);
elseif GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s%s
from your previously guessed spot.\n',DOWN,LEFT);
else
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',DOWN);
end
else
if GUESSCOLUMN
LEFT='West';
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',LEFT);
elseif GUESSCOLUMN>GCOLUMN
RIGHT='East';
fprintf('Incorrect spot. Please try again. The treasure lies %s
from your previously guessed spot.\n',RIGHT);
end
end
GUESSROW=input('Guess the row');
GUESSCOLUMN=input('Guess the column');
end
if goldp==1200;
fprintf('Unfortunately you took too long to find the treasure. You
lose:(');
break
end
end
end %%END OF HARD SETTING WITH ONE PLAYER
end
gold_player(PLAYER)=goldp;
end
for PLAYER=1:PLAYERS
if gold_player(PLAYER)==max(gold_player);
win_player=PLAYER;
end
end
fprintf('\n\nPlayer-%d wins\n',PLAYER);
Save the above program and execute it.
Result:
I hope this will help you.
I am creating a MATLAB game for my school project. The goal of the game is...
C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round,...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x's, y's, and v's to popup in the command window so I can put in any value and it will find the value for me using the equation I put in. function project_9_sjl() % PROJECT_9_SJL project_9_sjl() is the driver function for the program. % % Name: Scott Lawrence % Date: 3/27/2019 % Class: CMPSC 200 % Description: Determine the optimal...
Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...
JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** The user guesses a letter. All occurrences of the letter in the phrase are replaced in...
For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...
I need help fixing my python3 code. I am trying to get my Monty hall game working correctly. Below is my code. When I run the code it repeats the first question and doesn't work until the 3rd attempt or sometimes more than that. How do I fix this? I also need to be able to make it run 5 times in a row.(like ask the user at least 5 times, so it is re-playable. I added a image of...
can this code be provided? Project #3 Introduction As you wrap up with JavaScript, let's put together everything you've learned to make the classic game "Hangman" in a webpage. If you are unfamiliar with the rules of Hangman, the game works like this: A gallows is drawn on a surface, and Player 1 chooses a word that player 2 must guess. Empty dashes for each letter in the word are drawn next to the gallows (so a 7-letter word means...
Currently, the game allows players to play as many times as they wish. It does not provide any feedback on how the players are doing, however. Modify the game so that it keeps track of the number of games played as well as the average number of guesses made per game. To implement this change, add the following list of global variables to the beginning of the script’s Main Script Logic section. Assign each variable an initial value of zero....
HEy GUYS PLZ I WROTE THIS CODE BUT I WAS ASKED TO ADD SOME ASSERTION TESTS AND I HAVE NEVER DONE SUCH THING. CAN YOU GUYS HELPS ME OUT ON HOW TO TEST A SIMPLE CODE SINCE ITS A GUESSING GAME! THANK YOU. PYTHON import random # here it allows us to use the benefits of the functions random #function 1 which is just a screen organized wordings def screen): screeninstructions () name input("Your Name : ") print('Welcome, name, 'This...