Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# android-omok-precourse
# android-omok-precourse
## 게임기능
### 화면 그리기
- [x] 배경색을 가진 격자 그리기
- [x] 격자 교차점을 터치했을 때 돌을 그리기
- [x] 이미 돌이 있는 곳에는 돌을 놓을 수 없음
- [x] 흑, 백 번갈아 가며 그리기
### 게임 진행
- [x] 최대 연결 수 계산하기
- [x] 처음으로 5목 이상 배치시 게임 종료
- [x] 끝나면 다시하기 여부 물어보기
- [x] 재시작 시 맵 초기화 하기
138 changes: 138 additions & 0 deletions app/src/androidTest/java/nextstep/omok/OmokSystemAndroidTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package nextstep.omok

import org.assertj.core.api.Assertions.*
import android.widget.ImageView
import android.widget.TableLayout
import android.widget.TableRow
import androidx.test.core.app.ActivityScenario
import org.junit.Test

class OmokSystemAndroidTest {


@Test
fun getBoardImageViewTest() {
val activityScenario = ActivityScenario.launch(MainActivity::class.java)
activityScenario.onActivity {
val board = it.findViewById<TableLayout>(R.id.board)
val omokSystem = OmokSystem(it, board)
val imageView: ImageView = (board.getChildAt(1) as TableRow).getChildAt(1) as ImageView
assertThat(omokSystem.getBoardImageView(1,1)).isEqualTo(imageView)
}
activityScenario.close()
}

@Test
fun putStoneTest() {
val activityScenario = ActivityScenario.launch(MainActivity::class.java)
activityScenario.onActivity {
val board = it.findViewById<TableLayout>(R.id.board)
val omokSystem = OmokSystem(it, board)

// 지정한 위치에 착수
setStoneBlack(omokSystem)
omokSystem.putStone(1, 1)
val oldStone = (board.getChildAt(1) as TableRow).getChildAt(1) as ImageView
assertThat(omokSystem.getBoardImageView(1,1)).isEqualTo(oldStone)

// 이미 착수한 곳에 착수 시도: 기존의 돌이 유지되어야 함
omokSystem.putStone(1, 1)
assertThat(omokSystem.getBoardImageView(1, 1)).isEqualTo(oldStone)
}
activityScenario.close()
}

@Test
fun calculateCombo() {
val activityScenario = ActivityScenario.launch(MainActivity::class.java)

activityScenario.onActivity {
val board = it.findViewById<TableLayout>(R.id.board)
val omokSystem = OmokSystem(it, board)

setStoneBlack(omokSystem)
omokSystem.putStone(1, 1)
setStoneBlack(omokSystem)
omokSystem.putStone(1, 2)
setStoneBlack(omokSystem)
omokSystem.putStone(1, 3)
setStoneBlack(omokSystem)
omokSystem.putStone(1, 4)
setStoneBlack(omokSystem)
omokSystem.putStone(1, 5)
assertThat(omokSystem.calculateCombo(1,1)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(1,2)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(1,3)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(1,4)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(1,5)).isEqualTo(5)

setStoneWhite(omokSystem)
omokSystem.putStone(2, 2)
setStoneWhite(omokSystem)
omokSystem.putStone(3, 3)
setStoneWhite(omokSystem)
omokSystem.putStone(4, 4)
setStoneWhite(omokSystem)
omokSystem.putStone(5, 5)
setStoneWhite(omokSystem)
omokSystem.putStone(6, 6)
assertThat(omokSystem.calculateCombo(2,2)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(3,3)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(4,4)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(5,5)).isEqualTo(5)
assertThat(omokSystem.calculateCombo(6,6)).isEqualTo(5)
}
activityScenario.close()
}

@Test
fun isGameEndTest() {
val activityScenario = ActivityScenario.launch(MainActivity::class.java)

activityScenario.onActivity {
val board = it.findViewById<TableLayout>(R.id.board)
val omokSystem = OmokSystem(it, board)

assertThat(omokSystem.isGameEnd(omokSystem.scoreCombo - 1)).isEqualTo(false)
assertThat(omokSystem.isGameEnd(omokSystem.scoreCombo)).isEqualTo(true)
assertThat(omokSystem.isGameEnd(omokSystem.scoreCombo + 1)).isEqualTo(true)
}
activityScenario.close()

}

@Test
fun resetBoardTest() {
val activityScenario = ActivityScenario.launch(MainActivity::class.java)

activityScenario.onActivity {
val board = it.findViewById<TableLayout>(R.id.board)
val omokSystem = OmokSystem(it, board)

// 판에 돌을 모두 착수
for (i in 0..14) {
for (j in 0..14) {
omokSystem.putStone(i,j)
assertThat(omokSystem.getBoardImageView(i,j).drawable).isNotNull
}
}
omokSystem.resetBoard()
// 리셋되었는지 확인
for (i in 0..14) {
for (j in 0..14) {
assertThat(omokSystem.getBoardImageView(i,j).drawable).isNull()
}
}
assertThat(omokSystem.nowStone).isEqualTo(omokSystem.BLACK)
}
activityScenario.close()
}

fun setStoneBlack(omokSystem: OmokSystem) {
omokSystem.nowStone = omokSystem.BLACK
}

fun setStoneWhite(omokSystem: OmokSystem) {
omokSystem.nowStone = omokSystem.WHITE
}
}
8 changes: 2 additions & 6 deletions app/src/main/java/nextstep/omok/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

val board = findViewById<TableLayout>(R.id.board)
board
.children
.filterIsInstance<TableRow>()
.flatMap { it.children }
.filterIsInstance<ImageView>()
.forEach { view -> view.setOnClickListener { view.setImageResource(R.drawable.black_stone) } }
val omokSystem = OmokSystem(this, board)
omokSystem.registerClickListener()
}
}
Loading