From d796c9dd933ab96ec83b9a634feedd5d32e1ba3f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 8 Nov 2011 12:31:36 -0600 Subject: Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731 --- examples/tictac/tictac.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 examples/tictac/tictac.h (limited to 'examples/tictac/tictac.h') 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 +#include + +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 TicTacButtons; +typedef TQMemArray 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 -- cgit v1.2.1