This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar.cs
112 lines (100 loc) · 3.63 KB
/
Car.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Copyright (C) 2009-2010 Tom Postma, Gertjan Buijs
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
using System;
using System.Drawing;
namespace Frogger
{
class Car : MovingObject
{
private int carcolor;
private bool istruck = false;
/// <summary>
/// Creating a new instance of a car.
/// </summary>
public Car(int carcolor, int velocity, int pos, Direction direction, int width, int height)
:base(velocity, direction, pos)
{
this.carcolor = carcolor;
this.Size = new Size(width, height);
switch (direction)
{
case Direction.East:
base.Pic = CreateCarEast(carcolor);
break;
case Direction.West:
base.Pic = CreateCarWest(carcolor);
break;
}
}
/// <summary>
/// Color number of the car
/// 1 grey car
/// 2 yellow car
/// </summary>
public int Color
{
get
{
return this.carcolor;
}
}
public bool IsTruck {
get
{
return this.istruck;
}
}
private Bitmap CreateCarEast(int carcolor)
{
switch (carcolor)
{
case 1:
return ResizesResources.images["car_grey_east"]; //Frogger.Properties.Resources.car_grey_east;
case 2:
return ResizesResources.images["car_yellow_east"]; //Frogger.Properties.Resources.car_yellow_east;
case 3:
return ResizesResources.images["car_green_east"]; //Frogger.Properties.Resources.car_green_east;
case 4:
istruck = true;
return ResizesResources.images["truck_east"]; //Frogger.Properties.Resources.truck_east;
default:
ThrowCarColorNotFoundExc();
return null;
}
}
private Bitmap CreateCarWest(int carcolor)
{
switch (carcolor)
{
case 1:
return ResizesResources.images["car_grey_west"]; //Frogger.Properties.Resources.car_grey_west;
case 2:
return ResizesResources.images["car_yellow_west"]; //Frogger.Properties.Resources.car_yellow_west;
case 3:
return ResizesResources.images["car_green_west"]; //Frogger.Properties.Resources.car_green_west;
case 4:
istruck = true;
return ResizesResources.images["truck_west"];//Frogger.Properties.Resources.truck_west;
default:
ThrowCarColorNotFoundExc();
return null;
}
}
private void ThrowCarColorNotFoundExc()
{
throw new Exception("car color not found");
}
}
}