Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TicTacToeSWTHA2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWT_TicTacToe
TicTacToeSWTHA2
Commits
81b3e365
Commit
81b3e365
authored
2 years ago
by
Tarek
Committed by
Ricardo Müller
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Removed unnecessary class GameBoard
parent
a3b728f2
No related branches found
No related tags found
1 merge request
!9
Cleaned up and re-added GameBoard
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/example/tictactoeswtha2/GameBoard.java
+0
-103
0 additions, 103 deletions
src/main/java/com/example/tictactoeswtha2/GameBoard.java
with
0 additions
and
103 deletions
src/main/java/com/example/tictactoeswtha2/GameBoard.java
deleted
100644 → 0
+
0
−
103
View file @
a3b728f2
package
com.example.tictactoeswtha2
;
public
class
GameBoard
{
/**
* 3x3 game board
*/
private
int
[][]
board
=
new
int
[
3
][
3
];
/**
* Initialize every position with 0
*/
public
void
GameBoard
(){
for
(
int
y
=
0
;
y
<
3
;
y
++){
for
(
int
x
=
0
;
x
<
3
;
x
++){
board
[
y
][
x
]
=
0
;
}
}
}
/**
* Tries to place a symbol on the board
* @param position Position where the symbol should be placed 1-9
* @param symbol Symbol that should be placed
* @return Whether the symbol could be placed
*/
public
boolean
addSymbol
(
int
position
,
int
symbol
){
int
x
=
position
%
3
+
1
;
int
y
=
position
/
3
;
if
(
board
[
y
][
x
]
>
0
)
return
false
;
board
[
y
][
x
]
=
symbol
;
return
true
;
}
/**
* Checks if the game is finished
* 0: game isn't finished yet
* 1: Player 1 won
* 2: Player 2 won
* 3: tie
* @return Winner or tie or unfinished
*/
public
int
winCheck
(){
for
(
int
i
=
0
;
i
<
3
;
i
++){
// vertical
if
(
board
[
0
][
i
]
==
board
[
1
][
i
]
&&
board
[
1
][
i
]
==
board
[
2
][
i
]
&&
board
[
0
][
i
]
>
0
)
return
board
[
0
][
i
];
// horizontal
if
(
board
[
i
][
0
]
==
board
[
i
][
1
]
&&
board
[
i
][
1
]
==
board
[
i
][
2
]
&&
board
[
i
][
0
]
>
0
)
return
board
[
i
][
0
];
}
// diagonal
if
(
board
[
0
][
0
]
==
board
[
1
][
1
]
&&
board
[
1
][
1
]
==
board
[
2
][
2
]
&&
board
[
1
][
1
]
>
0
)
return
board
[
1
][
1
];
if
(
board
[
2
][
0
]
==
board
[
1
][
1
]
&&
board
[
1
][
1
]
==
board
[
0
][
2
]
&&
board
[
1
][
1
]
>
0
)
return
board
[
1
][
1
];
// game isn't finished
for
(
int
i
=
0
;
i
<
9
;
i
++)
{
int
x
=
i
%
3
+
1
;
int
y
=
i
/
3
;
if
(
board
[
y
][
x
]
==
0
)
return
0
;
}
// Tie
return
3
;
}
/**
* Gives back the game board to display it
* @return Game board
*/
public
int
[][]
getBoard
()
{
return
board
;
}
/**
* Prints the board on the console for debugging
*/
public
void
printOnConsole
(){
for
(
int
y
=
0
;
y
<
3
;
y
++){
for
(
int
x
=
0
;
x
<
3
;
x
++){
System
.
out
.
printf
(
Integer
.
toString
(
board
[
y
][
x
]));
}
System
.
out
.
printf
(
"\n"
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment