Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 21.06.2011, 22:24   #1
Alexander1205
Пользователь
 
Аватар для Alexander1205
 
Регистрация: 22.01.2011
Сообщений: 78
По умолчанию морской бой

В моем классе не вызываются поля через точку.В чем проблема? Кто подскажет как создать правильно этот класс?

Код:
#include<iostream>
using namespace std;

class Game
{
public:
 Player player;
 Computer computer;
	int x,y,x1,y1,x2,y2;
	bool PlayerWins;
	bool ComputerWins;
public:
	Game();
	~Game();
	void SetShips();
	void RunGame();
};
Game::Game()
{
	PlayerWins=false;
	ComputerWins=false;
}
Game::~Game(){}
void Game::SetShips()
{
	player.PrintFields();
	player.SetFlotShip(4);
	computer.SetFlotShip(4);
	for(int i=0;i<2;i++)
	{
		player.PrintFields();
		player.SetFlotShip(3);
		computer.SetFlotShip(3);
	}
	for(int i=0;i<3;i++)
	{
		player.PrintFields();
		player.SetFlotShip(2);
		computer.SetFlotShip(2);
	}
	for(int i=0;i<2;i++)
	{
		player.PrintFields();
		player.SetFlotShip(1);
		computer.SetFlotShip(1);
	}
	void Game::RunGame()
	{
		while(true)
		{
			while(true)
			{
				player.PrintFields();
				player.GetAttackCoordinates(x,y);
				if(player.GetSecondFieldElement(x,y)=='x'||player.GetSecondFieldElement(x,y)=='0')
					cout<<" It's no use to shoot !\n";
				getch();
			}
			else
			{
				if(computer.GetFirstFieldElement(x,y)=" ")
				{
					player.SetSecondFieldElemet(x,y,'0')
						player.PrintFields();
					break;
				}
				else
				{
					player.SetSecondFieldElement(x,y,'x');
					computer.SetFirstFieldElement(x,y,'x');
					if(computer.ShipTest(x,y)
					{
						computer.GetDeleteShipCoordinates(x,y,x1,y1,x2,y2);
						player.DeleteOpponentShip(x1,y1,x2,y2);
					}
					computer.DeleteFlotLife();
					if(computer.FlotLifeTest()//если эскадра разгромлена
					{
						PlayerWins=true;
						player.PrintFields();
						break;
					}
				}
				
		}
		if(PlayerWins==true)
		{
			player.PrintFields();
			cout<<" Player wins !\n";
			break;
		}
		while(true)
		{
			computer.GetAttackCoordinates(x,y);
			if(computer.GetSecondFieldElement(x,y)=='x'||computer.GetSecondFieldElement(x,y)=='0')
				continue;
			else
			{
				if(player.GetFirstFieldElement(x,y)==' ')
				{
					computer.SetSecondFieldElement(x,y,'0');
					player.SetFirstFieldElement(x,y,'0');
					break;
				}
				else
				{
					player.SetFirstFieldElement(x,y,'x');
					computer.SetSecondFieldElement(x,y,'x');
					player.PrintFields();
					getch();
					if(player.ShipTest))
					{
						player.GetDeleteShipCoordinates(x,y,x1,y1.x2,y2);
							player.GetDeletePlayerShip(x1,y1,x2,y2);
							player.PrintFields();
							getch();
							computer.DeleteOpponentShip(x1,y1,x2,y2)
					}
					player.DeleteFlotLife();
					if(player.FlotLifeTest())
					{
						ComputerWins=true;
						player.PrintFields();
						break;
					}
				}
			}
		}
		
		if(ComputerWins==true)
		{
			player.PrintFields();
			cout<<" Computer wins !\n";
			getch();
			break;
		}

		void main()
		{
			Game one;
			one.SetShips();
			one.RunGame();
			return 0;
		}
Alexander1205 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Морской бой flutt C++ Builder 10 12.10.2017 16:57
морской бой Joney_Hell Помощь студентам 1 11.11.2010 04:37
Морской Бой DanaBaitik Помощь студентам 0 12.09.2010 21:24
Морской бой NikolayBest Паскаль, Turbo Pascal, PascalABC.NET 0 13.05.2009 22:07
Морской Бой Liska-Melisska Microsoft Office Excel 9 29.12.2008 00:11