-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblock.cpp
More file actions
78 lines (78 loc) · 1.96 KB
/
Copy pathblock.cpp
File metadata and controls
78 lines (78 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*===========================
该文件实现了方块类的成员函数
=============================*/
#pragma once
#define BLUE FOREGROUND_BLUE
#define GREEN FOREGROUND_GREEN
#define RED FOREGROUND_RED
#define INTENSITY FOREGROUND_INTENSITY
#include<time.h>
#include<stdlib.h>
#include"block.h"
#include"player.h"
//构造函数
Block::Block() {
posX = 0;
posY = 0;
color = 0;
shape = 0;
}
//复制构造函数
Block::Block(const Block& b2) {
posX = b2.posX;
posY = b2.posY;
color = b2.color;
shape = b2.shape;
}
//设置方块x坐标
void Block::setX(int x) {
posX = x;
}
//设置方块y坐标
void Block::setY(int y) {
posY = y;
}
//设置方块形状
void Block::setShape(int s) {
shape = s;
}
/*===========================
随机生成方块
先随机方块的类型(7种类型之一)
若该类型的方块有不同变化形状 (如横条和竖条就是一种类型的两种变化形状)
则再随机一种变化形状
一种类型的方块始终对应一种颜色
最后存入方块的shape和color属性
=============================*/
void Block::roundBlock() {
int random;//随机数
random = rand() % 7;//产生0-6的随机数,随机一种方块
random = random * 4 + 1;
switch (random) {//随机方块形状和颜色
case 1:color = GREEN | INTENSITY; random += rand() % 2; break;//亮绿
case 5:color = RED | INTENSITY;break;//红
case 9:color = RED | BLUE | INTENSITY; random += rand() % 4; break;//品红
case 13:color = RED | GREEN | INTENSITY; random += rand() % 4; break;//黄
case 17:color = BLUE | GREEN | INTENSITY; random += rand() % 4; break;//青
case 21:color = BLUE | INTENSITY; random += rand() % 2; break;//蓝
case 25:color = GREEN; random += rand() % 2; break;//绿
default:break;
}
shape = random;
}
//获取方块x坐标
int Block::getX() {
return posX;
}
//获取方块y坐标
int Block::getY() {
return posY;
}
//获取方块颜色
int Block::getColor() {
return color;
}
//获取方块形状
int Block::getShape() {
return shape;
}