author | zecke <zecke> | 2004-02-17 16:24:32 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-17 16:24:32 (UTC) |
commit | 62b3979c6b23627eeca3b89f6feb491cdab97b08 (patch) (unidiff) | |
tree | 8545969e2a2bf63a618b50e4b0d8fbf7f73bedbd /noncore/games/zlines/field.cpp | |
parent | 1207607ebbc59841718b79508fc222cb4eee9fde (diff) | |
download | opie-62b3979c6b23627eeca3b89f6feb491cdab97b08.zip opie-62b3979c6b23627eeca3b89f6feb491cdab97b08.tar.gz opie-62b3979c6b23627eeca3b89f6feb491cdab97b08.tar.bz2 |
Add the zLines port to Opie
Diffstat (limited to 'noncore/games/zlines/field.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/zlines/field.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/noncore/games/zlines/field.cpp b/noncore/games/zlines/field.cpp new file mode 100644 index 0000000..2a87739 --- a/dev/null +++ b/noncore/games/zlines/field.cpp | |||
@@ -0,0 +1,132 @@ | |||
1 | /*************************************************************************** | ||
2 | field.cpp - description | ||
3 | ------------------- | ||
4 | begin : Fri May 19 2000 | ||
5 | copyright : (C) 2000 by Roman Merzlyakov | ||
6 | email : roman@sbrf.barrt.ru | ||
7 | copyright : (C) 2000 by Roman Razilov | ||
8 | email : Roman.Razilov@gmx.de | ||
9 | ***************************************************************************/ | ||
10 | |||
11 | /*************************************************************************** | ||
12 | * * | ||
13 | * This program is free software; you can redistribute it and/or modify * | ||
14 | * it under the terms of the GNU General Public License as published by * | ||
15 | * the Free Software Foundation; either version 2 of the License, or * | ||
16 | * (at your option) any later version. * | ||
17 | * * | ||
18 | ***************************************************************************/ | ||
19 | #include <stdlib.h> | ||
20 | #include "cfg.h" | ||
21 | #include "field.h" | ||
22 | |||
23 | Field::Field(QWidget* parent, const char* name) | ||
24 | : QWidget( parent, name ) | ||
25 | { | ||
26 | clearField(); | ||
27 | } | ||
28 | |||
29 | Field::~Field() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | void Field::clearField() | ||
34 | { | ||
35 | for(int y=0; y<NUMCELLSH; y++) | ||
36 | for(int x=0; x<NUMCELLSW; x++) | ||
37 | field[y][x].clear(); | ||
38 | } | ||
39 | void Field::clearAnim() | ||
40 | { | ||
41 | for(int y=0; y<NUMCELLSH; y++) | ||
42 | for(int x=0; x<NUMCELLSW; x++) | ||
43 | field[y][x].setAnim( ANIM_NO ); | ||
44 | } | ||
45 | int Field::deleteAnimatedBalls() | ||
46 | { | ||
47 | int deleted = 0; | ||
48 | for(int y=0; y<NUMCELLSH; y++) | ||
49 | for(int x=0; x<NUMCELLSW; x++) | ||
50 | { | ||
51 | if ( field[y][x].getAnim() != ANIM_NO ) | ||
52 | { | ||
53 | deleted++; | ||
54 | field[y][x].clear(); | ||
55 | } | ||
56 | } | ||
57 | return deleted; | ||
58 | } | ||
59 | |||
60 | bool Field::checkBounds(int x, int y) | ||
61 | { | ||
62 | return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH); | ||
63 | } | ||
64 | |||
65 | void Field::putBall(int x, int y, int color) | ||
66 | { | ||
67 | if( checkBounds(x,y) ) | ||
68 | field[y][x].setColor(color); | ||
69 | } | ||
70 | /* | ||
71 | void Field::putBall(int x, int y, char color) | ||
72 | { | ||
73 | if( checkBounds(x,y) ){ | ||
74 | field[y][x].setColor(color); | ||
75 | erase5Balls(); | ||
76 | repaint(FALSE); | ||
77 | } | ||
78 | }*/ | ||
79 | void Field::moveBall(int xa, int ya, int xb, int yb) | ||
80 | { | ||
81 | if( checkBounds(xa,ya) && checkBounds(xb,yb) && | ||
82 | field[yb][xb].isFree() && ( xa != xb || ya != yb) ) { | ||
83 | field[yb][xb].moveBall(field[ya][xa]); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | int Field::getBall(int x, int y) | ||
88 | { | ||
89 | if( checkBounds(x,y) ) | ||
90 | return field[y][x].getColor(); | ||
91 | else | ||
92 | return NOBALL; | ||
93 | } | ||
94 | int Field::getAnim(int x, int y) | ||
95 | { | ||
96 | if( checkBounds(x,y) ) | ||
97 | return field[y][x].getAnim(); | ||
98 | else | ||
99 | return NOBALL; | ||
100 | } | ||
101 | void Field::setAnim(int x, int y, int anim) | ||
102 | { | ||
103 | if( checkBounds(x,y) ) | ||
104 | field[y][x].setAnim( anim ); | ||
105 | } | ||
106 | |||
107 | void Field::removeBall(int x, int y ) | ||
108 | { | ||
109 | if( checkBounds(x,y) ) field[y][x].clear(); | ||
110 | } | ||
111 | |||
112 | int Field::freeSpace() | ||
113 | { | ||
114 | int s = 0; | ||
115 | for(int y=0; y<NUMCELLSH; y++) | ||
116 | for(int x=0; x<NUMCELLSW; x++) | ||
117 | if(field[y][x].isFree()) s++; | ||
118 | return s; | ||
119 | } | ||
120 | void Field::saveUndo() | ||
121 | { | ||
122 | void clearAnim(); | ||
123 | for(int y=0; y<NUMCELLSH; y++) | ||
124 | for(int x=0; x<NUMCELLSW; x++) | ||
125 | field_undo[y][x] = field[y][x]; | ||
126 | } | ||
127 | void Field::restoreUndo() | ||
128 | { | ||
129 | for(int y=0; y<NUMCELLSH; y++) | ||
130 | for(int x=0; x<NUMCELLSW; x++) | ||
131 | field[y][x] = field_undo[y][x]; | ||
132 | } | ||