summaryrefslogtreecommitdiffstats
path: root/examples/tictac/tictac.h
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
committerTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/tictac/tictac.h
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/tictac/tictac.h')
-rw-r--r--examples/tictac/tictac.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/examples/tictac/tictac.h b/examples/tictac/tictac.h
new file mode 100644
index 000000000..876def88d
--- /dev/null
+++ b/examples/tictac/tictac.h
@@ -0,0 +1,107 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#ifndef TICTAC_H
+#define TICTAC_H
+
+
+#include <qpushbutton.h>
+#include <qptrvector.h>
+
+class TQComboBox;
+class TQLabel;
+
+
+// --------------------------------------------------------------------------
+// TicTacButton implements a single tic-tac-toe button
+//
+
+class TicTacButton : public TQPushButton
+{
+ Q_OBJECT
+public:
+ TicTacButton( TQWidget *parent );
+ enum Type { Blank, Circle, Cross };
+ Type type() const { return t; }
+ void setType( Type type ) { t = type; repaint(); }
+ TQSizePolicy sizePolicy() const
+ { return TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred ); }
+ TQSize sizeHint() const { return TQSize( 32, 32 ); }
+ TQSize minimumSizeHint() const { return TQSize( 10, 10 ); }
+protected:
+ void drawButtonLabel( TQPainter * );
+private:
+ Type t;
+};
+
+// Using template vector to make vector-class of TicTacButton.
+// This vector is used by the TicTacGameBoard class defined below.
+
+typedef TQPtrVector<TicTacButton> TicTacButtons;
+typedef TQMemArray<int> TicTacArray;
+
+
+// --------------------------------------------------------------------------
+// TicTacGameBoard implements the tic-tac-toe game board.
+// TicTacGameBoard is a composite widget that contains N x N TicTacButtons.
+// N is specified in the constructor.
+//
+
+class TicTacGameBoard : public TQWidget
+{
+ Q_OBJECT
+public:
+ TicTacGameBoard( int n, TQWidget *parent=0, const char *name=0 );
+ ~TicTacGameBoard();
+ enum State { Init, HumansTurn, HumanWon, ComputerWon, NobodyWon };
+ State state() const { return st; }
+ void computerStarts( bool v );
+ void newGame();
+signals:
+ void finished(); // game finished
+private slots:
+ void buttonClicked();
+private:
+ void setState( State state ) { st = state; }
+ void updateButtons();
+ int checkBoard( TicTacArray * );
+ void computerMove();
+ State st;
+ int nBoard;
+ bool comp_starts;
+ TicTacArray *btArray;
+ TicTacButtons *buttons;
+};
+
+
+// --------------------------------------------------------------------------
+// TicTacToe implements the complete game.
+// TicTacToe is a composite widget that contains a TicTacGameBoard and
+// two push buttons for starting the game and tquitting.
+//
+
+class TicTacToe : public TQWidget
+{
+ Q_OBJECT
+public:
+ TicTacToe( int boardSize=3, TQWidget *parent=0, const char *name=0 );
+private slots:
+ void newGameClicked();
+ void gameOver();
+private:
+ void newState();
+ TQComboBox *whoStarts;
+ TQPushButton *newGame;
+ TQPushButton *tquit;
+ TQLabel *message;
+ TicTacGameBoard *board;
+};
+
+
+#endif // TICTAC_H