Changeset 27 for trunk


Ignore:
Timestamp:
Dec 20, 2005, 4:03:49 PM (14 years ago)
Author:
jtv
Message:

Code cleanup (finally unified those constructors)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gamelogic.cxx

    r23 r27  
    320320  m_moves(0)
    321321{
    322   assert(m_rows > 0);
    323   assert(m_cols > 0);
    324   assert(mines > 0);
    325   assert(mines <= m_rows*m_cols);
    326 
    327   m_patches = new Patch[arraysize()];
     322  init_field();
    328323
    329324  while (mines)
     
    331326    const int row = rand_coord(m_rows), col = rand_coord(m_cols);
    332327    mines -= place_mine_at(row,col);
    333   }
    334 
    335   for (int b=1; b<border; ++b)
    336   {
    337     border_row(-b);
    338     border_row(m_rows+b-1);
    339     border_col(-b);
    340     border_col(m_cols+b-1);
    341328  }
    342329}
     
    361348  m_patches_to_go = m_rows * m_cols;
    362349
    363   // TODO: Re-unify this with regular constructor
    364   assert(m_rows > 0);
    365   assert(m_cols > 0);
    366   assert(m_moves >= 0);
    367   assert(m_intelligence >= 0);
    368 
    369   m_patches = new Patch[arraysize()];
     350  init_field();
    370351
    371352  here = skip_whitespace(here);
     
    388369    here = read_eol(here, padding);
    389370  }
    390 
    391371  read_terminator(here);
    392 
    393   // TODO: Re-unify this with regular constructor
     372}
     373
     374
     375Lake::~Lake() throw ()
     376{
     377  delete [] m_patches;
     378}
     379
     380
     381void Lake::init_field()
     382{
     383  assert(m_rows > 0);
     384  assert(m_cols > 0);
     385  assert(m_moves >= 0);
     386  assert(m_intelligence >= 0);
     387
     388  m_patches = new Patch[arraysize()];
    394389  for (int b=1; b<border; ++b)
    395390  {
     
    400395  }
    401396}
    402 
    403 
    404 Lake::~Lake() throw ()
    405 {
    406   delete [] m_patches;
    407 }
    408 
    409397
    410398int Lake::savesize() const throw ()
  • trunk/gamelogic.hxx

    r22 r27  
    110110private:
    111111  enum { border = 3 };
     112  void init_field();
    112113  Patch &at(int row, int col);
    113114  const Patch &at(int row, int col) const;
    114 
    115   void init_field();
    116115
    117116  bool place_mine_at(int row, int col);
  • trunk/ui_cli.cxx

    r23 r27  
    9494         <<rows<<"x"<<cols<<" fields, "<<mines<<" mines." << endl;
    9595    Lake L(rows,cols,mines);
    96     L.set_intelligence(Lake::max_intelligence()+1);
     96    L.set_intelligence(Lake::max_intelligence());
    9797    while (L.to_go())
    9898    {
Note: See TracChangeset for help on using the changeset viewer.