Skip to content

Commit

Permalink
Merge pull request #28 from java-women/feature/stage201
Browse files Browse the repository at this point in the history
確認遅くなりすみません。
気になるところはありましたが、リファクタリングまたは、後日レビューで対応お願いします。
  • Loading branch information
cyoco committed Jun 8, 2016
2 parents 3014436 + 32328b3 commit d4d8223
Show file tree
Hide file tree
Showing 41 changed files with 465 additions and 0 deletions.
2 changes: 2 additions & 0 deletions JavajoTeachingForKids/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties

# Database
db/
2 changes: 2 additions & 0 deletions JavajoTeachingForKids/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dependencies {
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-websocket'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.hsqldb:hsqldb'
}

jar.baseName = 'javajo-teaching-for-kids'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
* セキュリティ設定を行うクラス.<br>
*
* Created by Eriko on 2016/02/10.
*/
@EnableWebSecurity
Expand All @@ -13,6 +15,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
// CSRF無効化(ハンズオンコンテンツでセキュリティはそこまで気にしたいため)
http.csrf().disable();

// HTTPヘッダの設定(iframeを使用可能にする)
http.headers()
.frameOptions()
.sameOrigin()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package javajo.controller;

import javajo.entity.MapEntity;
import javajo.service.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
* Created by Eriko on 2016/02/04.
*/
@Controller
public class GameController {

/** GameServiceをDI. */
@Autowired
private GameService mGameService;

/**
* Game Stage001.
* @return テンプレートHTML
Expand Down Expand Up @@ -46,6 +54,25 @@ public String stage101() {
return "stage101";
}

/**
* Game Stage201.
* @return テンプレートHTML
*/
@RequestMapping(value = "/stage201", method = RequestMethod.GET)
public String stage201() {
return "stage201";
}

/**
* Game Stage201(マップ保存).
* @param mapEntity MapEntity
*/
@ResponseBody
@RequestMapping(value = "/stage201/save", method = RequestMethod.POST)
public void stage201Save(final MapEntity mapEntity) {
this.mGameService.saveMap(mapEntity);
}

/**
* Chat.
* @return テンプレートHTML
Expand Down
82 changes: 82 additions & 0 deletions JavajoTeachingForKids/src/main/java/javajo/entity/MapEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package javajo.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* Mapテーブル用Entityクラス.<br>
* Created by Eriko on 2016/03/24.
*/
@Entity
@Table(name = "map")
public class MapEntity {

/** ID(自動採番). */
@Id
@GeneratedValue
@Column(name = "id")
private Long mId;

/** Mapデータ. */
@Column(name = "map_data", length = 2000)
private String mMapData;

/** 衝突データ */
@Column(name = "collision_data", length = 2000)
private String mCollisionData;

/**
* コンストラクタ.
*/
public MapEntity() {
}

/**
* Gets map data.
*
* @return the map data
*/
public String getMapData() {
return mMapData;
}

/**
* Sets map data.
*
* @param mapData the map data
*/
public void setMapData(final String mapData) {
this.mMapData = mapData;
}

/**
* Gets collision data.
*
* @return the collision data
*/
public String getCollisionData() {
return mCollisionData;
}

/**
* Sets collision data.
*
* @param collisionData the collision data
*/
public void setCollisionData(String collisionData) {
mCollisionData = collisionData;
}

@Override
public String toString() {
return "MapEntity{" +
"mId=" + mId +
", mMapData='" + mMapData + '\'' +
", mCollisionData='" + mCollisionData + '\'' +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package javajo.repository;

import javajo.entity.MapEntity;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* MapテーブルにアクセスするRepositoryインタフェース.<br>
* Created by Eriko on 2016/03/24.
*/
public interface MapRepository extends JpaRepository<MapEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package javajo.service;

import javajo.entity.MapEntity;
import javajo.repository.MapRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
* サービスクラス.<br>
* テンプレートHTMLを返す以外の処理(DB処理なと)を行う場合はServiceクラスで行う.
* Created by Eriko on 2016/03/24.
*/
@Component
public class GameService {

/** MapRepositoryをDI. */
@Autowired
private MapRepository mMapRepository;

/**
* Mapを保存する.
* @param mapEntity MapEntity
*/
@Transactional(readOnly = false)
public void saveMap(final MapEntity mapEntity) {

// TODO 衝突データを作成する

this.mMapRepository.save(mapEntity);

// TODO 確認用のため完成したら削除する
this.mMapRepository.findAll().forEach(System.out::println);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ server.port=18081
security.basic.path=/**
security.user.name=javajo
security.user.password=javajo

spring.datasource.url=jdbc:hsqldb:file:./db/testdb;shutdown=true
spring.jpa.hibernate.ddl-auto=update
hibernate.dialect=com.extensions.dialect.MyHsqlDialect
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions JavajoTeachingForKids/src/main/resources/static/css/stage201.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@charset "utf-8";

body {
margin: 0;
padding: 0;
}

#enchant-stage {
float: left;
}

#editor {
float: left !imoirtant;
width: 500px;
margin: 0px 10px;
}

#map-dropdown-btn {
width: 300px;
}

#map-selected {
float: left;
}

ul > li {
float: left;
width: 32%;
border: none;
}

ul > li:nth-child(3n+2) {
margin: 0 1%;
}
94 changes: 94 additions & 0 deletions JavajoTeachingForKids/src/main/resources/static/js/stage201.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
enchant();

/* 初期値 */
const WIDTH = 320;
const HEIGHT = 320;
const GRID = 16;
const SCALE = 1.5;
const FPS = 15;

// 初期マップ作成
var mapData = new Array();
var collisionData = new Array();
for (var i = 0; i < (HEIGHT / GRID); i++){
mapData[i] = new Array();
collisionData[i] = new Array();
for(var j = 0; j < (WIDTH / GRID); j++) {
mapData[i][j] = -1;
collisionData[i][j] = -1;
}
}

/* マス目の描画 */
function drawGrid() {
var surface = new Surface(WIDTH, HEIGHT);
surface.context.strokeStyle = "#808080";
surface.context.beginPath();
for(i = 1; i <= WIDTH / GRID; i++){
surface.context.moveTo(i * GRID, 0);
surface.context.lineTo(i * GRID, HEIGHT);
surface.context.stroke();
surface.context.moveTo(0, i * GRID);
surface.context.lineTo(WIDTH, i * GRID);
surface.context.stroke();
}
var grid = new Sprite(WIDTH,HEIGHT);
grid.image=surface;

return grid;
}

window.onload = function() {

core = new Core(WIDTH, HEIGHT);
core.scale = SCALE;
core.fps = FPS;
core.preload("chara0.png", "map0.png");
core.preload("start.png", "gameover.png", "clear.png");

core.onload = function() {
core.replaceScene(createGameScene());
};

core.start();
};

/**
* ゲームシーン
*/
function createGameScene() {
var scene = new Scene();

/* フレームリセット */
core.frame = 0;

var map = new Map(GRID, GRID);
map.image = core.assets["map0.png"];
map.loadData(mapData);
map.collisionData = collisionData;

// タッチイベント定義
scene.addEventListener("touchend", function(e) {
// 選んだマップ
id = document.getElementById("map-selected").children[0].getAttribute("data-id");
collision = document.getElementById("map-selected").children[0].getAttribute("data-collision");
if (id == null) {
alert("マップを選んでね");
} else {
mapData[Math.floor(e.y / GRID)][Math.floor(e.x / GRID)] = id;
collisionData[Math.floor(e.y / GRID)][Math.floor(e.x / GRID)] = collision;
core.replaceScene(createGameScene());
}
});

var stage = new Group();
stage.addChild(map);

// エディタで枠線の表示にチェックされていた場合のみ表示
if(document.getElementById("grid-checkbox").checked) {
stage.addChild(drawGrid());
}
scene.addChild(stage);

return scene;
}
Loading

0 comments on commit d4d8223

Please sign in to comment.