![]() |
|
|
Регистрация Восстановить пароль |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
![]() |
|
|
Опции темы | Поиск в этой теме |
![]() |
#1 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
Кто может помочь с кодом на С++? Пишите в ЛС.
|
![]() |
![]() |
![]() |
#2 |
Участник клуба
Регистрация: 21.03.2010
Сообщений: 1,508
|
![]()
Думаю, что многим будет интересно с Вами пообщаться здесь, на форуме. Так что - проблемный код в студию!
Последний раз редактировалось xwicked; 04.06.2011 в 09:51. |
![]() |
![]() |
![]() |
#3 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
Проблема в том, что код слишком длинный((( я не могу его скинуть
|
![]() |
![]() |
![]() |
#4 |
Старожил
Регистрация: 12.01.2011
Сообщений: 19,500
|
![]()
Если код настолько длинный, то вряд ли кто-то будет в нем бесплатно и даже без указания в чем проблема или примерного места ошибки разбираться. Но выложить можно на pastebin.com
Ушел с форума, https://www.programmersforum.rocks, alex.pantec@gmail.com, https://github.com/AlexP11223
ЛС отключены Аларом. |
![]() |
![]() |
![]() |
#5 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
# ifndef SHIP_H
# define SHIP_H #include <windows.h> #include <set> #include <map> #include <string> //include "CyrIOS.h" #define N 10 struct Cell; typedef std::set<Cell> CellSet; struct Cell { Cell (int _r=0, int _c=0):row(_r), col(_c) {} bool InSet(const CellSet&) const; bool operator<(const Cell&) const; int row; int col; }; struct Rect { Rect() {} Rect(Cell _It, Cell _rb):It(_It), rb(_rb) {FillCset();} void FillCset(); bool Intersect(const CellSet& cs) const; Cell It; Cell rb; CellSet cset; }; class Ship { friend class UserNavy; friend class RobotNavy; public: Ship():nDeck(0), nLiveDeck(0) {} Ship(int, std::string, Rect); protected: Rect place; std::string name; int nDeck; int nLiveDeck; }; |
![]() |
![]() |
![]() |
#6 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
[QUOTE=Maria_Добрая;817170]# ifndef SHIP_H
# define SHIP_H #include <windows.h> #include <set> #include <map> #include <string> //include "CyrIOS.h" #define N 10 struct Cell; typedef std::set<Cell> CellSet; struct Cell { Cell (int _r=0, int _c=0):row(_r), col(_c) {} bool InSet(const CellSet&) const; bool operator<(const Cell&) const; int row; int col; }; struct Rect { Rect() {} Rect(Cell _It, Cell _rb):It(_It), rb(_rb) {FillCset();} void FillCset(); bool Intersect(const CellSet& cs) const; Cell It; Cell rb; CellSet cset; }; class Ship { friend class UserNavy; friend class RobotNavy; public: Ship():nDeck(0), nLiveDeck(0) {} Ship(int, std::string, Rect); protected: Rect place; std::string name; int nDeck; int nLiveDeck; }; |
![]() |
![]() |
![]() |
#7 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
# endif /* SHIP_H */
//Ship.cpp #include <iostream> #include <string> #include <algorithm> #include "Ship.h" using namespace std; bool Cell::InSet(const CellSet& cs) const { return (cs.count(Cell(row. col))>0); } bool Cell: ![]() { return ((row<c.row) || ((row==c.row) && (col<c.col))); } void Rect::FillCset() { for (int i=It.row; i<=rb.row; i++) for (int j=It.col; j<=rb.col; j++) cset.insert(Cell(i,j)); } bool Rect::Intercset(const CellSet& cs) const { CellSet common_cell; set_intersection(cset.begin(), cset.end(), cs.begin(), cs.end(), inserter(common_cell, common_cell.begin())); return (common_cell.size()>0); } Ship::Ship(int _nDeck, string _name, Rect _place): place(_place), name(_name), nDeck(_nDeck), nLiveDrck(_nDeck) {} |
![]() |
![]() |
![]() |
#8 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
//Navy.h
#include "Ship.h" #define DECK 176 #define DAMAGE 'X' #define MISS '0' typedef unsigned char Field[N][N]; typedef std::map<Cell, int>ShipMap; enum CurrentState {Miss, Damage, Kill}; struct Space { public: static Cell u_fire; static Cell r_fire; static CurrentState u_state; static CurrentState r_state; static int step; }; class Navy ![]() { public: Navy(); void AllocShip(int, int, std::string); void Show() const; int GetInt(); bool IsLive() {return (nLiveShip>0);} Rect Shell(Rect) const; void AddToVetoSet(Rect); protected: Ship ship[10]; Field ownField; Field enemyField; ShipMap shipMap; CellSet vetoSet; CellSet crushSet; int nLiveShip; }; class UserNavy ![]() { public: UserNavy() {Allocation();} void Allocation(); void FireOff(); void ResultAnalys(); void GetFire(); void FillDeadZone(Rect r, Field&); }; class RobotNavy ![]() { public: RobotNavy(); void Allocation(); void FireOff(); void ResultAnalys(); void GetFire(); private: bool isCruchContinue; bool upEmpty; }; |
![]() |
![]() |
![]() |
#9 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
//Navy.cpp
#include <iostream> #include <cstlib> #include <time.h> #include <algorithm> #include "Navy.h" using namespace std; Cell Space::u_fire; Cell Space::r_fire; CurrentState Space::u_state=Mass; CurrentState Space::r_state=Mass; int Space::step=1; string gap(int n) {return string(n, ' ');} Navy::Navy():nLiveShip(10) { for (int i=0; i<N; i++) for (int j=0; j<N; j++) { ownField[i][j]='.'; enemyField[i][j]='.'; } } Rect Navy::Shell(Rect r) const { Rect sh(r); sh.It.row=(-sh.It.row<0) ? 0:sh.It.row; sh.It.col=(-sh.It.col<0) ? 0:sh.It.col; sh.rb.row=(++sh.rb.row>(N-1)) ? (N-1):sh.rb.row; sh.rb.col=(++sh.rb.col>(N-1)) ? (N-1): sh.rb.col; return sh; } void Navy::AddToVetoSet(Rect r) { for (int i=r.It.row; i<=r.rb.row; i++) for (int j=r.It.col; j<=r.rb.col; j++) vetoSet.insert(Cell(i,j)); } void Navy::AllocShip(int indShip, int nDeck, string name) { int i,j; Cell It, rb; while (1) { It.row=rand() % (N+1-nDeck); It.col=rb.col=rand() % N; rb.row=It.row+nDeck-1; if (!Rect(It, rb).Intersect(vetoSet)) break; } ship[indShip]=Ship(nDeck, name, Rect(It, rb)); for (i=It.row; i<=rb.row; i++) for (j=It.col; j<=rb.col; j++) { ownField[i][j]=DECK; shipMap[Cell(i,j)]=indShip; } AddToVetoSet(Shell(Rect(It, rb))); } void Navy::Show() const { char rowName[10]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'}; string colName("1 2 3 4 5 6 7 8 9 10"); int i,j; cout<<"________________________\n"; cout<<gap(3)<<"Мій флот"<<gap(18)<<"Флот ворога"<<endl; cout<<gap(3)<<colName<<gap(6)<<colN ame<<endl; for (i=0; i<N; i++) { //Own string line=gap(1)+rowName[i]; for (j=0; j<N; j++) line +=gap(1)+(char)ownField[i][j]; //Enemy line +=gap(5)+rowName[i]; for (j=0; j<N; j++) line +=gap(1)+(char)enemyField[i][j]; cout<<line<<endl; } cout<<endl; cout<<"============================ =====\n"; cout<<step<<"."<<"Мій постріл: "; step++; } int Navy::GetInt() { int value; while (true) { cin>>value; if ('\n'==cin.peek()) {cin.get(); break;} else { cout<<"Повторіть введення колонки (очікується ціле число):"<<endl; cin.clear(); while (cin.get() != '\n') {}; } } return value; } void UserNavy::Allocation() { srand((unsignet)time(NULL)); AllocShip(0, 4, "Авіаносець 'Варяг'"); AllocShip(1, 3, "Лінкор 'Муромець'"); AllocShip(2, 3, "Лінкор 'Микитович'"); AllocShip(3, 2, "Крейсер 'Чудний'"); AllocShip(4, 2, "Крейсер 'Добрий'"); AllocShip(5, 2, "Крейсер 'Справедливий'"); AllocShip(6, 1, "Міноносець 'Хоробрий'"); AllocShip(7, 1, "Міноносець 'Ушлий'"); AllocShip(8, 1, "Міноносець 'Моторний'"); AllocShip(9, 1, "Міноносець 'Сміливий'"); vetoSet.clear(); } void UserNavy::FillDeadZone(Rect r, Field& field) { int i,j; Rect sh=Shell(r); for (i=sh.It.row, j=sh.It.col; j<=sh.rb.col; j++) if (sh.It.row<r.It.row) field[i][j]=' '; for (i=sh.rb.row, j=sh.It.col; j<=sh.rb.col; j++) if (sh.rb.row>r.rb.row) field[i][j]=' '; for (j=sh.It.col, i=sh.It.row; i<=sh.rb.row; i++) if (sh.It.col<r.It.col) field[i][j]=' '; for (j=sh.rb.col. i=sh.It.row; i<=sh.rb.row; i++) if (sh.rb.col>r.rb.col) field[i][j]=' '; } |
![]() |
![]() |
![]() |
#10 |
Пользователь
Регистрация: 03.06.2011
Сообщений: 19
|
![]()
void UserNavy::FireOff()
{ string capital_letter="ABCDEFGHIJ"; string small_letter="abcdefghij"; unsigned char rowName; int colName; int row; int col; bool success=false; while (!success) { cin>>rowName; row=capital_letter.find(rowName); if (-1==row) row=small_letter.find(rowName); if (-1==row) {cout<<"Помилка. Повторіть ввід.\n"; continue'} colName=GetInt(); col=colName-1; if ((col<0)||(col>9)) cout<<"Помилка. Повторіть ввід.\n"; continue; } success=true; } u_fire=Cell(row, col); } void UserNavy::ResultAnalys() { //r_state; //u_fire; switch(r_state) { case Maiss: enemyField[u_fire.row][u_fire.col]=MISS; break; case Damage: enemyField[u_fire.row][u_fire.col]=DAMAGE; crushSet.insert(u_fire); break; case Kill: enemyField[u_fire.row][u_fire.col]=DAMAGE; crushSet.insert(u_fire); Rect kill; kill.It=*crushSet.begin(); kill.rb=*(-crushSet.end()); FillDeadZone(kill, enemyField); crushSet.clear(); } } |
![]() |
![]() |
![]() |
|
![]() |
||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
Кто может помочь разобраться с кодом!(Basic) | danbes1 | Помощь студентам | 10 | 07.04.2011 20:58 |
Кто может помочь..... | teres | C++ Builder | 1 | 18.03.2011 17:59 |
Может кто помочь с заданиями? | fatalistika | Фриланс | 15 | 30.12.2010 08:52 |
Кто может помочь с программой | codemasters | Фриланс | 2 | 28.11.2010 16:41 |