Skip to content
Snippets Groups Projects
Commit 84bdc282 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

src, gitignore and pom

parents
Branches master
No related tags found
No related merge requests found
target/
# Intellij
*.iml
.idea/
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fossgalaxy.games.server</groupId>
<artifactId>fireworks-server</artifactId>
<version>0.1-SNAPSHOT</version>
<parent>
<groupId>com.fossgalaxy.common</groupId>
<artifactId>parent-pom</artifactId>
<version>0.3</version>
</parent>
<dependencies>
<dependency>
<groupId>com.fossgalaxy.games</groupId>
<artifactId>fireworks</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.fossgalaxy.games.fireworks;
import com.fossgalaxy.games.fireworks.state.GameState;
import com.fossgalaxy.games.fireworks.state.actions.Action;
import com.fossgalaxy.games.fireworks.state.events.GameEvent;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by webpigeon on 10/04/17.
*/
public class GameRegistry {
private final Map<String, GameState> activeGames;
public GameRegistry() {
this.activeGames = new HashMap<>();
}
public void addServer(String name, GameState server) {
activeGames.put(name, server);
}
public List<GameEvent> advance(String gameID, int agentID, Action action) {
GameState state = activeGames.get(gameID);
if (state == null) {
return Collections.emptyList();
}
return action.apply(agentID, state);
}
}
package com.fossgalaxy.games.fireworks;
import com.fossgalaxy.games.fireworks.players.Player;
import com.fossgalaxy.games.fireworks.state.actions.Action;
import com.fossgalaxy.games.fireworks.state.events.GameEvent;
/**
* Created by webpigeon on 10/04/17.
*/
public class NetworkPlayer implements Player {
@Override
public Action getAction() {
return null;
}
@Override
public void sendMessage(GameEvent msg) {
}
@Override
public void setID(int id, int nPlayers) {
}
@Override
public String getName() {
return null;
}
}
package com.fossgalaxy.games.fireworks;
import com.fossgalaxy.games.fireworks.players.Player;
import com.fossgalaxy.games.fireworks.state.BasicState;
import com.fossgalaxy.games.fireworks.state.GameState;
import com.fossgalaxy.games.fireworks.state.events.GameEvent;
/**
* A network backed game for playing in real time.
*/
public class NetworkRunner {
private final GameState state;
private final Player[] players;
private int nextPlayer;
public NetworkRunner() {
this.players = new Player[5];
this.state = new BasicState(5);
this.nextPlayer = 0;
}
public void add(Player player) {
players[nextPlayer++] = player;
}
public void send(GameEvent event) {
for (int i=0; i<players.length; i++) {
if (event.isVisibleTo(i)) {
players[i].sendMessage(event);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment