/
Game.cs
126 lines (120 loc) · 5.49 KB
/
Game.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
namespace theQuest
{
class Game
{
public List<Enemy> Enemies;
public Weapon WeaponInRoom;
private Player player;
public Point PlayerLocation { get{ return player.Location;}}
public int PlayerHitPoints { get { return player.HitPoints; } }
public List<string> PlayerWeapons { get { return player.Weapons; } }
public string PlayerEquippedWeapon { get { return player.EquippedWeapon; } }
private int level = 0;
public int Level { get { return level; } }
private Rectangle boundaries;
public Rectangle Boundaries { get { return boundaries; } }
public Game(Rectangle boundaries)
{
this.boundaries = boundaries;
player = new Player(this, new Point(boundaries.Left + 10, boundaries.Top + 70), boundaries);
}
public void Move(Direction direction, Random random)
{
player.Move(direction);
foreach (Enemy enemy in Enemies)
{
if (enemy is Bat)
{
Bat currentEnemy = (Bat)enemy;
currentEnemy.Move(random);
}
else if(enemy is Ghost)
{
Ghost currentEnemy = (Ghost)enemy;
currentEnemy.Move(random);
}
else
{
Ghoul currentEnemy = (Ghoul)enemy;
currentEnemy.Move(random);
}
}
}
public void Equip(string weaponName)
{ player.Equip(weaponName); }
public bool CheckPlayerInventory(string weaponName)
{ return player.Weapons.Contains(weaponName); }
public void HitPlayer(int maxDamage, Random random)
{ player.Hit(maxDamage, random); }
public void IncreasePlayerHealth(int health, Random random)
{ player.IncreaseHealth(health, random); }
public void Attack(Direction direction, Random random)
{
player.Attack(direction, random);
foreach (Enemy enemy in Enemies) enemy.Move(random);
}
private Point GetRandomLocation(Random random)
{ return new Point(boundaries.Left + random.Next(boundaries.Right/10 - boundaries.Left /10)*10, boundaries.Top + random.Next(boundaries.Bottom/10 - boundaries.Top/10)*10);}
public void NewLevel(Random random)
{
level++;
switch(level)
{
case 1:
Enemies = new List<Enemy>();
Enemies.Add(new Bat(this, GetRandomLocation(random), boundaries));
WeaponInRoom = new Sword(this, GetRandomLocation(random));
break;
case 2:
Enemies = new List<Enemy>();
Enemies.Add(new Ghost(this, GetRandomLocation(random), boundaries));
WeaponInRoom = new BluePotion(this, GetRandomLocation(random));
break;
case 3:
Enemies = new List<Enemy>();
Enemies.Add(new Ghoul(this, GetRandomLocation(random), boundaries));
WeaponInRoom = new Bow(this, GetRandomLocation(random));
break;
case 4:
Enemies = new List<Enemy>();
Enemies.Add(new Bat(this, GetRandomLocation(random), boundaries));
Enemies.Add(new Ghost(this, GetRandomLocation(random), boundaries));
if(!CheckPlayerInventory("Bow")) WeaponInRoom = new Bow(this, GetRandomLocation(random));
else if (!CheckPlayerInventory("Blue Potion")) WeaponInRoom = new BluePotion(this, GetRandomLocation(random));
break;
case 5:
Enemies = new List<Enemy>();
Enemies.Add(new Bat(this, GetRandomLocation(random), boundaries));
Enemies.Add(new Ghoul(this, GetRandomLocation(random), boundaries));
WeaponInRoom = new RedPotion(this, GetRandomLocation(random));
break;
case 6:
Enemies = new List<Enemy>();
Enemies.Add(new Ghoul(this, GetRandomLocation(random), boundaries));
Enemies.Add(new Ghost(this, GetRandomLocation(random), boundaries));
WeaponInRoom = new Mace(this, GetRandomLocation(random));
break;
case 7:
Enemies = new List<Enemy>();
Enemies.Add(new Bat(this, GetRandomLocation(random), boundaries));
Enemies.Add(new Ghost(this, GetRandomLocation(random), boundaries));
Enemies.Add(new Ghoul(this, GetRandomLocation(random), boundaries));
if(!CheckPlayerInventory("Mace")) WeaponInRoom = new Mace(this, GetRandomLocation(random));
else if (!CheckPlayerInventory("Red Potion")) WeaponInRoom = new RedPotion(this, GetRandomLocation(random));
else if (!CheckPlayerInventory("Blue Potion")) WeaponInRoom = new BluePotion(this, GetRandomLocation(random));
break;
case 8:
Application.Exit();
break;
//end the game
}
}
}
}