author | nemo |
Sat, 23 Jan 2016 16:07:14 -0500 | |
changeset 11532 | 44e646598e6a |
parent 10017 | de822cd3df3a |
permissions | -rw-r--r-- |
7584
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
1 |
/* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
2 |
* Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
4 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
9 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
13 |
* GNU General Public License for more details. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
14 |
* |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
18 |
*/ |
7831c84cc644
License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents:
7582
diff
changeset
|
19 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
package org.hedgewars.hedgeroid; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
|
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
22 |
import java.util.Map; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
23 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
import org.hedgewars.hedgeroid.Datastructures.MapRecipe; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
import org.hedgewars.hedgeroid.Datastructures.Scheme; |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
26 |
import org.hedgewars.hedgeroid.Datastructures.Team; |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
27 |
import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
29 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
/** |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
31 |
* This interface is supposed to abstract the handling of room state for several |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
32 |
* fragments that can display and manipulate it. The purpose of this is to allow |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
33 |
* using these fragments both for setting up networked and local games, despite |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
34 |
* the fact that for local games the settings can be changed immediately in |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
35 |
* memory, while they have to be sent out to the server for networked games. |
10017 | 36 |
* |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
37 |
* If/when the state changes as result of calling one of the "changeX" or |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
38 |
* "requestX" functions, that will also trigger the corresponding change |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
39 |
* listener method. There is no guarantee that calling a changeX method will |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
40 |
* actually change the setting (e.g. if you're not room chief). |
10017 | 41 |
* |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
* For local games, getChiefStatus is always true. |
10017 | 43 |
* |
7582
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
44 |
* Implementations of this interface are probably not thread safe and should |
714310efad8f
Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
7508
diff
changeset
|
45 |
* only be used on the UI thread. |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
*/ |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
public interface RoomStateManager { |
10017 | 48 |
// Query current state |
49 |
MapRecipe getMapRecipe(); |
|
50 |
boolean getChiefStatus(); |
|
51 |
Scheme getScheme(); |
|
52 |
String getGameStyle(); |
|
53 |
Weaponset getWeaponset(); |
|
54 |
Map<String, TeamInGame> getTeams(); |
|
55 |
||
56 |
// Manipulate state |
|
57 |
void changeMapRecipe(MapRecipe map); |
|
58 |
void changeMapTheme(String theme); |
|
59 |
||
60 |
/** |
|
61 |
* This function sets both the map's name and generator. There is no function |
|
62 |
* to change them independendly since e.g. the QtFrontend relies on them being |
|
63 |
* consistent. |
|
64 |
* |
|
65 |
* If the name parameter is equal to one of the MapRecipe.MAPNAME_REGULAR, MAPNAME_MAZE |
|
66 |
* or MAPNAME_DRAWN constants, the map generator is set accordingly. Otherwise, the |
|
67 |
* map generator is set to represent a mapfile. The map's name is always set to |
|
68 |
* the parameter. |
|
69 |
*/ |
|
70 |
void changeMapNameAndGenerator(String mapName); |
|
71 |
void changeMapTemplate(int template); |
|
72 |
void changeMazeSize(int mazeSize); |
|
73 |
void changeMapSeed(String seed); |
|
74 |
void changeMapDrawdata(byte[] drawdata); |
|
75 |
||
76 |
void changeScheme(Scheme scheme); |
|
77 |
void changeGameStyle(String style); |
|
78 |
void changeWeaponset(Weaponset weaponset); |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
|
10017 | 80 |
void requestAddTeam(Team team, int colorIndex); |
81 |
void requestRemoveTeam(String teamname); |
|
82 |
void changeTeamColorIndex(String teamname, int colorIndex); |
|
83 |
void changeTeamHogCount(String teamname, int hogcount); |
|
84 |
||
85 |
// Observe changes |
|
86 |
void addListener(Listener observer); |
|
87 |
void removeListener(Listener observer); |
|
88 |
||
89 |
public interface Listener { |
|
90 |
void onMapChanged(MapRecipe recipe); |
|
91 |
void onChiefStatusChanged(boolean isChief); |
|
92 |
void onSchemeChanged(Scheme scheme); |
|
93 |
void onGameStyleChanged(String gameStyle); |
|
94 |
void onWeaponsetChanged(Weaponset weaponset); |
|
95 |
void onTeamsChanged(Map<String, TeamInGame> teams); |
|
96 |
} |
|
97 |
||
98 |
public static class ListenerAdapter implements Listener { |
|
99 |
public void onMapChanged(MapRecipe recipe) {} |
|
100 |
public void onChiefStatusChanged(boolean isChief) {} |
|
101 |
public void onSchemeChanged(Scheme scheme) {} |
|
102 |
public void onGameStyleChanged(String gameStyle) {} |
|
103 |
public void onWeaponsetChanged(Weaponset weaponset) {} |
|
104 |
public void onTeamsChanged(Map<String, TeamInGame> teams) {} |
|
105 |
} |
|
106 |
||
107 |
public interface Provider { |
|
108 |
RoomStateManager getRoomStateManager(); |
|
109 |
} |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
} |