Beispiel #1
0
    def CheckMapInfo(self, x, y):
        from DbClass import Dbclass
        db = Dbclass()
        db.Connect()
        Used = db.GetMapInfo(x, y)

        return Used
    def SetBoatsAI(self):
        from DbClass import Dbclass
        db = Dbclass()

        db.ClearMapAI()
        for boat in self.boats:
            self.SetBoatOnMap(boat)
Beispiel #3
0
def login():
    error = None
    db = Dbclass()

    UserID = session.get('UserID', 'notset')

    if UserID == "notset":
        if request.method == 'POST':
            if request.form["bsubmit"] == "Login":
                username = request.form['username']
                Password = request.form['password']

                User = db.GetUserByName(username)

                print(User)

                if username == User[1] and Password == User[2]:
                    #return render_template('index.html', user=username)
                    session['UserID'] = User[0]

                    return redirect(url_for('index', userID=User[0]))
                else:
                    error = 'Invalid Credentials. Please try again.'
            elif request.form["bsubmit"] == "Register":
                return redirect(url_for('register'))
        return render_template('login.html', error=error)
    else:
        return redirect(
            url_for('index', userID=session.get('UserID', 'notset')))
	def StartGame(self):
		db = Dbclass()
		db.ClearMap()
		self.ClearScreen(self.LengthMap)

		self.HP = 0

		for i in self.boats:
			self.HP += self.boats[i]

		for boat in self.boats:
			self.ClearCoord()
			self.ClearScreen(self.LengthMap)

			coord = self.GetCoords()
			self.SetBoat(coord[0], coord[1], boat)

		try:
			while self.HP > 0:
				coord = self.GetCoords()
				self.shootCell(coord[0], coord[1])
		except KeyboardInterrupt:
			GPIO.cleanup()

		if self.HP == 0:
			print("alles is dood")
			return 1
Beispiel #5
0
def index():
    db = Dbclass()
    UserID = session.get('UserID', 'notset')

    if UserID == "notset":
        return render_template('index.html')
    else:
        User = db.GetUserByID(UserID)
        return render_template('index.html', user=User)
    def ShootBoatAI(self):
        from DbClass import Dbclass
        db = Dbclass()

        coord = [random.randrange(0, 8), random.randrange(0, 8)]
        used = db.GetMapInfo(coord[0], coord[1])

        if used == 0:
            db.Connect()
            db.SetHitOnMapAI(coord[0], coord[1])
	def shootCell(self, x, y):
		db = Dbclass()
		isSpotUsed = self.CheckMapInfo(x, y)

		if isSpotUsed == 0:
			print("spot  empty, you missed!")
			db.SetMissOnMap(x, y)
		elif isSpotUsed == 1:
			print("You hit a boat!")
			self.HP -= 1
			db.SetHitOnMap(x, y)
	def SetBoat(self, x, y, boatLength):
		db = Dbclass()

		for l in range(boatLength):
			IsSpotUsed = self.CheckMapInfo(x + l, y)
			if IsSpotUsed == 0:
				db.Connect()
				db.SetBoatOnMap(x + l, y)

				self.changeRowOn(x + l)
				self.changeCollumnOn(y)
			else:
				print("spot is used")
		self.ClearCoord()
Beispiel #9
0
def playGame():
    UserID = session.get('UserID', 'notset')

    if UserID == "notset":
        error = "not logged in!"
        return render_template('PlayGame.html', error=error)
    else:
        db = Dbclass()
        User = db.GetUserByID(UserID)
        if request.method == 'POST':
            if request.form["bsubmit"] == "Play":
                Game = BattleShipGame()

                score = Game.StartGame()

                if score == 1:
                    db = Dbclass()
                    User = db.GetUserByID(UserID)
                    db.Connect()
                    db.SetWinInHistoryOnPlayerID(User[0], 0)
                    return render_template('PlayGame.html',
                                           user=User,
                                           score="won")
                else:
                    return render_template('PlayGame.html',
                                           user=User,
                                           score="lost")
        else:
            return render_template('PlayGame.html', user=User)
Beispiel #10
0
def register():
    error = None
    db = Dbclass()

    if request.method == 'POST':
        if request.form["bsubmit"] == "Register":
            Username = request.form['username']
            Password = request.form['password']
            Password2 = request.form['passwordSecond']
            email = request.form['email']

            if Password == Password2:
                # Query om user toe te voegen oproepen.
                db.InsertUser(Username, Password, email)
                return redirect(url_for('login'))
            else:
                error = "Passwords don't match"

    return render_template('register.html', error=error)
    def SetBoatOnMap(self, boatLength):
        from DbClass import Dbclass
        db = Dbclass()
        coord = [random.randrange(0, 8), random.randrange(0, 8)]

        for l in range(boatLength):
            db.Connect()
            used = db.GetMapInfo(coord[0] + l, coord[1])

            if used == 0:
                db.Connect()
                db.SetBoatOnMapAI(coord[0] + l, coord[1])
Beispiel #12
0
def profile():
    error = None
    db = Dbclass()

    UserID = session.get('UserID', 'notset')

    if UserID == "notset":
        error = "Please login first to begin playing!"
        return render_template('profile.html', error=error)
    else:
        User = db.GetUserByID(UserID)
        db.Connect()
        Won = db.GetUserWonHistory(UserID)
        db.Connect()
        Lost = db.GetUserLostHistory(UserID)

        error = ""
        return render_template('profile.html',
                               error=error,
                               user=User,
                               won=Won,
                               lost=Lost)
	def CheckMapInfo(self, x, y):
		db = Dbclass()
		Used = db.GetMapInfo(x, y)

		return Used
def collection():
    db = Dbclass()
    games = db.getcollection()
    return render_template("collection.html", games=games)
Beispiel #15
0
from DbClass import Dbclass

db = Dbclass()

db.SetWinInHistoryOnPlayerID(1, 2)