Giter Site home page Giter Site logo

dicegame's Introduction

DiceGame

Exercise 10

Download or clone the C# project DiceGame.

This exercise is about using an existing class, and completing an unfinished class. The solution contains two new classes called Die and DiceCup, in the files Die.cs and DiceCup.cs, respectively.

1.Investigate the Die class. It is complete, and fairly simple.Note that we use another class in the Die class, calledRandom. This class is from the .NET class library, so it is notas such part of the project – it is “given”. Try out the class;create a Die object (in the usual place for inserting code), callthe methods RollDie and GetValue, and print the value youget back. Notice that when you run the program again, youmay get different values, just like for a real die.

2.Investigate the DiceCup class. This class is supposed torepresent a cup with two dice in it. Therefore, the class hastwo instance fields, both of the type Die. The constructor ofthe class has also been completed. However, we would liketo have three public methods in the DiceCup class as well:

a.RollDice: Should roll both dices in the cup. No value isreturned.

b.GetTotalValue: Should return the total value of the twodice in the cup.

c.IsTotalValueLargerThan: This method should take oneinteger value as input, and return either true or false.The return value should be true if the total value of thetwo dice is larger than the input value; otherwise, itshould return false.

3.Your job is now to add these three methods to the DiceCupclass. As a help, the “headers” for each method is alreadyincluded as a comment in the class. Once you have comple-ted the methods, you should of course add some code overin InsertCodeHere to test that the completed class works asexpected

4.[Extra – only if you have time] How can you change the gamesuch that it uses 10-sided dice instead? Can you even make itso that the user decides how many sides the dice have?

dicegame's People

Contributors

martinkierkegaard avatar

Watchers

James Cloos avatar Natascha Jakobsen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.