Stuck? Need help? Ask questions on our forums.

View Battleship\inc\Computer.h

GPL'ed Battleship clone Win32/Linux 1.2.1

Submitted By: i_like_cpp
Rating: (Not rated) (Rate It)


/*
Free Battleship clone for Win32/Linux Console.
Copyright (C) 2005  Dennis Gertitschke

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef COMPUTER_H_
#define COMPUTER_H_

#include "../inc/Player.h"

class Computer:public Player{
public:
        typedef void(*F)(void*,char,int,bool&,int&);
        Computer();
        ~Computer();
        void deployFleet();
        void shoot();
        void validateUserShot(char cX,int iY);
        static void validateUserShotCallback(void *pObj,char cX,int iY);
        void validateCompShot(char cX,int iY,bool& bRefHit,int& iRefHitCount);
        static void validateCompShotCallback(void *pObj,char cX,int iY,bool& bRefHit,int& iRefHitCount);
        void reset();
        void setMode(int iMode);
        void registerCallback(void *pObj,F pFunc);
private:
        int m_iDistance;
        int m_iDirection;
        char m_cShotX,m_cFirstX;
        int  m_iShotY,m_iFirstY;
        int m_iInstance;
        static int m_iInstanceCount;
        int m_iMode;
        void *m_pObj;
        F m_pFunc;
        bool m_bHit;
        int m_iHitCount;
       
        void randomCoordinate(char& cRefX,int& iRefY);
        void randomDirection();
        void transformToCompScreen(char& cRefX, int& iRefY);                    
        void placeShip(Ship *pShip,char cStartX,int iStartY);
        void calculateValidStartEnd(Ship *pShip);
        bool checkStartEnd(char cStartX,int iStartY,int iLength);
};

#endif/*COMPUTER_H_*/
 
corner
© 1996-2008. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.