summaryrefslogtreecommitdiff
path: root/noncore/games/zlines/field.cpp
Unidiff
Diffstat (limited to 'noncore/games/zlines/field.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/zlines/field.cpp132
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 -------------------
4begin : Fri May 19 2000
5copyright : (C) 2000 by Roman Merzlyakov
6email : roman@sbrf.barrt.ru
7copyright : (C) 2000 by Roman Razilov
8email : 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
23Field::Field(QWidget* parent, const char* name)
24 : QWidget( parent, name )
25{
26 clearField();
27}
28
29Field::~Field()
30{
31}
32
33void 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}
39void 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}
45int 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
60bool Field::checkBounds(int x, int y)
61{
62 return (x>=0) && (x<NUMCELLSW) && (y>=0) && (y<NUMCELLSH);
63}
64
65void 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 }*/
79void 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
87int Field::getBall(int x, int y)
88{
89 if( checkBounds(x,y) )
90 return field[y][x].getColor();
91 else
92 return NOBALL;
93}
94int Field::getAnim(int x, int y)
95{
96 if( checkBounds(x,y) )
97 return field[y][x].getAnim();
98 else
99 return NOBALL;
100}
101void Field::setAnim(int x, int y, int anim)
102{
103 if( checkBounds(x,y) )
104 field[y][x].setAnim( anim );
105}
106
107void Field::removeBall(int x, int y )
108{
109 if( checkBounds(x,y) ) field[y][x].clear();
110}
111
112int 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}
120void 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}
127void 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}