-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuState.cs
147 lines (123 loc) · 5.36 KB
/
MenuState.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
namespace GoGame
{
public class MenuState : State
{
private Map _goBoard;
private List<Component> _components;
private Texture2D _mapTexture;
private Texture2D _bigMapTexture;
private Texture2D _buttonTexture;
private GraphicsDevice _graphicsDevice;
private Button _newGameButton;
private Button _nineMapButton;
private Button _nineteenMapButton;
private Button _quitGameButton;
public MenuState(Game1 game, GraphicsDeviceManager graphics, ContentManager content) : base(game, graphics, content)
{
_graphicsDevice = graphics.GraphicsDevice;
_mapTexture = _content.Load<Texture2D>("GoBoard");
_buttonTexture = _content.Load<Texture2D>("Button");
var buttonFont = _content.Load<SpriteFont>("Font");
_mapTexture = _content.Load<Texture2D>("GoBoard");
_bigMapTexture = _content.Load<Texture2D>("BigGoBoard");
_goBoard = new Map(_mapTexture, 9);
_graphics.IsFullScreen = false;
_graphics.PreferredBackBufferWidth = (int)_goBoard.Width;
_graphics.PreferredBackBufferHeight = (int)_goBoard.Height + 50;
_graphics.ApplyChanges();
_newGameButton = new Button(_buttonTexture, buttonFont)
{
Position = new Vector2((_goBoard.Width / 2) - (_buttonTexture.Width), ((_goBoard.Height / 2) - 150) - _buttonTexture.Height),
Text = "New Game"
};
_newGameButton.Click += NewGameButton_Click;
_nineMapButton = new Button(_buttonTexture, buttonFont)
{
Position = new Vector2(_goBoard.Width / 2 - (_buttonTexture.Width), ((_goBoard.Height / 2) - 50) - _buttonTexture.Height),
Text = "9x9 Map"
};
_nineMapButton.Click += NineMapButton_Click;
_nineteenMapButton = new Button(_buttonTexture, buttonFont)
{
Position = new Vector2(_goBoard.Width / 2 - (_buttonTexture.Width), ((_goBoard.Height / 2) + 50) - _buttonTexture.Height),
Text = "19x19 Map"
};
_nineteenMapButton.Click += NineteenMapButton_Click;
_quitGameButton = new Button(_buttonTexture, buttonFont)
{
Position = new Vector2(_goBoard.Width / 2 - (_buttonTexture.Width), ((_goBoard.Height / 2) + 150) - _buttonTexture.Height),
Text = "Quit Game"
};
_quitGameButton.Click += QuitGameButton_Click;
_components = new List<Component>()
{
_newGameButton,
_nineMapButton,
_nineteenMapButton,
_quitGameButton,
};
}
private void NineteenMapButton_Click(object sender, EventArgs e)
{
_goBoard = new Map(_bigMapTexture, 19);
_graphics.PreferredBackBufferWidth = (int)_goBoard.Width;
_graphics.PreferredBackBufferHeight = (int)_goBoard.Height + 50;
_graphics.ApplyChanges();
UpdateButtonPosition();
}
private void NineMapButton_Click(object sender, EventArgs e)
{
_goBoard = new Map(_mapTexture, 9);
_graphics.PreferredBackBufferWidth = (int)_goBoard.Width;
_graphics.PreferredBackBufferHeight = (int)_goBoard.Height + 50;
_graphics.ApplyChanges();
UpdateButtonPosition();
}
private void UpdateButtonPosition()
{
_newGameButton.Position =
new Vector2((_goBoard.Width / 2) - (_buttonTexture.Width), ((_goBoard.Height / 2) - 150) - _buttonTexture.Height);
_nineMapButton.Position =
new Vector2(_goBoard.Width / 2 - (_buttonTexture.Width), ((_goBoard.Height / 2) - 50) - _buttonTexture.Height);
_nineteenMapButton.Position =
new Vector2(_goBoard.Width / 2 - (_buttonTexture.Width), ((_goBoard.Height / 2) + 50) - _buttonTexture.Height);
_quitGameButton.Position =
new Vector2(_goBoard.Width / 2 - (_buttonTexture.Width), ((_goBoard.Height / 2) + 150) - _buttonTexture.Height);
}
private void QuitGameButton_Click(object sender, EventArgs e)
{
_game.Exit();
}
// wechselt von dem einen State in den Nächsten (z.B. GameState)
private void NewGameButton_Click(object sender, EventArgs e)
{
_game.ChangeState(new GameState(_game, _graphics, _content, _goBoard));
}
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Begin();
_goBoard.Draw(gameTime, spriteBatch);
foreach (var component in _components)
{
component.Draw(gameTime, spriteBatch);
}
spriteBatch.End();
}
public override void PostUpdate(GameTime gameTime)
{
//remove Sprites if they're not needed
}
public override void Update(GameTime gameTime)
{
foreach (var component in _components)
{
component.Update(gameTime);
}
}
}
}