Question

Is anyone familiar with programming in Swift? That is the language the solution must be implemented in.

Problem 2: Mini Snakes and Ladders (3 points) Snakes and laders You are going to build a function that mimics the classic boa

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Please find below program in Swift which will full fill your all 3 requirements.

Open xCode and select "Get Started with playground" option, and then select "Blank" and just copy past below code.

And run it, you will get result. Like you can pass different values in method call playYourTrun. I make it bold below.

------------------------------------------------------------------------Program in Swift-----------------------------------------------------------------

import UIKit

//This method check for snakes and ladders position logic.

//calculated_position is position which we will get after adding rolled dice value to current position

func getFinalPosition(calculated_position: Int)-> Int{

switch calculated_position{

case 1:

return 23

case 4:

return 15

case 13:

return 29

case 16:

return 3

case 25:

return 18

case 27:

return 6

default:

return calculated_position

}

}

//This is our main mehtod where we will pass current postion and dice value

func playYourTrun(currentPosition: Int,diceRoll: Int)->String{

if(currentPosition >= 30 || currentPosition<0){

return "Current Posstion Out Of Range."

}

if(diceRoll > 6 || diceRoll < 0){

return "Dice Value Out of Range."

}

  

let finalPosition = getFinalPosition(calculated_position: (currentPosition+diceRoll))

if(finalPosition >= 30){

return "You Won."

}else{

return "Current Position is \(finalPosition)"

}

  

}

playYourTrun(currentPosition: 28,diceRoll: 6)

Add a comment
Know the answer?
Add Answer to:
Is anyone familiar with programming in Swift? That is the language the solution must be implemented...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone please help me with this C++ problem? Let's Play Chutes and Ladders! The board...

    Can someone please help me with this C++ problem? Let's Play Chutes and Ladders! The board is shown below. Use a map structure to store all the chutes and ladders movements Key is the starting square Value is the final movement square EXAMPLE: std::make_pair(95, 75) handles one chute I see (Fall from 95 to 75) Both types can be stored in the same structure since they don't share spaces It looks like there are 9 ladders and 10 chutes total?...

  • question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user...

    question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • C programming language Purpose The purpose of this assignment is to help you to practice working...

    C programming language Purpose The purpose of this assignment is to help you to practice working with functions, arrays, and design simple algorithms Learning Outcomes ● Develop skills with multidimensional arrays ● Learn how to traverse multidimensional arrays ● Passing arrays to functions ● Develop algorithm design skills (e.g. recursion) Problem Overview Problem Overview Tic-Tac-Toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the...

  • I need just homework#6, I post homework# 5 to understand how to do it ? Please...

    I need just homework#6, I post homework# 5 to understand how to do it ? Please do it and please don't copy the answer CSCE 1030 Homework 5 Due: 11:59 PM on Monday, April 17,2017 PROGRAM DESCRIPTION: In this C++ program, you will start building the software infrastructure that will allow you to play a simplified version of the class game of Minesweeper that will display to the screen. In Homework 6, you will continue the work begun here to...

  • INTRODUCTION: Play sorry with two die, and one peg. Move your piece down the board first....

    INTRODUCTION: Play sorry with two die, and one peg. Move your piece down the board first. But rolling certain numbers will change the pace of the game. INCLUDE IN YOUR ASSIGNMENT: Annotation is a major part of any program. At the top of each of your C++ programs, you should have at least four lines of documentation: // Program name: tictactoe.cpp // Author: Twilight Sparkle // Date last updated: 5/26/2016 // Purpose: Play the game of Tic-Tac-Toe ASSIGNMENT: Sorry Game...

  • Python Complete the player_turn() function that completes a single turn of the game Tic-Tac-Toe (also called...

    Python Complete the player_turn() function that completes a single turn of the game Tic-Tac-Toe (also called Noughts and Crosses). The function takes 3 parameters: 1. The first parameter is called board. It is a list of length 3, where each entry is a string with 3 characters representing a row on a Tic-Tac-Toe board. Each character in a row represents a slot on the Tic-Tac-Toe board with the "#" character indicating an empty slot. An empty board looks like this:...

  • programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate...

    programming language: C++ *Include Line Documenatations* Overview For this assignment, write a program that will simulate a game of Roulette. Roulette is a casino game of chance where a player may choose to place bets on either a single number, the colors red or black, or whether a number is even or odd. (Note: bets may also be placed on a range of numbers, but we will not cover that situation in this program.) A winning number and color is...

  • C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

    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,...

  • (C++) Please create a tic tac toe game. Must write a Player class to store each...

    (C++) Please create a tic tac toe game. Must write a Player class to store each players’ information (name and score) and to update their information (increase their score if appropriate) and to retrieve their information (name and score).The players must be called by name during the game. The turns alternate starting with player 1 in the first move of round 1. Whoever plays last in a round will play second in the next round (assuming there is one).The rows...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT