~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to src/games/strategy/engine/data/GameStep.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-sehf2rwat36o2xqf
Tags: upstream-1.3.2.2
ImportĀ upstreamĀ versionĀ 1.3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; either version 2 of the License, or
 
5
 * (at your option) any later version.
 
6
 * This program is distributed in the hope that it will be useful,
 
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
 * GNU General Public License for more details.
 
10
 * You should have received a copy of the GNU General Public License
 
11
 * along with this program; if not, write to the Free Software
 
12
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
13
 */
 
14
 
 
15
/*
 
16
 * GameStep.java
 
17
 *
 
18
 * Created on October 14, 2001, 7:28 AM
 
19
 */
 
20
 
 
21
package games.strategy.engine.data;
 
22
 
 
23
import java.util.Properties;
 
24
 
 
25
import games.strategy.engine.delegate.*;
 
26
 
 
27
/**
 
28
 * A single step in a game.<p>
 
29
 * 
 
30
 * Typically turn based strategy games are composed of a set of distinct phases (in chess this would
 
31
 * be two, white move, black move).
 
32
 * 
 
33
 *
 
34
 * @author  Sean Bridges
 
35
 * @version 1.0
 
36
 */
 
37
public class GameStep extends GameDataComponent
 
38
{
 
39
  private final String m_name;
 
40
  private final String m_displayName;
 
41
  private final PlayerID m_player;
 
42
  private final String m_delegate;
 
43
  private int m_hashCode = -1;
 
44
  private int m_runCount = 0;
 
45
  private int m_maxRunCount = -1; 
 
46
  private final Properties m_properties;
 
47
 
 
48
 
 
49
  /** Creates new GameStep */
 
50
  public GameStep(String name, String displayName, PlayerID player, IDelegate delegate, GameData data, Properties stepProperties)
 
51
  {
 
52
    super(data);
 
53
    m_name = name;
 
54
    m_displayName = displayName;
 
55
    m_player = player;
 
56
    m_delegate = delegate.getName();
 
57
    m_properties = stepProperties;
 
58
  }
 
59
 
 
60
  public String getName()
 
61
  {
 
62
    return m_name;
 
63
  }
 
64
 
 
65
  public PlayerID getPlayerID()
 
66
  {
 
67
    return m_player;
 
68
  }
 
69
 
 
70
  public IDelegate getDelegate()
 
71
  {
 
72
    return getData().getDelegateList().getDelegate(m_delegate);
 
73
  }
 
74
 
 
75
  public boolean equals(Object o)
 
76
  {
 
77
    if(o == null || ! (o instanceof GameStep))
 
78
      return false;
 
79
 
 
80
    GameStep other = (GameStep) o;
 
81
 
 
82
    return other.m_name.equals(this.m_name) &&
 
83
           other.m_delegate.equals(this.m_delegate) &&
 
84
         other.m_player.equals(this.m_player);
 
85
  }
 
86
 
 
87
  public boolean hasReachedMaxRunCount()
 
88
  {
 
89
    if(m_maxRunCount == -1)
 
90
      return false;
 
91
    return  m_maxRunCount <= m_runCount;
 
92
  }
 
93
 
 
94
  public int getRunCount()
 
95
  {
 
96
    return m_runCount;
 
97
  }
 
98
 
 
99
  public void incrementRunCount()
 
100
  {
 
101
    m_runCount++;
 
102
  }
 
103
 
 
104
  public void setMaxRunCount(int count)
 
105
  {
 
106
    m_maxRunCount = count;
 
107
  }
 
108
 
 
109
  public int getMaxRunCount()
 
110
  {
 
111
    return m_maxRunCount;
 
112
  }
 
113
 
 
114
  public int hashCode()
 
115
  {
 
116
    if(m_hashCode == -1)
 
117
    {
 
118
      String s = m_name + m_delegate + m_player;
 
119
      m_hashCode = s.hashCode();
 
120
    }
 
121
 
 
122
    return m_hashCode;
 
123
  }
 
124
 
 
125
  public String getDisplayName()
 
126
  {
 
127
    if(m_displayName == null)
 
128
      return getDelegate().getDisplayName();
 
129
    else
 
130
      return m_displayName;
 
131
  }
 
132
  
 
133
  public Properties getProperties()
 
134
  {
 
135
      return m_properties;
 
136
  }
 
137
}