Skip to content

Commit

Permalink
default code
Browse files Browse the repository at this point in the history
  • Loading branch information
woowabrie authored and boorownie committed Mar 13, 2023
1 parent e9faa37 commit 07ad425
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 8 deletions.
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.10-SNAPSHOT'
id 'org.springframework.boot' version '2.7.9'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

sourceCompatibility = '11'

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RacingcarApplication {
public class RacingCarApplication {

public static void main(String[] args) {
SpringApplication.run(RacingcarApplication.class, args);
SpringApplication.run(RacingCarApplication.class, args);
}

}
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

7 changes: 7 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- TODO: 기능 구현에 필요한 내용을 추가하거나 수정하세요.
CREATE TABLE PLAY_RESULT (
id INT NOT NULL AUTO_INCREMENT,
winners VARCHAR(50) NOT NULL,
created_at DATETIME NOT NULL default current_timestamp,
PRIMARY KEY (id)
);
120 changes: 120 additions & 0 deletions src/main/resources/static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
h1 {
margin: 20px 0;
font-size: 24px;
text-align: center;
}
/* 입력 영역 */
.input-area {
display: flex;
flex-direction: column;
align-items: center;
margin: 50px 0;
}

.input-area label {
font-weight: bold;
font-size: 16px;
margin-bottom: 10px;
}

.input-area input[type="text"] {
padding: 10px;
border: none;
border-bottom: 1px solid #ccc;
width: 100%;
box-sizing: border-box;
margin-bottom: 30px;
font-size: 16px;
background-color: transparent;
transition: border-bottom-color 0.2s;
}

.input-area input[type="text"]:focus {
border-bottom-color: #444;
outline: none;
}

/* 출력 영역 */
.output-area {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 50px;
margin-bottom: 50px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #fff;
font-size: 16px;
font-weight: bold;
color: #444;
}

/* 폼 */
form {
max-width: 600px;
margin: 0 auto;
}

form button[type="submit"] {
background-color: #444;
color: #fff;
padding: 10px 15px;
margin: auto;
display: block;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.2s;
}

form button[type="submit"]:hover {
background-color: #333;
}

table {
border-collapse: collapse;
margin: 0 auto;
background-color: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
max-width: 800px;
width: 100%;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}

/* GNB 스타일 */
.gnb {
display: flex;
justify-content: space-between;
align-items: center;
height: 50px;
background-color: #444;
color: #fff;
padding: 0 20px;
}

.gnb button {
background-color: #444;
color: #fff;
padding: 10px 15px;
border: none;
border-radius: 3px;
cursor: pointer;
}

.gnb button:hover {
background-color: #444;
}
84 changes: 84 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>자동차 경주 게임</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<div class="gnb">
<h1>Racing Car</h1>
<div>
<button onclick="handlePlayButtonClick()">게임하기</button>
<button onclick="handleListButtonClick()">이력조회</button>
</div>
</div>
<h1>자동차 경주 게임</h1>
<form onsubmit="submitForm(); return false;">
<div class="input-area">
<label for="names">자동차 이름:</label>
<input type="text" id="names" name="names">

<label for="count">시도할 횟수:</label>
<input type="text" id="count" name="count">
</div>

<button type="submit">Submit</button>

<div class="output-area">
우승자: <span id="resultWinner"></span>
<br>
결과:
<div id="resultPosition"></div>
</div>
</form>

<script>
function submitForm() {
const names = document.getElementById("names").value;
const count = document.getElementById("count").value;
const data = {
names: names,
count: count
};
fetch("/plays", {
method: "POST",
headers: {
"Content-Type": "application/json;charset=UTF-8"
},
body: JSON.stringify(data)
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error("Network response was not ok.");
}
})
.then(data => {
const resultPosition = document.createElement("div");
for (let index in data.racingCars) {
const span = document.createElement("span");
span.innerHTML = `Name: ${data.racingCars[index].name}, Position: ${data.racingCars[index].position}<br>`;
resultPosition.appendChild(span);
}
document.getElementById("resultWinner").innerHTML = data.winners
document.getElementById("resultPosition").innerHTML = '';
document.getElementById("resultPosition").appendChild(resultPosition);
})
.catch(error => {
console.error("Error:", error);
});
}

function handlePlayButtonClick() {
window.location.href = "/";
}

function handleListButtonClick() {
window.location.href = "/list.html";
}
</script>
</body>
</html>

72 changes: 72 additions & 0 deletions src/main/resources/static/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>자동차 경주 게임 이력 조회</title>
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<div class="gnb">
<h1>Racing Car</h1>
<div>
<button onclick="handlePlayButtonClick()">게임하기</button>
<button onclick="handleListButtonClick()">이력조회</button>
</div>
</div>
<h1>자동차 경주 게임 이력 조회</h1>
<table>
<thead>
<tr>
<th>이동 횟수</th>
<th>우승자</th>
</tr>
</thead>
<tbody id="gameHistory"></tbody>
</table>

<script>
const tbody = document.getElementById("gameHistory");

fetch('/plays')
.then(response => response.json())
.then(results => {
results.forEach(result => {
const row = createTableRow(result);
tbody.appendChild(row);
});
});

function createTableRow(result) {
const row = document.createElement("tr");
row.appendChild(createMovesTableCell(result.racingCars));
row.appendChild(createTableCell(result.winners));
return row;
}

function createTableCell(content) {
const cell = document.createElement("td");
cell.textContent = content;
return cell;
}

function createMovesTableCell(racingCars) {
const cell = document.createElement("td");
let movesText = "";
for (let key in racingCars) {
movesText += `${racingCars[key].name}: ${racingCars[key].position}<br>`;
}
;
cell.innerHTML = movesText;
return cell;
}

function handlePlayButtonClick() {
window.location.href = "/";
}

function handleListButtonClick() {
window.location.href = "/list.html";
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class RacingcarApplicationTests {
class RacingCarApplicationTests {

@Test
void contextLoads() {
Expand Down

0 comments on commit 07ad425

Please sign in to comment.