Giter Site home page Giter Site logo

gameontext / sample-room-swift Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 7.0 93 KB

A sample room for the game written in Swift

License: Apache License 2.0

Swift 64.37% HTML 10.13% JavaScript 22.07% CSS 3.43%
swift adventure websocket-server microservice websocket-endpoint room docker

sample-room-swift's Introduction

Game On! Microservices and Swift

Build Status

Codacy Badge

Game On! is both a sample microservices application, and a throwback text adventure brought to you by the WASdev team at IBM. This application demonstrates how microservice architectures work from two points of view:

  1. As a Player: navigate through a network/maze of rooms, and interact with other players and the items or actions available in each room.
  2. As a Developer: extend the game by creating simple services that define rooms. Learn about microservice architectures and their supporting infrastructure as you build and scale your service.

You can learn more about Game On! at http://gameontext.org/.

Introduction

This walkthrough will guide you through creating and deploying a simple room (a microservice) to the running Game On! application. This microservice is written in Swift as a server-side Kitura application.

The microservice can be (a) deployed as a Cloud Foundry application or (b) built into a docker container.

Game On! communicates with this service (a room) over WebSockets using the Game On! WebSocket protocol. Consider this a stand-in for asynchronous messaging like MQTT, which requires a lot more setup than a simple WebSocket does.

Quick start for local development:

You can set up your development environment and use XCode 8 for editing, building, debugging, and testing your server application. To use XCode, you must use the command line tools for generating an XCode project.

  1. Download Xcode 8

  2. Create your own fork of this repository (what's a fork?)

  3. Create a local clone of your fork (Cloning a repository)

git clone https://github.com/<your-forked-repo>/sample-room-swift.git

  1. Make an XCode project

swift package generate-xcodeproj

  1. Install front-end dependencies including gulp and webpack

npm install

  1. Install Swift dependencies using gulp

gulp

  1. Run the server

.build/debug/GameOn

Then access http://localhost:8080/ in your browser. Visiting this page provides a small form you can use to test the WebSocket endpoint in your service directly.

Make your room public!

For Game On! to include your room, you need to tell it where the publicly reachable WebSocket endpoint is. This usually requires two steps:

Build a docker container

Creating a Docker image is straight-up: docker build . right from the root menu.

A docker-compose.yml file is also there, which can be used to specify overlay volumes to allow local development without restarting the container. See the Advanced Adventure for local development with Docker for a more detailed walkthrough.

Ok. So this thing is running... Now what?

We know, this walkthrough was simple. You have a nice shiny service that emulates async messaging behavior via a WebSocket. So?

The purpose of this text-based adventure is to help you grapple with microservices concepts and technologies while building something other than what you do for your day job (it can be easier to learn new things when not bogged down with old habits). This means that the simple service that should be humming along merrily with your name on it is the beginning of your adventures, rather than the end.

Here is a small roadmap to this basic service, so you can go about making it your own:

  • Sources/gameontext/swiftroom/RoomImplementation.swift This is class contains the core elements that make your microservice unique from others. Custom commands and items can be added here (via the org.gameontext.sample.RoomDescription member variable). The imaginatively named handleMessage method, in particular, is called when new messages arrive.

  • Sources/gameontext/Protocol/* This package contains a collection of classes that deal with the mechanics of the websocket connection that the game uses to allow players to interact with this service. RoomEndpoint is what it says: that is the WebSocket endpoint for the service.

  • Tests/* -- Yes! There are tests!

Things you might try:

  • Use ??? to manage all of the connected WebSockets together as one event stream.
  • Call out to another API (Watson API, Weather API) to perform actions in the room.
  • Integrate this room with IFTTT, or Slack, or ...
  • .. other Advanced Adventures!

Remember our https://gameontext.org/#/terms. Most importantly, there are kids around: make your parents proud.

Testing

Run swift test to run test cases.

sample-room-swift's People

Contributors

bardweller avatar nglevin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.