/
WizardBrosGame.cs
162 lines (139 loc) · 5.54 KB
/
WizardBrosGame.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using WizardBros.Model;
using WizardBros.Controller;
using WizardBros.View;
using System.Collections.Generic;
using System;
using Microsoft.Xna.Framework.Media;
namespace WizardBros
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class WizardBrosGame : Game
{
List<int> niveaux = new List<int>();
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
static public int height { get; private set; }
static public int width { get; private set; }
EditorMap editor;
public static World niveau;
MainController mController;
NiveauxController nController;
NiveauxView nView;
MainView mView;
Menu menu;
EditorMapView viewEditor;
MouseState oldMouseState; //car les updates sont très rapides
public static KeyboardState oldKeyboardState;
EditorMapController controllerEditor;
public static int level = 0;
public enum GameState //aide les controlleurs à gérer le cours du jeu
{
Start,
Niveau,
Playing,
Paused,
Death,
GameOver,
MapEditor,
Exit
};
private GameState currentState;
public WizardBrosGame()
{
graphics = new GraphicsDeviceManager(this);
height = width = 600;
graphics.PreferredBackBufferHeight = height;
graphics.PreferredBackBufferWidth = width;
this.Window.Title = "Little Gandalf";
IsMouseVisible = true;
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
niveaux = MapXml.getListNiveauxName();
currentState = GameState.Start;
nView = new NiveauxView(Content);
nController = new NiveauxController();
mController = new MainController();
mView = new MainView(Content);
menu = new Menu(Content);
editor = new EditorMap(600, 600);
viewEditor = new EditorMapView(Content);
controllerEditor = new EditorMapController();
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
mView.LoadContent(niveau);
nView.LoadContent();
viewEditor.LoadContent(editor);
menu.LoadContent();
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape) || currentState==GameState.Exit) //bug chez certains ordis
Exit();
// Appel du contrôleur approprié
if (currentState == GameState.MapEditor)
{
currentState = controllerEditor.Update(editor, currentState, ref oldMouseState, ref oldKeyboardState);
}
//controleur des menus, par élimination
else if (currentState != GameState.Playing)
{
if (currentState == GameState.Niveau)
{
niveaux = MapXml.getListNiveauxName();
currentState = nController.Update(currentState, ref oldKeyboardState, niveaux.Count);
}
if (currentState == GameState.Death) //la seule différence avec gameover, en attente de niveaux, est le reset du score
{
niveau.getJoueur().resetHealth();
niveau.getJoueur().ResetPos();
niveau.resetMap();
}
currentState = menu.Update(currentState, ref oldMouseState, ref oldKeyboardState);
}
//controleur jeu
else
{
currentState = mController.Update(niveau, currentState, ref oldMouseState, ref oldKeyboardState, niveau.getJoueur().getPosX(), niveau.getJoueur().getPosY());
}
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
spriteBatch.Begin(); //appel de l'afficheur approprié
if (currentState == GameState.Playing)
mView.Draw(spriteBatch, niveau);
else if (currentState == GameState.MapEditor)
viewEditor.Draw(spriteBatch, editor);
else if (currentState == GameState.Niveau)
nView.Draw(niveaux, spriteBatch);
else
menu.Draw(currentState, spriteBatch);
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}