Skip to content

Commit 0077efc

Browse files
committed
Merge remote-tracking branch 'sbonner1/master'
Conflicts: ZombieProjectModelClasses/src/zombieProject/shared/Game.java
2 parents 2c743e3 + b9c3c03 commit 0077efc

File tree

10 files changed

+256
-66
lines changed

10 files changed

+256
-66
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package zombieProject;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.util.ArrayList;
6+
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import zombieProject.shared.Game;
11+
import zombieProject.shared.Spawned;
12+
13+
public class GameTester {
14+
15+
Game game;
16+
17+
@Before
18+
public void setUp() throws Exception {
19+
game = new Game();
20+
}
21+
22+
23+
@Test
24+
public void testGetPlayer(){
25+
assertEquals(game.getPlayer(), game.getPlayer());
26+
}
27+
@Test
28+
public void testGetZombie(){
29+
assertEquals(game.getZombie(0), game.getZombie(0));
30+
}
31+
@Test
32+
public void testNewZombie(){
33+
game.newZombie();
34+
assertEquals(game.getZombie(0), game.getZombie(0));
35+
int count = game.listSize();
36+
game.removeZ(0);
37+
count -= 1;
38+
assertEquals(count, game.listSize());
39+
}
40+
@Test
41+
public void testGetSpawned(){
42+
game.newSpawn();
43+
assertEquals(game.getSpawned(0), game.getSpawned(0));
44+
game.newSpawn();
45+
int count = game.spawnSize();
46+
game.removeS(0);
47+
count -= 1;
48+
assertEquals(count, game.spawnSize());
49+
}
50+
@Test
51+
public void testZombieListSize(){
52+
int count = game.listSize();
53+
assertEquals(count, game.listSize());
54+
}
55+
@Test
56+
public void testSpawnSize(){
57+
int count = game.spawnSize();
58+
assertEquals(count, game.spawnSize());
59+
}
60+
61+
}

ZombieProjectModelClasses/JUnitTests/zombieProject/ObstacleTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99

1010
public class ObstacleTest {
1111

12-
Obstacle obstacle;
12+
Obstacle obstacle, obstacle2;
1313

1414
@Before
1515
public void setUp() throws Exception {
1616
obstacle = new Obstacle(10, 10, 50, 20);
17+
obstacle2 = new Obstacle(10, 10, 10);
1718
}
1819

1920
@Test

ZombieProjectModelClasses/JUnitTests/zombieProject/PlayerTest.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,85 @@ protected void setUp() throws Exception {
1717
p1 = new Player(0,0);
1818
p2 = new Player(128, 256);
1919
m = new Map();
20+
2021
}
21-
2222
@Test
2323
public void testGetX() throws Exception{
2424
assertEquals(0.0, p1.getX());
2525
assertEquals(128.0, p2.getX());
2626
}
27-
2827
@Test
2928
public void testSetX() throws Exception{
3029
p1.setX(90.0);
3130
assertEquals(90.0, p1.getX());
3231
p2.setX(346.0);
3332
assertEquals(346.0, p2.getX());
3433
}
35-
3634
@Test
3735
public void testGetY() throws Exception{
3836
assertEquals(0.0, p1.getY());
3937
assertEquals(256.0, p2.getY());
4038
}
41-
4239
@Test
4340
public void testSetY() throws Exception{
4441
p1.setY(72.0);
4542
assertEquals(72.0, p1.getY());
4643
p2.setY(925.0);
4744
assertEquals(925.0, p2.getY());
4845
}
49-
5046
@Test
5147
public void testGetHealth() throws Exception{
5248
assertEquals(100.0, p1.getHealth());
5349
assertEquals(100.0, p2.getHealth());
5450
}
55-
5651
@Test
5752
public void testIncreaseHealth() throws Exception{
5853
p1.increaseHealth(50.0);
5954
assertEquals(150.0, p1.getHealth());
6055
p2.increaseHealth(78.0);
6156
assertEquals(178.0, p2.getHealth());
6257
}
63-
6458
@Test
6559
public void testDecreaseHealth() throws Exception{
6660
p1.decreaseHealth(50.0);
6761
assertEquals(50.0, p1.getHealth());
6862
p2.decreaseHealth(50);
6963
assertEquals(50.0, p2.getHealth());
7064
}
71-
65+
@Test
66+
public void testGetPlayerScore(){
67+
assertEquals(0, p1.getPscore());
68+
}
69+
@Test
70+
public void testIncreasePlayerScore(){
71+
p1.increasePscore(10);
72+
assertEquals(10, p1.getPscore());
73+
}
74+
@Test
75+
public void testSetPlayerImageWidth(){
76+
p1.setPlayerImageWidth(50);
77+
assertEquals(50, p1.getPlayerImageWidth());
78+
}
79+
@Test
80+
public void testSetPlayerImageHeight(){
81+
p1.setPlayerImageHeight(20);
82+
assertEquals(20, p1.getPlayerImageHeight());
83+
}
7284
@Test
7385
public void testCanMove() throws Exception{
7486
p1.setX(-10.0);
7587
p1.setY(14.0);
7688
assertFalse(p1.canMove(m));
7789

90+
p2.setX(m.getLeft() + 10);
91+
p2.setY(m.getTop() + 10);
92+
assertTrue(p2.canMove(m));
93+
94+
p2.setX(m.getLeft() - 10);
95+
assertFalse(p2.canMove(m));
96+
7897

7998
}
99+
80100
}
101+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package zombieProject;
2+
3+
import static org.junit.Assert.*;
4+
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import zombieProject.shared.Spawned;
9+
10+
public class SpawnedTest {
11+
12+
Spawned tester;
13+
14+
@Before
15+
public void setUp() throws Exception {
16+
tester = new Spawned(0.0, 0.0);
17+
}
18+
19+
@Test
20+
public void testGetX() {
21+
assertEquals(0.0, tester.getX());
22+
}
23+
24+
@Test
25+
public void testGetY(){
26+
assertEquals(0.0, tester.getY());
27+
}
28+
29+
@Test
30+
public void testSetX(){
31+
tester.setX(10.0);
32+
assertEquals(10.0, tester.getX());
33+
}
34+
35+
@Test
36+
public void testSetY(){
37+
tester.setY(15.0);
38+
assertEquals(15.0, tester.getY());
39+
}
40+
41+
}

ZombieProjectModelClasses/JUnitTests/zombieProject/ZombieTest.java

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,42 @@ protected void setUp() throws Exception {
2424
p1 = new Player(10, 10);
2525
m = new Map();
2626
}
27-
2827
@Test
2928
public void testGetX() throws Exception{
3029
assertEquals(0.0, z1.getX());
3130
assertEquals(128.0, z2.getX());
3231
}
33-
3432
@Test
3533
public void testSetX() throws Exception{
3634
z1.setX(90.0);
3735
assertEquals(90.0, z1.getX());
3836
z2.setX(346.0);
3937
assertEquals(346.0, z2.getX());
4038
}
41-
4239
@Test
4340
public void testGetY() throws Exception{
4441
assertEquals(0.0, z1.getY());
4542
assertEquals(256.0, z2.getY());
4643
}
47-
4844
@Test
4945
public void testSetY() throws Exception{
5046
z1.setY(72.0);
5147
assertEquals(72.0, z1.getY());
5248
z2.setY(925.0);
5349
assertEquals(925.0, z2.getY());
5450
}
55-
5651
@Test
5752
public void testGetHealth() throws Exception{
5853
assertEquals(50.0, z1.getHealth());
5954
assertEquals(50.0, z2.getHealth());
6055
}
61-
62-
6356
@Test
6457
public void testDecreaseHealth() throws Exception{
6558
z1.decreaseHealth(50.0);
6659
assertEquals(0.0, z1.getHealth());
6760
z2.decreaseHealth(25);
6861
assertEquals(25.0, z2.getHealth());
6962
}
70-
71-
7263
@Test
7364
public void testMoveTowardsPlayerUp() throws Exception{
7465
p1.setY(10.0);
@@ -81,8 +72,6 @@ public void testMoveTowardsPlayerUp() throws Exception{
8172
assertEquals(6.0, z1.getY());
8273
assertEquals(6.0, z1.getX());
8374
}
84-
85-
8675
@Test
8776
public void testMoveTowardsPlayerDown() throws Exception{
8877
p1.setY(10.0);
@@ -94,10 +83,13 @@ public void testMoveTowardsPlayerDown() throws Exception{
9483
z1.moveTowardsPlayer(p1);
9584
assertEquals(14.0, z1.getX());
9685
assertEquals(14.0, z1.getY());
86+
87+
z1.setX(15.0);
88+
z1.moveTowardsPlayer(p1);
89+
assertEquals(14.0, z1.getX());
90+
91+
9792
}
98-
99-
100-
10193
@Test
10294
public void testzombieRoam() throws Exception{
10395
z1.setX(15.0);
@@ -110,8 +102,6 @@ public void testzombieRoam() throws Exception{
110102
assertEquals(false, true);
111103
}
112104
}
113-
114-
115105
@Test
116106
public void testZombieMove() throws Exception{
117107
p1.setY(10.0);
@@ -132,7 +122,6 @@ public void testZombieMove() throws Exception{
132122
}
133123

134124
}
135-
136125
@Test
137126
public void testCanMove(){
138127
assertTrue(z3.canMove(m)); //test inboundaries
@@ -146,30 +135,16 @@ public void testCanMove(){
146135
z3.setY(m.getBottom() + 20);
147136
assertFalse(z3.canMove(m)); // test bottom boundary
148137
}
149-
150-
/*
151-
*
152-
* one or the other should change
153-
*
154-
*
155138
@Test
156-
public void testzombieRoamX() throws Exception{
157-
z1.setX(15.0);
158-
z1.setY(15.0);
159-
z1.zombieRoam();
160-
System.out.println(z1.getX());
161-
assertEquals(15.0, z1.getX());
139+
public void setZombieImageWidth(){
140+
z1.setZombieImageWidth(50);
141+
assertEquals(50, z1.getZombieImageWidth());
162142
}
163-
164-
165143
@Test
166-
public void testzombieRoamY() throws Exception{
167-
z1.setX(15.0);
168-
z1.setY(15.0);
169-
z1.zombieRoam();
170-
System.out.println(z1.getY());
171-
assertEquals(15.0, z1.getY());
144+
public void setZombieImageHeight(){
145+
z1.setZombieImageHeight(20);
146+
assertEquals(20, z1.getZombieImageHeight());
172147
}
173-
*/
148+
174149
}
175150

ZombieProjectModelClasses/src/zombieProject/shared/Game.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,33 @@
1212
public class Game {
1313

1414

15-
Map m = new Map();
16-
1715

18-
Random generator = new Random();
16+
1917

2018
private Player player;
21-
// private Zombie zombie;
22-
2319
ArrayList<Zombie> zombieList = new ArrayList<Zombie>();
2420
ArrayList<Spawned> spawnList = new ArrayList<Spawned>();
2521
ArrayList<Ammo> AmmoList = new ArrayList<Ammo>();
2622

2723

24+
25+
26+
/**
27+
* game constructor
28+
*/
2829
public Game() {
2930
this.player = new Player(50, 50);
3031
this.zombieList.add(new Zombie(0, 0));
3132
}
32-
33+
34+
35+
36+
37+
38+
Random generator = new Random();
39+
40+
41+
3342
public Player getPlayer() {
3443
return player;
3544
}
@@ -56,14 +65,10 @@ public int listSize(){
5665
return zombieList.size();
5766
}
5867

59-
60-
61-
6268
public void removeZ(int i){
6369
this.zombieList.remove(i);
6470
}
6571

66-
6772
public int spawnSize(){
6873
return spawnList.size();
6974
}

0 commit comments

Comments
 (0)