The Game of Life Board

조회 수: 4 (최근 30일)
Edgardo Caban
Edgardo Caban 2020년 4월 18일
편집: Walter Roberson 2020년 4월 19일
Main_path = 1:150
Player1_turn = 0;
Player2_turn = 0;
for k = 1:length(Main_path)
randi(10)
end
For a project im recreating The Game of Life in Matlab, To create the board I have decided to utilize arrays. The board will have a total of 150 spaces and in order to move forward the player must use a spinner which goes from 1-10. I also have to choose pre-determined spaces to symbolize the action and payday spaces therefore i want to do it every 6 spaces there will be a payday space (which will be green) the rest should be yellow spaces. For now i cant figure out how to make the player move the amount of spaces depending on the number it gets on the spinner. So for example the spinner rolled 5 so the player moves 5 spaces. Then rolls 7 then the player moves 7 spaces therfore the player's position is Main_path(12)
  댓글 수: 3
Edgardo Caban
Edgardo Caban 2020년 4월 18일
What if there is a red space that must instantly stop the movement of the player, but then the player can roll the spinner again and keep moving
Edgardo Caban
Edgardo Caban 2020년 4월 18일
So for example the player is in postion 12 and he rolled 8 in the spinner but there is a red space at position 14 that he must instantly stop in, but then he can roll the spinner again and keep moving

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 19일
redpos = next_red_position(position); %function call
newposition = position + spinner_value;
go_again = false;
if newposition >= redpos
position = redpos;
go_again = true;
elseif newposition > last_position
do something if you have passed the end
else
position = newposition;
end
if position == last_position
do something when you reach the end
end
  댓글 수: 2
Edgardo Caban
Edgardo Caban 2020년 4월 19일
편집: Edgardo Caban 2020년 4월 19일
Thank you that was really helpful, I also have another question. I need to draw a random card from the following deck
Career1 = 'teacher (50,000)';
Career2 = 'Accountant (70,000)';
Career3 = 'Veterinarian (80,000)';
Career4 = 'Lawyer (90,000)';
Career5 = 'Salesperson (20,000)';
Career6 = 'Mechanic (40,000)';
Career7 = 'Police_Oficcer (50,000)';
Career8 = 'Entertainer (60,000)';
Career9 = 'Athlete (70,000)';
Career10 ='Doctor(110,000)';
Career11 = 'Pilot (100,000)'
Career12 = 'Film_Star (90,000)'
deck = [Career1, Career2, Career3, Career4, Career5, Career6, Career7, Career8, Career9, Career10, Career11, Career12];
card = rand(deck)
Walter Roberson
Walter Roberson 2020년 4월 19일
편집: Walter Roberson 2020년 4월 19일
deck = {Career1, Career2, Career3, Career4, Career5, Career6, Career7, Career8, Career9, Career10, Career11, Career12};
card = deck{randi(length(deck))};

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conway's Game of Life에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by