Hi im in a group project and were making a monopoly game with Matlab and are having troubles with a few things.

7 views (last 30 days)
We need help with trying to find a way to:
1.fix the the total laps counted for each player
2. find a way to add how to display a property when a player lands on it
3. in addition to that how to make it display wether or not a player wants to buy the property if its availible
4. how to end the game and declare a winner
thank you we are very stuck and have been at it for hours but this is a basic intro class to matlab so we are not that advanced
here is our entire script:
clc; clear
global player
Players_Ready=0;
Continue =input('Do you have a saved game to continue? (Y=1/N=0) ')
if(Continue==1)
% Saved game variable file must be in the Current Matlab folder
Game0=input('What is the name of the save file? ','s');
disp('Loading...')
load(Game0);
Players_Ready=1;
else
disp('Beginning a new game')
end
while ~Players_Ready
N=input('How many players? ');
if(N<2)
disp('Playing by yourself? kinda cringe... Please input a number between 2 and 8')
elseif(N>8)
disp('Too many players. Please input a number between 2 and 8')
else
fprintf('Setting up for %d players \n',N)
Players_Ready=1;
end
end
Player_set(N);
load Spaces;
Properties= xlsread('Monopoly_spaces');
%marker information
%First column is marker name
%Second column is zero if unused; one if being used by another player
marker{1,1}='Dog';
marker{2,1}='Wheelbarrow';
marker{3,1}='Iron';
marker{4,1}='Racecar';
marker{5,1}='Thimble';
marker{6,1}='Top Hat';
marker{7,1}='Shoe';
marker{8,1}='Battleship';
for k=1:8
marker{k,2}=0;
end
for k=1:N
fprintf('Player %d \n',k)
disp('___________________')
fprintf('What is Player %d''s name? ',k)
Player_name{k}=input(' ','s');
fprintf('Hello %s! Please choose a marker from the choices below \n',Player_name{k})
for kk=1:8
if (marker{kk,2}==0)
fprintf('(%d) %s \n',kk,marker{kk,1})
end
end
player(k,5)=input('Enter the number of your choice ');
marker{player(k,5),2}=player(k,5);
fprintf('%s has chosen the %s \n', Player_name{k},marker{player(k,5)})
clc;
end
% Main game script begins
Game_Not_Over= 1;
Round=1;
for k=1:N
fprintf('%s the %s is on %s', Player_name{k}, marker{player(k,5),1}, Spaces{player(k,1)})
end
while Game_Not_Over
for k=1:N
Turn_over=0;
Dice_rolls=1;
while ~Turn_over
mmenu(Player_name{k});
opt=input(' ','s');
switch opt
case {'R','r'}
double_count =0;
while Dice_rolls >= 1
Dice_rolls=Dice_rolls-1 ;
disp('rolling the dice')
die1 = randi(6);
die2 = randi(6);
roll=die1+die2
player (k,1)= player(k,1)+ roll
if die1==die2
double_count= double_count+1;
disp('Lucky you, you rolled doubles!')
disp('would you like to roll again, Yes or No?')
Ans = input(' ','s');
switch Ans
case {'Y','y','yes','Yes'}
disp ('rolling again')
Dice_rolls=Dice_rolls+1 ;
case {'N','n','no','No'}
disp('Passing Dice')
Turn_over=1;
end
if double_count == 3
disp('youre going to jail')
player (k,1)= 11;
Dice_rolls=0;
Turn_over=1;
J=3 ;
clear die1 + die2
end
else
end
if player (k,1)>= 40
player (k,1)= player (k,1)- 40;
player (k,7)= player (k,7)+1;
% This needs to be cleaned
fprintf('%s the %s is on a new Lap ',Player_name{k}, marker{player(k,5),1}, player (k,7))
end
double_count=0 ;
clear die1 + die2
Turn_over=1;
end
case {'U','u'}
disp('paying off the mortgage')
case {'J','j'}
disp('Prison break!')
case {'B','b'}
disp('building houses')
case {'P','p'}
disp('passing the dice')
Turn_over=1;
otherwise
disp('Choose from the letters in parentheses')
end
end
end
Round=Round+1;
disp('Do you want to save the game? (Yes or No)')
Game_save=input('','s') ;
switch Game_save
case {'Y','y','Yes','yes'}
disp('Name of Save Game file?')
Game0=input('','s');
save(Game0);
turn_over =1;
end
end
function Jail(J) = player(k,6)
while player(k,6)==~0
disp('You are in jail you scoundrel, What would you like to do?')
disp('(B)ail out (-50$),((W)ait it out),(R)oll for doubles)')
deci=input(' ','s');
switch deci
case{B,b,Bail,bail}
player(k,2)= player(k,2)- 50;
J=0;
case{W,w,wait,Wait}
J=J-1;
case{R,r,roll,Roll}
Jr1= randi(6);
Jr2= randi(6);
if Jr1==Jr2
disp('Lucky you! youre free to go')
J=0;
clear Jr1+ Jr2
else
disp('sorry buddy, not this time')
J=J-1;
clear Jr1+ Jr2
end
end
end
end
function mmenu(name)
% Turn_over=0;
% Dice_rolls=1;
disp('Choose your next action')
disp('(R)oll the dice')
disp('Get out of (J)ail')
disp('(U)nmortgage a property')
disp('(P)ass the dice to the next player')
fprintf('What do you want to do %s? ',name)
% opt=input(' ','s');
% switch opt
% case {'R','r'}
% disp('rolling the dice')
% Dice_rolls=Dice_rolls-1;
% case {'U','u'}
% disp('paying off the mortgage')
%
% case {'J','j'}
% disp('Prison break!')
% case {'B','b'}
% disp('building houses')
% case {'P','p'}
% disp('passing the dice')
% Turn_over=1;
% otherwise
% disp('Choose from the letters in parentheses')
% end
end
function Player_set(N)
%1st space occupied
%2nd cash balance
%3rd player wealth
%4th player active
%5th player token
%6th player crime
% 7th play Lap
global player;
player=zeros([N 7]);
for i=1:N
player(i,:)=[1 1500 1500 1 0 0 1];
end
end
% save((input('save name')));

Answers (0)

Categories

Find more on Card games in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!