board.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* $NetBSD: board.h,v 1.1.1.1 2003/12/26 17:57:03 christos Exp $ */
  2. /*-
  3. * Copyright (c) 2003 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to The NetBSD Foundation
  7. * by Christos Zoulas.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the NetBSD
  20. * Foundation, Inc. and its contributors.
  21. * 4. Neither the name of The NetBSD Foundation nor the names of its
  22. * contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  26. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  27. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  29. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. /*
  38. * board.h: Board functions
  39. */
  40. #ifndef _H_BOARD
  41. #define _H_BOARD
  42. #include <stdlib.h>
  43. class GAMESCREEN;
  44. class PLAYER;
  45. class BOARD {
  46. public:
  47. // Constructors and destructor
  48. BOARD(size_t y, size_t x, GAMESCREEN* scrn);// For the main screen
  49. BOARD(const BOARD& b); // For scratch screens
  50. ~BOARD();
  51. // member access
  52. size_t nx(void) const { return _nx; }
  53. size_t ny(void) const { return _ny; }
  54. size_t tx(void) const { return _tx; }
  55. size_t ty(void) const { return _ty; }
  56. GAMESCREEN* getScrn(void) const { return _scrn; }
  57. int& data(size_t y, size_t x) { return _b[y][x]; }
  58. // Computing
  59. int domove(size_t y, size_t x, int dir, char c); // Play move
  60. void init(void); // Initialize a new game
  61. int full(void) const; // True if no more moves
  62. int bounds(size_t y, size_t x) const; // True if in bounds
  63. // Screen updates
  64. void paint(void) const; // Redraw screen
  65. void clean(void) const; // Clear screen
  66. void setpos(size_t y, size_t x) const; // move cursor to pos
  67. int getmove(void) const; // Return move
  68. void bell(void) const; // Beep!
  69. void score(size_t i, const PLAYER& p); // Post score
  70. void games(size_t i, const PLAYER& p); // Post games
  71. void total(size_t i, const PLAYER& p); // Post totals
  72. void ties(const PLAYER& p); // Post ties
  73. void abort(const char *s, ...) const; // Algorithm error
  74. private:
  75. size_t _ty, _tx; // number of symbols in x and y dimension
  76. size_t _ny, _nx; // number of boxes in the x and y dimension
  77. int** _b; // board array of symbols
  78. GAMESCREEN* _scrn; // screen access, if we have one
  79. };
  80. #endif