Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
agile-java
/
ChessAndroid
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
830017af
authored
May 24, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lesson 4 in progress
parent
7ad17e3e
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
179 additions
and
125 deletions
app/src/main/AndroidManifest.xml
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
app/src/main/java/com/example/paktalin/agilejava_exercises/MainActivity.java
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
app/src/main/java/com/example/paktalin/agilejava_exercises/util/StringUtil.java
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/StringUtilTest.java
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PawnTest.java
app/src/main/AndroidManifest.xml
View file @
830017af
...
...
@@ -8,14 +8,6 @@
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".MainActivity"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
android:theme=
"@style/AppTheme"
></application>
</manifest>
\ No newline at end of file
app/src/main/java/com/example/paktalin/agilejava_exercises/Board.java
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
com.example.paktalin.agilejava_exercises.pieces.Pawn
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
com
.
example
.
paktalin
.
agilejava_exercises
.
util
.
StringUtil
.
NEW_LINE
;
/**
* Created by Paktalin on 23/05/2018.
*/
class
Board
{
private
List
<
Pawn
>
seventhRank
=
new
ArrayList
<>();
private
List
<
Pawn
>
secondRank
=
new
ArrayList
<>();
private
List
<
Piece
>
firstRank
=
new
ArrayList
<>();
private
List
<
Piece
>
secondRank
=
new
ArrayList
<>();
private
List
<
Piece
>
seventhRank
=
new
ArrayList
<>();
private
List
<
Piece
>
eightRank
=
new
ArrayList
<>();
private
final
String
blankRank
=
"........"
+
NEW_LINE
;
void
initialize
()
{
fillFirstRank
();
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
addWhitePawn
(
);
addBlackPawn
(
);
secondRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Pawn
)
);
seventhRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Pawn
)
);
}
fillEightRank
();
}
int
getNumberOfPieces
()
{
return
seventhRank
.
size
()
+
secondRank
.
size
();
private
void
fillFirstRank
()
{
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Rook
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Knight
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Bishop
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Queen
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
King
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Bishop
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Knight
));
firstRank
.
add
(
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Rook
));
}
void
addWhitePawn
()
{
seventhRank
.
add
(
new
Pawn
(
Pawn
.
COLOR_WHITE
));
private
void
fillEightRank
()
{
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Rook
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Knight
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Bishop
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Queen
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
King
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Bishop
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Knight
));
eightRank
.
add
(
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Rook
));
}
void
addBlackPawn
()
{
secondRank
.
add
(
new
Pawn
(
Pawn
.
COLOR_BLACK
)
);
int
pieceCount
()
{
return
firstRank
.
size
()
+
secondRank
.
size
()
+
seventhRank
.
size
()
+
eightRank
.
size
(
);
}
List
<
Pawn
>
getRank
(
int
rankNumber
)
{
if
(
rankNumber
==
2
)
List
<
Piece
>
getRank
(
int
rankNumber
)
{
switch
(
rankNumber
)
{
case
1
:
return
firstRank
;
case
2
:
return
secondRank
;
case
7
:
return
seventhRank
;
default
:
return
eightRank
;
}
}
String
printRank
(
int
rankNumber
)
{
StringBuilder
rankRepresentation
=
new
StringBuilder
();
for
(
Pawn
pawn
:
getRank
(
rankNumber
))
rankRepresentation
.
append
(
pawn
.
print
());
return
rankRepresentation
.
toString
();
StringBuilder
buffer
=
new
StringBuilder
();
for
(
Piece
piece
:
getRank
(
rankNumber
))
buffer
.
append
(
piece
.
print
());
return
buffer
.
toString
();
}
void
print
()
{
String
print
()
{
StringBuilder
buffer
=
new
StringBuilder
();
buffer
.
append
(
"........\n"
);
buffer
.
append
(
printRank
(
2
)
+
"\n"
);
buffer
.
append
(
printRank
(
1
)
+
NEW_LINE
);
buffer
.
append
(
printRank
(
2
)
+
NEW_LINE
);
for
(
int
i
=
3
;
i
<
7
;
i
++)
buffer
.
append
(
"........\n"
);
buffer
.
append
(
blankRank
);
buffer
.
append
(
printRank
(
7
)
+
"\n"
);
buffer
.
append
(
"........\n"
);
buffer
.
append
(
printRank
(
7
)
+
NEW_LINE
);
buffer
.
append
(
printRank
(
8
)
+
NEW_LINE
);
System
.
out
.
print
(
buffer
.
toString
()
);
return
buffer
.
toString
(
);
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/MainActivity.java
deleted
100644 → 0
View file @
7ad17e3e
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
public
class
MainActivity
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/Piece.java
0 → 100644
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
;
/**
* Created by Paktalin on 23/05/2018.
*/
public
class
Piece
{
enum
Name
{
Pawn
,
Knight
,
Rook
,
Bishop
,
Queen
,
King
}
enum
Color
{
White
,
Black
}
private
Name
name
;
private
Color
color
;
private
Piece
()
{}
Piece
(
final
Color
color
,
final
Name
name
)
{
this
.
color
=
color
;
this
.
name
=
name
;
}
public
Color
getColor
()
{
return
color
;
}
public
Name
getName
()
{
return
name
;
}
String
print
()
{
String
letter
=
""
;
switch
(
name
)
{
case
King:
letter
=
"k"
;
break
;
case
Queen:
letter
=
"q"
;
break
;
case
Pawn:
letter
=
"p"
;
break
;
case
Rook:
letter
=
"r"
;
break
;
case
Bishop:
letter
=
"b"
;
break
;
case
Knight:
letter
=
"n"
;
break
;
}
if
(
color
==
Color
.
Black
)
return
letter
.
toUpperCase
();
return
letter
;
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/pieces/Pawn.java
deleted
100644 → 0
View file @
7ad17e3e
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
/**
* Created by Paktalin on 23/05/2018.
*/
public
class
Pawn
{
public
static
String
COLOR_WHITE
=
"white"
;
public
static
String
COLOR_BLACK
=
"black"
;
private
String
color
;
Pawn
()
{
color
=
"white"
;
}
public
Pawn
(
final
String
color
)
{
this
.
color
=
color
;
}
public
String
getColor
()
{
return
color
;
}
public
String
print
()
{
if
(
this
.
getColor
().
equals
(
COLOR_BLACK
))
return
"P"
;
return
"p"
;
}
}
app/src/main/java/com/example/paktalin/agilejava_exercises/util/StringUtil.java
0 → 100644
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
.
util
;
/**
* Created by Paktalin on 24/05/2018.
*/
public
class
StringUtil
{
public
static
final
String
NEW_LINE
=
"\n"
;
private
StringUtil
()
{}
public
static
String
appendNewLine
(
String
string
)
{
return
string
+
NEW_LINE
;
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/AllTests.java
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
com.example.paktalin.agilejava_exercises.pieces.PawnTest
;
import
junit.framework.TestSuite
;
/**
...
...
@@ -13,7 +11,7 @@ public class AllTests extends TestSuite {
public
static
TestSuite
suite
()
{
TestSuite
suite
=
new
TestSuite
();
suite
.
addTestSuite
(
P
awn
Test
.
class
);
suite
.
addTestSuite
(
P
iece
Test
.
class
);
suite
.
addTestSuite
(
BoardTest
.
class
);
suite
.
addTestSuite
(
CharacterTest
.
class
);
...
...
app/src/test/java/com/example/paktalin/agilejava_exercises/BoardTest.java
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
com.example.paktalin.agilejava_exercises.util.StringUtil
;
import
junit.framework.TestCase
;
/**
...
...
@@ -7,21 +9,23 @@ import junit.framework.TestCase;
*/
public
class
BoardTest
extends
TestCase
{
private
Board
board
;
p
ublic
void
setUp
()
{
p
rotected
void
setUp
()
{
board
=
new
Board
();
}
public
void
test
Board
()
{
public
void
test
Create
()
{
board
.
initialize
();
assertEquals
(
16
,
board
.
getNumberOfPieces
());
assertEquals
(
"PPPPPPPP"
,
board
.
printRank
(
2
));
assertEquals
(
"pppppppp"
,
board
.
printRank
(
7
));
board
.
print
();
assertEquals
(
32
,
board
.
pieceCount
());
String
blankRank
=
StringUtil
.
appendNewLine
(
"........"
);
assertEquals
(
StringUtil
.
appendNewLine
(
"RNBQKBNR"
)
+
StringUtil
.
appendNewLine
(
"PPPPPPPP"
)
+
blankRank
+
blankRank
+
blankRank
+
blankRank
+
StringUtil
.
appendNewLine
(
"pppppppp"
)
+
StringUtil
.
appendNewLine
(
"rnbqkbnr"
),
board
.
print
());
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/PieceTest.java
0 → 100644
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 23/05/2018.
*/
public
class
PieceTest
extends
TestCase
{
private
Piece
blackPawn
,
whitePawn
;
public
void
setUp
()
{
blackPawn
=
new
Piece
(
Piece
.
Color
.
Black
,
Piece
.
Name
.
Pawn
);
whitePawn
=
new
Piece
(
Piece
.
Color
.
White
,
Piece
.
Name
.
Pawn
);
}
public
void
testPawnColor
()
{
assertEquals
(
Piece
.
Color
.
White
,
whitePawn
.
getColor
());
assertEquals
(
Piece
.
Color
.
Black
,
blackPawn
.
getColor
());
}
public
void
testPawnRepresentation
()
{
assertEquals
(
"P"
,
blackPawn
.
print
());
assertEquals
(
"p"
,
whitePawn
.
print
());
}
}
app/src/test/java/com/example/paktalin/agilejava_exercises/StringUtilTest.java
0 → 100644
View file @
830017af
package
com
.
example
.
paktalin
.
agilejava_exercises
;
import
junit.framework.TestCase
;
/**
* Created by Paktalin on 24/05/2018.
*/
public
class
StringUtilTest
extends
TestCase
{
}
app/src/test/java/com/example/paktalin/agilejava_exercises/pieces/PawnTest.java
deleted
100644 → 0
View file @
7ad17e3e
package
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
;
import
junit.framework.TestCase
;
import
static
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
.
Pawn
.
COLOR_BLACK
;
import
static
com
.
example
.
paktalin
.
agilejava_exercises
.
pieces
.
Pawn
.
COLOR_WHITE
;
/**
* Created by Paktalin on 23/05/2018.
*/
public
class
PawnTest
extends
TestCase
{
public
void
testCreate
()
{
Pawn
pawn
=
new
Pawn
(
COLOR_WHITE
);
assertEquals
(
"white"
,
pawn
.
getColor
());
Pawn
pawn2
=
new
Pawn
(
COLOR_BLACK
);
assertEquals
(
"black"
,
pawn2
.
getColor
());
}
public
void
testConstructor
()
{
Pawn
pawn
=
new
Pawn
();
assertEquals
(
"white"
,
pawn
.
getColor
());
}
public
void
testPawnRepresentation
()
{
Pawn
blackPawn
=
new
Pawn
(
Pawn
.
COLOR_BLACK
);
assertEquals
(
"P"
,
blackPawn
.
print
());
Pawn
whitePawn
=
new
Pawn
(
Pawn
.
COLOR_WHITE
);
assertEquals
(
"p"
,
whitePawn
.
print
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment