Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 890a1c3

Browse files
committed
Add .gitignore files and implement model classes for the project
1 parent 01065cb commit 890a1c3

File tree

28 files changed

+496
-0
lines changed

28 files changed

+496
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>GameManager</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=17
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=17
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package models;
2+
3+
public class Game {
4+
private int id;
5+
private Player player1;
6+
private Player player2;
7+
8+
public Game() {
9+
this.id = 0;
10+
this.player1 = new Player();
11+
this.player2 = new Player();
12+
}
13+
14+
public Game(int id, Player player1, Player player2) {
15+
this.id = id;
16+
this.player1 = player1;
17+
this.player2 = player2;
18+
}
19+
20+
public Player getWinner() {
21+
if (player1.isWinner() == true)
22+
return player1;
23+
if (player2.isWinner() == true)
24+
return player2;
25+
return null;
26+
}
27+
28+
public void resetGame() {
29+
player1.setScore(0);
30+
player2.setScore(0);
31+
}
32+
33+
public void swapPlayers() {
34+
Player t = player1;
35+
player1 = player2;
36+
player2 = t;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "Game [id=" + id + ", \nplayer1=" + player1 + ", \nplayer2=" + player2 + "]";
42+
}
43+
44+
public int getId() {
45+
return id;
46+
}
47+
48+
public void setId(int id) {
49+
this.id = id;
50+
}
51+
52+
public Player getPlayer1() {
53+
return player1;
54+
}
55+
56+
public void setPlayer1(Player player1) {
57+
this.player1 = player1;
58+
}
59+
60+
public Player getPlayer2() {
61+
return player2;
62+
}
63+
64+
public void setPlayer2(Player player2) {
65+
this.player2 = player2;
66+
}
67+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package models;
2+
3+
public class Player {
4+
private String name;
5+
private int age;
6+
private int score;
7+
private int positionX;
8+
private int positionY;
9+
10+
public Player() {
11+
this.name = "";
12+
this.age = 0;
13+
this.score = 0;
14+
this.positionX = 0;
15+
this.positionY = 0;
16+
}
17+
18+
public Player(String name, int age, int score, int positionX, int positionY) {
19+
this.name = name;
20+
this.age = age;
21+
this.score = score;
22+
this.positionX = positionX;
23+
this.positionY = positionY;
24+
}
25+
26+
public void increaseScore() {
27+
this.score++;
28+
}
29+
30+
public void decreaseScore() {
31+
this.score--;
32+
}
33+
34+
public void increaseScore(int n) {
35+
this.score += n;
36+
}
37+
38+
public void decreaseScore(int n) {
39+
this.score -= n;
40+
}
41+
42+
public boolean isWinner() {
43+
if (this.score >= 100)
44+
return true;
45+
else
46+
return false;
47+
}
48+
49+
50+
@Override
51+
public String toString() {
52+
return "Player [name=" + name + ", age=" + age + ", score=" + score + ", positionX=" + positionX
53+
+ ", positionY=" + positionY + "]";
54+
}
55+
56+
public String getName() {
57+
return name;
58+
}
59+
60+
public void setName(String name) {
61+
this.name = name;
62+
}
63+
64+
public int getAge() {
65+
return age;
66+
}
67+
68+
public void setAge(int age) {
69+
this.age = age;
70+
}
71+
72+
public int getScore() {
73+
return score;
74+
}
75+
76+
public void setScore(int score) {
77+
this.score = score;
78+
}
79+
80+
public int getPositionX() {
81+
return positionX;
82+
}
83+
84+
public void setPositionX(int positionX) {
85+
this.positionX = positionX;
86+
}
87+
88+
public int getPositionY() {
89+
return positionY;
90+
}
91+
92+
public void setPositionY(int positionY) {
93+
this.positionY = positionY;
94+
}
95+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test;
2+
3+
import models.Game;
4+
import models.Player;
5+
6+
public class Test {
7+
8+
public static void main(String[] args) {
9+
// TODO Auto-generated method stub
10+
11+
Game g = new Game(123, new Player("Hải", 26, 0, 10, 10), new Player("Mạnh Đức", 19, 0, 10, 10));
12+
13+
g.getPlayer2().setScore(100);
14+
g.getPlayer1().setScore(100);
15+
16+
System.out.println(g.getWinner());
17+
18+
}
19+
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.metadata/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /