Source: ksirk/kgamewin.h


Annotated List
Files
Globals
Hierarchy
Index
/**
  * The base class for KsirK application windows. It sets up the main
  * window and reads the config file as well as providing a menubar, toolbar
  * and statusbar. An instance of KsirKView creates your center view, which is
  * connected to the window's Doc object.
  * KsirKApp reimplements the methods that KMainWindow provides for main window
  * handling and supports full session management as well as using KActions.
  * @see KMainWindow
  * @see KApplication
  * @see KConfig
  *
  * @author Gaël de Chalendar (inspiration : Source Framework Automatically
  *  Generated by KDevelop, (c) The KDevelop Team.)
  * @version KDevelop version 1.2 code generation
  */
#define KDE_NO_COMPAT


#ifndef  KGAMEWIN_H
#define KGAMEWIN_H

#include "global.h"
#include "decoratedgameframe.h"
#include "onu.h"
#include "animspriteslist.h"
#include "player.h"
#include "kplayersetupdialog.h"
#include "ksirkresources.h"
#include "country.h"

#include 
#include 
#include 

// include files for Qt
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

// include files for KDE
#include 
#include 
#include 
#include 
#include 
#include 

#ifdef HAVE_CONFIG_H
#include 
#endif

// forward declaration of the KsirK classes
class DecoratedGameFrame;

/**
 *
 */
class KGameWindow: public KMainWindow
{
	Q_OBJECT

public:
	static const char* GameStateNames[] ;
	
	/**
	 * Create the window and initializes its members
	 */
	KGameWindow(QWidget* parent=0, const char* name=0);
	
	/**
	 * Deletes the background and the pool
	 */
	~KGameWindow();
	
	
	/**
	 * Ask all the sprites to repaint
	 */
	void paint(void);
	
	/**
	 * Returns the country where inside which is the argument point. 0 f none.
	 */
	Country *clickIn(const QPoint &Point);
	
	/**
	 * Returns the current player
	 */
	Player *currentPlayer(void);
	
	/**
	 * Creates a new game. Called when the New Game button is hit
	 */
	void newGame(void);
	

/************** METHODS BELOW ARE DEFINED IN gestionSprites.cpp **************/
	/**
	 * Prepares the sprites to be moved : removes the nb necessary sprites from
	 * source, creates the moving sprites and gives them their destination, etc
	 */
	void initArmiesMovement(int nb, Country* src, Country* dest);
	
	/**
	 * The 3 methods below manage the movement of, respectively, the cannons,
	 * the cavalrymen and the infantrymen. It ask them to move by a certain amount
	 * and, eventually, manages their arrival at destination
	 */
	void moveCannons(void);
	void moveCavalrymen(void);
	void moveInfantrymen(void);
	
	/**
	 * Initializes the sprites that will fight for the attacker and the
	 * defender. Prepares them for moving
	 */
	void initCombatMovement(Country *attacker, Country *defender);
	
	/**
	 * Handle the moving of the fighters towards destination
	 */
	void moveMovingCombatants(void);

	/**
	 * Handle the arrival of a fighter to destination
	 */
	void combatantArrival(AnimSprite *);

	/**
	 * Prepare the fighting animation : replace the sprites sequence by the
	 * sequence of explosion
	 */
	void animCombat(void);

	/**
	 * Replaces the animated fighters by the simple cannon image
	 */
	void stopCombat(void);

	/**
	 * Replaces the sequence of destroyed cannon(s) by the explosion sequence
	 */
	void animExplosion(int);

	/**
	 * When all the explosion sequence has been shown for all explosing
	 * devices, removes these sprites
	 */
	void stopExplosion(void);

	/**
	 * Set up the eventual survivor(s) to come back home
	 */
	void initCombatBringBack(int, Country *, Country *);

/************** END OF METHODS DEFINED IN gestionSprites.cpp *****************/

	/**
	 * called every 50ms, it causes the scrolling of the world if necessary the
	 * movement of the moving sprites. After it call the paint method to do the
	 * animation of the sprites and it asks the pool to update
	 */
	void evenementTimer(void);

	/**
	  * Prepares the players for the game with human interaction. Return true
	  * if successful or false if failure or cancel
	  */
	bool setupPlayers(void);

	/**
	 * Do the distribution of armies for all players in function of their
	 * number of countries
	 */
	void distribueArmees(void);

	/**
	 * Computes the number of armies to be distributed to p at the beginning of
	 * the turn, function of the number of countries he owns
	 * TODO : this method should be a method of Player
	 */
	int nbNewArmies(Player *p);

	/**
	 * Changes the owner of the attacked country if its number of armies
	 * becomes negative or null. Handle the end of the game of the
	 * winning conditions are fullfilled.
	 */
	void attackEnd(void);

	/**
	 * Computes the results of the fight
	 */
	void resolveAttack(void);

	/**
	  * Display and removes various toolbar buttons in function of the state
	  * of the game.
	  */
	void displayNextPlayerButton(void);
	void removeNextPlayerButton(void);
	void displayRecyclingButtons(void);
	void removeRecyclingButtons(void);
	void displayNormalGameButtons(void);
	void removeNormalGameButtons(void);
	void displayDefenseButtons(void);
	void removeDefenseButtons(void);
	void displayInvasionButtons(void);
	void removeInvasionButtons(void);
	void displayCancelButton(void);
	void removeCancelButton(void);

	/**
	  * Updates the flag in the statusbar with the one of the current player
	  */
	void setBarFlagButton(void);

	/**
	  * Shortcut for "statusBar()-> changeItem(text, id)"
	  */
	void changeItem ( const QString& text, int id );

	/**
	  * Reconnect the mouse events signals to their slots to allow human players
	  * to play
	  */
	void reconnectMouse(void);

	/**
	  * Disconnects the mouse events signals from their slots to avoid human
	  * player actions when it is the turn of the AI
	  */
	void disconnectMouse(void);
	
	/** returns the current state of the game */
	GameState getState(void) const;
  
	/** Return true if the state of the game is the argument; false otherwise */
	bool isMyState(GameState state) const;
  /** sets the new state of the game */
  void setState(GameState newState);
  /** returns the name of the current state */
  QString getStateName(void) const;
  /** sets the current player to be the first one. Makes associated actions. */
  int setCurrentPlayerToFirst();
  /** sets the current player to be the next one in the list. Makes the associated actions :
Changes the flag in the status bar,...
Returns 0 in case of success; non-zero otherwise. For example, it returns 1 the current player was the last one */
  int setCurrentPlayerToNext();

protected:

	/**
	 * Add the main toolbar buttons
	 */
	void initActions();

	/**
	 * Prepares the status bar
	 */
	void initStatusBar();

	/**
	 * creates and display the main frame with the background
	 */
	void initView();

	/**
	 * Prepares the sprites lists
	 */
	void initSprites();

	/**
	 * Add a button to the toolbar
	 */
	void addAButton(const QString& fileName, int id, const QString& slot, const QString& txt);

	/**
	  * Reimplementation of the inherited function : starts the timer.
	  */
	void enterEvent(QEvent* ev);

	/**
	  * Reimplementation of the inherited function : stops the timer.
	  */
	void leaveEvent(QEvent* ev);

  public slots:

	/**
	 * The slots associated to the buttons
	 */
	void slotExitGame(void);
	void slotNewGame(void);
	void slotOpenGame(void);
	void slotRecycling(void);
	void slotRecyclingFinished(void);
	void slotNextPlayer(void);
	void slotAttack1(void);
	void slotAttack2(void);
	void slotAttack3(void);
	void slotDefense1(void);
	void slotDefense2(void);
	void slotInvade1(void);
	void slotInvade5(void);
	void slotInvade10(void);
	void slotInvasionFinished(void);
	void slotRetreat1(void);
	void slotRetreat5(void);
	void slotRetreat10(void);
	void slotMove(void);
	void slotCancel(void);
	void slotDumpGameInformations(void);

	/**
	 * The standard showAboutApplication slot
	 */
	void showAboutApplication(void);

	/**
	 * Connected to the frame timer, it manages the behavior of the game in
	 * function of the value of the state.
	 *
	 * Fundamental method !!!
	 */
	void slotTimerEvent(void);

	/**
	 * Connected to the frame mouse buttons signals, they manages the reaction
	 * of the game to user interaction inside its main widget in function of
	 * the state of the game.
	 *
	 * Fundamental methods !!!
	 */
	void evenementLButtonDown(const QPoint&);
	void evenementLButtonUp(const QPoint&);
	void evenementRButtonDown(const QPoint&);


  private:

	/**
	 * NKD = Numberof Killed Defenders
	 * NKA = Numberof Killed Attackers
	 * These numbers are set up by resolveAttack() and are used to compute
	 * in various methods
	 * TODO : this solution is ugly. Change that.
	 */
	int NKD, NKA;

	/**
	 * the countries
	 */
	ONU *theWorld;

	/**
	 * The main canvas
	 */
	QCanvas* canvas;

	/**
	 * The background
	 */
	BackGnd* backGnd;

	/**
	 * The lists of currently moving animated sprites
	 */
	AnimSpritesList *movingCannons;
	AnimSpritesList *movingCavalrymen;
	AnimSpritesList *movingInfantrymen;

	/**
	 * The moving fighters (represented by cannon sprites)
	 */
	AnimSpritesList *movingCombatants;
	
	/**
	 * The fighting fighters (represented by firing cannons)
	 */
	AnimSpritesList *animCombatants;
	
	/**
	 * The explosiong fighters (explosing cannons)
	 */
	AnimSpritesList *animExplodings;
	
	/**
	 * The static fighters (stopped cannons)
	 */
	AnimSpritesList *combatants;
	
	/**
	 * The state of the game. Many method will act in function of this state
	 */
	GameState myState;
	
	/**
	 * The text of the second statusbar field. Used to display dynamic
	 * informations
	 */
	QString status2Text;

	/**
	 * The number of armies to move/moving/moved from one country to another
	 */
	int nbMovedArmies;

	/**
	 * The number of players
	 * TODO : maybe change that to a method to dynamically compute it ?
	 */
	unsigned int nbPlayers;
	
	/**
	 * The 2 countries involved in a fight or in a armies move
	 */
	Country *firstCountry, *secondCountry;
	
	/**
	 *
	 */
//	QDialog *dialog;
	
	/**
	 * The frame of the game, its visual component ; the main widget
	 */
	DecoratedGameFrame *frame;
	
	/**
	 * a shortcut to KGlobal::dirs
	 */
	KStandardDirs *dirs;
	
	/**
	 * For layout reasons, the frame is not the exact central widget ; it is
	 * put in the vbox
	 */
	QVBox *vbox;
	
	/**
	 * The objects representing the players of the game
	 */
	PlayersArray *players;
	
	/**
	 * the configuration object of the application
	 */
	KConfig *config;

	/**
	  * This button is used to display the flag of the currently active player
	  * in the status bar
	  */
	  QToolButton *barFlagButton;
private: // Private methods
	/** This method is called by the timer handling method (evenementTimer) in order to handle the actions of the AI player. */
	void aiAction();
	void attack(Country& attacker, Country& defender, int nb);
	void moveArmies(Country& src, Country& dest, int nb);
};

#endif // KGAMEWINDOW_H


Generated by: gael on noirdes.limsi.u-psud.fr on Fri Jan 3 17:03:38 2003, using kdoc 2.0a53.