Skip to content

Commit a85f56c

Browse files
committed
view is done
1 parent f66e26d commit a85f56c

File tree

5 files changed

+133
-8
lines changed

5 files changed

+133
-8
lines changed

app/src/main/java/com/example/tictactoemvc/TicTacToeGame.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.example.tictactoemvc
22

3+
import android.content.Context
4+
35
class TicTacToeGame {
46

57
private var board: Array<Array<Mark>> = Array(ROWS) { Array(COLUMNS) { Mark.MARK_NONE } }
68
var gameState: GameState = GameState.X_TURN
9+
private lateinit var context: Context
710

811
companion object {
912
val ROWS = 3
@@ -24,6 +27,10 @@ class TicTacToeGame {
2427
TIE_GAME
2528
}
2629

30+
constructor(context: Context) {
31+
this.context = context
32+
}
33+
2734
init {
2835
resetGame()
2936
}
@@ -140,4 +147,14 @@ class TicTacToeGame {
140147
}
141148
return true
142149
}
150+
151+
fun stringForGameState(): String {
152+
return when (gameState) {
153+
GameState.X_TURN -> context.getString(R.string.x_turn)
154+
GameState.O_TURN -> context.getString(R.string.o_turn)
155+
GameState.O_WINS -> context.getString(R.string.o_wins)
156+
GameState.X_WINS -> context.getString(R.string.x_wins)
157+
GameState.TIE_GAME -> context.getString(R.string.tie_game)
158+
}
159+
}
143160
}
Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,101 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
6+
android:background="@color/colorBackground"
77
tools:context=".MainActivity">
88

9+
<TableLayout
10+
android:id="@+id/button_table"
11+
android:layout_width="330dp"
12+
android:layout_height="330dp"
13+
android:layout_centerInParent="true"
14+
android:layout_margin="20dp">
15+
16+
<TableRow
17+
android:layout_width="wrap_content"
18+
android:layout_height="match_parent">
19+
20+
<Button
21+
android:id="@+id/button00"
22+
style="@style/game_btn"
23+
tools:text="X" />
24+
25+
<Button
26+
android:id="@+id/button01"
27+
style="@style/game_btn"
28+
tools:text="X" />
29+
30+
<Button
31+
android:id="@+id/button02"
32+
style="@style/game_btn"
33+
tools:text="X" />
34+
35+
</TableRow>
36+
37+
<TableRow
38+
android:layout_width="wrap_content"
39+
android:layout_height="match_parent">
40+
41+
<Button
42+
android:id="@+id/button10"
43+
style="@style/game_btn"
44+
tools:text="X" />
45+
46+
<Button
47+
android:id="@+id/button11"
48+
style="@style/game_btn"
49+
tools:text="X" />
50+
51+
<Button
52+
android:id="@+id/button22"
53+
style="@style/game_btn"
54+
tools:text="X" />
55+
56+
</TableRow>
57+
58+
<TableRow
59+
android:layout_width="wrap_content"
60+
android:layout_height="match_parent">
61+
62+
<Button
63+
android:id="@+id/button30"
64+
style="@style/game_btn"
65+
tools:text="X" />
66+
67+
<Button
68+
android:id="@+id/button31"
69+
style="@style/game_btn"
70+
tools:text="X" />
71+
72+
<Button
73+
android:id="@+id/button32"
74+
style="@style/game_btn"
75+
tools:text="X" />
76+
77+
</TableRow>
78+
79+
</TableLayout>
80+
981
<TextView
82+
android:id="@+id/game_state_view"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:layout_above="@+id/button_table"
86+
android:layout_centerHorizontal="true"
87+
android:textColor="@color/colorText"
88+
android:textSize="24sp"
89+
android:textStyle="bold"
90+
tools:text="@string/x_turn" />
91+
92+
<Button
93+
android:id="@+id/new_game_button"
1094
android:layout_width="wrap_content"
1195
android:layout_height="wrap_content"
12-
android:text="Hello World!"
13-
app:layout_constraintBottom_toBottomOf="parent"
14-
app:layout_constraintEnd_toEndOf="parent"
15-
app:layout_constraintStart_toStartOf="parent"
16-
app:layout_constraintTop_toTopOf="parent" />
96+
android:layout_below="@+id/button_table"
97+
android:layout_alignEnd="@+id/button_table"
98+
android:backgroundTint="@color/colorBtn"
99+
android:text="@string/new_game" />
17100

18-
</androidx.constraintlayout.widget.ConstraintLayout>
101+
</RelativeLayout>

app/src/main/res/values/colors.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10+
<color name="colorBackground">#5387C5</color>
11+
<color name="colorText">#FFFFFFFF</color>
12+
<color name="colorBtn">#379A2D</color>
13+
<color name="colorBtnGame">#46D195</color>
1014
</resources>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
<resources>
22
<string name="app_name">TicTacToeMVC</string>
3+
4+
<string name="x_turn">X Turn</string>
5+
<string name="o_turn">O Turn</string>
6+
<string name="x_wins">X Wins</string>
7+
<string name="o_wins">O Wins</string>
8+
<string name="tie_game">Tie Game</string>
9+
10+
<string name="new_game">New Game</string>
11+
<string name="space">" "</string>
312
</resources>

app/src/main/res/values/styles.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<style name="game_btn">
5+
<item name="android:backgroundTint">@color/colorBtnGame</item>
6+
<item name="android:textSize">50sp</item>
7+
<item name="android:textStyle">bold</item>
8+
<item name="android:layout_width">100dp</item>
9+
<item name="android:layout_height">100dp</item>
10+
<item name="android:layout_margin">5dp</item>
11+
</style>
12+
</resources>

0 commit comments

Comments
 (0)