Advertisement
A4L

Chapter - 18 - Designing-Building Classes (Ball Class)

A4L
Dec 8th, 2018
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. /*--== Create a Ball class ==--
  7.     The Ball class should have instance variables for size and color(the Color class you just
  8. created). Let's also add an instance variable that keeps track of the number of times it has
  9. been thrown.
  10.     Create any constructors you feel would be useful.
  11.     Create a Pop method, which changes the ball's size to 0.
  12.     Create a Throw method that adds 1 to the throw count, but only if the ball hasn't been
  13. popped (has a size of 0).
  14.     A method that returns the number of times the ball has been thrown*/
  15. namespace Chapter18DesigningBuildingClasses
  16. {
  17.     class Ball
  18.     {
  19.         private Random ranCol = new Random();
  20.         public int size { set; get; }
  21.         private int thrown = 0;
  22.         //private bool popped = false;
  23.         public Colour colour = new Colour();
  24.  
  25.         public Ball()
  26.         {
  27.             colour.red = Convert.ToByte(ranCol.Next(255));
  28.             colour.green = Convert.ToByte(ranCol.Next(255));
  29.             colour.blue = Convert.ToByte(ranCol.Next(255));
  30.             this.size = Convert.ToInt32(ranCol.Next(255));
  31.         }
  32.  
  33.         public Ball(int s)
  34.         {
  35.             colour.red = Convert.ToByte(ranCol.Next(255));
  36.             colour.green = Convert.ToByte(ranCol.Next(255));
  37.             colour.blue = Convert.ToByte(ranCol.Next(255));
  38.             this.size = s;
  39.         }
  40.  
  41.         public Ball(int s, byte a)
  42.         {
  43.             colour.red = Convert.ToByte(ranCol.Next(255));
  44.             colour.green = Convert.ToByte(ranCol.Next(255));
  45.             colour.blue = Convert.ToByte(ranCol.Next(255));
  46.             colour.alpha = a;
  47.             this.size = s;
  48.         }
  49.  
  50.         public Ball(byte r, byte g, byte b, int s)
  51.         {
  52.             colour.red = r;
  53.             colour.green = g;
  54.             colour.blue = b;
  55.             this.size = s;
  56.         }
  57.  
  58.         public Ball(byte r, byte g, byte b, int s, byte a)
  59.         {
  60.             colour.red = r;
  61.             colour.green = g;
  62.             colour.blue = b;
  63.             colour.alpha = a;
  64.             this.size = s;
  65.         }
  66.  
  67.         public void Pop()
  68.         {
  69.             size = 0;
  70.         }
  71.  
  72.         public void ThrowBall()
  73.         {
  74.             if (size > 0) { thrown++; }
  75.         }
  76.  
  77.         public int GetThrown()
  78.         {
  79.             return thrown;
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement