### Backend (Golang) .Zip
### Backend (Golang) .Zip
```go
package main
import (
"encoding/json"
"net/http"
"sync"
)
if !exists {
http.Error(w, "Player not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(state)
}
mu.Lock()
gameStates[state.PlayerID] = &state
mu.Unlock()
w.WriteHeader(http.StatusNoContent)
}
func main() {
http.HandleFunc("/gamestate", getGameState)
http.HandleFunc("/update", updateGameState)
http.ListenAndServe(":8080", nil)
}
```
```typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class GameService {
private apiUrl = 'http://localhost:8080';
```typescript
import { Component, OnInit } from '@angular/core';
import { GameService, GameState } from './game.service';
@Component({
selector: 'app-game',
templateUrl: './game.component.html',
styleUrls: ['./game.component.css']
})
export class GameComponent implements OnInit {
gameState: GameState;
ngOnInit(): void {
const playerId = 'player1'; // Exemplo de ID do jogador
this.gameService.getGameState(playerId).subscribe(state => {
this.gameState = state;
});
}
updateGame() {
// Lógica para atualizar o estado do jogo
this.gameService.updateGameState(this.gameState).subscribe();
}
}
```